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