cairo 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of cairo might be problematic. Click here for more details.

Files changed (207) hide show
  1. data/ChangeLog +153 -0
  2. data/NEWS +16 -2
  3. data/README +2 -0
  4. data/Rakefile +21 -7
  5. data/doc/doc.css +69 -0
  6. data/doc/en/cairo-antialias.html +27 -0
  7. data/doc/en/cairo-clip-not-representable-error.html +36 -0
  8. data/doc/en/cairo-color-base.html +58 -0
  9. data/doc/en/cairo-color-cmyk.html +146 -0
  10. data/doc/en/cairo-color-hsv.html +126 -0
  11. data/doc/en/cairo-color-rgb.html +131 -0
  12. data/doc/en/cairo-color-x11.html +162 -0
  13. data/doc/en/cairo-color.html +227 -0
  14. data/doc/en/cairo-content.html +26 -0
  15. data/doc/en/cairo-context-blur.html +28 -0
  16. data/doc/en/cairo-context-circle.html +28 -0
  17. data/doc/en/cairo-context-color.html +28 -0
  18. data/doc/en/cairo-context-path.html +33 -0
  19. data/doc/en/cairo-context-rectangle.html +28 -0
  20. data/doc/en/cairo-context-triangle.html +28 -0
  21. data/doc/en/cairo-context.html +622 -0
  22. data/doc/en/cairo-error.html +33 -0
  23. data/doc/en/cairo-extend.html +27 -0
  24. data/doc/en/cairo-file-not-found.html +36 -0
  25. data/doc/en/cairo-fill-rule.html +25 -0
  26. data/doc/en/cairo-filter.html +29 -0
  27. data/doc/en/cairo-font-extents.html +60 -0
  28. data/doc/en/cairo-font-face.html +27 -0
  29. data/doc/en/cairo-font-options.html +128 -0
  30. data/doc/en/cairo-font-slant.html +26 -0
  31. data/doc/en/cairo-font-weight.html +25 -0
  32. data/doc/en/cairo-format.html +35 -0
  33. data/doc/en/cairo-glyph.html +88 -0
  34. data/doc/en/cairo-gradient-pattern.html +63 -0
  35. data/doc/en/cairo-hint-metrics.html +26 -0
  36. data/doc/en/cairo-hint-style.html +28 -0
  37. data/doc/en/cairo-image-surface.html +71 -0
  38. data/doc/en/cairo-invalid-content-error.html +36 -0
  39. data/doc/en/cairo-invalid-dash-error.html +36 -0
  40. data/doc/en/cairo-invalid-dsc-comment-error.html +36 -0
  41. data/doc/en/cairo-invalid-format-error.html +36 -0
  42. data/doc/en/cairo-invalid-index-error.html +36 -0
  43. data/doc/en/cairo-invalid-matrix-error.html +36 -0
  44. data/doc/en/cairo-invalid-path-data-error.html +36 -0
  45. data/doc/en/cairo-invalid-pop-group-error.html +36 -0
  46. data/doc/en/cairo-invalid-restore-error.html +36 -0
  47. data/doc/en/cairo-invalid-status-error.html +36 -0
  48. data/doc/en/cairo-invalid-stride-error.html +36 -0
  49. data/doc/en/cairo-invalid-string-error.html +36 -0
  50. data/doc/en/cairo-invalid-visual-error.html +36 -0
  51. data/doc/en/cairo-line-cap.html +26 -0
  52. data/doc/en/cairo-line-join.html +26 -0
  53. data/doc/en/cairo-linear-pattern.html +49 -0
  54. data/doc/en/cairo-matrix.html +243 -0
  55. data/doc/en/cairo-no-current-point-error.html +36 -0
  56. data/doc/en/cairo-null-pointer-error.html +36 -0
  57. data/doc/en/cairo-operator.html +37 -0
  58. data/doc/en/cairo-paper-parse-error.html +36 -0
  59. data/doc/en/cairo-paper-unknown-paper-name.html +55 -0
  60. data/doc/en/cairo-paper-unknown-unit.html +55 -0
  61. data/doc/en/cairo-paper-unrecognized-paper-description.html +55 -0
  62. data/doc/en/cairo-paper.html +173 -0
  63. data/doc/en/cairo-path-close-path.html +38 -0
  64. data/doc/en/cairo-path-curve-to.html +38 -0
  65. data/doc/en/cairo-path-data-type.html +27 -0
  66. data/doc/en/cairo-path-data.html +87 -0
  67. data/doc/en/cairo-path-line-to.html +38 -0
  68. data/doc/en/cairo-path-move-to.html +38 -0
  69. data/doc/en/cairo-path.html +144 -0
  70. data/doc/en/cairo-pattern-type-mismatch-error.html +36 -0
  71. data/doc/en/cairo-pattern.html +88 -0
  72. data/doc/en/cairo-pdf-surface.html +46 -0
  73. data/doc/en/cairo-point.html +63 -0
  74. data/doc/en/cairo-ps-level.html +38 -0
  75. data/doc/en/cairo-ps-surface.html +81 -0
  76. data/doc/en/cairo-quartz-surface.html +38 -0
  77. data/doc/en/cairo-radial-pattern.html +49 -0
  78. data/doc/en/cairo-read-error.html +36 -0
  79. data/doc/en/cairo-rectangle.html +78 -0
  80. data/doc/en/cairo-scaled-font.html +73 -0
  81. data/doc/en/cairo-solid-pattern.html +51 -0
  82. data/doc/en/cairo-subpixel-order.html +28 -0
  83. data/doc/en/cairo-surface-finished-error.html +36 -0
  84. data/doc/en/cairo-surface-pattern.html +46 -0
  85. data/doc/en/cairo-surface-type-mismatch-error.html +36 -0
  86. data/doc/en/cairo-surface.html +100 -0
  87. data/doc/en/cairo-svg-surface.html +66 -0
  88. data/doc/en/cairo-svg-version.html +38 -0
  89. data/doc/en/cairo-temp-file-error.html +36 -0
  90. data/doc/en/cairo-text-extents.html +65 -0
  91. data/doc/en/cairo-win32-surface.html +43 -0
  92. data/doc/en/cairo-write-error.html +36 -0
  93. data/doc/en/cairo.html +109 -0
  94. data/doc/en/index.html +1058 -0
  95. data/doc/index.html +18 -0
  96. data/doc/ja/cairo-antialias.html +43 -0
  97. data/doc/ja/cairo-clip-not-representable-error.html +42 -0
  98. data/doc/ja/cairo-color-base.html +61 -0
  99. data/doc/ja/cairo-color-cmyk.html +138 -0
  100. data/doc/ja/cairo-color-hsv.html +121 -0
  101. data/doc/ja/cairo-color-rgb.html +131 -0
  102. data/doc/ja/cairo-color-x11.html +169 -0
  103. data/doc/ja/cairo-color.html +303 -0
  104. data/doc/ja/cairo-content.html +37 -0
  105. data/doc/ja/cairo-context-blur.html +39 -0
  106. data/doc/ja/cairo-context-circle.html +40 -0
  107. data/doc/ja/cairo-context-color.html +38 -0
  108. data/doc/ja/cairo-context-path.html +63 -0
  109. data/doc/ja/cairo-context-rectangle.html +46 -0
  110. data/doc/ja/cairo-context-triangle.html +33 -0
  111. data/doc/ja/cairo-context.html +1435 -0
  112. data/doc/ja/cairo-error.html +42 -0
  113. data/doc/ja/cairo-extend.html +42 -0
  114. data/doc/ja/cairo-file-not-found.html +37 -0
  115. data/doc/ja/cairo-fill-rule.html +44 -0
  116. data/doc/ja/cairo-filter.html +29 -0
  117. data/doc/ja/cairo-font-extents.html +96 -0
  118. data/doc/ja/cairo-font-face.html +41 -0
  119. data/doc/ja/cairo-font-options.html +172 -0
  120. data/doc/ja/cairo-font-slant.html +36 -0
  121. data/doc/ja/cairo-font-weight.html +33 -0
  122. data/doc/ja/cairo-format.html +67 -0
  123. data/doc/ja/cairo-glyph.html +101 -0
  124. data/doc/ja/cairo-gradient-pattern.html +105 -0
  125. data/doc/ja/cairo-hint-metrics.html +43 -0
  126. data/doc/ja/cairo-hint-style.html +50 -0
  127. data/doc/ja/cairo-image-surface.html +117 -0
  128. data/doc/ja/cairo-invalid-content-error.html +40 -0
  129. data/doc/ja/cairo-invalid-dash-error.html +40 -0
  130. data/doc/ja/cairo-invalid-dsc-comment-error.html +40 -0
  131. data/doc/ja/cairo-invalid-format-error.html +40 -0
  132. data/doc/ja/cairo-invalid-index-error.html +40 -0
  133. data/doc/ja/cairo-invalid-matrix-error.html +40 -0
  134. data/doc/ja/cairo-invalid-path-data-error.html +40 -0
  135. data/doc/ja/cairo-invalid-pop-group-error.html +40 -0
  136. data/doc/ja/cairo-invalid-restore-error.html +41 -0
  137. data/doc/ja/cairo-invalid-status-error.html +41 -0
  138. data/doc/ja/cairo-invalid-stride-error.html +41 -0
  139. data/doc/ja/cairo-invalid-string-error.html +40 -0
  140. data/doc/ja/cairo-invalid-visual-error.html +43 -0
  141. data/doc/ja/cairo-line-cap.html +36 -0
  142. data/doc/ja/cairo-line-join.html +39 -0
  143. data/doc/ja/cairo-linear-pattern.html +73 -0
  144. data/doc/ja/cairo-matrix.html +329 -0
  145. data/doc/ja/cairo-no-current-point-error.html +40 -0
  146. data/doc/ja/cairo-null-pointer-error.html +40 -0
  147. data/doc/ja/cairo-operator.html +37 -0
  148. data/doc/ja/cairo-paper-parse-error.html +41 -0
  149. data/doc/ja/cairo-paper-unknown-paper-name.html +62 -0
  150. data/doc/ja/cairo-paper-unknown-unit.html +61 -0
  151. data/doc/ja/cairo-paper-unrecognized-paper-description.html +62 -0
  152. data/doc/ja/cairo-paper.html +343 -0
  153. data/doc/ja/cairo-path-close-path.html +43 -0
  154. data/doc/ja/cairo-path-curve-to.html +56 -0
  155. data/doc/ja/cairo-path-data-type.html +39 -0
  156. data/doc/ja/cairo-path-data.html +113 -0
  157. data/doc/ja/cairo-path-line-to.html +48 -0
  158. data/doc/ja/cairo-path-move-to.html +48 -0
  159. data/doc/ja/cairo-path.html +130 -0
  160. data/doc/ja/cairo-pattern-type-mismatch-error.html +42 -0
  161. data/doc/ja/cairo-pattern.html +114 -0
  162. data/doc/ja/cairo-pdf-surface.html +72 -0
  163. data/doc/ja/cairo-point.html +76 -0
  164. data/doc/ja/cairo-ps-level.html +48 -0
  165. data/doc/ja/cairo-ps-surface.html +200 -0
  166. data/doc/ja/cairo-quartz-surface.html +78 -0
  167. data/doc/ja/cairo-radial-pattern.html +79 -0
  168. data/doc/ja/cairo-read-error.html +41 -0
  169. data/doc/ja/cairo-rectangle.html +95 -0
  170. data/doc/ja/cairo-scaled-font.html +130 -0
  171. data/doc/ja/cairo-solid-pattern.html +73 -0
  172. data/doc/ja/cairo-subpixel-order.html +43 -0
  173. data/doc/ja/cairo-surface-finished-error.html +40 -0
  174. data/doc/ja/cairo-surface-pattern.html +54 -0
  175. data/doc/ja/cairo-surface-type-mismatch-error.html +42 -0
  176. data/doc/ja/cairo-surface.html +177 -0
  177. data/doc/ja/cairo-svg-surface.html +100 -0
  178. data/doc/ja/cairo-svg-version.html +52 -0
  179. data/doc/ja/cairo-temp-file-error.html +36 -0
  180. data/doc/ja/cairo-text-extents.html +87 -0
  181. data/doc/ja/cairo-win32-surface.html +86 -0
  182. data/doc/ja/cairo-write-error.html +41 -0
  183. data/doc/ja/cairo.html +134 -0
  184. data/doc/ja/index.html +1059 -0
  185. data/extconf.rb +53 -17
  186. data/pkg-config.rb +197 -52
  187. data/samples/pac.rb +8 -9
  188. data/samples/pac2.rb +6 -6
  189. data/samples/png.rb +1 -2
  190. data/samples/text2.rb +9 -3
  191. data/src/cairo.def +6 -0
  192. data/src/lib/cairo.rb +35 -5
  193. data/src/lib/cairo/paper.rb +183 -0
  194. data/src/lib/cairo/papers.rb +41 -0
  195. data/src/rb_cairo.c +4 -3
  196. data/src/rb_cairo.h +18 -1
  197. data/src/rb_cairo_constants.c +124 -2
  198. data/src/rb_cairo_context.c +35 -5
  199. data/src/rb_cairo_exception.c +23 -1
  200. data/src/rb_cairo_font_options.c +1 -1
  201. data/src/rb_cairo_path.c +1 -14
  202. data/src/rb_cairo_surface.c +301 -82
  203. data/test/run-test.rb +15 -0
  204. data/test/test_paper.rb +81 -0
  205. data/test/test_pkg_config.rb +121 -0
  206. metadata +187 -3
  207. data/samples/.#blur.rb.1.1 +0 -36
@@ -3,7 +3,7 @@
3
3
  * Ruby Cairo Binding
4
4
  *
5
5
  * $Author: kou $
6
- * $Date: 2007/05/20 09:18:49 $
6
+ * $Date: 2008-04-04 04:25:16 $
7
7
  *
8
8
  * Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
9
9
  * Copyright 2004-2005 MenTaLguY <mental@rydia.com>
@@ -31,7 +31,8 @@ VALUE rb_mCairo_Content;
31
31
  VALUE rb_mCairo_Format;
32
32
  VALUE rb_mCairo_Extend;
33
33
  VALUE rb_mCairo_Filter;
34
- VALUE rb_mCairo_SVGVersion;
34
+ VALUE rb_mCairo_SVGVersion = Qnil;
35
+ VALUE rb_mCairo_PSLevel = Qnil;
35
36
 
36
37
  #define CAIRO_OPERATOR_MIN CAIRO_OPERATOR_CLEAR
37
38
  #define CAIRO_OPERATOR_MAX CAIRO_OPERATOR_SATURATE
@@ -81,6 +82,9 @@ VALUE rb_mCairo_SVGVersion;
81
82
  #define CAIRO_SVG_VERSION_MIN CAIRO_SVG_VERSION_1_1
82
83
  #define CAIRO_SVG_VERSION_MAX CAIRO_SVG_VERSION_1_2
83
84
 
85
+ #define CAIRO_PS_LEVEL_MIN CAIRO_PS_LEVEL_2
86
+ #define CAIRO_PS_LEVEL_MAX CAIRO_PS_LEVEL_3
87
+
84
88
  #define DEFINE_RVAL2ENUM(name, const_name) \
85
89
  cairo_ ## name ## _t \
86
90
  rb_cairo_ ## name ## _from_ruby_object (VALUE rb_ ## name) \
@@ -123,6 +127,102 @@ DEFINE_RVAL2ENUM(filter, FILTER)
123
127
  #if CAIRO_HAS_SVG_SURFACE
124
128
  DEFINE_RVAL2ENUM(svg_version, SVG_VERSION)
125
129
  #endif
130
+ #if CAIRO_HAS_PS_SURFACE && CAIRO_CHECK_VERSION(1, 5, 2)
131
+ DEFINE_RVAL2ENUM(ps_level, PS_LEVEL)
132
+ #else
133
+ # ifdef RB_CAIRO_PLATFORM_WIN32
134
+ void
135
+ rb_cairo_ps_level_from_ruby_object (VALUE rb_ps_level)
136
+ {
137
+ /* dummy */
138
+ }
139
+ # endif
140
+ #endif
141
+
142
+
143
+ #if CAIRO_HAS_SVG_SURFACE
144
+ static VALUE
145
+ cr_svg_get_versions (VALUE self)
146
+ {
147
+ VALUE rb_versions;
148
+ int i, num_versions;
149
+ cairo_svg_version_t const *versions;
150
+
151
+ cairo_svg_get_versions (&versions, &num_versions);
152
+
153
+ rb_versions = rb_ary_new2 (num_versions);
154
+
155
+ for (i = 0; i < num_versions; i++)
156
+ {
157
+ rb_ary_push (rb_versions, INT2NUM (versions[i]));
158
+ }
159
+
160
+ return rb_versions;
161
+ }
162
+
163
+ static VALUE
164
+ cr_svg_version_to_string (int argc, VALUE *argv, VALUE self)
165
+ {
166
+ if (argc == 0)
167
+ {
168
+ return rb_call_super (argc, argv);
169
+ }
170
+ else
171
+ {
172
+ VALUE version;
173
+ const char *ver_str;
174
+ rb_scan_args (argc, argv, "1", &version);
175
+ ver_str = cairo_svg_version_to_string (RVAL2CRSVGVERSION(version));
176
+ return rb_str_new2 (ver_str);
177
+ }
178
+ }
179
+ #endif
180
+
181
+ #if CAIRO_CHECK_VERSION(1, 5, 8)
182
+ static VALUE
183
+ cr_format_stride_for_width (VALUE self, VALUE format, VALUE width)
184
+ {
185
+ return INT2NUM (cairo_format_stride_for_width (RVAL2CRFORMAT (format),
186
+ NUM2INT (width)));
187
+ }
188
+ #endif
189
+
190
+ #if CAIRO_HAS_PS_SURFACE
191
+ # if CAIRO_CHECK_VERSION(1, 5, 8)
192
+ static VALUE
193
+ cr_ps_get_levels (VALUE self)
194
+ {
195
+ VALUE rb_levels;
196
+ const cairo_ps_level_t *levels;
197
+ int i, n_levels;
198
+
199
+ cairo_ps_get_levels (&levels, &n_levels);
200
+
201
+ rb_levels = rb_ary_new2 (n_levels);
202
+ for (i = 0; i < n_levels; i++)
203
+ {
204
+ rb_ary_push (rb_levels, INT2NUM (levels[i]));
205
+ }
206
+
207
+ return rb_levels;
208
+ }
209
+
210
+ static VALUE
211
+ cr_ps_level_to_string (int argc, VALUE *argv, VALUE self)
212
+ {
213
+ if (argc == 0)
214
+ {
215
+ return rb_call_super (argc, argv);
216
+ }
217
+ else
218
+ {
219
+ VALUE level;
220
+ rb_scan_args (argc, argv, "1", &level);
221
+ return rb_str_new2 (cairo_ps_level_to_string (RVAL2CRPSLEVEL (level)));
222
+ }
223
+ }
224
+ # endif
225
+ #endif
126
226
 
127
227
  void
128
228
  Init_cairo_constants (void)
@@ -295,6 +395,11 @@ Init_cairo_constants (void)
295
395
  INT2FIX (CAIRO_FORMAT_RGB16_565));
296
396
  #endif
297
397
 
398
+ #if CAIRO_CHECK_VERSION(1, 5, 8)
399
+ rb_define_singleton_method (rb_mCairo_Format, "stride_for_width",
400
+ cr_format_stride_for_width, 2);
401
+ #endif
402
+
298
403
 
299
404
  /* cairo_extend_t */
300
405
  rb_mCairo_Extend = rb_define_module_under (rb_mCairo, "Extend");
@@ -330,5 +435,22 @@ Init_cairo_constants (void)
330
435
  INT2FIX (CAIRO_SVG_VERSION_1_1));
331
436
  rb_define_const (rb_mCairo_SVGVersion, "VERSION_1_2",
332
437
  INT2FIX (CAIRO_SVG_VERSION_1_2));
438
+
439
+ rb_define_singleton_method (rb_mCairo_SVGVersion, "list",
440
+ cr_svg_get_versions, 0);
441
+ rb_define_singleton_method (rb_mCairo_SVGVersion, "name",
442
+ cr_svg_version_to_string, -1);
443
+ #endif
444
+
445
+ #if CAIRO_HAS_PS_SURFACE && CAIRO_CHECK_VERSION(1, 5, 2)
446
+ /* cairo_ps_level_t */
447
+ rb_mCairo_PSLevel = rb_define_module_under (rb_mCairo, "PSLevel");
448
+ rb_define_const (rb_mCairo_PSLevel, "LEVEL_2", INT2FIX (CAIRO_PS_LEVEL_2));
449
+ rb_define_const (rb_mCairo_PSLevel, "LEVEL_3", INT2FIX (CAIRO_PS_LEVEL_3));
450
+
451
+ rb_define_singleton_method (rb_mCairo_PSLevel, "list",
452
+ cr_ps_get_levels, 0);
453
+ rb_define_singleton_method (rb_mCairo_PSLevel, "name",
454
+ cr_ps_level_to_string, -1);
333
455
  #endif
334
456
  }
@@ -3,7 +3,7 @@
3
3
  * Ruby Cairo Binding
4
4
  *
5
5
  * $Author: kou $
6
- * $Date: 2007-12-29 11:42:26 $
6
+ * $Date: 2008-03-25 13:43:50 $
7
7
  *
8
8
  * Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
9
9
  * Copyright 2004-2005 MenTaLguY <mental@rydia.com>
@@ -22,12 +22,12 @@ static ID cr_id_plus, cr_id_minus, cr_id_multi, cr_id_div;
22
22
 
23
23
  #define _SELF (RVAL2CRCONTEXT(self))
24
24
 
25
+ static VALUE cr_get_current_point (VALUE self);
26
+
25
27
  #if CAIRO_CHECK_VERSION(1, 3, 0)
26
28
  static VALUE rb_cCairo_Rectangle;
27
29
  static ID at_x, at_y, at_width, at_height;
28
30
 
29
- static VALUE cr_get_current_point (VALUE self);
30
-
31
31
  static VALUE
32
32
  cr_rectangle_initialize (VALUE self, VALUE x, VALUE y,
33
33
  VALUE width, VALUE height)
@@ -97,7 +97,7 @@ cr_initialize (VALUE self, VALUE target)
97
97
  cr = cairo_create (RVAL2CRSURFACE (target));
98
98
  cr_check_status (cr);
99
99
  rb_ivar_set (self, cr_id_surface, target);
100
- DATA_PTR(self) = cr;
100
+ DATA_PTR (self) = cr;
101
101
  return Qnil;
102
102
  }
103
103
 
@@ -738,6 +738,19 @@ cr_close_path (VALUE self)
738
738
  return self;
739
739
  }
740
740
 
741
+ #if CAIRO_CHECK_VERSION(1, 5, 8)
742
+ static VALUE
743
+ cr_path_extents (VALUE self)
744
+ {
745
+ double x1, y1, x2, y2;
746
+ cairo_path_extents (_SELF, &x1, &y1, &x2, &y2);
747
+ cr_check_status (_SELF);
748
+ return rb_ary_new3 (4,
749
+ rb_float_new(x1), rb_float_new(y1),
750
+ rb_float_new(x2), rb_float_new(y2));
751
+ }
752
+ #endif
753
+
741
754
  /* Painting functions */
742
755
  static VALUE
743
756
  cr_paint (VALUE self)
@@ -1216,9 +1229,17 @@ cr_get_tolerance (VALUE self)
1216
1229
  static VALUE
1217
1230
  cr_get_antialias(VALUE self)
1218
1231
  {
1219
- return INT2NUM (cairo_get_antialias(_SELF));
1232
+ return INT2NUM (cairo_get_antialias (_SELF));
1220
1233
  }
1221
1234
 
1235
+ #if CAIRO_CHECK_VERSION(1, 5, 10)
1236
+ static VALUE
1237
+ cr_has_current_point(VALUE self)
1238
+ {
1239
+ return RTEST (cairo_has_current_point (_SELF));
1240
+ }
1241
+ #endif
1242
+
1222
1243
  static VALUE
1223
1244
  cr_get_current_point (VALUE self)
1224
1245
  {
@@ -1438,6 +1459,9 @@ Init_cairo_context (void)
1438
1459
  cr_rel_curve_to_generic, -1);
1439
1460
  rb_define_method (rb_cCairo_Context, "rectangle", cr_rectangle, 4);
1440
1461
  rb_define_method (rb_cCairo_Context, "close_path", cr_close_path, 0);
1462
+ #if CAIRO_CHECK_VERSION(1, 5, 8)
1463
+ rb_define_method (rb_cCairo_Context, "path_extents", cr_path_extents, 0);
1464
+ #endif
1441
1465
 
1442
1466
  /* Painting functions */
1443
1467
  rb_define_method (rb_cCairo_Context, "paint", cr_paint_generic, -1);
@@ -1494,6 +1518,12 @@ Init_cairo_context (void)
1494
1518
  rb_define_method (rb_cCairo_Context, "source", cr_get_source, 0);
1495
1519
  rb_define_method (rb_cCairo_Context, "tolerance", cr_get_tolerance, 0);
1496
1520
  rb_define_method (rb_cCairo_Context, "antialias", cr_get_antialias, 0);
1521
+ #if CAIRO_CHECK_VERSION(1, 5, 10)
1522
+ rb_define_method (rb_cCairo_Context, "have_current_point?",
1523
+ cr_has_current_point, 0);
1524
+ rb_define_alias (rb_cCairo_Context,
1525
+ "has_current_point?", "have_current_point?");
1526
+ #endif
1497
1527
  rb_define_method (rb_cCairo_Context, "current_point",
1498
1528
  cr_get_current_point, 0);
1499
1529
  rb_define_method (rb_cCairo_Context, "fill_rule", cr_get_fill_rule, 0);
@@ -3,7 +3,7 @@
3
3
  * Ruby Cairo Binding
4
4
  *
5
5
  * $Author: kou $
6
- * $Date: 2007/03/06 12:17:34 $
6
+ * $Date: 2008-02-21 13:18:10 $
7
7
  *
8
8
  * Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
9
9
  * Copyright 2004-2005 MenTaLguY <mental@rydia.com>
@@ -37,6 +37,10 @@ static VALUE rb_eCairo_InvalidDscCommentError;
37
37
  static VALUE rb_eCairo_InvalidIndexError;
38
38
  static VALUE rb_eCairo_ClipNotRepresentableError;
39
39
  #endif
40
+ #if CAIRO_CHECK_VERSION(1, 5, 6)
41
+ static VALUE rb_eCairo_TempFileError;
42
+ static VALUE rb_eCairo_InvalidStrideError;
43
+ #endif
40
44
 
41
45
  void
42
46
  rb_cairo_check_status (cairo_status_t status)
@@ -114,6 +118,14 @@ rb_cairo_check_status (cairo_status_t status)
114
118
  case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE:
115
119
  rb_raise (rb_eCairo_ClipNotRepresentableError, string);
116
120
  break;
121
+ #endif
122
+ #if CAIRO_CHECK_VERSION(1, 5, 6)
123
+ case CAIRO_STATUS_TEMP_FILE_ERROR:
124
+ rb_raise (rb_eCairo_TempFileError, string);
125
+ break;
126
+ case CAIRO_STATUS_INVALID_STRIDE:
127
+ rb_raise (rb_eCairo_InvalidStringError, string);
128
+ break;
117
129
  #endif
118
130
  }
119
131
  }
@@ -189,4 +201,14 @@ Init_cairo_exception ()
189
201
  rb_define_class_under (rb_mCairo, "ClipNotRepresentableError",
190
202
  rb_eCairo_Error);
191
203
  #endif
204
+
205
+ #if CAIRO_CHECK_VERSION(1, 5, 6)
206
+ rb_eCairo_TempFileError =
207
+ rb_define_class_under (rb_mCairo, "TempFileError",
208
+ rb_eCairo_Error);
209
+
210
+ rb_eCairo_InvalidStrideError =
211
+ rb_define_class_under (rb_mCairo, "InvalidStrideError",
212
+ rb_eArgError);
213
+ #endif
192
214
  }
@@ -3,7 +3,7 @@
3
3
  * Ruby Cairo Binding
4
4
  *
5
5
  * $Author: kou $
6
- * $Date: 2007/05/26 15:13:25 $
6
+ * $Date: 2007-05-26 15:13:25 $
7
7
  *
8
8
  * Copyright 2005 Kouhei Sutou <kou@cozmixng.org>
9
9
  *
@@ -3,7 +3,7 @@
3
3
  * Ruby Cairo Binding
4
4
  *
5
5
  * $Author: kou $
6
- * $Date: 2007/05/22 11:41:45 $
6
+ * $Date: 2008-04-04 03:52:31 $
7
7
  *
8
8
  * Copyright 2005 Kouhei Sutou <kou@cozmixng.org>
9
9
  *
@@ -132,19 +132,6 @@ cr_path_data_to_ruby_object (cairo_path_data_t *data)
132
132
  }
133
133
 
134
134
  return rb_data;
135
-
136
- int i;
137
- VALUE points;
138
-
139
- points = rb_ary_new ();
140
- for (i = 1; i < data->header.length; i++)
141
- {
142
- rb_ary_push (points, cr_point_new (rb_float_new (data[i].point.x),
143
- rb_float_new (data[i].point.y)));
144
- }
145
-
146
- return rb_funcall (rb_cCairo_PathData, id_new, 2,
147
- INT2FIX (data->header.type), points);
148
135
  }
149
136
 
150
137
 
@@ -3,7 +3,7 @@
3
3
  * Ruby Cairo Binding
4
4
  *
5
5
  * $Author: kou $
6
- * $Date: 2008-01-11 12:19:44 $
6
+ * $Date: 2008-04-11 11:07:10 $
7
7
  *
8
8
  * Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
9
9
  * Copyright 2004-2005 MenTaLguY <mental@rydia.com>
@@ -30,15 +30,38 @@ VALUE rb_cCairo_PDFSurface = Qnil;
30
30
  VALUE rb_cCairo_PSSurface = Qnil;
31
31
  VALUE rb_cCairo_SVGSurface = Qnil;
32
32
  VALUE rb_cCairo_Win32Surface = Qnil;
33
+ VALUE rb_cCairo_Win32PrintingSurface = Qnil;
33
34
  VALUE rb_cCairo_QuartzSurface = Qnil;
35
+ VALUE rb_cCairo_QuartzImageSurface = Qnil;
34
36
 
35
37
  static ID cr_id_target;
36
38
  static ID cr_id_read;
37
39
  static ID cr_id_write;
40
+ static ID cr_id_inspect;
41
+ static ID cr_id_parse;
42
+ static ID cr_id_size;
43
+ static ID cr_id_set_unit;
38
44
  static cairo_user_data_key_t cr_closure_key;
39
45
 
40
46
  #define _SELF (RVAL2CRSURFACE(self))
41
47
 
48
+ static VALUE
49
+ cr_paper_parse (VALUE paper_description)
50
+ {
51
+ return rb_funcall (rb_cCairo_Paper, cr_id_parse, 2, paper_description, Qtrue);
52
+ }
53
+
54
+ static void
55
+ cr_paper_to_size_in_points (VALUE paper_description, VALUE *width, VALUE *height)
56
+ {
57
+ VALUE paper, size;
58
+
59
+ paper = cr_paper_parse (paper_description);
60
+ size = rb_funcall (paper, cr_id_size, 1, rb_str_new2 ("pt"));
61
+ *width = RARRAY_PTR (size)[0];
62
+ *height = RARRAY_PTR (size)[1];
63
+ }
64
+
42
65
  static inline void
43
66
  cr_surface_check_status (cairo_surface_t *surface)
44
67
  {
@@ -63,20 +86,44 @@ cr_surface_get_klass (cairo_surface_t *surface)
63
86
  case CAIRO_SURFACE_TYPE_PS:
64
87
  klass = rb_cCairo_PSSurface;
65
88
  break;
66
- case CAIRO_SURFACE_TYPE_SVG:
67
- klass = rb_cCairo_SVGSurface;
89
+ case CAIRO_SURFACE_TYPE_QUARTZ:
90
+ klass = rb_cCairo_QuartzSurface;
68
91
  break;
69
92
  case CAIRO_SURFACE_TYPE_WIN32:
70
93
  klass = rb_cCairo_Win32Surface;
71
94
  break;
95
+ case CAIRO_SURFACE_TYPE_SVG:
96
+ klass = rb_cCairo_SVGSurface;
97
+ break;
98
+ #if CAIRO_CHECK_VERSION(1, 5, 2)
99
+ case CAIRO_SURFACE_TYPE_WIN32_PRINTING:
100
+ klass = rb_cCairo_Win32PrintingSurface;
101
+ break;
102
+ #endif
103
+ #if CAIRO_CHECK_VERSION(1, 5, 12)
104
+ case CAIRO_SURFACE_TYPE_QUARTZ_IMAGE:
105
+ klass = rb_cCairo_QuartzImageSurface;
106
+ break;
107
+ #endif
72
108
  default:
73
109
  rb_raise (rb_eArgError, "unknown source type: %d", type);
74
110
  break;
75
111
  }
76
112
 
113
+ if (NIL_P (klass))
114
+ rb_raise (rb_eArgError, "unknown source type: %d", type);
115
+
77
116
  return klass;
78
117
  }
79
118
 
119
+ static char *
120
+ inspect (VALUE object)
121
+ {
122
+ VALUE inspected;
123
+ inspected = rb_funcall (object, cr_id_inspect, 0);
124
+ return StringValueCStr(inspected);
125
+ }
126
+
80
127
  /* read/write callback */
81
128
  typedef struct cr_io_callback_closure {
82
129
  VALUE target;
@@ -248,6 +295,16 @@ rb_cairo_surface_to_ruby_object (cairo_surface_t *surface)
248
295
  }
249
296
  }
250
297
 
298
+ VALUE
299
+ rb_cairo_surface_to_ruby_object_with_destroy (cairo_surface_t *surface)
300
+ {
301
+ VALUE rb_surface;
302
+ rb_surface = rb_cairo_surface_to_ruby_object (surface);
303
+ if (surface)
304
+ cairo_surface_destroy (surface);
305
+ return rb_surface;
306
+ }
307
+
251
308
  static VALUE
252
309
  cr_surface_allocate (VALUE klass)
253
310
  {
@@ -275,8 +332,7 @@ yield_and_finish (VALUE self)
275
332
  }
276
333
 
277
334
  static VALUE
278
- cr_surface_create_similar (VALUE self, VALUE content,
279
- VALUE width, VALUE height)
335
+ cr_surface_create_similar (VALUE self, VALUE content, VALUE width, VALUE height)
280
336
  {
281
337
  cairo_surface_t *surface;
282
338
 
@@ -284,7 +340,7 @@ cr_surface_create_similar (VALUE self, VALUE content,
284
340
  RVAL2CRCONTENT (content),
285
341
  NUM2INT (width), NUM2INT (height));
286
342
  cr_surface_check_status (surface);
287
- return CRSURFACE2RVAL (surface);
343
+ return CRSURFACE2RVAL_WITH_DESTROY (surface);
288
344
  }
289
345
 
290
346
  static VALUE
@@ -385,8 +441,18 @@ cr_surface_mark_dirty (int argc, VALUE *argv, VALUE self)
385
441
  }
386
442
  else
387
443
  {
444
+ int i;
445
+ VALUE args;
446
+
447
+ args = rb_ary_new2 (n);
448
+ for (i = 0; i < n; i++)
449
+ {
450
+ rb_ary_push (args, argv[i]);
451
+ }
452
+
388
453
  rb_raise (rb_eArgError,
389
- "invalid argument (expect () or (x, y, width, height))");
454
+ "invalid argument (expect () or (x, y, width, height)): %s",
455
+ inspect (args));
390
456
  }
391
457
 
392
458
  cr_surface_check_status (_SELF);
@@ -425,6 +491,23 @@ cr_surface_set_fallback_resolution (VALUE self,
425
491
  return self;
426
492
  }
427
493
 
494
+ #if CAIRO_CHECK_VERSION(1, 5, 2)
495
+ static VALUE
496
+ cr_surface_copy_page (VALUE self)
497
+ {
498
+ cairo_surface_copy_page (_SELF);
499
+ cr_surface_check_status (_SELF);
500
+ return self;
501
+ }
502
+
503
+ static VALUE
504
+ cr_surface_show_page (VALUE self)
505
+ {
506
+ cairo_surface_show_page (_SELF);
507
+ cr_surface_check_status (_SELF);
508
+ return self;
509
+ }
510
+ #endif
428
511
 
429
512
  /* Image-surface functions */
430
513
  #if CAIRO_HAS_PNG_FUNCTIONS
@@ -469,7 +552,6 @@ cr_image_surface_create_from_png_generic (VALUE klass, VALUE target)
469
552
  }
470
553
  #endif
471
554
 
472
-
473
555
  static cairo_surface_t *
474
556
  cr_image_surface_create (VALUE self, VALUE format, VALUE width, VALUE height)
475
557
  {
@@ -516,7 +598,8 @@ cr_image_surface_initialize (int argc, VALUE *argv, VALUE self)
516
598
  "invalid argument (expect "
517
599
  "(width, height) or "
518
600
  "(format, width, height) or "
519
- "(data, format, width, height, stride))");
601
+ "(data, format, width, height, stride)): %s",
602
+ inspect (rb_ary_new3 (4, arg1, arg2, arg3, arg4)));
520
603
 
521
604
  cr_surface_check_status (surface);
522
605
  DATA_PTR (self) = surface;
@@ -570,13 +653,29 @@ cr_image_surface_get_stride (VALUE self)
570
653
  /* Printing surfaces */
571
654
  #define DEFINE_SURFACE(type) \
572
655
  static VALUE \
573
- cr_ ## type ## _surface_initialize (VALUE self, VALUE target, \
574
- VALUE rb_width_in_points, \
575
- VALUE rb_height_in_points) \
656
+ cr_ ## type ## _surface_initialize (int argc, VALUE *argv, VALUE self) \
576
657
  { \
658
+ VALUE target, rb_width_in_points, rb_height_in_points; \
659
+ VALUE arg2, arg3; \
577
660
  cairo_surface_t *surface; \
578
661
  double width_in_points, height_in_points; \
579
662
  \
663
+ rb_scan_args (argc, argv, "21", &target, &arg2, &arg3); \
664
+ if (argc == 2) \
665
+ { \
666
+ VALUE paper; \
667
+ \
668
+ paper = arg2; \
669
+ cr_paper_to_size_in_points (paper, \
670
+ &rb_width_in_points, \
671
+ &rb_height_in_points); \
672
+ } \
673
+ else \
674
+ { \
675
+ rb_width_in_points = arg2; \
676
+ rb_height_in_points = arg3; \
677
+ } \
678
+ \
580
679
  width_in_points = NUM2DBL (rb_width_in_points); \
581
680
  height_in_points = NUM2DBL (rb_height_in_points); \
582
681
  \
@@ -618,22 +717,40 @@ cr_ ## type ## _surface_initialize (VALUE self, VALUE target, \
618
717
  return Qnil; \
619
718
  }
620
719
 
720
+ #define DEFINE_SURFACE_SET_SIZE(type) \
721
+ static VALUE \
722
+ cr_ ## type ## _surface_set_size (int argc, VALUE *argv, VALUE self) \
723
+ { \
724
+ VALUE arg1, arg2; \
725
+ VALUE width_in_points, height_in_points; \
726
+ \
727
+ rb_scan_args(argc, argv, "11", &arg1, &arg2); \
728
+ if (argc == 1) \
729
+ { \
730
+ VALUE paper; \
731
+ \
732
+ paper = arg1; \
733
+ cr_paper_to_size_in_points (paper, \
734
+ &width_in_points, \
735
+ &height_in_points); \
736
+ } \
737
+ else \
738
+ { \
739
+ width_in_points = arg1; \
740
+ height_in_points = arg2; \
741
+ } \
742
+ \
743
+ cairo_ ## type ## _surface_set_size (_SELF, \
744
+ NUM2DBL (width_in_points), \
745
+ NUM2DBL (height_in_points)); \
746
+ cr_surface_check_status (_SELF); \
747
+ return Qnil; \
748
+ }
621
749
 
622
750
  #if CAIRO_HAS_PS_SURFACE
623
751
  /* PS-surface functions */
624
752
  DEFINE_SURFACE(ps)
625
-
626
- static VALUE
627
- cr_ps_surface_set_size (VALUE self,
628
- VALUE width_in_points,
629
- VALUE height_in_points)
630
- {
631
- cairo_ps_surface_set_size (_SELF,
632
- NUM2DBL (width_in_points),
633
- NUM2DBL (height_in_points));
634
- cr_surface_check_status (_SELF);
635
- return Qnil;
636
- }
753
+ DEFINE_SURFACE_SET_SIZE(ps)
637
754
 
638
755
  static VALUE
639
756
  cr_ps_surface_dsc_comment (VALUE self, VALUE comment)
@@ -664,23 +781,36 @@ cr_ps_surface_dsc_begin_page_setup (VALUE self)
664
781
  else
665
782
  return Qnil;
666
783
  }
667
- #endif
668
784
 
669
- #if CAIRO_HAS_PDF_SURFACE
670
- /* PDF-surface functions */
671
- DEFINE_SURFACE(pdf)
785
+ # if CAIRO_CHECK_VERSION(1, 5, 2)
786
+ static VALUE
787
+ cr_ps_surface_restrict_to_level (VALUE self, VALUE level)
788
+ {
789
+ cairo_ps_surface_restrict_to_level (_SELF, RVAL2CRPSLEVEL (level));
790
+ cr_surface_check_status (_SELF);
791
+ return Qnil;
792
+ }
793
+
794
+ static VALUE
795
+ cr_ps_surface_get_eps (VALUE self)
796
+ {
797
+ return cairo_ps_surface_get_eps (_SELF) ? Qtrue : Qfalse;
798
+ }
672
799
 
673
800
  static VALUE
674
- cr_pdf_surface_set_size (VALUE self,
675
- VALUE width_in_points,
676
- VALUE height_in_points)
801
+ cr_ps_surface_set_eps (VALUE self, VALUE eps)
677
802
  {
678
- cairo_pdf_surface_set_size (_SELF,
679
- NUM2DBL (width_in_points),
680
- NUM2DBL (height_in_points));
803
+ cairo_ps_surface_set_eps (_SELF, RTEST (eps));
681
804
  cr_surface_check_status (_SELF);
682
805
  return Qnil;
683
806
  }
807
+ # endif
808
+ #endif
809
+
810
+ #if CAIRO_HAS_PDF_SURFACE
811
+ /* PDF-surface functions */
812
+ DEFINE_SURFACE(pdf)
813
+ DEFINE_SURFACE_SET_SIZE(pdf)
684
814
  #endif
685
815
 
686
816
  #if CAIRO_HAS_SVG_SURFACE
@@ -694,33 +824,6 @@ cr_svg_surface_restrict_to_version (VALUE self, VALUE version)
694
824
  cr_surface_check_status (_SELF);
695
825
  return Qnil;
696
826
  }
697
-
698
- static VALUE
699
- cr_svg_get_versions (VALUE self)
700
- {
701
- VALUE rb_versions;
702
- int i, num_versions;
703
- cairo_svg_version_t const *versions;
704
-
705
- cairo_svg_get_versions (&versions, &num_versions);
706
-
707
- rb_versions = rb_ary_new2 (num_versions);
708
-
709
- for (i = 0; i < num_versions; i++)
710
- {
711
- rb_ary_push (rb_versions, INT2NUM (versions[i]));
712
- }
713
-
714
- return rb_versions;
715
- }
716
-
717
- static VALUE
718
- cr_svg_version_to_string (VALUE self, VALUE version)
719
- {
720
- const char *ver_str;
721
- ver_str = cairo_svg_version_to_string (RVAL2CRSVGVERSION(version));
722
- return rb_str_new2 (ver_str);
723
- }
724
827
  #endif
725
828
 
726
829
  #if CAIRO_HAS_WIN32_SURFACE
@@ -762,14 +865,21 @@ cr_win32_surface_initialize (int argc, VALUE *argv, VALUE self)
762
865
  (rb_cairo__is_kind_of (arg1, rb_cNumeric) &&
763
866
  NUM2INT (arg1) != CAIRO_FORMAT_RGB24))
764
867
  {
868
+ # if CAIRO_CHECK_VERSION(1, 4, 0)
869
+ HDC win32_hdc;
765
870
  hdc = arg1;
766
871
  width = arg2;
767
872
  height = arg3;
768
- HDC win32_hdc = NIL_P (hdc) ? NULL : NUM2PTR (hdc);
873
+ win32_hdc = NIL_P (hdc) ? NULL : NUM2PTR (hdc);
769
874
  surface = cairo_win32_surface_create_with_ddb (win32_hdc,
770
875
  CAIRO_FORMAT_RGB24,
771
876
  NUM2INT (width),
772
877
  NUM2INT (height));
878
+ # else
879
+ rb_raise (rb_eArgError,
880
+ "Cairo::Win32Surface.new(hdc, width, height) "
881
+ "is available since cairo >= 1.4.0");
882
+ # endif
773
883
  }
774
884
  else
775
885
  {
@@ -783,6 +893,7 @@ cr_win32_surface_initialize (int argc, VALUE *argv, VALUE self)
783
893
  break;
784
894
  case 4:
785
895
  {
896
+ # if CAIRO_CHECK_VERSION(1, 4, 0)
786
897
  HDC win32_hdc;
787
898
  hdc = arg1;
788
899
  format = arg2;
@@ -793,6 +904,11 @@ cr_win32_surface_initialize (int argc, VALUE *argv, VALUE self)
793
904
  RVAL2CRFORMAT (format),
794
905
  NUM2INT (width),
795
906
  NUM2INT (height));
907
+ # else
908
+ rb_raise (rb_eArgError,
909
+ "Cairo::Win32Surface.new(hdc, format, width, height) "
910
+ "is available since cairo >= 1.4.0");
911
+ # endif
796
912
  }
797
913
  break;
798
914
  }
@@ -806,6 +922,21 @@ cr_win32_surface_initialize (int argc, VALUE *argv, VALUE self)
806
922
  return Qnil;
807
923
  }
808
924
 
925
+ # if CAIRO_CHECK_VERSION(1, 5, 2)
926
+ static VALUE
927
+ cr_win32_printing_surface_initialize (VALUE self, VALUE hdc)
928
+ {
929
+ cairo_surface_t *surface = NULL;
930
+
931
+ surface = cairo_win32_printing_surface_create (NUM2PTR (hdc));
932
+ cr_surface_check_status (surface);
933
+ DATA_PTR (self) = surface;
934
+ if (rb_block_given_p ())
935
+ yield_and_finish (self);
936
+ return Qnil;
937
+ }
938
+ # endif
939
+
809
940
  static VALUE
810
941
  cr_win32_surface_get_hdc (VALUE self)
811
942
  {
@@ -818,6 +949,7 @@ cr_win32_surface_get_hdc (VALUE self)
818
949
  return PTR2NUM (hdc);
819
950
  }
820
951
 
952
+ # if CAIRO_CHECK_VERSION(1, 4, 0)
821
953
  static VALUE
822
954
  cr_win32_surface_get_image (VALUE self)
823
955
  {
@@ -826,19 +958,19 @@ cr_win32_surface_get_image (VALUE self)
826
958
  surface = cairo_win32_surface_get_image (_SELF);
827
959
  if (!surface)
828
960
  return Qnil;
829
- rb_cairo_check_status (cairo_surface_status (surface));
961
+ cr_surface_check_status (surface);
830
962
  return CRSURFACE2RVAL (surface);
831
963
  }
964
+ # endif
832
965
  #endif
833
966
 
834
- #if CAIRO_HAS_QUARTZ_SURFACE
967
+ #if CAIRO_HAS_QUARTZ_SURFACE && defined(HAVE_RUBY_COCOA)
835
968
  /* Quartz-surface functions */
836
969
 
837
970
  #include <objc/objc-runtime.h>
838
971
 
839
- VALUE ocobj_s_new (id ocid);
840
- id rbobj_get_ocid (VALUE obj);
841
-
972
+ BOOL rbobj_to_nsobj (VALUE obj, id* nsobj);
973
+ VALUE ocid_to_rbobj (VALUE context_obj, id ocid);
842
974
 
843
975
  static VALUE
844
976
  cr_quartz_surface_initialize (int argc, VALUE *argv, VALUE self)
@@ -849,6 +981,7 @@ cr_quartz_surface_initialize (int argc, VALUE *argv, VALUE self)
849
981
  cairo_surface_t *surface = NULL;
850
982
  cairo_format_t format = CAIRO_FORMAT_ARGB32;
851
983
  VALUE arg1, arg2, arg3, rb_width, rb_height;
984
+ static VALUE rb_cOSXCGContextRef = Qnil;
852
985
 
853
986
  rb_scan_args (argc, argv, "21", &arg1, &arg2, &arg3);
854
987
 
@@ -859,9 +992,32 @@ cr_quartz_surface_initialize (int argc, VALUE *argv, VALUE self)
859
992
  }
860
993
  else
861
994
  {
862
- objc_object = rbobj_get_ocid (arg1);
863
- if (objc_object == nil)
864
- format = RVAL2CRFORMAT (arg1);
995
+ switch (TYPE (arg1))
996
+ {
997
+ case T_NIL:
998
+ break;
999
+ case T_STRING:
1000
+ case T_SYMBOL:
1001
+ case T_FIXNUM:
1002
+ format = RVAL2CRFORMAT (arg1);
1003
+ break;
1004
+ default:
1005
+ if (NIL_P (rb_cOSXCGContextRef))
1006
+ rb_cOSXCGContextRef =
1007
+ rb_const_get (rb_const_get (rb_cObject, rb_intern ("OSX")),
1008
+ rb_intern ("CGContextRef"));
1009
+
1010
+ if (RTEST (rb_obj_is_kind_of (arg1, rb_cOSXCGContextRef)))
1011
+ rbobj_to_nsobj (arg1, &objc_object);
1012
+ else
1013
+ rb_raise (rb_eArgError,
1014
+ "invalid argument (expect "
1015
+ "(width, height), "
1016
+ "(format, width, height) or "
1017
+ "(cg_context, width, height)): %s",
1018
+ inspect (rb_ary_new3 (3, arg1, arg2, arg3)));
1019
+ break;
1020
+ }
865
1021
 
866
1022
  rb_width = arg2;
867
1023
  rb_height = arg3;
@@ -896,8 +1052,35 @@ cr_quartz_surface_get_cg_context (VALUE self)
896
1052
 
897
1053
  context = cairo_quartz_surface_get_cg_context (_SELF);
898
1054
  objc_object = (id)context;
899
- return ocobj_s_new (objc_object);
1055
+ return ocid_to_rbobj (Qnil, objc_object);
1056
+ }
1057
+
1058
+ # if CAIRO_CHECK_VERSION(1, 5, 12)
1059
+ static VALUE
1060
+ cr_quartz_image_surface_initialize (VALUE self, VALUE image_surface)
1061
+ {
1062
+ cairo_surface_t *surface;
1063
+
1064
+ surface = cairo_quartz_image_surface_create (RVAL2CRSURFACE (image_surface));
1065
+ cr_surface_check_status (surface);
1066
+ DATA_PTR (self) = surface;
1067
+ if (rb_block_given_p ())
1068
+ yield_and_finish (self);
1069
+ return Qnil;
1070
+ }
1071
+
1072
+ static VALUE
1073
+ cr_quartz_image_surface_get_image (VALUE self)
1074
+ {
1075
+ cairo_surface_t *surface;
1076
+
1077
+ surface = cairo_quartz_image_surface_get_image (_SELF);
1078
+ if (!surface)
1079
+ return Qnil;
1080
+ cr_surface_check_status (surface);
1081
+ return CRSURFACE2RVAL (surface);
900
1082
  }
1083
+ # endif
901
1084
  #endif
902
1085
 
903
1086
 
@@ -907,7 +1090,11 @@ Init_cairo_surface (void)
907
1090
  cr_id_target = rb_intern ("target");
908
1091
  cr_id_read = rb_intern ("read");
909
1092
  cr_id_write = rb_intern ("write");
910
-
1093
+ cr_id_inspect = rb_intern ("inspect");
1094
+ cr_id_parse = rb_intern ("parse");
1095
+ cr_id_size = rb_intern ("size");
1096
+ cr_id_set_unit = rb_intern ("unit=");
1097
+
911
1098
  rb_cCairo_Surface =
912
1099
  rb_define_class_under (rb_mCairo, "Surface", rb_cObject);
913
1100
  rb_define_alloc_func (rb_cCairo_Surface, cr_surface_allocate);
@@ -920,13 +1107,19 @@ Init_cairo_surface (void)
920
1107
  rb_define_method (rb_cCairo_Surface, "font_options",
921
1108
  cr_surface_get_font_options, 0);
922
1109
  rb_define_method (rb_cCairo_Surface, "flush", cr_surface_flush, 0);
923
- rb_define_method (rb_cCairo_Surface, "mark_dirty", cr_surface_mark_dirty, 0);
1110
+ rb_define_method (rb_cCairo_Surface, "mark_dirty", cr_surface_mark_dirty, -1);
924
1111
  rb_define_method (rb_cCairo_Surface, "set_device_offset",
925
1112
  cr_surface_set_device_offset, 2);
926
1113
  rb_define_method (rb_cCairo_Surface, "device_offset",
927
1114
  cr_surface_get_device_offset, 0);
928
1115
  rb_define_method (rb_cCairo_Surface, "set_fallback_resolution",
929
1116
  cr_surface_set_fallback_resolution, 2);
1117
+ #if CAIRO_CHECK_VERSION(1, 5, 2)
1118
+ rb_define_method (rb_cCairo_Surface, "copy_page",
1119
+ cr_surface_copy_page, 2);
1120
+ rb_define_method (rb_cCairo_Surface, "show_page",
1121
+ cr_surface_show_page, 2);
1122
+ #endif
930
1123
 
931
1124
  #if CAIRO_HAS_PNG_FUNCTIONS
932
1125
  rb_define_method (rb_cCairo_Surface, "write_to_png",
@@ -964,13 +1157,13 @@ Init_cairo_surface (void)
964
1157
  rb_cCairo_Surface); \
965
1158
  \
966
1159
  rb_define_method (rb_cCairo_ ## name ## Surface, "initialize", \
967
- cr_ ## type ## _surface_initialize, 3);
1160
+ cr_ ## type ## _surface_initialize, -1);
968
1161
 
969
1162
  #if CAIRO_HAS_PS_SURFACE
970
1163
  /* PS-surface */
971
1164
  INIT_SURFACE(ps, PS)
972
1165
 
973
- rb_define_method (rb_cCairo_PSSurface, "set_size", cr_ps_surface_set_size, 2);
1166
+ rb_define_method (rb_cCairo_PSSurface, "set_size", cr_ps_surface_set_size, -1);
974
1167
  rb_define_method (rb_cCairo_PSSurface, "dsc_comment",
975
1168
  cr_ps_surface_dsc_comment, 1);
976
1169
  rb_define_method (rb_cCairo_PSSurface, "dsc_begin_setup",
@@ -978,6 +1171,13 @@ Init_cairo_surface (void)
978
1171
  rb_define_method (rb_cCairo_PSSurface, "dsc_begin_page_setup",
979
1172
  cr_ps_surface_dsc_begin_page_setup, 0);
980
1173
 
1174
+ #if CAIRO_CHECK_VERSION(1, 5, 2)
1175
+ rb_define_method (rb_cCairo_PSSurface, "restrict_to_level",
1176
+ cr_ps_surface_restrict_to_level, 1);
1177
+ rb_define_method (rb_cCairo_PSSurface, "eps?", cr_ps_surface_get_eps, 0);
1178
+ rb_define_method (rb_cCairo_PSSurface, "set_eps", cr_ps_surface_set_eps, 1);
1179
+ #endif
1180
+
981
1181
  RB_CAIRO_DEF_SETTERS (rb_cCairo_PSSurface);
982
1182
  #endif
983
1183
 
@@ -986,7 +1186,7 @@ Init_cairo_surface (void)
986
1186
  INIT_SURFACE(pdf, PDF)
987
1187
 
988
1188
  rb_define_method (rb_cCairo_PDFSurface, "set_size",
989
- cr_pdf_surface_set_size, 2);
1189
+ cr_pdf_surface_set_size, -1);
990
1190
 
991
1191
  RB_CAIRO_DEF_SETTERS (rb_cCairo_PDFSurface);
992
1192
  #endif
@@ -995,11 +1195,6 @@ Init_cairo_surface (void)
995
1195
  /* SVG-surface */
996
1196
  INIT_SURFACE(svg, SVG)
997
1197
 
998
- rb_define_singleton_method (rb_cCairo_SVGSurface, "versions",
999
- cr_svg_get_versions, 0);
1000
- rb_define_singleton_method (rb_cCairo_SVGSurface, "version_to_string",
1001
- cr_svg_version_to_string, 1);
1002
-
1003
1198
  rb_define_method (rb_cCairo_SVGSurface, "restrict_to_version",
1004
1199
  cr_svg_surface_restrict_to_version, 1);
1005
1200
 
@@ -1015,11 +1210,24 @@ Init_cairo_surface (void)
1015
1210
  cr_win32_surface_initialize, -1);
1016
1211
  rb_define_method (rb_cCairo_Win32Surface, "hdc",
1017
1212
  cr_win32_surface_get_hdc, 0);
1213
+ # if CAIRO_CHECK_VERSION(1, 4, 0)
1018
1214
  rb_define_method (rb_cCairo_Win32Surface, "image",
1019
1215
  cr_win32_surface_get_image, 0);
1216
+ # endif
1217
+
1218
+ # if CAIRO_CHECK_VERSION(1, 5, 2)
1219
+ rb_cCairo_Win32PrintingSurface =
1220
+ rb_define_class_under (rb_mCairo, "Win32PrintingSurface", rb_cCairo_Surface);
1221
+
1222
+ rb_define_method (rb_cCairo_Win32PrintingSurface, "initialize",
1223
+ cr_win32_printing_surface_initialize, -1);
1224
+ rb_define_method (rb_cCairo_Win32PrintingSurface, "hdc",
1225
+ cr_win32_surface_get_hdc, 0);
1226
+ # endif
1227
+
1020
1228
  #endif
1021
1229
 
1022
- #if CAIRO_HAS_QUARTZ_SURFACE
1230
+ #if CAIRO_HAS_QUARTZ_SURFACE && defined(HAVE_RUBY_COCOA)
1023
1231
  /* Quartz-surface */
1024
1232
 
1025
1233
  rb_cCairo_QuartzSurface =
@@ -1029,5 +1237,16 @@ Init_cairo_surface (void)
1029
1237
  cr_quartz_surface_initialize, -1);
1030
1238
  rb_define_method (rb_cCairo_QuartzSurface, "cg_context",
1031
1239
  cr_quartz_surface_get_cg_context, 0);
1240
+
1241
+ # if CAIRO_CHECK_VERSION(1, 5, 12)
1242
+ rb_cCairo_QuartzImageSurface =
1243
+ rb_define_class_under (rb_mCairo, "QuartzImageSurface", rb_cCairo_Surface);
1244
+
1245
+ rb_define_method (rb_cCairo_QuartzImageSurface, "initialize",
1246
+ cr_quartz_image_surface_initialize, 1);
1247
+ rb_define_method (rb_cCairo_Win32PrintingSurface, "hdc",
1248
+ cr_quartz_image_surfaceE_get_image, 0);
1249
+ # endif
1250
+
1032
1251
  #endif
1033
1252
  }