]>
Commit | Line | Data |
---|---|---|
2b5f62a0 VZ |
1 | /** |
2 | * This file gets included from dcclient.cpp and implements | |
3 | * the X11 interface to Pango. | |
4 | * Copyright (C) Owen Taylor and Robert Roebling. | |
84969af7 | 5 | * Licence: The wxWindows licence |
2b5f62a0 VZ |
6 | */ |
7 | ||
8 | /* Declaration */ | |
9 | ||
10 | void | |
11 | x11_draw_glyphs( Drawable drawable, | |
12 | GC gc, | |
13 | PangoFont *font, | |
14 | int x, | |
15 | int y, | |
16 | PangoGlyphString *glyphs, | |
17 | wxColour &colour ); | |
18 | ||
19 | void | |
20 | x11_draw_layout_line_with_colors( Drawable drawable, | |
21 | GC gc, | |
22 | int x, | |
23 | int y, | |
24 | PangoLayoutLine *line, | |
25 | wxColour &colour ); | |
26 | ||
27 | void | |
28 | x11_draw_layout_with_colors( Drawable drawable, | |
29 | GC gc, | |
30 | int x, | |
31 | int y, | |
32 | PangoLayout *layout, | |
33 | wxColour &colour ); | |
34 | ||
35 | void | |
36 | x11_draw_layout( Drawable drawable, | |
37 | GC gc, | |
38 | int x, | |
39 | int y, | |
40 | PangoLayout *layout, | |
41 | wxColour &colour); | |
42 | ||
43 | void | |
44 | x11_pango_get_item_properties( PangoItem *item, | |
45 | PangoUnderline *uline, | |
46 | gboolean *strikethrough, | |
47 | gint *rise, | |
48 | PangoColor *fg_color, | |
49 | gboolean *fg_set, | |
50 | PangoColor *bg_color, | |
51 | gboolean *bg_set, | |
52 | gboolean *shape_set, | |
53 | PangoRectangle *ink_rect, | |
54 | PangoRectangle *logical_rect); | |
55 | ||
56 | /* Implementation */ | |
57 | ||
58 | void | |
59 | x11_draw_glyphs( Drawable drawable, | |
60 | GC gc, | |
61 | PangoFont *font, | |
62 | int x, | |
63 | int y, | |
64 | PangoGlyphString *glyphs, | |
65 | wxColour &colour ) | |
66 | { | |
67 | if (PANGO_XFT_IS_FONT (font)) | |
68 | { | |
69 | Display* xdisplay = wxGlobalDisplay(); | |
70 | int xscreen = DefaultScreen( xdisplay ); | |
71 | Visual* xvisual = DefaultVisual( xdisplay, xscreen ); | |
72 | ||
73 | Colormap xcolormap = DefaultColormapOfScreen( XScreenOfDisplay( xdisplay, xscreen ) ); | |
74 | ||
75 | XftDraw *draw = XftDrawCreate( xdisplay, drawable, xvisual, xcolormap ); | |
76 | XftColor color; | |
77 | color.pixel = 0; | |
78 | color.color.red = colour.Red() << 8; | |
79 | color.color.green = colour.Green() << 8; | |
80 | color.color.blue = colour.Blue() << 8; | |
81 | color.color.alpha = 65000; | |
82 | pango_xft_render( draw, &color, font, glyphs, x, y ); | |
83 | ||
84 | XftDrawDestroy( draw ); | |
85 | } | |
86 | else | |
87 | { | |
88 | pango_x_render( wxGlobalDisplay(), drawable, gc, font, glyphs, x, y ); | |
89 | } | |
90 | } | |
91 | ||
92 | void | |
93 | x11_draw_layout_line_with_colors( Drawable drawable, | |
94 | GC gc, | |
95 | int x, | |
96 | int y, | |
97 | PangoLayoutLine *line, | |
98 | wxColour &colour ) | |
99 | { | |
100 | PangoRectangle overall_rect; | |
101 | PangoRectangle logical_rect; | |
102 | PangoRectangle ink_rect; | |
103 | PangoContext *context; | |
104 | gint x_off = 0; | |
105 | gint rise = 0; | |
106 | ||
107 | context = pango_layout_get_context (line->layout); | |
108 | ||
109 | pango_layout_line_get_extents (line,NULL, &overall_rect); | |
110 | ||
111 | GSList *tmp_list = line->runs; | |
112 | while (tmp_list) | |
113 | { | |
114 | PangoUnderline uline = PANGO_UNDERLINE_NONE; | |
115 | PangoLayoutRun *run = (PangoLayoutRun *) tmp_list->data; | |
116 | PangoColor fg_color, bg_color; | |
117 | gboolean strike, fg_set, bg_set, shape_set; | |
118 | gint risen_y; | |
119 | ||
120 | tmp_list = tmp_list->next; | |
121 | ||
122 | x11_pango_get_item_properties (run->item, &uline, | |
123 | &strike, &rise, &fg_color, &fg_set, &bg_color, &bg_set, | |
124 | &shape_set, &ink_rect, &logical_rect); | |
125 | ||
126 | /* we subtract the rise because X coordinates are upside down */ | |
127 | risen_y = y - rise / PANGO_SCALE; | |
128 | ||
129 | if (!shape_set) | |
130 | { | |
131 | if (uline == PANGO_UNDERLINE_NONE) | |
132 | pango_glyph_string_extents (run->glyphs, run->item->analysis.font, NULL, &logical_rect); | |
133 | else | |
134 | pango_glyph_string_extents (run->glyphs, run->item->analysis.font, &ink_rect, &logical_rect); | |
135 | } | |
136 | ||
137 | #if 0 | |
138 | XDrawRectangle( drawable, gc, TRUE, | |
139 | x + (x_off + logical_rect.x) / PANGO_SCALE, | |
140 | risen_y + overall_rect.y / PANGO_SCALE, | |
141 | logical_rect.width / PANGO_SCALE, | |
142 | overall_rect.height / PANGO_SCALE); | |
143 | #endif | |
144 | ||
145 | if (!shape_set) | |
146 | { | |
147 | int gx = x + x_off / PANGO_SCALE; | |
148 | int gy = risen_y; | |
149 | ||
150 | x11_draw_glyphs( drawable, gc, run->item->analysis.font, gx, gy, run->glyphs, colour ); | |
151 | } | |
152 | ||
153 | if (uline == PANGO_UNDERLINE_SINGLE) | |
154 | { | |
155 | XDrawLine( wxGlobalDisplay(), drawable, gc, | |
156 | x + (x_off + ink_rect.x) / PANGO_SCALE - 1, | |
157 | risen_y + 1, | |
158 | x + (x_off + ink_rect.x + ink_rect.width) / PANGO_SCALE, | |
159 | risen_y + 1); | |
160 | } | |
161 | ||
162 | x_off += logical_rect.width; | |
163 | } | |
164 | } | |
165 | ||
166 | void | |
167 | x11_draw_layout_with_colors( Drawable drawable, | |
168 | GC gc, | |
169 | int x, | |
170 | int y, | |
171 | PangoLayout *layout, | |
172 | wxColour &colour ) | |
173 | { | |
174 | PangoLayoutIter *iter = pango_layout_get_iter (layout); | |
175 | ||
176 | do | |
177 | { | |
178 | PangoLayoutLine *line = pango_layout_iter_get_line (iter); | |
179 | ||
180 | PangoRectangle logical_rect; | |
181 | pango_layout_iter_get_line_extents (iter, NULL, &logical_rect); | |
182 | ||
183 | int baseline = pango_layout_iter_get_baseline (iter); | |
184 | ||
185 | x11_draw_layout_line_with_colors( drawable, gc, | |
186 | x + logical_rect.x / PANGO_SCALE, | |
187 | y + baseline / PANGO_SCALE, | |
188 | line, | |
189 | colour ); | |
190 | ||
191 | } while (pango_layout_iter_next_line (iter)); | |
192 | ||
193 | pango_layout_iter_free (iter); | |
194 | } | |
195 | ||
196 | void | |
197 | x11_draw_layout( Drawable drawable, | |
198 | GC gc, | |
199 | int x, | |
200 | int y, | |
201 | PangoLayout *layout, | |
202 | wxColour &colour) | |
203 | { | |
204 | wxCHECK_RET( layout, wxT("No layout") ); | |
205 | ||
206 | x11_draw_layout_with_colors (drawable, gc, x, y, layout, colour ); | |
207 | } | |
208 | ||
209 | void | |
210 | x11_pango_get_item_properties( PangoItem *item, | |
211 | PangoUnderline *uline, | |
212 | gboolean *strikethrough, | |
213 | gint *rise, | |
214 | PangoColor *fg_color, | |
215 | gboolean *fg_set, | |
216 | PangoColor *bg_color, | |
217 | gboolean *bg_set, | |
218 | gboolean *shape_set, | |
219 | PangoRectangle *ink_rect, | |
220 | PangoRectangle *logical_rect) | |
221 | { | |
222 | GSList *tmp_list = item->analysis.extra_attrs; | |
223 | ||
224 | if (strikethrough) | |
225 | *strikethrough = FALSE; | |
226 | ||
227 | if (fg_set) | |
228 | *fg_set = FALSE; | |
229 | ||
230 | if (bg_set) | |
231 | *bg_set = FALSE; | |
232 | ||
233 | if (shape_set) | |
234 | *shape_set = FALSE; | |
235 | ||
236 | if (rise) | |
237 | *rise = 0; | |
238 | ||
239 | while (tmp_list) | |
240 | { | |
241 | PangoAttribute *attr = (PangoAttribute *) tmp_list->data; | |
242 | ||
243 | switch (attr->klass->type) | |
244 | { | |
245 | case PANGO_ATTR_UNDERLINE: | |
246 | if (uline) | |
247 | *uline = (PangoUnderline) ((PangoAttrInt *)attr)->value; | |
248 | break; | |
249 | ||
250 | case PANGO_ATTR_STRIKETHROUGH: | |
251 | if (strikethrough) | |
252 | *strikethrough = ((PangoAttrInt *)attr)->value; | |
253 | break; | |
254 | ||
255 | case PANGO_ATTR_FOREGROUND: | |
256 | if (fg_color) | |
257 | *fg_color = ((PangoAttrColor *)attr)->color; | |
258 | if (fg_set) | |
259 | *fg_set = TRUE; | |
260 | ||
261 | break; | |
262 | ||
263 | case PANGO_ATTR_BACKGROUND: | |
264 | if (bg_color) | |
265 | *bg_color = ((PangoAttrColor *)attr)->color; | |
266 | if (bg_set) | |
267 | *bg_set = TRUE; | |
268 | ||
269 | break; | |
270 | ||
271 | case PANGO_ATTR_SHAPE: | |
272 | if (shape_set) | |
273 | *shape_set = TRUE; | |
274 | if (logical_rect) | |
275 | *logical_rect = ((PangoAttrShape *)attr)->logical_rect; | |
276 | if (ink_rect) | |
277 | *ink_rect = ((PangoAttrShape *)attr)->ink_rect; | |
278 | break; | |
279 | ||
280 | case PANGO_ATTR_RISE: | |
281 | if (rise) | |
282 | *rise = ((PangoAttrInt *)attr)->value; | |
283 | break; | |
284 | ||
285 | default: | |
286 | break; | |
287 | } | |
288 | tmp_list = tmp_list->next; | |
289 | } | |
290 | } | |
291 |