| 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 | * Licence: The wxWindows licence |
| 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 | |
| 18 | void |
| 19 | x11_draw_layout_line_with_colors( Drawable drawable, |
| 20 | GC gc, |
| 21 | int x, |
| 22 | int y, |
| 23 | PangoLayoutLine *line, |
| 24 | XColor *foreground, |
| 25 | XColor *background); |
| 26 | |
| 27 | void |
| 28 | x11_draw_layout_with_colors( Drawable drawable, |
| 29 | GC gc, |
| 30 | int x, |
| 31 | int y, |
| 32 | PangoLayout *layout, |
| 33 | XColor *foreground, |
| 34 | XColor *background); |
| 35 | |
| 36 | void |
| 37 | x11_draw_layout( Drawable drawable, |
| 38 | GC gc, |
| 39 | int x, |
| 40 | int y, |
| 41 | PangoLayout *layout); |
| 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 | { |
| 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 | |
| 76 | void |
| 77 | x11_draw_layout_line_with_colors( Drawable drawable, |
| 78 | GC gc, |
| 79 | int x, |
| 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); |
| 93 | |
| 94 | pango_layout_line_get_extents (line,NULL, &overall_rect); |
| 95 | |
| 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; |
| 104 | |
| 105 | tmp_list = tmp_list->next; |
| 106 | |
| 107 | x11_pango_get_item_properties (run->item, &uline, |
| 108 | &strike, &rise, &fg_color, &fg_set, &bg_color, &bg_set, |
| 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; |
| 113 | |
| 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; |
| 134 | |
| 135 | x11_draw_glyphs( drawable, gc, run->item->analysis.font, gx, gy, run->glyphs); |
| 136 | } |
| 137 | |
| 138 | if (uline == PANGO_UNDERLINE_SINGLE) |
| 139 | { |
| 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 | |
| 151 | void |
| 152 | x11_draw_layout_with_colors( Drawable drawable, |
| 153 | GC gc, |
| 154 | int x, |
| 155 | int y, |
| 156 | PangoLayout *layout, |
| 157 | XColor *foreground, |
| 158 | XColor *background) |
| 159 | { |
| 160 | PangoLayoutIter *iter = pango_layout_get_iter (layout); |
| 161 | |
| 162 | do |
| 163 | { |
| 164 | PangoLayoutLine *line = pango_layout_iter_get_line (iter); |
| 165 | |
| 166 | PangoRectangle logical_rect; |
| 167 | pango_layout_iter_get_line_extents (iter, NULL, &logical_rect); |
| 168 | |
| 169 | int baseline = pango_layout_iter_get_baseline (iter); |
| 170 | |
| 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); |
| 177 | |
| 178 | } while (pango_layout_iter_next_line (iter)); |
| 179 | |
| 180 | pango_layout_iter_free (iter); |
| 181 | } |
| 182 | |
| 183 | void |
| 184 | x11_draw_layout( Drawable drawable, |
| 185 | GC gc, |
| 186 | int x, |
| 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 | |
| 195 | void |
| 196 | x11_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; |
| 212 | |
| 213 | if (fg_set) |
| 214 | *fg_set = FALSE; |
| 215 | |
| 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; |
| 240 | |
| 241 | case PANGO_ATTR_FOREGROUND: |
| 242 | if (fg_color) |
| 243 | *fg_color = ((PangoAttrColor *)attr)->color; |
| 244 | if (fg_set) |
| 245 | *fg_set = TRUE; |
| 246 | |
| 247 | break; |
| 248 | |
| 249 | case PANGO_ATTR_BACKGROUND: |
| 250 | if (bg_color) |
| 251 | *bg_color = ((PangoAttrColor *)attr)->color; |
| 252 | if (bg_set) |
| 253 | *bg_set = TRUE; |
| 254 | |
| 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; |
| 270 | |
| 271 | default: |
| 272 | break; |
| 273 | } |
| 274 | tmp_list = tmp_list->next; |
| 275 | } |
| 276 | } |
| 277 | |