1#[cfg(feature = "v1_50")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
7use crate::Context;
8#[cfg(feature = "v1_46")]
9#[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
10use crate::FontFace;
11use crate::{ffi, Coverage, FontDescription, FontMap, FontMetrics, Glyph, Language, Rectangle};
12use glib::{prelude::*, translate::*};
13
14glib::wrapper! {
15 #[doc(alias = "PangoFont")]
16 pub struct Font(Object<ffi::PangoFont, ffi::PangoFontClass>);
17
18 match fn {
19 type_ => || ffi::pango_font_get_type(),
20 }
21}
22
23impl Font {
24 pub const NONE: Option<&'static Font> = None;
25
26 #[cfg(feature = "v1_50")]
27 #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
28 #[doc(alias = "pango_font_deserialize")]
29 pub fn deserialize(
30 context: &Context,
31 bytes: &glib::Bytes,
32 ) -> Result<Option<Font>, glib::Error> {
33 unsafe {
34 let mut error = std::ptr::null_mut();
35 let ret = ffi::pango_font_deserialize(
36 context.to_glib_none().0,
37 bytes.to_glib_none().0,
38 &mut error,
39 );
40 if error.is_null() {
41 Ok(from_glib_full(ret))
42 } else {
43 Err(from_glib_full(error))
44 }
45 }
46 }
47}
48
49pub trait FontExt: IsA<Font> + 'static {
50 #[doc(alias = "pango_font_describe")]
51 fn describe(&self) -> FontDescription {
52 unsafe { from_glib_full(ffi::pango_font_describe(self.as_ref().to_glib_none().0)) }
53 }
54
55 #[doc(alias = "pango_font_describe_with_absolute_size")]
56 fn describe_with_absolute_size(&self) -> FontDescription {
57 unsafe {
58 from_glib_full(ffi::pango_font_describe_with_absolute_size(
59 self.as_ref().to_glib_none().0,
60 ))
61 }
62 }
63
64 #[doc(alias = "pango_font_get_coverage")]
65 #[doc(alias = "get_coverage")]
66 fn coverage(&self, language: &Language) -> Coverage {
67 unsafe {
68 from_glib_full(ffi::pango_font_get_coverage(
69 self.as_ref().to_glib_none().0,
70 mut_override(language.to_glib_none().0),
71 ))
72 }
73 }
74
75 #[cfg(feature = "v1_46")]
76 #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
77 #[doc(alias = "pango_font_get_face")]
78 #[doc(alias = "get_face")]
79 fn face(&self) -> Option<FontFace> {
80 unsafe { from_glib_none(ffi::pango_font_get_face(self.as_ref().to_glib_none().0)) }
81 }
82
83 #[doc(alias = "pango_font_get_font_map")]
92 #[doc(alias = "get_font_map")]
93 fn font_map(&self) -> Option<FontMap> {
94 unsafe { from_glib_none(ffi::pango_font_get_font_map(self.as_ref().to_glib_none().0)) }
95 }
96
97 #[doc(alias = "pango_font_get_glyph_extents")]
98 #[doc(alias = "get_glyph_extents")]
99 fn glyph_extents(&self, glyph: Glyph) -> (Rectangle, Rectangle) {
100 unsafe {
101 let mut ink_rect = Rectangle::uninitialized();
102 let mut logical_rect = Rectangle::uninitialized();
103 ffi::pango_font_get_glyph_extents(
104 self.as_ref().to_glib_none().0,
105 glyph,
106 ink_rect.to_glib_none_mut().0,
107 logical_rect.to_glib_none_mut().0,
108 );
109 (ink_rect, logical_rect)
110 }
111 }
112
113 #[cfg(feature = "v1_50")]
122 #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
123 #[doc(alias = "pango_font_get_languages")]
124 #[doc(alias = "get_languages")]
125 fn languages(&self) -> Vec<Language> {
126 unsafe {
127 FromGlibPtrContainer::from_glib_none(ffi::pango_font_get_languages(
128 self.as_ref().to_glib_none().0,
129 ))
130 }
131 }
132
133 #[doc(alias = "pango_font_get_metrics")]
134 #[doc(alias = "get_metrics")]
135 fn metrics(&self, language: Option<&Language>) -> FontMetrics {
136 unsafe {
137 from_glib_full(ffi::pango_font_get_metrics(
138 self.as_ref().to_glib_none().0,
139 mut_override(language.to_glib_none().0),
140 ))
141 }
142 }
143
144 #[cfg(feature = "v1_44")]
145 #[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
146 #[doc(alias = "pango_font_has_char")]
147 fn has_char(&self, wc: char) -> bool {
148 unsafe {
149 from_glib(ffi::pango_font_has_char(
150 self.as_ref().to_glib_none().0,
151 wc.into_glib(),
152 ))
153 }
154 }
155
156 #[cfg(feature = "v1_50")]
157 #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
158 #[doc(alias = "pango_font_serialize")]
159 fn serialize(&self) -> glib::Bytes {
160 unsafe { from_glib_full(ffi::pango_font_serialize(self.as_ref().to_glib_none().0)) }
161 }
162}
163
164impl<O: IsA<Font>> FontExt for O {}