PageRenderTime 27ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/ExtLibs/wxWidgets/src/x11/pangox11.cpp

https://bitbucket.org/lennonchan/cafu
C++ | 277 lines | 221 code | 47 blank | 9 comment | 26 complexity | af1b7b146ac9e1f0312f75c9e39b61e7 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. void
  16. x11_draw_layout_line_with_colors( Drawable drawable,
  17. GC gc,
  18. int x,
  19. int y,
  20. PangoLayoutLine *line,
  21. XColor *foreground,
  22. XColor *background);
  23. void
  24. x11_draw_layout_with_colors( Drawable drawable,
  25. GC gc,
  26. int x,
  27. int y,
  28. PangoLayout *layout,
  29. XColor *foreground,
  30. XColor *background);
  31. void
  32. x11_draw_layout( Drawable drawable,
  33. GC gc,
  34. int x,
  35. int y,
  36. PangoLayout *layout);
  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. {
  58. if (PANGO_XFT_IS_FONT (font))
  59. {
  60. pango_xft_picture_render( wxGlobalDisplay(), drawable, drawable, font, glyphs, x, y );
  61. }
  62. else
  63. {
  64. pango_x_render( wxGlobalDisplay(), drawable, gc, font, glyphs, x, y );
  65. }
  66. }
  67. void
  68. x11_draw_layout_line_with_colors( Drawable drawable,
  69. GC gc,
  70. int x,
  71. int y,
  72. PangoLayoutLine *line,
  73. XColor *foreground,
  74. XColor *background)
  75. {
  76. PangoRectangle overall_rect;
  77. PangoRectangle logical_rect;
  78. PangoRectangle ink_rect;
  79. PangoContext *context;
  80. gint x_off = 0;
  81. gint rise = 0;
  82. context = pango_layout_get_context (line->layout);
  83. pango_layout_line_get_extents (line,NULL, &overall_rect);
  84. GSList *tmp_list = line->runs;
  85. while (tmp_list)
  86. {
  87. PangoUnderline uline = PANGO_UNDERLINE_NONE;
  88. PangoLayoutRun *run = (PangoLayoutRun *) tmp_list->data;
  89. PangoColor fg_color, bg_color;
  90. gboolean strike, fg_set, bg_set, shape_set;
  91. gint risen_y;
  92. tmp_list = tmp_list->next;
  93. x11_pango_get_item_properties (run->item, &uline,
  94. &strike, &rise, &fg_color, &fg_set, &bg_color, &bg_set,
  95. &shape_set, &ink_rect, &logical_rect);
  96. /* we subtract the rise because X coordinates are upside down */
  97. risen_y = y - rise / PANGO_SCALE;
  98. if (!shape_set)
  99. {
  100. if (uline == PANGO_UNDERLINE_NONE)
  101. pango_glyph_string_extents (run->glyphs, run->item->analysis.font, NULL, &logical_rect);
  102. else
  103. pango_glyph_string_extents (run->glyphs, run->item->analysis.font, &ink_rect, &logical_rect);
  104. }
  105. #if 0
  106. XDrawRectangle( drawable, gc, TRUE,
  107. x + (x_off + logical_rect.x) / PANGO_SCALE,
  108. risen_y + overall_rect.y / PANGO_SCALE,
  109. logical_rect.width / PANGO_SCALE,
  110. overall_rect.height / PANGO_SCALE);
  111. #endif
  112. if (!shape_set)
  113. {
  114. int gx = x + x_off / PANGO_SCALE;
  115. int gy = risen_y;
  116. x11_draw_glyphs( drawable, gc, run->item->analysis.font, gx, gy, run->glyphs);
  117. }
  118. if (uline == PANGO_UNDERLINE_SINGLE)
  119. {
  120. XDrawLine( wxGlobalDisplay(), drawable, gc,
  121. x + (x_off + ink_rect.x) / PANGO_SCALE - 1,
  122. risen_y + 1,
  123. x + (x_off + ink_rect.x + ink_rect.width) / PANGO_SCALE,
  124. risen_y + 1);
  125. }
  126. x_off += logical_rect.width;
  127. }
  128. }
  129. void
  130. x11_draw_layout_with_colors( Drawable drawable,
  131. GC gc,
  132. int x,
  133. int y,
  134. PangoLayout *layout,
  135. XColor *foreground,
  136. XColor *background)
  137. {
  138. PangoLayoutIter *iter = pango_layout_get_iter (layout);
  139. do
  140. {
  141. PangoLayoutLine *line = pango_layout_iter_get_line (iter);
  142. PangoRectangle logical_rect;
  143. pango_layout_iter_get_line_extents (iter, NULL, &logical_rect);
  144. int baseline = pango_layout_iter_get_baseline (iter);
  145. x11_draw_layout_line_with_colors( drawable, gc,
  146. x + logical_rect.x / PANGO_SCALE,
  147. y + baseline / PANGO_SCALE,
  148. line,
  149. foreground,
  150. background);
  151. } while (pango_layout_iter_next_line (iter));
  152. pango_layout_iter_free (iter);
  153. }
  154. void
  155. x11_draw_layout( Drawable drawable,
  156. GC gc,
  157. int x,
  158. int y,
  159. PangoLayout *layout)
  160. {
  161. wxCHECK_RET( layout, wxT("No layout") );
  162. x11_draw_layout_with_colors (drawable, gc, x, y, layout, NULL, NULL);
  163. }
  164. void
  165. x11_pango_get_item_properties( PangoItem *item,
  166. PangoUnderline *uline,
  167. gboolean *strikethrough,
  168. gint *rise,
  169. PangoColor *fg_color,
  170. gboolean *fg_set,
  171. PangoColor *bg_color,
  172. gboolean *bg_set,
  173. gboolean *shape_set,
  174. PangoRectangle *ink_rect,
  175. PangoRectangle *logical_rect)
  176. {
  177. GSList *tmp_list = item->analysis.extra_attrs;
  178. if (strikethrough)
  179. *strikethrough = FALSE;
  180. if (fg_set)
  181. *fg_set = FALSE;
  182. if (bg_set)
  183. *bg_set = FALSE;
  184. if (shape_set)
  185. *shape_set = FALSE;
  186. if (rise)
  187. *rise = 0;
  188. while (tmp_list)
  189. {
  190. PangoAttribute *attr = (PangoAttribute *) tmp_list->data;
  191. switch (attr->klass->type)
  192. {
  193. case PANGO_ATTR_UNDERLINE:
  194. if (uline)
  195. *uline = (PangoUnderline) ((PangoAttrInt *)attr)->value;
  196. break;
  197. case PANGO_ATTR_STRIKETHROUGH:
  198. if (strikethrough)
  199. *strikethrough = ((PangoAttrInt *)attr)->value;
  200. break;
  201. case PANGO_ATTR_FOREGROUND:
  202. if (fg_color)
  203. *fg_color = ((PangoAttrColor *)attr)->color;
  204. if (fg_set)
  205. *fg_set = TRUE;
  206. break;
  207. case PANGO_ATTR_BACKGROUND:
  208. if (bg_color)
  209. *bg_color = ((PangoAttrColor *)attr)->color;
  210. if (bg_set)
  211. *bg_set = TRUE;
  212. break;
  213. case PANGO_ATTR_SHAPE:
  214. if (shape_set)
  215. *shape_set = TRUE;
  216. if (logical_rect)
  217. *logical_rect = ((PangoAttrShape *)attr)->logical_rect;
  218. if (ink_rect)
  219. *ink_rect = ((PangoAttrShape *)attr)->ink_rect;
  220. break;
  221. case PANGO_ATTR_RISE:
  222. if (rise)
  223. *rise = ((PangoAttrInt *)attr)->value;
  224. break;
  225. default:
  226. break;
  227. }
  228. tmp_list = tmp_list->next;
  229. }
  230. }