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