Skip to main content

pango/auto/
functions.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5#[cfg(feature = "v1_60")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v1_60")))]
7use crate::{AttrIterator, Context, Item};
8use crate::{AttrList, Direction, Stretch, Style, Variant, Weight, ffi};
9use glib::translate::*;
10
11//#[cfg_attr(feature = "v1_44", deprecated = "Since 1.44")]
12//#[allow(deprecated)]
13//#[doc(alias = "pango_break")]
14//#[doc(alias = "break")]
15//pub fn break_(text: &str, analysis: &mut Analysis, attrs: /*Ignored*/Vec<LogAttr>) {
16//    unsafe { TODO: call ffi:pango_break() }
17//}
18
19//#[doc(alias = "pango_default_break")]
20//pub fn default_break(text: &str, analysis: Option<&mut Analysis>, attrs: /*Ignored*/Vec<LogAttr>) {
21//    unsafe { TODO: call ffi:pango_default_break() }
22//}
23
24/// Searches a string the first character that has a strong
25/// direction, according to the Unicode bidirectional algorithm.
26/// ## `text`
27/// the text to process. Must be valid UTF-8
28/// ## `length`
29/// length of @text in bytes (may be -1 if @text is nul-terminated)
30///
31/// # Returns
32///
33/// The direction corresponding to the first strong character.
34///   If no such character is found, then [`Direction::Neutral`][crate::Direction::Neutral] is returned.
35#[doc(alias = "pango_find_base_dir")]
36pub fn find_base_dir(text: &str) -> Direction {
37    let length = text.len() as _;
38    unsafe { from_glib(ffi::pango_find_base_dir(text.to_glib_none().0, length)) }
39}
40
41/// Locates a paragraph boundary in @text.
42///
43/// A boundary is caused by delimiter characters, such as
44/// a newline, carriage return, carriage return-newline pair,
45/// or Unicode paragraph separator character.
46///
47/// The index of the run of delimiters is returned in
48/// @paragraph_delimiter_index. The index of the start of the
49/// next paragraph (index after all delimiters) is stored n
50/// @next_paragraph_start.
51///
52/// If no delimiters are found, both @paragraph_delimiter_index
53/// and @next_paragraph_start are filled with the length of @text
54/// (an index one off the end).
55/// ## `text`
56/// UTF-8 text
57/// ## `length`
58/// length of @text in bytes, or -1 if nul-terminated
59///
60/// # Returns
61///
62///
63/// ## `paragraph_delimiter_index`
64/// return location
65///  for index of delimiter
66///
67/// ## `next_paragraph_start`
68/// return location for
69///  start of next paragraph
70#[doc(alias = "pango_find_paragraph_boundary")]
71pub fn find_paragraph_boundary(text: &str) -> (i32, i32) {
72    let length = text.len() as _;
73    unsafe {
74        let mut paragraph_delimiter_index = std::mem::MaybeUninit::uninit();
75        let mut next_paragraph_start = std::mem::MaybeUninit::uninit();
76        ffi::pango_find_paragraph_boundary(
77            text.to_glib_none().0,
78            length,
79            paragraph_delimiter_index.as_mut_ptr(),
80            next_paragraph_start.as_mut_ptr(),
81        );
82        (
83            paragraph_delimiter_index.assume_init(),
84            next_paragraph_start.assume_init(),
85        )
86    }
87}
88
89//#[doc(alias = "pango_get_log_attrs")]
90//#[doc(alias = "get_log_attrs")]
91//pub fn log_attrs(text: &str, level: i32, language: &mut Language, attrs: /*Ignored*/Vec<LogAttr>) {
92//    unsafe { TODO: call ffi:pango_get_log_attrs() }
93//}
94
95/// Checks if a character that should not be normally rendered.
96///
97/// This includes all Unicode characters with "ZERO WIDTH" in their name,
98/// as well as *bidi* formatting characters, and a few other ones.
99///
100/// This is totally different from `unichar_iszerowidth()` and is at best misnamed.
101/// ## `ch`
102/// a Unicode character
103///
104/// # Returns
105///
106/// [`true`] if @ch is a zero-width character, [`false`] otherwise
107#[doc(alias = "pango_is_zero_width")]
108pub fn is_zero_width(ch: char) -> bool {
109    unsafe { from_glib(ffi::pango_is_zero_width(ch.into_glib())) }
110}
111
112/// Itemizes a range using embedding levels computed for the complete paragraph.
113///
114/// This is useful when itemizing bounded ranges of a paragraph without changing
115/// the directional analysis at range boundaries. The embedding levels must
116/// contain one entry for every Unicode character in @text. @start_index and
117/// @length must identify UTF-8 character boundaries.
118/// ## `context`
119/// a structure holding information that affects itemization
120/// ## `base_dir`
121/// base direction of the paragraph
122/// ## `text`
123/// valid UTF-8 paragraph text
124/// ## `start_index`
125/// first byte in @text to process
126/// ## `length`
127/// number of bytes to process
128/// ## `attrs`
129/// attributes that apply to @text
130/// ## `cached_iter`
131/// cached attribute iterator
132/// ## `embedding_levels`
133/// one embedding level
134///   for each character in @text
135///
136/// # Returns
137///
138/// newly allocated items in logical order
139#[cfg(feature = "v1_60")]
140#[cfg_attr(docsrs, doc(cfg(feature = "v1_60")))]
141#[doc(alias = "pango_itemize_with_base_dir_and_embedding_levels")]
142pub fn itemize_with_base_dir_and_embedding_levels(
143    context: &Context,
144    base_dir: Direction,
145    text: &str,
146    start_index: i32,
147    length: i32,
148    attrs: Option<&AttrList>,
149    cached_iter: Option<&AttrIterator>,
150    embedding_levels: &[u8],
151) -> Vec<Item> {
152    let n_embedding_levels = embedding_levels.len() as _;
153    unsafe {
154        FromGlibPtrContainer::from_glib_full(ffi::pango_itemize_with_base_dir_and_embedding_levels(
155            context.to_glib_none().0,
156            base_dir.into_glib(),
157            text.to_glib_none().0,
158            start_index,
159            length,
160            attrs.to_glib_none().0,
161            mut_override(cached_iter.to_glib_none().0),
162            embedding_levels.to_glib_none().0,
163            n_embedding_levels,
164        ))
165    }
166}
167
168/// Finishes parsing markup.
169///
170/// After feeding a Pango markup parser some data with [`glib::MarkupParseContext::parse()`][crate::glib::MarkupParseContext::parse()],
171/// use this function to get the list of attributes and text out of the
172/// markup. This function will not free @context, use `GLib::MarkupParseContext::free()`
173/// to do so.
174/// ## `context`
175/// A valid parse context that was returned from [`markup_parser_new()`][crate::markup_parser_new()]
176///
177/// # Returns
178///
179/// [`false`] if @error is set, otherwise [`true`]
180///
181/// ## `attr_list`
182/// address of return location for a [`AttrList`][crate::AttrList]
183///
184/// ## `text`
185/// address of return location for text with tags stripped
186///
187/// ## `accel_char`
188/// address of return location for accelerator char
189#[doc(alias = "pango_markup_parser_finish")]
190pub fn markup_parser_finish(
191    context: &glib::MarkupParseContext,
192) -> Result<(AttrList, glib::GString, char), glib::Error> {
193    unsafe {
194        let mut attr_list = std::ptr::null_mut();
195        let mut text = std::ptr::null_mut();
196        let mut accel_char = std::mem::MaybeUninit::uninit();
197        let mut error = std::ptr::null_mut();
198        let is_ok = ffi::pango_markup_parser_finish(
199            context.to_glib_none().0,
200            &mut attr_list,
201            &mut text,
202            accel_char.as_mut_ptr(),
203            &mut error,
204        );
205        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
206        if error.is_null() {
207            Ok((
208                from_glib_full(attr_list),
209                from_glib_full(text),
210                std::convert::TryFrom::try_from(accel_char.assume_init())
211                    .expect("conversion from an invalid Unicode value attempted"),
212            ))
213        } else {
214            Err(from_glib_full(error))
215        }
216    }
217}
218
219/// Incrementally parses marked-up text to create a plain-text string
220/// and an attribute list.
221///
222/// See the [Pango Markup](pango_markup.html) docs for details about the
223/// supported markup.
224///
225/// If @accel_marker is nonzero, the given character will mark the
226/// character following it as an accelerator. For example, @accel_marker
227/// might be an ampersand or underscore. All characters marked
228/// as an accelerator will receive a [`Underline::Low`][crate::Underline::Low] attribute,
229/// and the first character so marked will be returned in @accel_char,
230/// when calling [`markup_parser_finish()`][crate::markup_parser_finish()]. Two @accel_marker characters
231/// following each other produce a single literal @accel_marker character.
232///
233/// To feed markup to the parser, use [`glib::MarkupParseContext::parse()`][crate::glib::MarkupParseContext::parse()]
234/// on the returned [`glib::MarkupParseContext`][crate::glib::MarkupParseContext]. When done with feeding markup
235/// to the parser, use [`markup_parser_finish()`][crate::markup_parser_finish()] to get the data out
236/// of it, and then use `GLib::MarkupParseContext::free()` to free it.
237///
238/// This function is designed for applications that read Pango markup
239/// from streams. To simply parse a string containing Pango markup,
240/// the [`parse_markup()`][crate::parse_markup()] API is recommended instead.
241/// ## `accel_marker`
242/// character that precedes an accelerator, or 0 for none
243///
244/// # Returns
245///
246/// a `GMarkupParseContext` that should be
247/// destroyed with `GLib::MarkupParseContext::free()`.
248#[doc(alias = "pango_markup_parser_new")]
249pub fn markup_parser_new(accel_marker: char) -> glib::MarkupParseContext {
250    unsafe { from_glib_none(ffi::pango_markup_parser_new(accel_marker.into_glib())) }
251}
252
253/// Parses marked-up text to create a plain-text string and an attribute list.
254///
255/// See the [Pango Markup](pango_markup.html) docs for details about the
256/// supported markup.
257///
258/// If @accel_marker is nonzero, the given character will mark the
259/// character following it as an accelerator. For example, @accel_marker
260/// might be an ampersand or underscore. All characters marked
261/// as an accelerator will receive a [`Underline::Low`][crate::Underline::Low] attribute,
262/// and the first character so marked will be returned in @accel_char.
263/// Two @accel_marker characters following each other produce a single
264/// literal @accel_marker character.
265///
266/// To parse a stream of pango markup incrementally, use [`markup_parser_new()`][crate::markup_parser_new()].
267///
268/// If any error happens, none of the output arguments are touched except
269/// for @error.
270/// ## `markup_text`
271/// markup to parse (see the [Pango Markup](pango_markup.html) docs)
272/// ## `length`
273/// length of @markup_text, or -1 if nul-terminated
274/// ## `accel_marker`
275/// character that precedes an accelerator, or 0 for none
276///
277/// # Returns
278///
279/// [`false`] if @error is set, otherwise [`true`]
280///
281/// ## `attr_list`
282/// address of return location for a [`AttrList`][crate::AttrList]
283///
284/// ## `text`
285/// address of return location for text with tags stripped
286///
287/// ## `accel_char`
288/// address of return location for accelerator char
289#[doc(alias = "pango_parse_markup")]
290pub fn parse_markup(
291    markup_text: &str,
292    accel_marker: char,
293) -> Result<(AttrList, glib::GString, char), glib::Error> {
294    let length = markup_text.len() as _;
295    unsafe {
296        let mut attr_list = std::ptr::null_mut();
297        let mut text = std::ptr::null_mut();
298        let mut accel_char = std::mem::MaybeUninit::uninit();
299        let mut error = std::ptr::null_mut();
300        let is_ok = ffi::pango_parse_markup(
301            markup_text.to_glib_none().0,
302            length,
303            accel_marker.into_glib(),
304            &mut attr_list,
305            &mut text,
306            accel_char.as_mut_ptr(),
307            &mut error,
308        );
309        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
310        if error.is_null() {
311            Ok((
312                from_glib_full(attr_list),
313                from_glib_full(text),
314                std::convert::TryFrom::try_from(accel_char.assume_init())
315                    .expect("conversion from an invalid Unicode value attempted"),
316            ))
317        } else {
318            Err(from_glib_full(error))
319        }
320    }
321}
322
323/// Parses a font stretch.
324///
325/// The allowed values are
326/// "ultra_condensed", "extra_condensed", "condensed",
327/// "semi_condensed", "normal", "semi_expanded", "expanded",
328/// "extra_expanded" and "ultra_expanded". Case variations are
329/// ignored and the '_' characters may be omitted.
330/// ## `str`
331/// a string to parse.
332/// ## `warn`
333/// if [`true`], issue a g_warning() on bad input.
334///
335/// # Returns
336///
337/// [`true`] if @str was successfully parsed.
338///
339/// ## `stretch`
340/// a [`Stretch`][crate::Stretch] to store the result in.
341#[doc(alias = "pango_parse_stretch")]
342pub fn parse_stretch(str: &str, warn: bool) -> Option<Stretch> {
343    unsafe {
344        let mut stretch = std::mem::MaybeUninit::uninit();
345        let ret = from_glib(ffi::pango_parse_stretch(
346            str.to_glib_none().0,
347            stretch.as_mut_ptr(),
348            warn.into_glib(),
349        ));
350        if ret {
351            Some(from_glib(stretch.assume_init()))
352        } else {
353            None
354        }
355    }
356}
357
358/// Parses a font style.
359///
360/// The allowed values are "normal", "italic" and "oblique", case
361/// variations being
362/// ignored.
363/// ## `str`
364/// a string to parse.
365/// ## `warn`
366/// if [`true`], issue a g_warning() on bad input.
367///
368/// # Returns
369///
370/// [`true`] if @str was successfully parsed.
371///
372/// ## `style`
373/// a [`Style`][crate::Style] to store the result in.
374#[doc(alias = "pango_parse_style")]
375pub fn parse_style(str: &str, warn: bool) -> Option<Style> {
376    unsafe {
377        let mut style = std::mem::MaybeUninit::uninit();
378        let ret = from_glib(ffi::pango_parse_style(
379            str.to_glib_none().0,
380            style.as_mut_ptr(),
381            warn.into_glib(),
382        ));
383        if ret {
384            Some(from_glib(style.assume_init()))
385        } else {
386            None
387        }
388    }
389}
390
391/// Parses a font variant.
392///
393/// The allowed values are "normal", "small-caps", "all-small-caps",
394/// "petite-caps", "all-petite-caps", "unicase" and "title-caps",
395/// case variations being ignored.
396/// ## `str`
397/// a string to parse.
398/// ## `warn`
399/// if [`true`], issue a g_warning() on bad input.
400///
401/// # Returns
402///
403/// [`true`] if @str was successfully parsed.
404///
405/// ## `variant`
406/// a [`Variant`][struct@crate::Variant] to store the result in.
407#[doc(alias = "pango_parse_variant")]
408pub fn parse_variant(str: &str, warn: bool) -> Option<Variant> {
409    unsafe {
410        let mut variant = std::mem::MaybeUninit::uninit();
411        let ret = from_glib(ffi::pango_parse_variant(
412            str.to_glib_none().0,
413            variant.as_mut_ptr(),
414            warn.into_glib(),
415        ));
416        if ret {
417            Some(from_glib(variant.assume_init()))
418        } else {
419            None
420        }
421    }
422}
423
424/// Parses a font weight.
425///
426/// The allowed values are "heavy",
427/// "ultrabold", "bold", "normal", "light", "ultraleight"
428/// and integers. Case variations are ignored.
429/// ## `str`
430/// a string to parse.
431/// ## `warn`
432/// if [`true`], issue a g_warning() on bad input.
433///
434/// # Returns
435///
436/// [`true`] if @str was successfully parsed.
437///
438/// ## `weight`
439/// a [`Weight`][crate::Weight] to store the result in.
440#[doc(alias = "pango_parse_weight")]
441pub fn parse_weight(str: &str, warn: bool) -> Option<Weight> {
442    unsafe {
443        let mut weight = std::mem::MaybeUninit::uninit();
444        let ret = from_glib(ffi::pango_parse_weight(
445            str.to_glib_none().0,
446            weight.as_mut_ptr(),
447            warn.into_glib(),
448        ));
449        if ret {
450            Some(from_glib(weight.assume_init()))
451        } else {
452            None
453        }
454    }
455}
456
457/// Quantizes the thickness and position of a line to whole device pixels.
458///
459/// This is typically used for underline or strikethrough. The purpose of
460/// this function is to avoid such lines looking blurry.
461///
462/// Care is taken to make sure @thickness is at least one pixel when this
463/// function returns, but returned @position may become zero as a result
464/// of rounding.
465///
466/// # Returns
467///
468///
469/// ## `thickness`
470/// pointer to the thickness of a line, in Pango units
471///
472/// ## `position`
473/// corresponding position
474#[doc(alias = "pango_quantize_line_geometry")]
475pub fn quantize_line_geometry(thickness: &mut i32, position: &mut i32) {
476    unsafe {
477        ffi::pango_quantize_line_geometry(thickness, position);
478    }
479}
480
481//#[cfg(feature = "v1_44")]
482//#[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
483//#[doc(alias = "pango_tailor_break")]
484//pub fn tailor_break(text: &str, analysis: &mut Analysis, offset: i32, attrs: /*Ignored*/Vec<LogAttr>) {
485//    unsafe { TODO: call ffi:pango_tailor_break() }
486//}
487
488/// Determines the inherent direction of a character.
489///
490/// The inherent direction is either `PANGO_DIRECTION_LTR`, `PANGO_DIRECTION_RTL`,
491/// or `PANGO_DIRECTION_NEUTRAL`.
492///
493/// This function is useful to categorize characters into left-to-right
494/// letters, right-to-left letters, and everything else. If full Unicode
495/// bidirectional type of a character is needed, [`BidiType::for_unichar()`][crate::BidiType::for_unichar()]
496/// can be used instead.
497/// ## `ch`
498/// a Unicode character
499///
500/// # Returns
501///
502/// the direction of the character.
503#[doc(alias = "pango_unichar_direction")]
504pub fn unichar_direction(ch: char) -> Direction {
505    unsafe { from_glib(ffi::pango_unichar_direction(ch.into_glib())) }
506}
507
508/// Converts a floating-point number to Pango units.
509///
510/// The conversion is done by multiplying @d by `PANGO_SCALE` and
511/// rounding the result to nearest integer.
512/// ## `d`
513/// double floating-point value
514///
515/// # Returns
516///
517/// the value in Pango units.
518#[doc(alias = "pango_units_from_double")]
519pub fn units_from_double(d: f64) -> i32 {
520    unsafe { ffi::pango_units_from_double(d) }
521}
522
523/// Converts a number in Pango units to floating-point.
524///
525/// The conversion is done by dividing @i by `PANGO_SCALE`.
526/// ## `i`
527/// value in Pango units
528///
529/// # Returns
530///
531/// the double value.
532#[doc(alias = "pango_units_to_double")]
533pub fn units_to_double(i: i32) -> f64 {
534    unsafe { ffi::pango_units_to_double(i) }
535}
536
537/// Returns the encoded version of Pango available at run-time.
538///
539/// This is similar to the macro `PANGO_VERSION` except that the macro
540/// returns the encoded version available at compile-time. A version
541/// number can be encoded into an integer using PANGO_VERSION_ENCODE().
542///
543/// # Returns
544///
545/// The encoded version of Pango library available at run time.
546#[doc(alias = "pango_version")]
547pub fn version() -> i32 {
548    unsafe { ffi::pango_version() }
549}
550
551/// Checks that the Pango library in use is compatible with the
552/// given version.
553///
554/// Generally you would pass in the constants `PANGO_VERSION_MAJOR`,
555/// `PANGO_VERSION_MINOR`, `PANGO_VERSION_MICRO` as the three arguments
556/// to this function; that produces a check that the library in use at
557/// run-time is compatible with the version of Pango the application or
558/// module was compiled against.
559///
560/// Compatibility is defined by two things: first the version
561/// of the running library is newer than the version
562/// @required_major.required_minor.@required_micro. Second
563/// the running library must be binary compatible with the
564/// version @required_major.required_minor.@required_micro
565/// (same major version.)
566///
567/// For compile-time version checking use PANGO_VERSION_CHECK().
568/// ## `required_major`
569/// the required major version
570/// ## `required_minor`
571/// the required minor version
572/// ## `required_micro`
573/// the required major version
574///
575/// # Returns
576///
577/// [`None`] if the Pango library is compatible
578///   with the given version, or a string describing the version
579///   mismatch.  The returned string is owned by Pango and should not
580///   be modified or freed.
581#[doc(alias = "pango_version_check")]
582pub fn version_check(
583    required_major: i32,
584    required_minor: i32,
585    required_micro: i32,
586) -> Option<glib::GString> {
587    unsafe {
588        from_glib_none(ffi::pango_version_check(
589            required_major,
590            required_minor,
591            required_micro,
592        ))
593    }
594}
595
596/// Returns the version of Pango available at run-time.
597///
598/// This is similar to the macro `PANGO_VERSION_STRING` except that the
599/// macro returns the version available at compile-time.
600///
601/// # Returns
602///
603/// A string containing the version of Pango library available
604///   at run time. The returned string is owned by Pango and should not
605///   be modified or freed.
606#[doc(alias = "pango_version_string")]
607pub fn version_string() -> glib::GString {
608    unsafe { from_glib_none(ffi::pango_version_string()) }
609}