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