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