1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::Analysis;
use crate::AttrIterator;
use crate::AttrList;
use crate::Context;
use crate::Direction;
use crate::GlyphString;
use crate::Item;
use crate::Rectangle;
use crate::Stretch;
use crate::Style;
use crate::Variant;
use crate::Weight;
use glib::translate::*;
use std::mem;
use std::ptr;

//#[cfg_attr(feature = "v1_44", deprecated = "Since 1.44")]
//#[doc(alias = "pango_break")]
//#[doc(alias = "break")]
//pub fn break_(text: &str, analysis: &mut Analysis, attrs: /*Ignored*/&[&LogAttr]) {
//    unsafe { TODO: call ffi:pango_break() }
//}

//#[doc(alias = "pango_default_break")]
//pub fn default_break(text: &str, analysis: Option<&mut Analysis>, attrs: /*Ignored*/&mut LogAttr, attrs_len: i32) {
//    unsafe { TODO: call ffi:pango_default_break() }
//}

/// Converts extents from Pango units to device units, dividing by the
/// `PANGO_SCALE` factor and performing rounding.
///
/// The `inclusive` rectangle is converted by flooring the x/y coordinates and extending
/// width/height, such that the final rectangle completely includes the original
/// rectangle.
///
/// The `nearest` rectangle is converted by rounding the coordinates
/// of the rectangle to the nearest device unit (pixel).
///
/// The rule to which argument to use is: if you want the resulting device-space
/// rectangle to completely contain the original rectangle, pass it in as `inclusive`.
/// If you want two touching-but-not-overlapping rectangles stay
/// touching-but-not-overlapping after rounding to device units, pass them in
/// as `nearest`.
/// ## `inclusive`
/// rectangle to round to pixels inclusively, or [`None`].
/// ## `nearest`
/// rectangle to round to nearest pixels, or [`None`].
#[doc(alias = "pango_extents_to_pixels")]
pub fn extents_to_pixels(inclusive: Option<&Rectangle>, nearest: Option<&Rectangle>) {
    unsafe {
        ffi::pango_extents_to_pixels(
            mut_override(inclusive.to_glib_none().0),
            mut_override(nearest.to_glib_none().0),
        );
    }
}

/// Searches a string the first character that has a strong
/// direction, according to the Unicode bidirectional algorithm.
/// ## `text`
/// the text to process. Must be valid UTF-8
/// ## `length`
/// length of `text` in bytes (may be -1 if `text` is nul-terminated)
///
/// # Returns
///
/// The direction corresponding to the first strong character.
/// If no such character is found, then [`Direction::Neutral`][crate::Direction::Neutral] is returned.
#[doc(alias = "pango_find_base_dir")]
pub fn find_base_dir(text: &str) -> Direction {
    let length = text.len() as i32;
    unsafe { from_glib(ffi::pango_find_base_dir(text.to_glib_none().0, length)) }
}

/// Locates a paragraph boundary in `text`. A boundary is caused by
/// delimiter characters, such as a newline, carriage return, carriage
/// return-newline pair, or Unicode paragraph separator character. The
/// index of the run of delimiters is returned in
/// `paragraph_delimiter_index`. The index of the start of the paragraph
/// (index after all delimiters) is stored in `next_paragraph_start`.
///
/// If no delimiters are found, both `paragraph_delimiter_index` and
/// `next_paragraph_start` are filled with the length of `text` (an index one
/// off the end).
/// ## `text`
/// UTF-8 text
/// ## `length`
/// length of `text` in bytes, or -1 if nul-terminated
///
/// # Returns
///
///
/// ## `paragraph_delimiter_index`
/// return location for index of
///  delimiter
///
/// ## `next_paragraph_start`
/// return location for start of next
///  paragraph
#[doc(alias = "pango_find_paragraph_boundary")]
pub fn find_paragraph_boundary(text: &str) -> (i32, i32) {
    let length = text.len() as i32;
    unsafe {
        let mut paragraph_delimiter_index = mem::MaybeUninit::uninit();
        let mut next_paragraph_start = mem::MaybeUninit::uninit();
        ffi::pango_find_paragraph_boundary(
            text.to_glib_none().0,
            length,
            paragraph_delimiter_index.as_mut_ptr(),
            next_paragraph_start.as_mut_ptr(),
        );
        let paragraph_delimiter_index = paragraph_delimiter_index.assume_init();
        let next_paragraph_start = next_paragraph_start.assume_init();
        (paragraph_delimiter_index, next_paragraph_start)
    }
}

//#[doc(alias = "pango_get_log_attrs")]
//#[doc(alias = "get_log_attrs")]
//pub fn log_attrs(text: &str, level: i32, language: &mut Language, log_attrs: /*Ignored*/&[&LogAttr]) {
//    unsafe { TODO: call ffi:pango_get_log_attrs() }
//}

/// Checks `ch` to see if it is a character that should not be
/// normally rendered on the screen. This includes all Unicode characters
/// with "ZERO WIDTH" in their name, as well as `<firstterm>`bidi`</firstterm>` formatting characters, and
/// a few other ones. This is totally different from `g_unichar_iszerowidth()`
/// and is at best misnamed.
/// ## `ch`
/// a Unicode character
///
/// # Returns
///
/// [`true`] if `ch` is a zero-width character, [`false`] otherwise
#[doc(alias = "pango_is_zero_width")]
pub fn is_zero_width(ch: char) -> bool {
    unsafe { from_glib(ffi::pango_is_zero_width(ch.into_glib())) }
}

/// Breaks a piece of text into segments with consistent
/// directional level and shaping engine. Each byte of `text` will
/// be contained in exactly one of the items in the returned list;
/// the generated list of items will be in logical order (the start
/// offsets of the items are ascending).
///
/// `cached_iter` should be an iterator over `attrs` currently positioned at a
/// range before or containing `start_index`; `cached_iter` will be advanced to
/// the range covering the position just after `start_index` + `length`.
/// (i.e. if itemizing in a loop, just keep passing in the same `cached_iter`).
/// ## `context`
/// a structure holding information that affects
///      the itemization process.
/// ## `text`
/// the text to itemize. Must be valid UTF-8
/// ## `start_index`
/// first byte in `text` to process
/// ## `length`
/// the number of bytes (not characters) to process
///  after `start_index`.
///  This must be >= 0.
/// ## `attrs`
/// the set of attributes that apply to `text`.
/// ## `cached_iter`
/// Cached attribute iterator, or [`None`]
///
/// # Returns
///
/// a `GList` of [`Item`][crate::Item]
///  structures. The items should be freed using `pango_item_free()`
///  probably in combination with `g_list_foreach()`, and the list itself
///  using `g_list_free()`.
#[doc(alias = "pango_itemize")]
pub fn itemize(
    context: &Context,
    text: &str,
    start_index: i32,
    length: i32,
    attrs: &AttrList,
    cached_iter: Option<&AttrIterator>,
) -> Vec<Item> {
    unsafe {
        FromGlibPtrContainer::from_glib_full(ffi::pango_itemize(
            context.to_glib_none().0,
            text.to_glib_none().0,
            start_index,
            length,
            attrs.to_glib_none().0,
            mut_override(cached_iter.to_glib_none().0),
        ))
    }
}

/// Like [`itemize()`][crate::itemize()], but the base direction to use when
/// computing bidirectional levels (see pango_context_set_base_dir ()),
/// is specified explicitly rather than gotten from the [`Context`][crate::Context].
/// ## `context`
/// a structure holding information that affects
///  the itemization process.
/// ## `base_dir`
/// base direction to use for bidirectional processing
/// ## `text`
/// the text to itemize.
/// ## `start_index`
/// first byte in `text` to process
/// ## `length`
/// the number of bytes (not characters) to process
///  after `start_index`. This must be >= 0.
/// ## `attrs`
/// the set of attributes that apply to `text`.
/// ## `cached_iter`
/// Cached attribute iterator, or [`None`]
///
/// # Returns
///
/// a `GList` of
///  [`Item`][crate::Item] structures. The items should be freed using
///  `pango_item_free()` probably in combination with
///  `g_list_foreach()`, and the list itself using `g_list_free()`.
#[doc(alias = "pango_itemize_with_base_dir")]
pub fn itemize_with_base_dir(
    context: &Context,
    base_dir: Direction,
    text: &str,
    start_index: i32,
    length: i32,
    attrs: &AttrList,
    cached_iter: Option<&AttrIterator>,
) -> Vec<Item> {
    unsafe {
        FromGlibPtrContainer::from_glib_full(ffi::pango_itemize_with_base_dir(
            context.to_glib_none().0,
            base_dir.into_glib(),
            text.to_glib_none().0,
            start_index,
            length,
            attrs.to_glib_none().0,
            mut_override(cached_iter.to_glib_none().0),
        ))
    }
}

//#[doc(alias = "pango_markup_parser_finish")]
//pub fn markup_parser_finish(context: /*Ignored*/&glib::MarkupParseContext) -> Result<(AttrList, glib::GString, char), glib::Error> {
//    unsafe { TODO: call ffi:pango_markup_parser_finish() }
//}

//#[doc(alias = "pango_markup_parser_new")]
//pub fn markup_parser_new(accel_marker: char) -> /*Ignored*/Option<glib::MarkupParseContext> {
//    unsafe { TODO: call ffi:pango_markup_parser_new() }
//}

/// Parses marked-up text (see
/// <link linkend="PangoMarkupFormat">markup format`</link>`) to create
/// a plain-text string and an attribute list.
///
/// If `accel_marker` is nonzero, the given character will mark the
/// character following it as an accelerator. For example, `accel_marker`
/// might be an ampersand or underscore. All characters marked
/// as an accelerator will receive a [`Underline::Low`][crate::Underline::Low] attribute,
/// and the first character so marked will be returned in `accel_char`.
/// Two `accel_marker` characters following each other produce a single
/// literal `accel_marker` character.
///
/// To parse a stream of pango markup incrementally, use `pango_markup_parser_new()`.
///
/// If any error happens, none of the output arguments are touched except
/// for `error`.
/// ## `markup_text`
/// markup to parse (see <link linkend="PangoMarkupFormat">markup format`</link>`)
/// ## `length`
/// length of `markup_text`, or -1 if nul-terminated
/// ## `accel_marker`
/// character that precedes an accelerator, or 0 for none
///
/// # Returns
///
/// [`false`] if `error` is set, otherwise [`true`]
///
/// ## `attr_list`
/// address of return location for a [`AttrList`][crate::AttrList], or [`None`]
///
/// ## `text`
/// address of return location for text with tags stripped, or [`None`]
///
/// ## `accel_char`
/// address of return location for accelerator char, or [`None`]
#[doc(alias = "pango_parse_markup")]
pub fn parse_markup(
    markup_text: &str,
    accel_marker: char,
) -> Result<(AttrList, glib::GString, char), glib::Error> {
    let length = markup_text.len() as i32;
    unsafe {
        let mut attr_list = ptr::null_mut();
        let mut text = ptr::null_mut();
        let mut accel_char = mem::MaybeUninit::uninit();
        let mut error = ptr::null_mut();
        let _ = ffi::pango_parse_markup(
            markup_text.to_glib_none().0,
            length,
            accel_marker.into_glib(),
            &mut attr_list,
            &mut text,
            accel_char.as_mut_ptr(),
            &mut error,
        );
        let accel_char = accel_char.assume_init();
        if error.is_null() {
            Ok((
                from_glib_full(attr_list),
                from_glib_full(text),
                std::convert::TryFrom::try_from(accel_char)
                    .expect("conversion from an invalid Unicode value attempted"),
            ))
        } else {
            Err(from_glib_full(error))
        }
    }
}

/// Parses a font stretch. The allowed values are
/// "ultra_condensed", "extra_condensed", "condensed",
/// "semi_condensed", "normal", "semi_expanded", "expanded",
/// "extra_expanded" and "ultra_expanded". Case variations are
/// ignored and the '_' characters may be omitted.
/// ## `str`
/// a string to parse.
/// ## `warn`
/// if [`true`], issue a `g_warning()` on bad input.
///
/// # Returns
///
/// [`true`] if `str` was successfully parsed.
///
/// ## `stretch`
/// a [`Stretch`][crate::Stretch] to store the
///  result in.
#[doc(alias = "pango_parse_stretch")]
pub fn parse_stretch(str: &str, warn: bool) -> Option<Stretch> {
    unsafe {
        let mut stretch = mem::MaybeUninit::uninit();
        let ret = from_glib(ffi::pango_parse_stretch(
            str.to_glib_none().0,
            stretch.as_mut_ptr(),
            warn.into_glib(),
        ));
        let stretch = stretch.assume_init();
        if ret {
            Some(from_glib(stretch))
        } else {
            None
        }
    }
}

/// Parses a font style. The allowed values are "normal",
/// "italic" and "oblique", case variations being
/// ignored.
/// ## `str`
/// a string to parse.
/// ## `warn`
/// if [`true`], issue a `g_warning()` on bad input.
///
/// # Returns
///
/// [`true`] if `str` was successfully parsed.
///
/// ## `style`
/// a [`Style`][crate::Style] to store the result
///  in.
#[doc(alias = "pango_parse_style")]
pub fn parse_style(str: &str, warn: bool) -> Option<Style> {
    unsafe {
        let mut style = mem::MaybeUninit::uninit();
        let ret = from_glib(ffi::pango_parse_style(
            str.to_glib_none().0,
            style.as_mut_ptr(),
            warn.into_glib(),
        ));
        let style = style.assume_init();
        if ret {
            Some(from_glib(style))
        } else {
            None
        }
    }
}

/// Parses a font variant. The allowed values are "normal"
/// and "smallcaps" or "small_caps", case variations being
/// ignored.
/// ## `str`
/// a string to parse.
/// ## `warn`
/// if [`true`], issue a `g_warning()` on bad input.
///
/// # Returns
///
/// [`true`] if `str` was successfully parsed.
///
/// ## `variant`
/// a [`Variant`][crate::Variant] to store the
///  result in.
#[doc(alias = "pango_parse_variant")]
pub fn parse_variant(str: &str, warn: bool) -> Option<Variant> {
    unsafe {
        let mut variant = mem::MaybeUninit::uninit();
        let ret = from_glib(ffi::pango_parse_variant(
            str.to_glib_none().0,
            variant.as_mut_ptr(),
            warn.into_glib(),
        ));
        let variant = variant.assume_init();
        if ret {
            Some(from_glib(variant))
        } else {
            None
        }
    }
}

/// Parses a font weight. The allowed values are "heavy",
/// "ultrabold", "bold", "normal", "light", "ultraleight"
/// and integers. Case variations are ignored.
/// ## `str`
/// a string to parse.
/// ## `warn`
/// if [`true`], issue a `g_warning()` on bad input.
///
/// # Returns
///
/// [`true`] if `str` was successfully parsed.
///
/// ## `weight`
/// a [`Weight`][crate::Weight] to store the result
///  in.
#[doc(alias = "pango_parse_weight")]
pub fn parse_weight(str: &str, warn: bool) -> Option<Weight> {
    unsafe {
        let mut weight = mem::MaybeUninit::uninit();
        let ret = from_glib(ffi::pango_parse_weight(
            str.to_glib_none().0,
            weight.as_mut_ptr(),
            warn.into_glib(),
        ));
        let weight = weight.assume_init();
        if ret {
            Some(from_glib(weight))
        } else {
            None
        }
    }
}

/// Quantizes the thickness and position of a line, typically an
/// underline or strikethrough, to whole device pixels, that is integer
/// multiples of `PANGO_SCALE`. The purpose of this function is to avoid
/// such lines looking blurry.
///
/// Care is taken to make sure `thickness` is at least one pixel when this
/// function returns, but returned `position` may become zero as a result
/// of rounding.
/// ## `thickness`
/// pointer to the thickness of a line, in Pango units
/// ## `position`
/// corresponding position
#[doc(alias = "pango_quantize_line_geometry")]
pub fn quantize_line_geometry(thickness: &mut i32, position: &mut i32) {
    unsafe {
        ffi::pango_quantize_line_geometry(thickness, position);
    }
}

/// Given a segment of text and the corresponding
/// [`Analysis`][crate::Analysis] structure returned from [`itemize()`][crate::itemize()],
/// convert the characters into glyphs. You may also pass
/// in only a substring of the item from [`itemize()`][crate::itemize()].
///
/// It is recommended that you use `pango_shape_full()` instead, since
/// that API allows for shaping interaction happening across text item
/// boundaries.
/// ## `text`
/// the text to process
/// ## `length`
/// the length (in bytes) of `text`
/// ## `analysis`
/// [`Analysis`][crate::Analysis] structure from [`itemize()`][crate::itemize()]
/// ## `glyphs`
/// glyph string in which to store results
#[doc(alias = "pango_shape")]
pub fn shape(text: &str, analysis: &Analysis, glyphs: &mut GlyphString) {
    let length = text.len() as i32;
    unsafe {
        ffi::pango_shape(
            text.to_glib_none().0,
            length,
            analysis.to_glib_none().0,
            glyphs.to_glib_none_mut().0,
        );
    }
}

//#[cfg(any(feature = "v1_44", feature = "dox"))]
//#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_44")))]
//#[doc(alias = "pango_tailor_break")]
//pub fn tailor_break(text: &str, analysis: &mut Analysis, offset: i32, log_attrs: /*Ignored*/&[&LogAttr]) {
//    unsafe { TODO: call ffi:pango_tailor_break() }
//}

/// Determines the inherent direction of a character; either
/// [`Direction::Ltr`][crate::Direction::Ltr], [`Direction::Rtl`][crate::Direction::Rtl], or
/// [`Direction::Neutral`][crate::Direction::Neutral].
///
/// This function is useful to categorize characters into left-to-right
/// letters, right-to-left letters, and everything else. If full
/// Unicode bidirectional type of a character is needed,
/// [`BidiType::for_unichar()`][crate::BidiType::for_unichar()] can be used instead.
/// ## `ch`
/// a Unicode character
///
/// # Returns
///
/// the direction of the character.
#[doc(alias = "pango_unichar_direction")]
pub fn unichar_direction(ch: char) -> Direction {
    unsafe { from_glib(ffi::pango_unichar_direction(ch.into_glib())) }
}

/// Converts a floating-point number to Pango units: multiplies
/// it by `PANGO_SCALE` and rounds to nearest integer.
/// ## `d`
/// double floating-point value
///
/// # Returns
///
/// the value in Pango units.
#[doc(alias = "pango_units_from_double")]
pub fn units_from_double(d: f64) -> i32 {
    unsafe { ffi::pango_units_from_double(d) }
}

/// Converts a number in Pango units to floating-point: divides
/// it by `PANGO_SCALE`.
/// ## `i`
/// value in Pango units
///
/// # Returns
///
/// the double value.
#[doc(alias = "pango_units_to_double")]
pub fn units_to_double(i: i32) -> f64 {
    unsafe { ffi::pango_units_to_double(i) }
}

/// This is similar to the macro `PANGO_VERSION` except that
/// it returns the encoded version of Pango available at run-time,
/// as opposed to the version available at compile-time.
///
/// A version number can be encoded into an integer using
/// PANGO_VERSION_ENCODE().
///
/// # Returns
///
/// The encoded version of Pango library
///  available at run time.
#[doc(alias = "pango_version")]
pub fn version() -> i32 {
    unsafe { ffi::pango_version() }
}

/// Checks that the Pango library in use is compatible with the
/// given version. Generally you would pass in the constants
/// `PANGO_VERSION_MAJOR`, `PANGO_VERSION_MINOR`, `PANGO_VERSION_MICRO`
/// as the three arguments to this function; that produces
/// a check that the library in use at run-time is compatible with
/// the version of Pango the application or module was compiled against.
///
/// Compatibility is defined by two things: first the version
/// of the running library is newer than the version
/// `required_major`.`required_micro`. Second
/// the running library must be binary compatible with the
/// version `required_major`.`required_micro`
/// (same major version.)
///
/// For compile-time version checking use PANGO_VERSION_CHECK().
/// ## `required_major`
/// the required major version.
/// ## `required_minor`
/// the required minor version.
/// ## `required_micro`
/// the required major version.
///
/// # Returns
///
/// [`None`] if the Pango library is compatible
///  with the given version, or a string describing the version
///  mismatch. The returned string is owned by Pango and should not
///  be modified or freed.
#[doc(alias = "pango_version_check")]
pub fn version_check(
    required_major: i32,
    required_minor: i32,
    required_micro: i32,
) -> Option<glib::GString> {
    unsafe {
        from_glib_none(ffi::pango_version_check(
            required_major,
            required_minor,
            required_micro,
        ))
    }
}

/// This is similar to the macro `PANGO_VERSION_STRING` except that
/// it returns the version of Pango available at run-time, as opposed to
/// the version available at compile-time.
///
/// # Returns
///
/// A string containing the version of Pango library
///  available at run time.
///  The returned string is owned by Pango and should not be modified
///  or freed.
#[doc(alias = "pango_version_string")]
pub fn version_string() -> Option<glib::GString> {
    unsafe { from_glib_none(ffi::pango_version_string()) }
}