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 /// offset`.
123 ///
124 /// If @text is [`None`], this simply calls [`draw_glyphs()`][Self::draw_glyphs()].
125 ///
126 /// The default implementation of this method simply falls back to
127 /// [`draw_glyphs()`][Self::draw_glyphs()].
128 /// ## `text`
129 /// the UTF-8 text that @glyph_item refers to
130 /// ## `glyph_item`
131 /// a [`GlyphItem`][crate::GlyphItem]
132 /// ## `x`
133 /// X position of left edge of baseline, in user space coordinates
134 /// in Pango units
135 /// ## `y`
136 /// Y position of left edge of baseline, in user space coordinates
137 /// in Pango units
138 #[doc(alias = "pango_renderer_draw_glyph_item")]
139 fn draw_glyph_item(&self, text: Option<&str>, glyph_item: &mut GlyphItem, x: i32, y: i32) {
140 unsafe {
141 ffi::pango_renderer_draw_glyph_item(
142 self.as_ref().to_glib_none().0,
143 text.to_glib_none().0,
144 glyph_item.to_glib_none_mut().0,
145 x,
146 y,
147 );
148 }
149 }
150
151 /// Draws the glyphs in @glyphs with the specified [`Renderer`][crate::Renderer].
152 /// ## `font`
153 /// a [`Font`][crate::Font]
154 /// ## `glyphs`
155 /// a [`GlyphString`][crate::GlyphString]
156 /// ## `x`
157 /// X position of left edge of baseline, in user space coordinates
158 /// in Pango units.
159 /// ## `y`
160 /// Y position of left edge of baseline, in user space coordinates
161 /// in Pango units.
162 #[doc(alias = "pango_renderer_draw_glyphs")]
163 fn draw_glyphs(&self, font: &impl IsA<Font>, glyphs: &mut GlyphString, x: i32, y: i32) {
164 unsafe {
165 ffi::pango_renderer_draw_glyphs(
166 self.as_ref().to_glib_none().0,
167 font.as_ref().to_glib_none().0,
168 glyphs.to_glib_none_mut().0,
169 x,
170 y,
171 );
172 }
173 }
174
175 /// Draws @layout with the specified [`Renderer`][crate::Renderer].
176 ///
177 /// This is equivalent to drawing the lines of the layout, at their
178 /// respective positions relative to @x, @y.
179 /// ## `layout`
180 /// a [`Layout`][crate::Layout]
181 /// ## `x`
182 /// X position of left edge of baseline, in user space coordinates
183 /// in Pango units.
184 /// ## `y`
185 /// Y position of left edge of baseline, in user space coordinates
186 /// in Pango units.
187 #[doc(alias = "pango_renderer_draw_layout")]
188 fn draw_layout(&self, layout: &Layout, x: i32, y: i32) {
189 unsafe {
190 ffi::pango_renderer_draw_layout(
191 self.as_ref().to_glib_none().0,
192 layout.to_glib_none().0,
193 x,
194 y,
195 );
196 }
197 }
198
199 /// Draws @line with the specified [`Renderer`][crate::Renderer].
200 ///
201 /// This draws the glyph items that make up the line, as well as
202 /// shapes, backgrounds and lines that are specified by the attributes
203 /// of those items.
204 /// ## `line`
205 /// a [`LayoutLine`][crate::LayoutLine]
206 /// ## `x`
207 /// X position of left edge of baseline, in user space coordinates
208 /// in Pango units.
209 /// ## `y`
210 /// Y position of left edge of baseline, in user space coordinates
211 /// in Pango units.
212 #[doc(alias = "pango_renderer_draw_layout_line")]
213 fn draw_layout_line(&self, line: &LayoutLine, x: i32, y: i32) {
214 unsafe {
215 ffi::pango_renderer_draw_layout_line(
216 self.as_ref().to_glib_none().0,
217 line.to_glib_none().0,
218 x,
219 y,
220 );
221 }
222 }
223
224 /// Draws an axis-aligned rectangle in user space coordinates with the
225 /// specified [`Renderer`][crate::Renderer].
226 ///
227 /// This should be called while @self is already active.
228 /// Use [`activate()`][Self::activate()] to activate a renderer.
229 /// ## `part`
230 /// type of object this rectangle is part of
231 /// ## `x`
232 /// X position at which to draw rectangle, in user space coordinates
233 /// in Pango units
234 /// ## `y`
235 /// Y position at which to draw rectangle, in user space coordinates
236 /// in Pango units
237 /// ## `width`
238 /// width of rectangle in Pango units
239 /// ## `height`
240 /// height of rectangle in Pango units
241 #[doc(alias = "pango_renderer_draw_rectangle")]
242 fn draw_rectangle(&self, part: RenderPart, x: i32, y: i32, width: i32, height: i32) {
243 unsafe {
244 ffi::pango_renderer_draw_rectangle(
245 self.as_ref().to_glib_none().0,
246 part.into_glib(),
247 x,
248 y,
249 width,
250 height,
251 );
252 }
253 }
254
255 /// Draws a trapezoid with the parallel sides aligned with the X axis
256 /// using the given [`Renderer`][crate::Renderer]; coordinates are in device space.
257 /// ## `part`
258 /// type of object this trapezoid is part of
259 /// ## `y1_`
260 /// Y coordinate of top of trapezoid
261 /// ## `x11`
262 /// X coordinate of left end of top of trapezoid
263 /// ## `x21`
264 /// X coordinate of right end of top of trapezoid
265 /// ## `y2`
266 /// Y coordinate of bottom of trapezoid
267 /// ## `x12`
268 /// X coordinate of left end of bottom of trapezoid
269 /// ## `x22`
270 /// X coordinate of right end of bottom of trapezoid
271 #[doc(alias = "pango_renderer_draw_trapezoid")]
272 fn draw_trapezoid(
273 &self,
274 part: RenderPart,
275 y1_: f64,
276 x11: f64,
277 x21: f64,
278 y2: f64,
279 x12: f64,
280 x22: f64,
281 ) {
282 unsafe {
283 ffi::pango_renderer_draw_trapezoid(
284 self.as_ref().to_glib_none().0,
285 part.into_glib(),
286 y1_,
287 x11,
288 x21,
289 y2,
290 x12,
291 x22,
292 );
293 }
294 }
295
296 /// Gets the current alpha for the specified part.
297 /// ## `part`
298 /// the part to get the alpha for
299 ///
300 /// # Returns
301 ///
302 /// the alpha for the specified part,
303 /// or 0 if it hasn't been set and should be
304 /// inherited from the environment.
305 #[doc(alias = "pango_renderer_get_alpha")]
306 #[doc(alias = "get_alpha")]
307 fn alpha(&self, part: RenderPart) -> u16 {
308 unsafe { ffi::pango_renderer_get_alpha(self.as_ref().to_glib_none().0, part.into_glib()) }
309 }
310
311 /// Gets the current rendering color for the specified part.
312 /// ## `part`
313 /// the part to get the color for
314 ///
315 /// # Returns
316 ///
317 /// the color for the
318 /// specified part, or [`None`] if it hasn't been set and should be
319 /// inherited from the environment.
320 #[doc(alias = "pango_renderer_get_color")]
321 #[doc(alias = "get_color")]
322 fn color(&self, part: RenderPart) -> Option<Color> {
323 unsafe {
324 from_glib_none(ffi::pango_renderer_get_color(
325 self.as_ref().to_glib_none().0,
326 part.into_glib(),
327 ))
328 }
329 }
330
331 /// Gets the components that are included in the output of the renderer.
332 ///
333 /// # Returns
334 ///
335 /// the components
336 #[cfg(feature = "v1_58")]
337 #[cfg_attr(docsrs, doc(cfg(feature = "v1_58")))]
338 #[doc(alias = "pango_renderer_get_components")]
339 #[doc(alias = "get_components")]
340 fn components(&self) -> RenderComponent {
341 unsafe {
342 from_glib(ffi::pango_renderer_get_components(
343 self.as_ref().to_glib_none().0,
344 ))
345 }
346 }
347
348 /// Gets the layout currently being rendered using @self.
349 ///
350 /// Calling this function only makes sense from inside a subclass's
351 /// methods, like in its draw_shape vfunc, for example.
352 ///
353 /// The returned layout should not be modified while still being
354 /// rendered.
355 ///
356 /// # Returns
357 ///
358 /// the layout, or [`None`] if
359 /// no layout is being rendered using @self at this time.
360 #[doc(alias = "pango_renderer_get_layout")]
361 #[doc(alias = "get_layout")]
362 fn layout(&self) -> Option<Layout> {
363 unsafe {
364 from_glib_none(ffi::pango_renderer_get_layout(
365 self.as_ref().to_glib_none().0,
366 ))
367 }
368 }
369
370 /// Gets the layout line currently being rendered using @self.
371 ///
372 /// Calling this function only makes sense from inside a subclass's
373 /// methods, like in its draw_shape vfunc, for example.
374 ///
375 /// The returned layout line should not be modified while still being
376 /// rendered.
377 ///
378 /// # Returns
379 ///
380 /// the layout line, or [`None`]
381 /// if no layout line is being rendered using @self at this time.
382 #[doc(alias = "pango_renderer_get_layout_line")]
383 #[doc(alias = "get_layout_line")]
384 fn layout_line(&self) -> Option<LayoutLine> {
385 unsafe {
386 from_glib_none(ffi::pango_renderer_get_layout_line(
387 self.as_ref().to_glib_none().0,
388 ))
389 }
390 }
391
392 /// Gets the transformation matrix that will be applied when
393 /// rendering.
394 ///
395 /// See [`set_matrix()`][Self::set_matrix()].
396 ///
397 /// # Returns
398 ///
399 /// the matrix, or [`None`] if no matrix has
400 /// been set (which is the same as the identity matrix). The returned
401 /// matrix is owned by Pango and must not be modified or freed.
402 #[doc(alias = "pango_renderer_get_matrix")]
403 #[doc(alias = "get_matrix")]
404 fn matrix(&self) -> Option<Matrix> {
405 unsafe {
406 from_glib_none(ffi::pango_renderer_get_matrix(
407 self.as_ref().to_glib_none().0,
408 ))
409 }
410 }
411
412 /// Informs Pango that the way that the rendering is done
413 /// for @part has changed.
414 ///
415 /// This should be called if the rendering changes in a way that would
416 /// prevent multiple pieces being joined together into one drawing call.
417 /// For instance, if a subclass of [`Renderer`][crate::Renderer] was to add a stipple
418 /// option for drawing underlines, it needs to call
419 ///
420 /// ```text
421 /// pango_renderer_part_changed (render, PANGO_RENDER_PART_UNDERLINE);
422 /// ```
423 ///
424 /// When the stipple changes or underlines with different stipples
425 /// might be joined together. Pango automatically calls this for
426 /// changes to colors. (See [`set_color()`][Self::set_color()])
427 /// ## `part`
428 /// the part for which rendering has changed.
429 #[doc(alias = "pango_renderer_part_changed")]
430 fn part_changed(&self, part: RenderPart) {
431 unsafe {
432 ffi::pango_renderer_part_changed(self.as_ref().to_glib_none().0, part.into_glib());
433 }
434 }
435
436 /// Sets the alpha for part of the rendering.
437 ///
438 /// Note that the alpha may only be used if a color is
439 /// specified for @part as well.
440 /// ## `part`
441 /// the part to set the alpha for
442 /// ## `alpha`
443 /// an alpha value between 1 and 65536, or 0 to unset the alpha
444 #[doc(alias = "pango_renderer_set_alpha")]
445 fn set_alpha(&self, part: RenderPart, alpha: u16) {
446 unsafe {
447 ffi::pango_renderer_set_alpha(self.as_ref().to_glib_none().0, part.into_glib(), alpha);
448 }
449 }
450
451 /// Sets the color for part of the rendering.
452 ///
453 /// Also see [`set_alpha()`][Self::set_alpha()].
454 /// ## `part`
455 /// the part to change the color of
456 /// ## `color`
457 /// the new color or [`None`] to unset the current color
458 #[doc(alias = "pango_renderer_set_color")]
459 fn set_color(&self, part: RenderPart, color: Option<&Color>) {
460 unsafe {
461 ffi::pango_renderer_set_color(
462 self.as_ref().to_glib_none().0,
463 part.into_glib(),
464 color.to_glib_none().0,
465 );
466 }
467 }
468
469 /// Sets the components to include in the output of the renderer.
470 /// ## `components`
471 /// the components to include
472 #[cfg(feature = "v1_58")]
473 #[cfg_attr(docsrs, doc(cfg(feature = "v1_58")))]
474 #[doc(alias = "pango_renderer_set_components")]
475 fn set_components(&self, components: RenderComponent) {
476 unsafe {
477 ffi::pango_renderer_set_components(
478 self.as_ref().to_glib_none().0,
479 components.into_glib(),
480 );
481 }
482 }
483
484 /// Sets the transformation matrix that will be applied when rendering.
485 /// ## `matrix`
486 /// a [`Matrix`][crate::Matrix], or [`None`] to unset any existing matrix
487 /// (No matrix set is the same as setting the identity matrix.)
488 #[doc(alias = "pango_renderer_set_matrix")]
489 fn set_matrix(&self, matrix: Option<&Matrix>) {
490 unsafe {
491 ffi::pango_renderer_set_matrix(self.as_ref().to_glib_none().0, matrix.to_glib_none().0);
492 }
493 }
494}
495
496impl<O: IsA<Renderer>> RendererExt for O {}