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
49mod sealed {
50 pub trait Sealed {}
51 impl<T: super::IsA<super::Font>> Sealed for T {}
52}
53
54pub trait FontExt: IsA<Font> + sealed::Sealed + 'static {
55 #[doc(alias = "pango_font_describe")]
56 fn describe(&self) -> FontDescription {
57 unsafe { from_glib_full(ffi::pango_font_describe(self.as_ref().to_glib_none().0)) }
58 }
59
60 #[doc(alias = "pango_font_describe_with_absolute_size")]
61 fn describe_with_absolute_size(&self) -> FontDescription {
62 unsafe {
63 from_glib_full(ffi::pango_font_describe_with_absolute_size(
64 self.as_ref().to_glib_none().0,
65 ))
66 }
67 }
68
69 #[doc(alias = "pango_font_get_coverage")]
70 #[doc(alias = "get_coverage")]
71 fn coverage(&self, language: &Language) -> Coverage {
72 unsafe {
73 from_glib_full(ffi::pango_font_get_coverage(
74 self.as_ref().to_glib_none().0,
75 mut_override(language.to_glib_none().0),
76 ))
77 }
78 }
79
80 #[cfg(feature = "v1_46")]
81 #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
82 #[doc(alias = "pango_font_get_face")]
83 #[doc(alias = "get_face")]
84 fn face(&self) -> FontFace {
85 unsafe { from_glib_none(ffi::pango_font_get_face(self.as_ref().to_glib_none().0)) }
86 }
87
88 #[doc(alias = "pango_font_get_font_map")]
97 #[doc(alias = "get_font_map")]
98 fn font_map(&self) -> Option<FontMap> {
99 unsafe { from_glib_none(ffi::pango_font_get_font_map(self.as_ref().to_glib_none().0)) }
100 }
101
102 #[doc(alias = "pango_font_get_glyph_extents")]
103 #[doc(alias = "get_glyph_extents")]
104 fn glyph_extents(&self, glyph: Glyph) -> (Rectangle, Rectangle) {
105 unsafe {
106 let mut ink_rect = Rectangle::uninitialized();
107 let mut logical_rect = Rectangle::uninitialized();
108 ffi::pango_font_get_glyph_extents(
109 self.as_ref().to_glib_none().0,
110 glyph,
111 ink_rect.to_glib_none_mut().0,
112 logical_rect.to_glib_none_mut().0,
113 );
114 (ink_rect, logical_rect)
115 }
116 }
117
118 #[cfg(feature = "v1_50")]
127 #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
128 #[doc(alias = "pango_font_get_languages")]
129 #[doc(alias = "get_languages")]
130 fn languages(&self) -> Vec<Language> {
131 unsafe {
132 FromGlibPtrContainer::from_glib_none(ffi::pango_font_get_languages(
133 self.as_ref().to_glib_none().0,
134 ))
135 }
136 }
137
138 #[doc(alias = "pango_font_get_metrics")]
139 #[doc(alias = "get_metrics")]
140 fn metrics(&self, language: Option<&Language>) -> FontMetrics {
141 unsafe {
142 from_glib_full(ffi::pango_font_get_metrics(
143 self.as_ref().to_glib_none().0,
144 mut_override(language.to_glib_none().0),
145 ))
146 }
147 }
148
149 #[cfg(feature = "v1_44")]
150 #[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
151 #[doc(alias = "pango_font_has_char")]
152 fn has_char(&self, wc: char) -> bool {
153 unsafe {
154 from_glib(ffi::pango_font_has_char(
155 self.as_ref().to_glib_none().0,
156 wc.into_glib(),
157 ))
158 }
159 }
160
161 #[cfg(feature = "v1_50")]
162 #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
163 #[doc(alias = "pango_font_serialize")]
164 fn serialize(&self) -> glib::Bytes {
165 unsafe { from_glib_full(ffi::pango_font_serialize(self.as_ref().to_glib_none().0)) }
166 }
167}
168
169impl<O: IsA<Font>> FontExt for O {}