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
// 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::Color;
use crate::Font;
use crate::Glyph;
use crate::GlyphItem;
use crate::GlyphString;
use crate::Layout;
use crate::LayoutLine;
use crate::Matrix;
use crate::RenderPart;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;

glib::wrapper! {
    /// [`Renderer`][crate::Renderer] is a base class for objects that are used to
    /// render Pango objects such as [`GlyphString`][crate::GlyphString] and
    /// [`Layout`][crate::Layout].
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// # Implements
    ///
    /// [`RendererExt`][trait@crate::prelude::RendererExt]
    #[doc(alias = "PangoRenderer")]
    pub struct Renderer(Object<ffi::PangoRenderer, ffi::PangoRendererClass>);

    match fn {
        type_ => || ffi::pango_renderer_get_type(),
    }
}

pub const NONE_RENDERER: Option<&Renderer> = None;

/// Trait containing all [`struct@Renderer`] methods.
///
/// # Implementors
///
/// [`Renderer`][struct@crate::Renderer]
pub trait RendererExt: 'static {
    /// Does initial setup before rendering operations on `self`.
    /// [`deactivate()`][Self::deactivate()] should be called when done drawing.
    /// Calls such as [`draw_layout()`][Self::draw_layout()] automatically
    /// activate the layout before drawing on it. Calls to
    /// [`activate()`][Self::activate()] and [`deactivate()`][Self::deactivate()] can
    /// be nested and the renderer will only be initialized and
    /// deinitialized once.
    #[doc(alias = "pango_renderer_activate")]
    fn activate(&self);

    /// Cleans up after rendering operations on `self`. See
    /// docs for [`activate()`][Self::activate()].
    #[doc(alias = "pango_renderer_deactivate")]
    fn deactivate(&self);

    /// Draw a squiggly line that approximately covers the given rectangle
    /// in the style of an underline used to indicate a spelling error.
    /// (The width of the underline is rounded to an integer number
    /// of up/down segments and the resulting rectangle is centered
    /// in the original rectangle)
    ///
    /// This should be called while `self` is already active. Use
    /// [`activate()`][Self::activate()] to activate a renderer.
    /// ## `x`
    /// X coordinate of underline, in Pango units in user coordinate system
    /// ## `y`
    /// Y coordinate of underline, in Pango units in user coordinate system
    /// ## `width`
    /// width of underline, in Pango units in user coordinate system
    /// ## `height`
    /// height of underline, in Pango units in user coordinate system
    #[doc(alias = "pango_renderer_draw_error_underline")]
    fn draw_error_underline(&self, x: i32, y: i32, width: i32, height: i32);

    /// Draws a single glyph with coordinates in device space.
    /// ## `font`
    /// a [`Font`][crate::Font]
    /// ## `glyph`
    /// the glyph index of a single glyph
    /// ## `x`
    /// X coordinate of left edge of baseline of glyph
    /// ## `y`
    /// Y coordinate of left edge of baseline of glyph
    #[doc(alias = "pango_renderer_draw_glyph")]
    fn draw_glyph<P: IsA<Font>>(&self, font: &P, glyph: Glyph, x: f64, y: f64);

    /// Draws the glyphs in `glyph_item` with the specified [`Renderer`][crate::Renderer],
    /// embedding the text associated with the glyphs in the output if the
    /// output format supports it (PDF for example).
    ///
    /// Note that `text` is the start of the text for layout, which is then
    /// indexed by `<literal>``glyph_item`->item->offset`</literal>`.
    ///
    /// If `text` is [`None`], this simply calls [`draw_glyphs()`][Self::draw_glyphs()].
    ///
    /// The default implementation of this method simply falls back to
    /// [`draw_glyphs()`][Self::draw_glyphs()].
    /// ## `text`
    /// the UTF-8 text that `glyph_item` refers to, or [`None`]
    /// ## `glyph_item`
    /// a [`GlyphItem`][crate::GlyphItem]
    /// ## `x`
    /// X position of left edge of baseline, in user space coordinates
    ///  in Pango units.
    /// ## `y`
    /// Y position of left edge of baseline, in user space coordinates
    ///  in Pango units.
    #[doc(alias = "pango_renderer_draw_glyph_item")]
    fn draw_glyph_item(&self, text: Option<&str>, glyph_item: &mut GlyphItem, x: i32, y: i32);

    /// Draws the glyphs in `glyphs` with the specified [`Renderer`][crate::Renderer].
    /// ## `font`
    /// a [`Font`][crate::Font]
    /// ## `glyphs`
    /// a [`GlyphString`][crate::GlyphString]
    /// ## `x`
    /// X position of left edge of baseline, in user space coordinates
    ///  in Pango units.
    /// ## `y`
    /// Y position of left edge of baseline, in user space coordinates
    ///  in Pango units.
    #[doc(alias = "pango_renderer_draw_glyphs")]
    fn draw_glyphs<P: IsA<Font>>(&self, font: &P, glyphs: &mut GlyphString, x: i32, y: i32);

    /// Draws `layout` with the specified [`Renderer`][crate::Renderer].
    /// ## `layout`
    /// a [`Layout`][crate::Layout]
    /// ## `x`
    /// X position of left edge of baseline, in user space coordinates
    ///  in Pango units.
    /// ## `y`
    /// Y position of left edge of baseline, in user space coordinates
    ///  in Pango units.
    #[doc(alias = "pango_renderer_draw_layout")]
    fn draw_layout(&self, layout: &Layout, x: i32, y: i32);

    /// Draws `line` with the specified [`Renderer`][crate::Renderer].
    /// ## `line`
    /// a [`LayoutLine`][crate::LayoutLine]
    /// ## `x`
    /// X position of left edge of baseline, in user space coordinates
    ///  in Pango units.
    /// ## `y`
    /// Y position of left edge of baseline, in user space coordinates
    ///  in Pango units.
    #[doc(alias = "pango_renderer_draw_layout_line")]
    fn draw_layout_line(&self, line: &LayoutLine, x: i32, y: i32);

    /// Draws an axis-aligned rectangle in user space coordinates with the
    /// specified [`Renderer`][crate::Renderer].
    ///
    /// This should be called while `self` is already active. Use
    /// [`activate()`][Self::activate()] to activate a renderer.
    /// ## `part`
    /// type of object this rectangle is part of
    /// ## `x`
    /// X position at which to draw rectangle, in user space coordinates in Pango units
    /// ## `y`
    /// Y position at which to draw rectangle, in user space coordinates in Pango units
    /// ## `width`
    /// width of rectangle in Pango units in user space coordinates
    /// ## `height`
    /// height of rectangle in Pango units in user space coordinates
    #[doc(alias = "pango_renderer_draw_rectangle")]
    fn draw_rectangle(&self, part: RenderPart, x: i32, y: i32, width: i32, height: i32);

    /// Draws a trapezoid with the parallel sides aligned with the X axis
    /// using the given [`Renderer`][crate::Renderer]; coordinates are in device space.
    /// ## `part`
    /// type of object this trapezoid is part of
    /// ## `y1_`
    /// Y coordinate of top of trapezoid
    /// ## `x11`
    /// X coordinate of left end of top of trapezoid
    /// ## `x21`
    /// X coordinate of right end of top of trapezoid
    /// ## `y2`
    /// Y coordinate of bottom of trapezoid
    /// ## `x12`
    /// X coordinate of left end of bottom of trapezoid
    /// ## `x22`
    /// X coordinate of right end of bottom of trapezoid
    #[doc(alias = "pango_renderer_draw_trapezoid")]
    fn draw_trapezoid(
        &self,
        part: RenderPart,
        y1_: f64,
        x11: f64,
        x21: f64,
        y2: f64,
        x12: f64,
        x22: f64,
    );

    /// Gets the current alpha for the specified part.
    /// ## `part`
    /// the part to get the alpha for
    ///
    /// # Returns
    ///
    /// the alpha for the specified part,
    ///  or 0 if it hasn't been set and should be
    ///  inherited from the environment.
    #[doc(alias = "pango_renderer_get_alpha")]
    #[doc(alias = "get_alpha")]
    fn alpha(&self, part: RenderPart) -> u16;

    /// Gets the current rendering color for the specified part.
    /// ## `part`
    /// the part to get the color for
    ///
    /// # Returns
    ///
    /// the color for the
    ///  specified part, or [`None`] if it hasn't been set and should be
    ///  inherited from the environment.
    #[doc(alias = "pango_renderer_get_color")]
    #[doc(alias = "get_color")]
    fn color(&self, part: RenderPart) -> Option<Color>;

    /// Gets the layout currently being rendered using `self`.
    /// Calling this function only makes sense from inside a subclass's
    /// methods, like in its draw_shape vfunc, for example.
    ///
    /// The returned layout should not be modified while still being
    /// rendered.
    ///
    /// # Returns
    ///
    /// the layout, or [`None`] if
    ///  no layout is being rendered using `self` at this time.
    #[doc(alias = "pango_renderer_get_layout")]
    #[doc(alias = "get_layout")]
    fn layout(&self) -> Option<Layout>;

    /// Gets the layout line currently being rendered using `self`.
    /// Calling this function only makes sense from inside a subclass's
    /// methods, like in its draw_shape vfunc, for example.
    ///
    /// The returned layout line should not be modified while still being
    /// rendered.
    ///
    /// # Returns
    ///
    /// the layout line, or [`None`]
    ///  if no layout line is being rendered using `self` at this time.
    #[doc(alias = "pango_renderer_get_layout_line")]
    #[doc(alias = "get_layout_line")]
    fn layout_line(&self) -> Option<LayoutLine>;

    /// Gets the transformation matrix that will be applied when
    /// rendering. See [`set_matrix()`][Self::set_matrix()].
    ///
    /// # Returns
    ///
    /// the matrix, or [`None`] if no matrix has
    ///  been set (which is the same as the identity matrix). The returned
    ///  matrix is owned by Pango and must not be modified or freed.
    #[doc(alias = "pango_renderer_get_matrix")]
    #[doc(alias = "get_matrix")]
    fn matrix(&self) -> Option<Matrix>;

    /// Informs Pango that the way that the rendering is done
    /// for `part` has changed in a way that would prevent multiple
    /// pieces being joined together into one drawing call. For
    /// instance, if a subclass of [`Renderer`][crate::Renderer] was to add a stipple
    /// option for drawing underlines, it needs to call
    ///
    /// `<informalexample>``<programlisting>`
    /// pango_renderer_part_changed (render, PANGO_RENDER_PART_UNDERLINE);
    /// `</programlisting>``</informalexample>`
    ///
    /// When the stipple changes or underlines with different stipples
    /// might be joined together. Pango automatically calls this for
    /// changes to colors. (See [`set_color()`][Self::set_color()])
    /// ## `part`
    /// the part for which rendering has changed.
    #[doc(alias = "pango_renderer_part_changed")]
    fn part_changed(&self, part: RenderPart);

    /// Sets the alpha for part of the rendering.
    /// Note that the alpha may only be used if a color is
    /// specified for `part` as well.
    /// ## `part`
    /// the part to set the alpha for
    /// ## `alpha`
    /// an alpha value between 1 and 65536, or 0 to unset the alpha
    #[doc(alias = "pango_renderer_set_alpha")]
    fn set_alpha(&self, part: RenderPart, alpha: u16);

    /// Sets the color for part of the rendering.
    /// Also see [`set_alpha()`][Self::set_alpha()].
    /// ## `part`
    /// the part to change the color of
    /// ## `color`
    /// the new color or [`None`] to unset the current color
    #[doc(alias = "pango_renderer_set_color")]
    fn set_color(&self, part: RenderPart, color: Option<&Color>);

    /// Sets the transformation matrix that will be applied when rendering.
    /// ## `matrix`
    /// a [`Matrix`][crate::Matrix], or [`None`] to unset any existing matrix.
    ///  (No matrix set is the same as setting the identity matrix.)
    #[doc(alias = "pango_renderer_set_matrix")]
    fn set_matrix(&self, matrix: Option<&Matrix>);
}

impl<O: IsA<Renderer>> RendererExt for O {
    fn activate(&self) {
        unsafe {
            ffi::pango_renderer_activate(self.as_ref().to_glib_none().0);
        }
    }

    fn deactivate(&self) {
        unsafe {
            ffi::pango_renderer_deactivate(self.as_ref().to_glib_none().0);
        }
    }

    fn draw_error_underline(&self, x: i32, y: i32, width: i32, height: i32) {
        unsafe {
            ffi::pango_renderer_draw_error_underline(
                self.as_ref().to_glib_none().0,
                x,
                y,
                width,
                height,
            );
        }
    }

    fn draw_glyph<P: IsA<Font>>(&self, font: &P, glyph: Glyph, x: f64, y: f64) {
        unsafe {
            ffi::pango_renderer_draw_glyph(
                self.as_ref().to_glib_none().0,
                font.as_ref().to_glib_none().0,
                glyph,
                x,
                y,
            );
        }
    }

    fn draw_glyph_item(&self, text: Option<&str>, glyph_item: &mut GlyphItem, x: i32, y: i32) {
        unsafe {
            ffi::pango_renderer_draw_glyph_item(
                self.as_ref().to_glib_none().0,
                text.to_glib_none().0,
                glyph_item.to_glib_none_mut().0,
                x,
                y,
            );
        }
    }

    fn draw_glyphs<P: IsA<Font>>(&self, font: &P, glyphs: &mut GlyphString, x: i32, y: i32) {
        unsafe {
            ffi::pango_renderer_draw_glyphs(
                self.as_ref().to_glib_none().0,
                font.as_ref().to_glib_none().0,
                glyphs.to_glib_none_mut().0,
                x,
                y,
            );
        }
    }

    fn draw_layout(&self, layout: &Layout, x: i32, y: i32) {
        unsafe {
            ffi::pango_renderer_draw_layout(
                self.as_ref().to_glib_none().0,
                layout.to_glib_none().0,
                x,
                y,
            );
        }
    }

    fn draw_layout_line(&self, line: &LayoutLine, x: i32, y: i32) {
        unsafe {
            ffi::pango_renderer_draw_layout_line(
                self.as_ref().to_glib_none().0,
                line.to_glib_none().0,
                x,
                y,
            );
        }
    }

    fn draw_rectangle(&self, part: RenderPart, x: i32, y: i32, width: i32, height: i32) {
        unsafe {
            ffi::pango_renderer_draw_rectangle(
                self.as_ref().to_glib_none().0,
                part.into_glib(),
                x,
                y,
                width,
                height,
            );
        }
    }

    fn draw_trapezoid(
        &self,
        part: RenderPart,
        y1_: f64,
        x11: f64,
        x21: f64,
        y2: f64,
        x12: f64,
        x22: f64,
    ) {
        unsafe {
            ffi::pango_renderer_draw_trapezoid(
                self.as_ref().to_glib_none().0,
                part.into_glib(),
                y1_,
                x11,
                x21,
                y2,
                x12,
                x22,
            );
        }
    }

    fn alpha(&self, part: RenderPart) -> u16 {
        unsafe { ffi::pango_renderer_get_alpha(self.as_ref().to_glib_none().0, part.into_glib()) }
    }

    fn color(&self, part: RenderPart) -> Option<Color> {
        unsafe {
            from_glib_none(ffi::pango_renderer_get_color(
                self.as_ref().to_glib_none().0,
                part.into_glib(),
            ))
        }
    }

    fn layout(&self) -> Option<Layout> {
        unsafe {
            from_glib_none(ffi::pango_renderer_get_layout(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn layout_line(&self) -> Option<LayoutLine> {
        unsafe {
            from_glib_none(ffi::pango_renderer_get_layout_line(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn matrix(&self) -> Option<Matrix> {
        unsafe {
            from_glib_none(ffi::pango_renderer_get_matrix(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn part_changed(&self, part: RenderPart) {
        unsafe {
            ffi::pango_renderer_part_changed(self.as_ref().to_glib_none().0, part.into_glib());
        }
    }

    fn set_alpha(&self, part: RenderPart, alpha: u16) {
        unsafe {
            ffi::pango_renderer_set_alpha(self.as_ref().to_glib_none().0, part.into_glib(), alpha);
        }
    }

    fn set_color(&self, part: RenderPart, color: Option<&Color>) {
        unsafe {
            ffi::pango_renderer_set_color(
                self.as_ref().to_glib_none().0,
                part.into_glib(),
                color.to_glib_none().0,
            );
        }
    }

    fn set_matrix(&self, matrix: Option<&Matrix>) {
        unsafe {
            ffi::pango_renderer_set_matrix(self.as_ref().to_glib_none().0, matrix.to_glib_none().0);
        }
    }
}

impl fmt::Display for Renderer {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("Renderer")
    }
}