pangocairo/font_map.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::{prelude::*, translate::*};
4
5use crate::{ffi, FontMap};
6
7pub trait PangoCairoFontMapExtManual: IsA<FontMap> + 'static {
8 /// Gets the type of Cairo font backend that @self uses.
9 ///
10 /// # Returns
11 ///
12 /// the [`cairo::FontType`][crate::cairo::FontType] cairo font backend type
13 #[doc(alias = "pango_cairo_font_map_get_font_type")]
14 #[doc(alias = "get_font_type")]
15 fn font_type(&self) -> cairo::FontType {
16 unsafe { ffi::pango_cairo_font_map_get_font_type(self.as_ref().to_glib_none().0).into() }
17 }
18}
19
20impl<O: IsA<FontMap>> PangoCairoFontMapExtManual for O {}
21
22impl FontMap {
23 #[doc(alias = "pango_cairo_font_map_new_for_font_type")]
24 #[doc(alias = "new_for_font_type")]
25 pub fn for_font_type(fonttype: cairo::FontType) -> Option<pango::FontMap> {
26 unsafe { from_glib_full(ffi::pango_cairo_font_map_new_for_font_type(fonttype.into())) }
27 }
28
29 /// Creates a new [`FontMap`][crate::FontMap] object.
30 ///
31 /// A fontmap is used to cache information about available fonts,
32 /// and holds certain global parameters such as the resolution.
33 /// In most cases, you can use `func@PangoCairo.font_map_get_default]
34 /// instead.
35 ///
36 /// Note that the type of the returned object will depend
37 /// on the particular font backend Cairo was compiled to use;
38 /// You generally should only use the [`pango::FontMap`][crate::pango::FontMap] and
39 /// [`FontMap`][crate::FontMap] interfaces on the returned object.
40 ///
41 /// You can override the type of backend returned by using an
42 /// environment variable `PANGOCAIRO_BACKEND`. Supported types,
43 /// based on your build, are fc (fontconfig), win32, and coretext.
44 /// If requested type is not available, NULL is returned. Ie.
45 /// this is only useful for testing, when at least two backends
46 /// are compiled in.
47 ///
48 /// # Returns
49 ///
50 /// the newly allocated [`pango::FontMap`][crate::pango::FontMap],
51 /// which should be freed with g_object_unref().
52 #[allow(clippy::new_ret_no_self)]
53 #[doc(alias = "pango_cairo_font_map_new")]
54 pub fn new() -> pango::FontMap {
55 unsafe { from_glib_full(ffi::pango_cairo_font_map_new()) }
56 }
57
58 #[doc(alias = "pango_cairo_font_map_set_default")]
59 pub fn set_default(font_map: Option<&Self>) {
60 unsafe {
61 ffi::pango_cairo_font_map_set_default(font_map.as_ref().to_glib_none().0);
62 }
63 }
64}