PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/ExtLibs/wxWidgets/src/x11/pango_x.cpp

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