Skip to main content

pango/auto/
renderer.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_58")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v1_58")))]
7use crate::RenderComponent;
8use crate::{
9    Color, Font, Glyph, GlyphItem, GlyphString, Layout, LayoutLine, Matrix, RenderPart, ffi,
10};
11use glib::{prelude::*, translate::*};
12
13glib::wrapper! {
14    /// [`Renderer`][crate::Renderer] is a base class for objects that can render text
15    /// provided as [`GlyphString`][crate::GlyphString] or [`Layout`][crate::Layout].
16    ///
17    /// By subclassing [`Renderer`][crate::Renderer] and overriding operations such as
18    /// @draw_glyphs and @draw_rectangle, renderers for particular font
19    /// backends and destinations can be created.
20    ///
21    /// This is an Abstract Base Class, you cannot instantiate it.
22    ///
23    /// # Implements
24    ///
25    /// [`RendererExt`][trait@crate::prelude::RendererExt]
26    #[doc(alias = "PangoRenderer")]
27    pub struct Renderer(Object<ffi::PangoRenderer, ffi::PangoRendererClass>);
28
29    match fn {
30        type_ => || ffi::pango_renderer_get_type(),
31    }
32}
33
34impl Renderer {
35    pub const NONE: Option<&'static Renderer> = None;
36}
37
38/// Trait containing all [`struct@Renderer`] methods.
39///
40/// # Implementors
41///
42/// [`Renderer`][struct@crate::Renderer]
43pub trait RendererExt: IsA<Renderer> + 'static {
44    /// Does initial setup before rendering operations on @self.
45    ///
46    /// [`deactivate()`][Self::deactivate()] should be called when done drawing.
47    /// Calls such as [`draw_layout()`][Self::draw_layout()] automatically
48    /// activate the layout before drawing on it.
49    ///
50    /// Calls to [`activate()`][Self::activate()] and
51    /// [`deactivate()`][Self::deactivate()] can be nested and the
52    /// renderer will only be initialized and deinitialized once.
53    #[doc(alias = "pango_renderer_activate")]
54    fn activate(&self) {
55        unsafe {
56            ffi::pango_renderer_activate(self.as_ref().to_glib_none().0);
57        }
58    }
59
60    /// Cleans up after rendering operations on @self.
61    ///
62    /// See docs for [`activate()`][Self::activate()].
63    #[doc(alias = "pango_renderer_deactivate")]
64    fn deactivate(&self) {
65        unsafe {
66            ffi::pango_renderer_deactivate(self.as_ref().to_glib_none().0);
67        }
68    }
69
70    /// Draw a squiggly line that approximately covers the given rectangle
71    /// in the style of an underline used to indicate a spelling error.
72    ///
73    /// The width of the underline is rounded to an integer number
74    /// of up/down segments and the resulting rectangle is centered
75    /// in the original rectangle.
76    ///
77    /// This should be called while @self is already active.
78    /// Use [`activate()`][Self::activate()] to activate a renderer.
79    /// ## `x`
80    /// X coordinate of underline, in Pango units in user coordinate system
81    /// ## `y`
82    /// Y coordinate of underline, in Pango units in user coordinate system
83    /// ## `width`
84    /// width of underline, in Pango units in user coordinate system
85    /// ## `height`
86    /// height of underline, in Pango units in user coordinate system
87    #[doc(alias = "pango_renderer_draw_error_underline")]
88    fn draw_error_underline(&self, x: i32, y: i32, width: i32, height: i32) {
89        unsafe {
90            ffi::pango_renderer_draw_error_underline(
91                self.as_ref().to_glib_none().0,
92                x,
93                y,
94                width,
95                height,
96            );
97        }
98    }
99
100    /// Draws a single glyph with coordinates in device space.
101    /// ## `font`
102    /// a [`Font`][crate::Font]
103    /// ## `glyph`
104    /// the glyph index of a single glyph
105    /// ## `x`
106    /// X coordinate of left edge of baseline of glyph
107    /// ## `y`
108    /// Y coordinate of left edge of baseline of glyph
109    #[doc(alias = "pango_renderer_draw_glyph")]
110    fn draw_glyph(&self, font: &impl IsA<Font>, glyph: Glyph, x: f64, y: f64) {
111        unsafe {
112            ffi::pango_renderer_draw_glyph(
113                self.as_ref().to_glib_none().0,
114                font.as_ref().to_glib_none().0,
115                glyph,
116                x,
117                y,
118            );
119        }
120    }
121
122    /// Draws the glyphs in @glyph_item with the specified [`Renderer`][crate::Renderer],
123    /// embedding the text associated with the glyphs in the output if the
124    /// output format supports it.
125    ///
126    /// This is useful for rendering text in PDF.
127    ///
128    /// Note that this method does not handle attributes in @glyph_item.
129    /// If you want colors, shapes and lines handled automatically according
130    /// to those attributes, you need to use pango_renderer_draw_layout_line()
131    /// or pango_renderer_draw_layout().
132    ///
133    /// Note that @text is the start of the text for layout, which is then
134    /// indexed by `glyph_item->item->offset`.
135    ///
136    /// If @text is [`None`], this simply calls [`draw_glyphs()`][Self::draw_glyphs()].
137    ///
138    /// The default implementation of this method simply falls back to
139    /// [`draw_glyphs()`][Self::draw_glyphs()].
140    /// ## `text`
141    /// the UTF-8 text that @glyph_item refers to
142    /// ## `glyph_item`
143    /// a [`GlyphItem`][crate::GlyphItem]
144    /// ## `x`
145    /// X position of left edge of baseline, in user space coordinates
146    ///   in Pango units
147    /// ## `y`
148    /// Y position of left edge of baseline, in user space coordinates
149    ///   in Pango units
150    #[doc(alias = "pango_renderer_draw_glyph_item")]
151    fn draw_glyph_item(&self, text: Option<&str>, glyph_item: &mut GlyphItem, x: i32, y: i32) {
152        unsafe {
153            ffi::pango_renderer_draw_glyph_item(
154                self.as_ref().to_glib_none().0,
155                text.to_glib_none().0,
156                glyph_item.to_glib_none_mut().0,
157                x,
158                y,
159            );
160        }
161    }
162
163    /// Draws the glyphs in @glyphs with the specified [`Renderer`][crate::Renderer].
164    /// ## `font`
165    /// a [`Font`][crate::Font]
166    /// ## `glyphs`
167    /// a [`GlyphString`][crate::GlyphString]
168    /// ## `x`
169    /// X position of left edge of baseline, in user space coordinates
170    ///   in Pango units.
171    /// ## `y`
172    /// Y position of left edge of baseline, in user space coordinates
173    ///   in Pango units.
174    #[doc(alias = "pango_renderer_draw_glyphs")]
175    fn draw_glyphs(&self, font: &impl IsA<Font>, glyphs: &mut GlyphString, x: i32, y: i32) {
176        unsafe {
177            ffi::pango_renderer_draw_glyphs(
178                self.as_ref().to_glib_none().0,
179                font.as_ref().to_glib_none().0,
180                glyphs.to_glib_none_mut().0,
181                x,
182                y,
183            );
184        }
185    }
186
187    /// Draws @layout with the specified [`Renderer`][crate::Renderer].
188    ///
189    /// This is equivalent to drawing the lines of the layout, at their
190    /// respective positions relative to @x, @y.
191    /// ## `layout`
192    /// a [`Layout`][crate::Layout]
193    /// ## `x`
194    /// X position of left edge of baseline, in user space coordinates
195    ///   in Pango units.
196    /// ## `y`
197    /// Y position of left edge of baseline, in user space coordinates
198    ///   in Pango units.
199    #[doc(alias = "pango_renderer_draw_layout")]
200    fn draw_layout(&self, layout: &Layout, x: i32, y: i32) {
201        unsafe {
202            ffi::pango_renderer_draw_layout(
203                self.as_ref().to_glib_none().0,
204                layout.to_glib_none().0,
205                x,
206                y,
207            );
208        }
209    }
210
211    /// Draws @line with the specified [`Renderer`][crate::Renderer].
212    ///
213    /// This draws the glyph items that make up the line, as well as
214    /// shapes, backgrounds and lines that are specified by the attributes
215    /// of those items.
216    /// ## `line`
217    /// a [`LayoutLine`][crate::LayoutLine]
218    /// ## `x`
219    /// X position of left edge of baseline, in user space coordinates
220    ///   in Pango units.
221    /// ## `y`
222    /// Y position of left edge of baseline, in user space coordinates
223    ///   in Pango units.
224    #[doc(alias = "pango_renderer_draw_layout_line")]
225    fn draw_layout_line(&self, line: &LayoutLine, x: i32, y: i32) {
226        unsafe {
227            ffi::pango_renderer_draw_layout_line(
228                self.as_ref().to_glib_none().0,
229                line.to_glib_none().0,
230                x,
231                y,
232            );
233        }
234    }
235
236    /// Draws an axis-aligned rectangle in user space coordinates with the
237    /// specified [`Renderer`][crate::Renderer].
238    ///
239    /// This should be called while @self is already active.
240    /// Use [`activate()`][Self::activate()] to activate a renderer.
241    /// ## `part`
242    /// type of object this rectangle is part of
243    /// ## `x`
244    /// X position at which to draw rectangle, in user space coordinates
245    ///   in Pango units
246    /// ## `y`
247    /// Y position at which to draw rectangle, in user space coordinates
248    ///   in Pango units
249    /// ## `width`
250    /// width of rectangle in Pango units
251    /// ## `height`
252    /// height of rectangle in Pango units
253    #[doc(alias = "pango_renderer_draw_rectangle")]
254    fn draw_rectangle(&self, part: RenderPart, x: i32, y: i32, width: i32, height: i32) {
255        unsafe {
256            ffi::pango_renderer_draw_rectangle(
257                self.as_ref().to_glib_none().0,
258                part.into_glib(),
259                x,
260                y,
261                width,
262                height,
263            );
264        }
265    }
266
267    /// Draws a trapezoid with the parallel sides aligned with the X axis
268    /// using the given [`Renderer`][crate::Renderer]; coordinates are in device space.
269    /// ## `part`
270    /// type of object this trapezoid is part of
271    /// ## `y1_`
272    /// Y coordinate of top of trapezoid
273    /// ## `x11`
274    /// X coordinate of left end of top of trapezoid
275    /// ## `x21`
276    /// X coordinate of right end of top of trapezoid
277    /// ## `y2`
278    /// Y coordinate of bottom of trapezoid
279    /// ## `x12`
280    /// X coordinate of left end of bottom of trapezoid
281    /// ## `x22`
282    /// X coordinate of right end of bottom of trapezoid
283    #[doc(alias = "pango_renderer_draw_trapezoid")]
284    fn draw_trapezoid(
285        &self,
286        part: RenderPart,
287        y1_: f64,
288        x11: f64,
289        x21: f64,
290        y2: f64,
291        x12: f64,
292        x22: f64,
293    ) {
294        unsafe {
295            ffi::pango_renderer_draw_trapezoid(
296                self.as_ref().to_glib_none().0,
297                part.into_glib(),
298                y1_,
299                x11,
300                x21,
301                y2,
302                x12,
303                x22,
304            );
305        }
306    }
307
308    /// Gets the current alpha for the specified part.
309    /// ## `part`
310    /// the part to get the alpha for
311    ///
312    /// # Returns
313    ///
314    /// the alpha for the specified part,
315    ///   or 0 if it hasn't been set and should be
316    ///   inherited from the environment.
317    #[doc(alias = "pango_renderer_get_alpha")]
318    #[doc(alias = "get_alpha")]
319    fn alpha(&self, part: RenderPart) -> u16 {
320        unsafe { ffi::pango_renderer_get_alpha(self.as_ref().to_glib_none().0, part.into_glib()) }
321    }
322
323    /// Gets the current rendering color for the specified part.
324    /// ## `part`
325    /// the part to get the color for
326    ///
327    /// # Returns
328    ///
329    /// the color for the
330    ///   specified part, or [`None`] if it hasn't been set and should be
331    ///   inherited from the environment.
332    #[doc(alias = "pango_renderer_get_color")]
333    #[doc(alias = "get_color")]
334    fn color(&self, part: RenderPart) -> Option<Color> {
335        unsafe {
336            from_glib_none(ffi::pango_renderer_get_color(
337                self.as_ref().to_glib_none().0,
338                part.into_glib(),
339            ))
340        }
341    }
342
343    /// Gets the components that are included in the output of the renderer.
344    ///
345    /// # Returns
346    ///
347    /// the components
348    #[cfg(feature = "v1_58")]
349    #[cfg_attr(docsrs, doc(cfg(feature = "v1_58")))]
350    #[doc(alias = "pango_renderer_get_components")]
351    #[doc(alias = "get_components")]
352    fn components(&self) -> RenderComponent {
353        unsafe {
354            from_glib(ffi::pango_renderer_get_components(
355                self.as_ref().to_glib_none().0,
356            ))
357        }
358    }
359
360    /// Gets the layout currently being rendered using @self.
361    ///
362    /// Calling this function only makes sense from inside a subclass's
363    /// methods, like in its draw_shape vfunc, for example.
364    ///
365    /// The returned layout should not be modified while still being
366    /// rendered.
367    ///
368    /// # Returns
369    ///
370    /// the layout, or [`None`] if
371    ///   no layout is being rendered using @self at this time.
372    #[doc(alias = "pango_renderer_get_layout")]
373    #[doc(alias = "get_layout")]
374    fn layout(&self) -> Option<Layout> {
375        unsafe {
376            from_glib_none(ffi::pango_renderer_get_layout(
377                self.as_ref().to_glib_none().0,
378            ))
379        }
380    }
381
382    /// Gets the layout line currently being rendered using @self.
383    ///
384    /// Calling this function only makes sense from inside a subclass's
385    /// methods, like in its draw_shape vfunc, for example.
386    ///
387    /// The returned layout line should not be modified while still being
388    /// rendered.
389    ///
390    /// # Returns
391    ///
392    /// the layout line, or [`None`]
393    ///   if no layout line is being rendered using @self at this time.
394    #[doc(alias = "pango_renderer_get_layout_line")]
395    #[doc(alias = "get_layout_line")]
396    fn layout_line(&self) -> Option<LayoutLine> {
397        unsafe {
398            from_glib_none(ffi::pango_renderer_get_layout_line(
399                self.as_ref().to_glib_none().0,
400            ))
401        }
402    }
403
404    /// Gets the transformation matrix that will be applied when
405    /// rendering.
406    ///
407    /// See [`set_matrix()`][Self::set_matrix()].
408    ///
409    /// # Returns
410    ///
411    /// the matrix, or [`None`] if no matrix has
412    ///   been set (which is the same as the identity matrix). The returned
413    ///   matrix is owned by Pango and must not be modified or freed.
414    #[doc(alias = "pango_renderer_get_matrix")]
415    #[doc(alias = "get_matrix")]
416    fn matrix(&self) -> Option<Matrix> {
417        unsafe {
418            from_glib_none(ffi::pango_renderer_get_matrix(
419                self.as_ref().to_glib_none().0,
420            ))
421        }
422    }
423
424    /// Informs Pango that the way that the rendering is done
425    /// for @part has changed.
426    ///
427    /// This should be called if the rendering changes in a way that would
428    /// prevent multiple pieces being joined together into one drawing call.
429    /// For instance, if a subclass of [`Renderer`][crate::Renderer] was to add a stipple
430    /// option for drawing underlines, it needs to call
431    ///
432    /// ```text
433    /// pango_renderer_part_changed (render, PANGO_RENDER_PART_UNDERLINE);
434    /// ```
435    ///
436    /// When the stipple changes or underlines with different stipples
437    /// might be joined together. Pango automatically calls this for
438    /// changes to colors. (See [`set_color()`][Self::set_color()])
439    /// ## `part`
440    /// the part for which rendering has changed.
441    #[doc(alias = "pango_renderer_part_changed")]
442    fn part_changed(&self, part: RenderPart) {
443        unsafe {
444            ffi::pango_renderer_part_changed(self.as_ref().to_glib_none().0, part.into_glib());
445        }
446    }
447
448    /// Sets the alpha for part of the rendering.
449    ///
450    /// Note that the alpha may only be used if a color is
451    /// specified for @part as well.
452    /// ## `part`
453    /// the part to set the alpha for
454    /// ## `alpha`
455    /// an alpha value between 1 and 65536, or 0 to unset the alpha
456    #[doc(alias = "pango_renderer_set_alpha")]
457    fn set_alpha(&self, part: RenderPart, alpha: u16) {
458        unsafe {
459            ffi::pango_renderer_set_alpha(self.as_ref().to_glib_none().0, part.into_glib(), alpha);
460        }
461    }
462
463    /// Sets the color for part of the rendering.
464    ///
465    /// Also see [`set_alpha()`][Self::set_alpha()].
466    /// ## `part`
467    /// the part to change the color of
468    /// ## `color`
469    /// the new color or [`None`] to unset the current color
470    #[doc(alias = "pango_renderer_set_color")]
471    fn set_color(&self, part: RenderPart, color: Option<&Color>) {
472        unsafe {
473            ffi::pango_renderer_set_color(
474                self.as_ref().to_glib_none().0,
475                part.into_glib(),
476                color.to_glib_none().0,
477            );
478        }
479    }
480
481    /// Sets the components to include in the output of the renderer.
482    /// ## `components`
483    /// the components to include
484    #[cfg(feature = "v1_58")]
485    #[cfg_attr(docsrs, doc(cfg(feature = "v1_58")))]
486    #[doc(alias = "pango_renderer_set_components")]
487    fn set_components(&self, components: RenderComponent) {
488        unsafe {
489            ffi::pango_renderer_set_components(
490                self.as_ref().to_glib_none().0,
491                components.into_glib(),
492            );
493        }
494    }
495
496    /// Sets the transformation matrix that will be applied when rendering.
497    /// ## `matrix`
498    /// a [`Matrix`][crate::Matrix], or [`None`] to unset any existing matrix
499    ///  (No matrix set is the same as setting the identity matrix.)
500    #[doc(alias = "pango_renderer_set_matrix")]
501    fn set_matrix(&self, matrix: Option<&Matrix>) {
502        unsafe {
503            ffi::pango_renderer_set_matrix(self.as_ref().to_glib_none().0, matrix.to_glib_none().0);
504        }
505    }
506}
507
508impl<O: IsA<Renderer>> RendererExt for O {}