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