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