1use glib::object::IsA;
6use glib::translate::*;
7use pango_sys;
8use std::fmt;
9use Color;
10use Font;
11use Glyph;
12use GlyphItem;
13use GlyphString;
14use Layout;
15use LayoutLine;
16use Matrix;
17use RenderPart;
18
19glib_wrapper! {
20 pub struct Renderer(Object<pango_sys::PangoRenderer, pango_sys::PangoRendererClass, RendererClass>);
21
22 match fn {
23 get_type => || pango_sys::pango_renderer_get_type(),
24 }
25}
26
27pub const NONE_RENDERER: Option<&Renderer> = None;
28
29pub trait RendererExt: 'static {
30 fn activate(&self);
31
32 fn deactivate(&self);
33
34 fn draw_error_underline(&self, x: i32, y: i32, width: i32, height: i32);
35
36 fn draw_glyph<P: IsA<Font>>(&self, font: &P, glyph: Glyph, x: f64, y: f64);
37
38 fn draw_glyph_item(&self, text: Option<&str>, glyph_item: &mut GlyphItem, x: i32, y: i32);
39
40 fn draw_glyphs<P: IsA<Font>>(&self, font: &P, glyphs: &mut GlyphString, x: i32, y: i32);
41
42 fn draw_layout(&self, layout: &Layout, x: i32, y: i32);
43
44 fn draw_layout_line(&self, line: &LayoutLine, x: i32, y: i32);
45
46 fn draw_rectangle(&self, part: RenderPart, x: i32, y: i32, width: i32, height: i32);
47
48 fn draw_trapezoid(
49 &self,
50 part: RenderPart,
51 y1_: f64,
52 x11: f64,
53 x21: f64,
54 y2: f64,
55 x12: f64,
56 x22: f64,
57 );
58
59 #[cfg(any(feature = "v1_38", feature = "dox"))]
60 fn get_alpha(&self, part: RenderPart) -> u16;
61
62 fn get_color(&self, part: RenderPart) -> Option<Color>;
63
64 fn get_layout(&self) -> Option<Layout>;
65
66 fn get_layout_line(&self) -> Option<LayoutLine>;
67
68 fn get_matrix(&self) -> Option<Matrix>;
69
70 fn part_changed(&self, part: RenderPart);
71
72 #[cfg(any(feature = "v1_38", feature = "dox"))]
73 fn set_alpha(&self, part: RenderPart, alpha: u16);
74
75 fn set_color(&self, part: RenderPart, color: Option<&Color>);
76
77 fn set_matrix(&self, matrix: Option<&Matrix>);
78}
79
80impl<O: IsA<Renderer>> RendererExt for O {
81 fn activate(&self) {
82 unsafe {
83 pango_sys::pango_renderer_activate(self.as_ref().to_glib_none().0);
84 }
85 }
86
87 fn deactivate(&self) {
88 unsafe {
89 pango_sys::pango_renderer_deactivate(self.as_ref().to_glib_none().0);
90 }
91 }
92
93 fn draw_error_underline(&self, x: i32, y: i32, width: i32, height: i32) {
94 unsafe {
95 pango_sys::pango_renderer_draw_error_underline(
96 self.as_ref().to_glib_none().0,
97 x,
98 y,
99 width,
100 height,
101 );
102 }
103 }
104
105 fn draw_glyph<P: IsA<Font>>(&self, font: &P, glyph: Glyph, x: f64, y: f64) {
106 unsafe {
107 pango_sys::pango_renderer_draw_glyph(
108 self.as_ref().to_glib_none().0,
109 font.as_ref().to_glib_none().0,
110 glyph,
111 x,
112 y,
113 );
114 }
115 }
116
117 fn draw_glyph_item(&self, text: Option<&str>, glyph_item: &mut GlyphItem, x: i32, y: i32) {
118 unsafe {
119 pango_sys::pango_renderer_draw_glyph_item(
120 self.as_ref().to_glib_none().0,
121 text.to_glib_none().0,
122 glyph_item.to_glib_none_mut().0,
123 x,
124 y,
125 );
126 }
127 }
128
129 fn draw_glyphs<P: IsA<Font>>(&self, font: &P, glyphs: &mut GlyphString, x: i32, y: i32) {
130 unsafe {
131 pango_sys::pango_renderer_draw_glyphs(
132 self.as_ref().to_glib_none().0,
133 font.as_ref().to_glib_none().0,
134 glyphs.to_glib_none_mut().0,
135 x,
136 y,
137 );
138 }
139 }
140
141 fn draw_layout(&self, layout: &Layout, x: i32, y: i32) {
142 unsafe {
143 pango_sys::pango_renderer_draw_layout(
144 self.as_ref().to_glib_none().0,
145 layout.to_glib_none().0,
146 x,
147 y,
148 );
149 }
150 }
151
152 fn draw_layout_line(&self, line: &LayoutLine, x: i32, y: i32) {
153 unsafe {
154 pango_sys::pango_renderer_draw_layout_line(
155 self.as_ref().to_glib_none().0,
156 line.to_glib_none().0,
157 x,
158 y,
159 );
160 }
161 }
162
163 fn draw_rectangle(&self, part: RenderPart, x: i32, y: i32, width: i32, height: i32) {
164 unsafe {
165 pango_sys::pango_renderer_draw_rectangle(
166 self.as_ref().to_glib_none().0,
167 part.to_glib(),
168 x,
169 y,
170 width,
171 height,
172 );
173 }
174 }
175
176 fn draw_trapezoid(
177 &self,
178 part: RenderPart,
179 y1_: f64,
180 x11: f64,
181 x21: f64,
182 y2: f64,
183 x12: f64,
184 x22: f64,
185 ) {
186 unsafe {
187 pango_sys::pango_renderer_draw_trapezoid(
188 self.as_ref().to_glib_none().0,
189 part.to_glib(),
190 y1_,
191 x11,
192 x21,
193 y2,
194 x12,
195 x22,
196 );
197 }
198 }
199
200 #[cfg(any(feature = "v1_38", feature = "dox"))]
201 fn get_alpha(&self, part: RenderPart) -> u16 {
202 unsafe {
203 pango_sys::pango_renderer_get_alpha(self.as_ref().to_glib_none().0, part.to_glib())
204 }
205 }
206
207 fn get_color(&self, part: RenderPart) -> Option<Color> {
208 unsafe {
209 from_glib_none(pango_sys::pango_renderer_get_color(
210 self.as_ref().to_glib_none().0,
211 part.to_glib(),
212 ))
213 }
214 }
215
216 fn get_layout(&self) -> Option<Layout> {
217 unsafe {
218 from_glib_none(pango_sys::pango_renderer_get_layout(
219 self.as_ref().to_glib_none().0,
220 ))
221 }
222 }
223
224 fn get_layout_line(&self) -> Option<LayoutLine> {
225 unsafe {
226 from_glib_none(pango_sys::pango_renderer_get_layout_line(
227 self.as_ref().to_glib_none().0,
228 ))
229 }
230 }
231
232 fn get_matrix(&self) -> Option<Matrix> {
233 unsafe {
234 from_glib_none(pango_sys::pango_renderer_get_matrix(
235 self.as_ref().to_glib_none().0,
236 ))
237 }
238 }
239
240 fn part_changed(&self, part: RenderPart) {
241 unsafe {
242 pango_sys::pango_renderer_part_changed(self.as_ref().to_glib_none().0, part.to_glib());
243 }
244 }
245
246 #[cfg(any(feature = "v1_38", feature = "dox"))]
247 fn set_alpha(&self, part: RenderPart, alpha: u16) {
248 unsafe {
249 pango_sys::pango_renderer_set_alpha(
250 self.as_ref().to_glib_none().0,
251 part.to_glib(),
252 alpha,
253 );
254 }
255 }
256
257 fn set_color(&self, part: RenderPart, color: Option<&Color>) {
258 unsafe {
259 pango_sys::pango_renderer_set_color(
260 self.as_ref().to_glib_none().0,
261 part.to_glib(),
262 color.to_glib_none().0,
263 );
264 }
265 }
266
267 fn set_matrix(&self, matrix: Option<&Matrix>) {
268 unsafe {
269 pango_sys::pango_renderer_set_matrix(
270 self.as_ref().to_glib_none().0,
271 matrix.to_glib_none().0,
272 );
273 }
274 }
275}
276
277impl fmt::Display for Renderer {
278 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
279 write!(f, "Renderer")
280 }
281}