Skip to main content

pangocairo/auto/
functions.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::ffi;
6use glib::{prelude::*, translate::*};
7
8/// Gets the resolution for the context.
9///
10/// See [`context_set_resolution()`][crate::context_set_resolution()]
11/// ## `context`
12/// a [`pango::Context`][crate::pango::Context], from a pangocairo font map
13///
14/// # Returns
15///
16/// the resolution in "dots per inch". A negative value will
17///   be returned if no resolution has previously been set.
18#[doc(alias = "pango_cairo_context_get_resolution")]
19pub fn context_get_resolution(context: &pango::Context) -> f64 {
20    unsafe { ffi::pango_cairo_context_get_resolution(context.to_glib_none().0) }
21}
22
23//#[doc(alias = "pango_cairo_context_get_shape_renderer")]
24//pub fn context_get_shape_renderer(context: &pango::Context, data: /*Unimplemented*/Option<Basic: Pointer>) -> /*Unimplemented*/Fn(&cairo::Context, /*Ignored*/pango::AttrShape, bool) {
25//    unsafe { TODO: call ffi:pango_cairo_context_get_shape_renderer() }
26//}
27
28/// Sets the font options used when rendering text with this context.
29///
30/// These options override any options that [`update_context()`][crate::update_context()]
31/// derives from the target surface.
32/// ## `context`
33/// a [`pango::Context`][crate::pango::Context], from a pangocairo font map
34/// ## `options`
35/// a [`cairo::FontOptions`][crate::cairo::FontOptions], or [`None`] to unset
36///   any previously set options. A copy is made.
37#[doc(alias = "pango_cairo_context_set_font_options")]
38pub fn context_set_font_options(context: &pango::Context, options: Option<&cairo::FontOptions>) {
39    unsafe {
40        ffi::pango_cairo_context_set_font_options(
41            context.to_glib_none().0,
42            options.to_glib_none().0,
43        );
44    }
45}
46
47/// Sets the resolution for the context.
48///
49/// This is a scale factor between points specified in a `PangoFontDescription`
50/// and Cairo units. The default value is 96, meaning that a 10 point font will
51/// be 13 units high. (10 * 96. / 72. = 13.3).
52/// ## `context`
53/// a [`pango::Context`][crate::pango::Context], from a pangocairo font map
54/// ## `dpi`
55/// the resolution in "dots per inch". (Physical inches aren't actually
56///   involved; the terminology is conventional.) A 0 or negative value
57///   means to use the resolution from the font map.
58#[doc(alias = "pango_cairo_context_set_resolution")]
59pub fn context_set_resolution(context: &pango::Context, dpi: f64) {
60    unsafe {
61        ffi::pango_cairo_context_set_resolution(context.to_glib_none().0, dpi);
62    }
63}
64
65//#[doc(alias = "pango_cairo_context_set_shape_renderer")]
66//pub fn context_set_shape_renderer(context: &pango::Context, func: /*Unimplemented*/Fn(&cairo::Context, /*Ignored*/pango::AttrShape, bool), data: /*Unimplemented*/Option<Basic: Pointer>) {
67//    unsafe { TODO: call ffi:pango_cairo_context_set_shape_renderer() }
68//}
69
70/// Creates a context object set up to match the current transformation
71/// and target surface of the Cairo context.
72///
73/// This context can then be
74/// used to create a layout using [`pango::Layout::new()`][crate::pango::Layout::new()].
75///
76/// This function is a convenience function that creates a context using
77/// the default font map, then updates it to @cr. If you just need to
78/// create a layout for use with @cr and do not need to access [`pango::Context`][crate::pango::Context]
79/// directly, you can use [`create_layout()`][crate::create_layout()] instead.
80/// ## `cr`
81/// a Cairo context
82///
83/// # Returns
84///
85/// the newly created [`pango::Context`][crate::pango::Context]
86#[doc(alias = "pango_cairo_create_context")]
87pub fn create_context(cr: &cairo::Context) -> pango::Context {
88    unsafe {
89        from_glib_full(ffi::pango_cairo_create_context(mut_override(
90            cr.to_glib_none().0,
91        )))
92    }
93}
94
95/// Creates a layout object set up to match the current transformation
96/// and target surface of the Cairo context.
97///
98/// This layout can then be used for text measurement with functions
99/// like [`Layout::size()`][crate::pango::Layout::size()] or drawing with functions like
100/// [`show_layout()`][crate::show_layout()]. If you change the transformation or target
101/// surface for @cr, you need to call [`update_layout()`][crate::update_layout()].
102///
103/// This function is the most convenient way to use Cairo with Pango,
104/// however it is slightly inefficient since it creates a separate
105/// [`pango::Context`][crate::pango::Context] object for each layout. This might matter in an
106/// application that was laying out large amounts of text.
107/// ## `cr`
108/// a Cairo context
109///
110/// # Returns
111///
112/// the newly created [`pango::Layout`][crate::pango::Layout]
113#[doc(alias = "pango_cairo_create_layout")]
114pub fn create_layout(cr: &cairo::Context) -> pango::Layout {
115    unsafe {
116        from_glib_full(ffi::pango_cairo_create_layout(mut_override(
117            cr.to_glib_none().0,
118        )))
119    }
120}
121
122/// Add a squiggly line to the current path in the specified cairo context that
123/// approximately covers the given rectangle in the style of an underline used
124/// to indicate a spelling error.
125///
126/// The width of the underline is rounded to an integer number of up/down
127/// segments and the resulting rectangle is centered in the original rectangle.
128/// ## `cr`
129/// a Cairo context
130/// ## `x`
131/// The X coordinate of one corner of the rectangle
132/// ## `y`
133/// The Y coordinate of one corner of the rectangle
134/// ## `width`
135/// Non-negative width of the rectangle
136/// ## `height`
137/// Non-negative height of the rectangle
138#[doc(alias = "pango_cairo_error_underline_path")]
139pub fn error_underline_path(cr: &cairo::Context, x: f64, y: f64, width: f64, height: f64) {
140    unsafe {
141        ffi::pango_cairo_error_underline_path(
142            mut_override(cr.to_glib_none().0),
143            x,
144            y,
145            width,
146            height,
147        );
148    }
149}
150
151/// Adds the glyphs in @glyphs to the current path in the specified
152/// cairo context.
153///
154/// The origin of the glyphs (the left edge of the baseline)
155/// will be at the current point of the cairo context.
156/// ## `cr`
157/// a Cairo context
158/// ## `font`
159/// a [`pango::Font`][crate::pango::Font] from a [`FontMap`][crate::FontMap]
160/// ## `glyphs`
161/// a [`pango::GlyphString`][crate::pango::GlyphString]
162#[doc(alias = "pango_cairo_glyph_string_path")]
163pub fn glyph_string_path(
164    cr: &cairo::Context,
165    font: &impl IsA<pango::Font>,
166    glyphs: &mut pango::GlyphString,
167) {
168    unsafe {
169        ffi::pango_cairo_glyph_string_path(
170            mut_override(cr.to_glib_none().0),
171            font.as_ref().to_glib_none().0,
172            glyphs.to_glib_none_mut().0,
173        );
174    }
175}
176
177/// Adds the text in [`pango::LayoutLine`][crate::pango::LayoutLine] to the current path in the
178/// specified cairo context.
179///
180/// The origin of the glyphs (the left edge of the line) will be
181/// at the current point of the cairo context.
182/// ## `cr`
183/// a Cairo context
184/// ## `line`
185/// a [`pango::LayoutLine`][crate::pango::LayoutLine]
186#[doc(alias = "pango_cairo_layout_line_path")]
187pub fn layout_line_path(cr: &cairo::Context, line: &pango::LayoutLine) {
188    unsafe {
189        ffi::pango_cairo_layout_line_path(mut_override(cr.to_glib_none().0), line.to_glib_none().0);
190    }
191}
192
193/// Adds the text in a [`pango::Layout`][crate::pango::Layout] to the current path in the
194/// specified cairo context.
195///
196/// The top-left corner of the [`pango::Layout`][crate::pango::Layout] will be at the
197/// current point of the cairo context.
198/// ## `cr`
199/// a Cairo context
200/// ## `layout`
201/// a Pango layout
202#[doc(alias = "pango_cairo_layout_path")]
203pub fn layout_path(cr: &cairo::Context, layout: &pango::Layout) {
204    unsafe {
205        ffi::pango_cairo_layout_path(mut_override(cr.to_glib_none().0), layout.to_glib_none().0);
206    }
207}
208
209/// Adds components of a [`pango::Layout`][crate::pango::Layout] to the current path
210/// in the specified cairo context.
211///
212/// The top-left corner of the [`pango::Layout`][crate::pango::Layout] will be at the
213/// current point of the cairo context.
214/// ## `cr`
215/// a Cairo context
216/// ## `layout`
217/// a Pango layout
218/// ## `components`
219/// the components to include
220#[cfg(feature = "v1_58")]
221#[cfg_attr(docsrs, doc(cfg(feature = "v1_58")))]
222#[doc(alias = "pango_cairo_layout_path_for_components")]
223pub fn layout_path_for_components(
224    cr: &cairo::Context,
225    layout: &pango::Layout,
226    components: pango::RenderComponent,
227) {
228    unsafe {
229        ffi::pango_cairo_layout_path_for_components(
230            mut_override(cr.to_glib_none().0),
231            layout.to_glib_none().0,
232            components.into_glib(),
233        );
234    }
235}
236
237/// Draw a squiggly line in the specified cairo context that approximately
238/// covers the given rectangle in the style of an underline used to indicate a
239/// spelling error.
240///
241/// The width of the underline is rounded to an integer
242/// number of up/down segments and the resulting rectangle is centered in the
243/// original rectangle.
244/// ## `cr`
245/// a Cairo context
246/// ## `x`
247/// The X coordinate of one corner of the rectangle
248/// ## `y`
249/// The Y coordinate of one corner of the rectangle
250/// ## `width`
251/// Non-negative width of the rectangle
252/// ## `height`
253/// Non-negative height of the rectangle
254#[doc(alias = "pango_cairo_show_error_underline")]
255pub fn show_error_underline(cr: &cairo::Context, x: f64, y: f64, width: f64, height: f64) {
256    unsafe {
257        ffi::pango_cairo_show_error_underline(
258            mut_override(cr.to_glib_none().0),
259            x,
260            y,
261            width,
262            height,
263        );
264    }
265}
266
267/// Draws the glyphs in @glyph_item in the specified cairo context,
268///
269/// embedding the text associated with the glyphs in the output if the
270/// output format supports it (PDF for example), otherwise it acts
271/// similar to [`show_glyph_string()`][crate::show_glyph_string()].
272///
273/// The origin of the glyphs (the left edge of the baseline) will
274/// be drawn at the current point of the cairo context.
275///
276/// Note that @text is the start of the text for layout, which is then
277/// indexed by `glyph_item->item->offset`.
278/// ## `cr`
279/// a Cairo context
280/// ## `text`
281/// the UTF-8 text that @glyph_item refers to
282/// ## `glyph_item`
283/// a [`pango::GlyphItem`][crate::pango::GlyphItem]
284#[doc(alias = "pango_cairo_show_glyph_item")]
285pub fn show_glyph_item(cr: &cairo::Context, text: &str, glyph_item: &mut pango::GlyphItem) {
286    unsafe {
287        ffi::pango_cairo_show_glyph_item(
288            mut_override(cr.to_glib_none().0),
289            text.to_glib_none().0,
290            glyph_item.to_glib_none_mut().0,
291        );
292    }
293}
294
295/// Draws the glyphs in @glyphs in the specified cairo context.
296///
297/// The origin of the glyphs (the left edge of the baseline) will
298/// be drawn at the current point of the cairo context.
299/// ## `cr`
300/// a Cairo context
301/// ## `font`
302/// a [`pango::Font`][crate::pango::Font] from a [`FontMap`][crate::FontMap]
303/// ## `glyphs`
304/// a [`pango::GlyphString`][crate::pango::GlyphString]
305#[doc(alias = "pango_cairo_show_glyph_string")]
306pub fn show_glyph_string(
307    cr: &cairo::Context,
308    font: &impl IsA<pango::Font>,
309    glyphs: &mut pango::GlyphString,
310) {
311    unsafe {
312        ffi::pango_cairo_show_glyph_string(
313            mut_override(cr.to_glib_none().0),
314            font.as_ref().to_glib_none().0,
315            glyphs.to_glib_none_mut().0,
316        );
317    }
318}
319
320/// Draws a [`pango::Layout`][crate::pango::Layout] in the specified cairo context.
321///
322/// The top-left corner of the [`pango::Layout`][crate::pango::Layout] will be drawn
323/// at the current point of the cairo context.
324/// ## `cr`
325/// a Cairo context
326/// ## `layout`
327/// a Pango layout
328#[doc(alias = "pango_cairo_show_layout")]
329pub fn show_layout(cr: &cairo::Context, layout: &pango::Layout) {
330    unsafe {
331        ffi::pango_cairo_show_layout(mut_override(cr.to_glib_none().0), layout.to_glib_none().0);
332    }
333}
334
335/// Draws a [`pango::LayoutLine`][crate::pango::LayoutLine] in the specified cairo context.
336///
337/// The origin of the glyphs (the left edge of the line) will
338/// be drawn at the current point of the cairo context.
339/// ## `cr`
340/// a Cairo context
341/// ## `line`
342/// a [`pango::LayoutLine`][crate::pango::LayoutLine]
343#[doc(alias = "pango_cairo_show_layout_line")]
344pub fn show_layout_line(cr: &cairo::Context, line: &pango::LayoutLine) {
345    unsafe {
346        ffi::pango_cairo_show_layout_line(mut_override(cr.to_glib_none().0), line.to_glib_none().0);
347    }
348}
349
350/// Updates a [`pango::Context`][crate::pango::Context] previously created for use with Cairo to
351/// match the current transformation and target surface of a Cairo
352/// context.
353///
354/// If any layouts have been created for the context, it's necessary
355/// to call [`Layout::context_changed()`][crate::pango::Layout::context_changed()] on those layouts.
356/// ## `cr`
357/// a Cairo context
358/// ## `context`
359/// a [`pango::Context`][crate::pango::Context], from a pangocairo font map
360#[doc(alias = "pango_cairo_update_context")]
361pub fn update_context(cr: &cairo::Context, context: &pango::Context) {
362    unsafe {
363        ffi::pango_cairo_update_context(
364            mut_override(cr.to_glib_none().0),
365            context.to_glib_none().0,
366        );
367    }
368}
369
370/// Updates the private [`pango::Context`][crate::pango::Context] of a [`pango::Layout`][crate::pango::Layout] created with
371/// [`create_layout()`][crate::create_layout()] to match the current transformation and target
372/// surface of a Cairo context.
373/// ## `cr`
374/// a Cairo context
375/// ## `layout`
376/// a [`pango::Layout`][crate::pango::Layout], from [`create_layout()`][crate::create_layout()]
377#[doc(alias = "pango_cairo_update_layout")]
378pub fn update_layout(cr: &cairo::Context, layout: &pango::Layout) {
379    unsafe {
380        ffi::pango_cairo_update_layout(mut_override(cr.to_glib_none().0), layout.to_glib_none().0);
381    }
382}