/pango/ext/pango/rbpangocairo.c

https://github.com/geoffyoungs/ruby-gnome2 · C · 215 lines · 165 code · 31 blank · 19 comment · 1 complexity · 2cad5e03c8bbe7f0796e67a1685eefbf MD5 · raw file

  1. /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
  2. /************************************************
  3. rbpangocairo.c -
  4. $Author: ktou $
  5. $Date: 2007/08/13 11:10:22 $
  6. Copyright (C) 2005 Kouhei Sutou
  7. Copyright (C) 2006 Ruby-GNOME2 Project Team
  8. ************************************************/
  9. #include "rbpango.h"
  10. #if PANGO_CHECK_VERSION(1,10,0) && defined(HAVE_RB_CAIRO_H)
  11. # define CAIRO_AVAILABLE 1
  12. #endif
  13. #ifdef CAIRO_AVAILABLE
  14. #define _SELF(self) (PANGO_CAIRO_FONT_MAP(RVAL2GOBJ(self)))
  15. #define RVAL2CONTEXT(v) (PANGO_CONTEXT(RVAL2GOBJ(v)))
  16. #define RVAL2LAYOUT(v) (PANGO_LAYOUT(RVAL2GOBJ(v)))
  17. #define RVAL2FONT(v) (PANGO_FONT(RVAL2GOBJ(v)))
  18. #define RVAL2GLYPH(v) ((PangoGlyphString*)(RVAL2BOXED(self, PANGO_TYPE_GLYPH_STRING)))
  19. #define RVAL2LINE(v) ((PangoLayoutLine*)RVAL2BOXED(v, PANGO_TYPE_LAYOUT_LINE))
  20. static VALUE
  21. font_map_create(VALUE klass)
  22. {
  23. return GOBJ2RVAL(pango_cairo_font_map_new());
  24. }
  25. static VALUE
  26. font_map_get_default(VALUE klass)
  27. {
  28. return GOBJ2RVAL(pango_cairo_font_map_get_default());
  29. }
  30. static VALUE
  31. font_map_set_resolution(VALUE self, VALUE dpi)
  32. {
  33. pango_cairo_font_map_set_resolution(_SELF(self), NUM2DBL(dpi));
  34. return self;
  35. }
  36. static VALUE
  37. font_map_get_resolution(VALUE self)
  38. {
  39. return rb_float_new(pango_cairo_font_map_get_resolution(_SELF(self)));
  40. }
  41. static VALUE
  42. font_map_create_context(VALUE self)
  43. {
  44. return GOBJ2RVAL_UNREF(pango_cairo_font_map_create_context(_SELF(self)));
  45. }
  46. static VALUE
  47. update_context(VALUE self, VALUE context)
  48. {
  49. pango_cairo_update_context(RVAL2CRCONTEXT(self), RVAL2CONTEXT(context));
  50. return self;
  51. }
  52. /* Convenience */
  53. static VALUE
  54. create_layout(VALUE self)
  55. {
  56. return GOBJ2RVAL_UNREF(pango_cairo_create_layout(RVAL2CRCONTEXT(self)));
  57. }
  58. static VALUE
  59. update_layout(VALUE self, VALUE layout)
  60. {
  61. pango_cairo_update_layout(RVAL2CRCONTEXT(self), RVAL2LAYOUT(layout));
  62. return self;
  63. }
  64. /* Rendering */
  65. static VALUE
  66. show_glyph_string(VALUE self, VALUE font, VALUE glyphs)
  67. {
  68. pango_cairo_show_glyph_string(RVAL2CRCONTEXT(self),
  69. RVAL2FONT(font),
  70. RVAL2GLYPH(glyphs));
  71. return self;
  72. }
  73. static VALUE
  74. show_layout_line(VALUE self, VALUE line)
  75. {
  76. pango_cairo_show_layout_line(RVAL2CRCONTEXT(self), RVAL2LINE(line));
  77. return self;
  78. }
  79. static VALUE
  80. show_layout(VALUE self, VALUE layout)
  81. {
  82. pango_cairo_show_layout(RVAL2CRCONTEXT(self), RVAL2LAYOUT(layout));
  83. return self;
  84. }
  85. #if PANGO_CHECK_VERSION(1,14,0)
  86. static VALUE
  87. show_error_underline(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
  88. {
  89. pango_cairo_show_error_underline(RVAL2CRCONTEXT(self),
  90. NUM2DBL(x), NUM2DBL(y),
  91. NUM2DBL(width), NUM2DBL(height));
  92. return self;
  93. }
  94. #endif
  95. /* Rendering to a path */
  96. static VALUE
  97. glyph_string_path(VALUE self, VALUE font, VALUE glyphs)
  98. {
  99. pango_cairo_glyph_string_path(RVAL2CRCONTEXT(self),
  100. RVAL2FONT(font),
  101. RVAL2GLYPH(glyphs));
  102. return self;
  103. }
  104. static VALUE
  105. layout_line_path(VALUE self, VALUE line)
  106. {
  107. pango_cairo_layout_line_path(RVAL2CRCONTEXT(self), RVAL2LINE(line));
  108. return self;
  109. }
  110. static VALUE
  111. layout_path(VALUE self, VALUE layout)
  112. {
  113. pango_cairo_layout_path(RVAL2CRCONTEXT(self), RVAL2LAYOUT(layout));
  114. return self;
  115. }
  116. #if PANGO_CHECK_VERSION(1,14,0)
  117. static VALUE
  118. error_underline_path(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
  119. {
  120. pango_cairo_error_underline_path(RVAL2CRCONTEXT(self),
  121. NUM2DBL(x), NUM2DBL(y),
  122. NUM2DBL(width), NUM2DBL(height));
  123. return self;
  124. }
  125. #endif
  126. #endif
  127. static VALUE
  128. cairo_available_p(VALUE self)
  129. {
  130. #if CAIRO_AVAILABLE
  131. return Qtrue;
  132. #else
  133. return Qfalse;
  134. #endif
  135. }
  136. void
  137. Init_pango_cairo()
  138. {
  139. #ifdef CAIRO_AVAILABLE
  140. VALUE pFontMap;
  141. /* Pango::CairoFontMap */
  142. pFontMap = G_DEF_CLASS(PANGO_TYPE_CAIRO_FONT_MAP, "CairoFontMap", mPango);
  143. rb_define_singleton_method(pFontMap, "create", font_map_create, 0);
  144. rb_define_singleton_method(pFontMap, "default", font_map_get_default, 0);
  145. rb_define_method(pFontMap, "set_resolution", font_map_set_resolution, 1);
  146. rb_define_method(pFontMap, "resolution", font_map_get_resolution, 0);
  147. rb_define_method(pFontMap, "create_context", font_map_create_context, 0);
  148. G_DEF_SETTERS(pFontMap);
  149. /* Cairo::Context */
  150. rb_define_method(rb_cCairo_Context, "update_pango_context",
  151. update_context, 1);
  152. /* Convenience */
  153. rb_define_method(rb_cCairo_Context, "create_pango_layout",
  154. create_layout, 0);
  155. rb_define_method(rb_cCairo_Context, "update_pango_layout",
  156. update_layout, 1);
  157. /* Rendering */
  158. rb_define_method(rb_cCairo_Context, "show_pango_glyph_string",
  159. show_glyph_string, 2);
  160. rb_define_method(rb_cCairo_Context, "show_pango_layout_line",
  161. show_layout_line, 1);
  162. rb_define_method(rb_cCairo_Context, "show_pango_layout",
  163. show_layout, 1);
  164. #if PANGO_CHECK_VERSION(1,14,0)
  165. rb_define_method(rb_cCairo_Context, "show_pango_error_underline",
  166. show_error_underline, 4);
  167. #endif
  168. /* Rendering to a path */
  169. rb_define_method(rb_cCairo_Context, "pango_glyph_string_path",
  170. glyph_string_path, 2);
  171. rb_define_method(rb_cCairo_Context, "pango_layout_line_path",
  172. layout_line_path, 1);
  173. rb_define_method(rb_cCairo_Context, "pango_layout_path",
  174. layout_path, 1);
  175. #if PANGO_CHECK_VERSION(1,14,0)
  176. rb_define_method(rb_cCairo_Context, "pango_error_underline_path",
  177. error_underline_path, 4);
  178. #endif
  179. #endif
  180. rb_define_module_function(mPango, "cairo_available?", cairo_available_p, 0);
  181. }