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
// 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::Layout;
use crate::LayoutLine;
use crate::LayoutRun;
use crate::Rectangle;
use glib::translate::*;
use std::mem;

glib::wrapper! {
    /// A [`LayoutIter`][crate::LayoutIter] can be used to iterate over the visual
    /// extents of a [`Layout`][crate::Layout].
    ///
    /// To obtain a [`LayoutIter`][crate::LayoutIter], use [`Layout::iter()`][crate::Layout::iter()].
    ///
    /// The [`LayoutIter`][crate::LayoutIter] structure is opaque, and has no user-visible fields.
    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct LayoutIter(Boxed<ffi::PangoLayoutIter>);

    match fn {
        copy => |ptr| ffi::pango_layout_iter_copy(mut_override(ptr)),
        free => |ptr| ffi::pango_layout_iter_free(ptr),
        type_ => || ffi::pango_layout_iter_get_type(),
    }
}

impl LayoutIter {
    /// Determines whether @self is on the last line of the layout.
    ///
    /// # Returns
    ///
    /// [`true`] if @self is on the last line
    #[doc(alias = "pango_layout_iter_at_last_line")]
    pub fn at_last_line(&mut self) -> bool {
        unsafe {
            from_glib(ffi::pango_layout_iter_at_last_line(
                self.to_glib_none_mut().0,
            ))
        }
    }

    /// Gets the Y position of the current line's baseline, in layout
    /// coordinates.
    ///
    /// Layout coordinates have the origin at the top left of the entire layout.
    ///
    /// # Returns
    ///
    /// baseline of current line
    #[doc(alias = "pango_layout_iter_get_baseline")]
    #[doc(alias = "get_baseline")]
    pub fn baseline(&mut self) -> i32 {
        unsafe { ffi::pango_layout_iter_get_baseline(self.to_glib_none_mut().0) }
    }

    /// Gets the extents of the current character, in layout coordinates.
    ///
    /// Layout coordinates have the origin at the top left of the entire layout.
    ///
    /// Only logical extents can sensibly be obtained for characters;
    /// ink extents make sense only down to the level of clusters.
    ///
    /// # Returns
    ///
    ///
    /// ## `logical_rect`
    /// rectangle to fill with
    ///   logical extents
    #[doc(alias = "pango_layout_iter_get_char_extents")]
    #[doc(alias = "get_char_extents")]
    pub fn char_extents(&mut self) -> Rectangle {
        unsafe {
            let mut logical_rect = Rectangle::uninitialized();
            ffi::pango_layout_iter_get_char_extents(
                self.to_glib_none_mut().0,
                logical_rect.to_glib_none_mut().0,
            );
            logical_rect
        }
    }

    /// Gets the extents of the current cluster, in layout coordinates.
    ///
    /// Layout coordinates have the origin at the top left of the entire layout.
    ///
    /// # Returns
    ///
    ///
    /// ## `ink_rect`
    /// rectangle to fill with ink extents
    ///
    /// ## `logical_rect`
    /// rectangle to fill with logical extents
    #[doc(alias = "pango_layout_iter_get_cluster_extents")]
    #[doc(alias = "get_cluster_extents")]
    pub fn cluster_extents(&mut self) -> (Rectangle, Rectangle) {
        unsafe {
            let mut ink_rect = Rectangle::uninitialized();
            let mut logical_rect = Rectangle::uninitialized();
            ffi::pango_layout_iter_get_cluster_extents(
                self.to_glib_none_mut().0,
                ink_rect.to_glib_none_mut().0,
                logical_rect.to_glib_none_mut().0,
            );
            (ink_rect, logical_rect)
        }
    }

    /// Gets the current byte index.
    ///
    /// Note that iterating forward by char moves in visual order,
    /// not logical order, so indexes may not be sequential. Also,
    /// the index may be equal to the length of the text in the
    /// layout, if on the [`None`] run (see [`run()`][Self::run()]).
    ///
    /// # Returns
    ///
    /// current byte index
    #[doc(alias = "pango_layout_iter_get_index")]
    #[doc(alias = "get_index")]
    pub fn index(&mut self) -> i32 {
        unsafe { ffi::pango_layout_iter_get_index(self.to_glib_none_mut().0) }
    }

    /// Gets the layout associated with a [`LayoutIter`][crate::LayoutIter].
    ///
    /// # Returns
    ///
    /// the layout associated with @self
    #[doc(alias = "pango_layout_iter_get_layout")]
    #[doc(alias = "get_layout")]
    pub fn layout(&mut self) -> Option<Layout> {
        unsafe { from_glib_none(ffi::pango_layout_iter_get_layout(self.to_glib_none_mut().0)) }
    }

    /// Obtains the extents of the [`Layout`][crate::Layout] being iterated over.
    ///
    /// # Returns
    ///
    ///
    /// ## `ink_rect`
    /// rectangle to fill with ink extents
    ///
    /// ## `logical_rect`
    /// rectangle to fill with logical extents
    #[doc(alias = "pango_layout_iter_get_layout_extents")]
    #[doc(alias = "get_layout_extents")]
    pub fn layout_extents(&mut self) -> (Rectangle, Rectangle) {
        unsafe {
            let mut ink_rect = Rectangle::uninitialized();
            let mut logical_rect = Rectangle::uninitialized();
            ffi::pango_layout_iter_get_layout_extents(
                self.to_glib_none_mut().0,
                ink_rect.to_glib_none_mut().0,
                logical_rect.to_glib_none_mut().0,
            );
            (ink_rect, logical_rect)
        }
    }

    /// Gets the current line.
    ///
    /// Use the faster [`line_readonly()`][Self::line_readonly()] if
    /// you do not plan to modify the contents of the line (glyphs,
    /// glyph widths, etc.).
    ///
    /// # Returns
    ///
    /// the current line
    #[doc(alias = "pango_layout_iter_get_line")]
    #[doc(alias = "get_line")]
    pub fn line(&mut self) -> Option<LayoutLine> {
        unsafe { from_glib_none(ffi::pango_layout_iter_get_line(self.to_glib_none_mut().0)) }
    }

    /// Obtains the extents of the current line.
    ///
    /// Extents are in layout coordinates (origin is the top-left corner
    /// of the entire [`Layout`][crate::Layout]). Thus the extents returned by this
    /// function will be the same width/height but not at the same x/y
    /// as the extents returned from [`LayoutLine::extents()`][crate::LayoutLine::extents()].
    ///
    /// # Returns
    ///
    ///
    /// ## `ink_rect`
    /// rectangle to fill with ink extents
    ///
    /// ## `logical_rect`
    /// rectangle to fill with logical extents
    #[doc(alias = "pango_layout_iter_get_line_extents")]
    #[doc(alias = "get_line_extents")]
    pub fn line_extents(&mut self) -> (Rectangle, Rectangle) {
        unsafe {
            let mut ink_rect = Rectangle::uninitialized();
            let mut logical_rect = Rectangle::uninitialized();
            ffi::pango_layout_iter_get_line_extents(
                self.to_glib_none_mut().0,
                ink_rect.to_glib_none_mut().0,
                logical_rect.to_glib_none_mut().0,
            );
            (ink_rect, logical_rect)
        }
    }

    /// Gets the current line for read-only access.
    ///
    /// This is a faster alternative to [`line()`][Self::line()],
    /// but the user is not expected to modify the contents of the line
    /// (glyphs, glyph widths, etc.).
    ///
    /// # Returns
    ///
    /// the current line, that should not be
    ///   modified
    #[doc(alias = "pango_layout_iter_get_line_readonly")]
    #[doc(alias = "get_line_readonly")]
    pub fn line_readonly(&mut self) -> Option<LayoutLine> {
        unsafe {
            from_glib_none(ffi::pango_layout_iter_get_line_readonly(
                self.to_glib_none_mut().0,
            ))
        }
    }

    /// Divides the vertical space in the [`Layout`][crate::Layout] being iterated over
    /// between the lines in the layout, and returns the space belonging to
    /// the current line.
    ///
    /// A line's range includes the line's logical extents. plus half of the
    /// spacing above and below the line, if [`Layout::set_spacing()`][crate::Layout::set_spacing()]
    /// has been called to set layout spacing. The Y positions are in layout
    /// coordinates (origin at top left of the entire layout).
    ///
    /// Note: Since 1.44, Pango uses line heights for placing lines, and there
    /// may be gaps between the ranges returned by this function.
    ///
    /// # Returns
    ///
    ///
    /// ## `y0_`
    /// start of line
    ///
    /// ## `y1_`
    /// end of line
    #[doc(alias = "pango_layout_iter_get_line_yrange")]
    #[doc(alias = "get_line_yrange")]
    pub fn line_yrange(&mut self) -> (i32, i32) {
        unsafe {
            let mut y0_ = mem::MaybeUninit::uninit();
            let mut y1_ = mem::MaybeUninit::uninit();
            ffi::pango_layout_iter_get_line_yrange(
                self.to_glib_none_mut().0,
                y0_.as_mut_ptr(),
                y1_.as_mut_ptr(),
            );
            let y0_ = y0_.assume_init();
            let y1_ = y1_.assume_init();
            (y0_, y1_)
        }
    }

    /// Gets the current run.
    ///
    /// When iterating by run, at the end of each line, there's a position
    /// with a [`None`] run, so this function can return [`None`]. The [`None`] run
    /// at the end of each line ensures that all lines have at least one run,
    /// even lines consisting of only a newline.
    ///
    /// Use the faster [`run_readonly()`][Self::run_readonly()] if you do not
    /// plan to modify the contents of the run (glyphs, glyph widths, etc.).
    ///
    /// # Returns
    ///
    /// the current run
    #[doc(alias = "pango_layout_iter_get_run")]
    #[doc(alias = "get_run")]
    pub fn run(&mut self) -> Option<LayoutRun> {
        unsafe { from_glib_none(ffi::pango_layout_iter_get_run(self.to_glib_none_mut().0)) }
    }

    /// Gets the Y position of the current run's baseline, in layout
    /// coordinates.
    ///
    /// Layout coordinates have the origin at the top left of the entire layout.
    ///
    /// The run baseline can be different from the line baseline, for
    /// example due to superscript or subscript positioning.
    #[cfg(any(feature = "v1_50", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_50")))]
    #[doc(alias = "pango_layout_iter_get_run_baseline")]
    #[doc(alias = "get_run_baseline")]
    pub fn run_baseline(&mut self) -> i32 {
        unsafe { ffi::pango_layout_iter_get_run_baseline(self.to_glib_none_mut().0) }
    }

    /// Gets the extents of the current run in layout coordinates.
    ///
    /// Layout coordinates have the origin at the top left of the entire layout.
    ///
    /// # Returns
    ///
    ///
    /// ## `ink_rect`
    /// rectangle to fill with ink extents
    ///
    /// ## `logical_rect`
    /// rectangle to fill with logical extents
    #[doc(alias = "pango_layout_iter_get_run_extents")]
    #[doc(alias = "get_run_extents")]
    pub fn run_extents(&mut self) -> (Rectangle, Rectangle) {
        unsafe {
            let mut ink_rect = Rectangle::uninitialized();
            let mut logical_rect = Rectangle::uninitialized();
            ffi::pango_layout_iter_get_run_extents(
                self.to_glib_none_mut().0,
                ink_rect.to_glib_none_mut().0,
                logical_rect.to_glib_none_mut().0,
            );
            (ink_rect, logical_rect)
        }
    }

    /// Gets the current run for read-only access.
    ///
    /// When iterating by run, at the end of each line, there's a position
    /// with a [`None`] run, so this function can return [`None`]. The [`None`] run
    /// at the end of each line ensures that all lines have at least one run,
    /// even lines consisting of only a newline.
    ///
    /// This is a faster alternative to [`run()`][Self::run()],
    /// but the user is not expected to modify the contents of the run (glyphs,
    /// glyph widths, etc.).
    ///
    /// # Returns
    ///
    /// the current run, that
    ///   should not be modified
    #[doc(alias = "pango_layout_iter_get_run_readonly")]
    #[doc(alias = "get_run_readonly")]
    pub fn run_readonly(&mut self) -> Option<LayoutRun> {
        unsafe {
            from_glib_none(ffi::pango_layout_iter_get_run_readonly(
                self.to_glib_none_mut().0,
            ))
        }
    }

    /// Moves @self forward to the next character in visual order.
    ///
    /// If @self was already at the end of the layout, returns [`false`].
    ///
    /// # Returns
    ///
    /// whether motion was possible
    #[doc(alias = "pango_layout_iter_next_char")]
    pub fn next_char(&mut self) -> bool {
        unsafe { from_glib(ffi::pango_layout_iter_next_char(self.to_glib_none_mut().0)) }
    }

    /// Moves @self forward to the next cluster in visual order.
    ///
    /// If @self was already at the end of the layout, returns [`false`].
    ///
    /// # Returns
    ///
    /// whether motion was possible
    #[doc(alias = "pango_layout_iter_next_cluster")]
    pub fn next_cluster(&mut self) -> bool {
        unsafe {
            from_glib(ffi::pango_layout_iter_next_cluster(
                self.to_glib_none_mut().0,
            ))
        }
    }

    /// Moves @self forward to the start of the next line.
    ///
    /// If @self is already on the last line, returns [`false`].
    ///
    /// # Returns
    ///
    /// whether motion was possible
    #[doc(alias = "pango_layout_iter_next_line")]
    pub fn next_line(&mut self) -> bool {
        unsafe { from_glib(ffi::pango_layout_iter_next_line(self.to_glib_none_mut().0)) }
    }

    /// Moves @self forward to the next run in visual order.
    ///
    /// If @self was already at the end of the layout, returns [`false`].
    ///
    /// # Returns
    ///
    /// whether motion was possible
    #[doc(alias = "pango_layout_iter_next_run")]
    pub fn next_run(&mut self) -> bool {
        unsafe { from_glib(ffi::pango_layout_iter_next_run(self.to_glib_none_mut().0)) }
    }
}