cairo 1.4.1 → 1.5.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.

@@ -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: 2007/05/20 09:18:49 $
7
7
  *
8
8
  * Copyright 2005 Kouhei Sutou <kou@cozmixng.org>
9
9
  *
@@ -29,7 +29,7 @@ cairo_scaled_font_t *
29
29
  rb_cairo_scaled_font_from_ruby_object (VALUE obj)
30
30
  {
31
31
  cairo_scaled_font_t *font;
32
- if (!RTEST (rb_obj_is_kind_of (obj, rb_cCairo_ScaledFont)))
32
+ if (!rb_cairo__is_kind_of (obj, rb_cCairo_ScaledFont))
33
33
  {
34
34
  rb_raise (rb_eTypeError, "not a cairo scaled font");
35
35
  }
@@ -82,12 +82,6 @@ cr_scaled_font_initialize (VALUE self, VALUE face, VALUE matrix,
82
82
  return Qnil;
83
83
  }
84
84
 
85
- static VALUE
86
- cr_scaled_font_get_type (VALUE self)
87
- {
88
- return INT2NUM (cairo_scaled_font_get_type ( _SELF (self)));
89
- }
90
-
91
85
  static VALUE
92
86
  cr_scaled_font_extents (VALUE self)
93
87
  {
@@ -114,7 +108,7 @@ cr_scaled_font_glyph_extents (VALUE self, VALUE rb_glyphs)
114
108
  cairo_glyph_t *glyphs;
115
109
  int count;
116
110
 
117
- rb_cairo__glyphs_to_array (rb_glyphs, &glyphs, &count);
111
+ RB_CAIRO__GLYPHS_TO_ARRAY (rb_glyphs, glyphs, count);
118
112
  cairo_scaled_font_glyph_extents (_SELF (self), glyphs, count, &extents);
119
113
  cr_scaled_font_check_status (_SELF (self));
120
114
  return CRTEXTEXTENTS2RVAL (&extents);
@@ -168,7 +162,6 @@ Init_cairo_scaled_font (void)
168
162
  rb_define_method (rb_cCairo_ScaledFont, "initialize",
169
163
  cr_scaled_font_initialize, 4);
170
164
 
171
- rb_define_method (rb_cCairo_ScaledFont, "type", cr_scaled_font_get_type, 0);
172
165
  rb_define_method (rb_cCairo_ScaledFont, "extents", cr_scaled_font_extents, 0);
173
166
  rb_define_method (rb_cCairo_ScaledFont, "text_extents",
174
167
  cr_scaled_font_text_extents, 1);
@@ -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: 2007/05/20 23:31:57 $
7
7
  *
8
8
  * Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
9
9
  * Copyright 2004-2005 MenTaLguY <mental@rydia.com>
@@ -29,11 +29,11 @@ VALUE rb_cCairo_ImageSurface;
29
29
  VALUE rb_cCairo_PDFSurface;
30
30
  VALUE rb_cCairo_PSSurface;
31
31
  VALUE rb_cCairo_SVGSurface;
32
+ VALUE rb_cCairo_WIN32Surface;
32
33
 
33
34
  static ID cr_id_target;
34
35
  static ID cr_id_read;
35
36
  static ID cr_id_write;
36
- static cairo_user_data_key_t cr_klass_key;
37
37
  static cairo_user_data_key_t cr_closure_key;
38
38
 
39
39
  #define _SELF (RVAL2CRSURFACE(self))
@@ -44,43 +44,33 @@ cr_surface_check_status (cairo_surface_t *surface)
44
44
  rb_cairo_check_status (cairo_surface_status (surface));
45
45
  }
46
46
 
47
- static void
48
- cr_surface_set_klass (cairo_surface_t *surface, VALUE klass)
49
- {
50
- cairo_status_t status;
51
- status = cairo_surface_set_user_data (surface, &cr_klass_key,
52
- (void *)klass, NULL);
53
- rb_cairo_check_status (status);
54
- }
55
-
56
47
  static VALUE
57
48
  cr_surface_get_klass (cairo_surface_t *surface)
58
49
  {
59
50
  VALUE klass;
60
- void *data = cairo_surface_get_user_data (surface, &cr_klass_key);
51
+ cairo_surface_type_t type;
61
52
 
62
- if (data)
63
- klass = (VALUE) data;
64
- else
53
+ type = cairo_surface_get_type (surface);
54
+ switch (type)
65
55
  {
66
- switch (cairo_surface_get_type (surface))
67
- {
68
- case CAIRO_SURFACE_TYPE_IMAGE:
69
- klass = rb_cCairo_ImageSurface;
70
- break;
71
- case CAIRO_SURFACE_TYPE_PDF:
72
- klass = rb_cCairo_PDFSurface;
73
- break;
74
- case CAIRO_SURFACE_TYPE_PS:
75
- klass = rb_cCairo_PSSurface;
76
- break;
77
- case CAIRO_SURFACE_TYPE_SVG:
78
- klass = rb_cCairo_SVGSurface;
79
- break;
80
- default:
81
- klass = rb_cCairo_Surface;
82
- break;
83
- }
56
+ case CAIRO_SURFACE_TYPE_IMAGE:
57
+ klass = rb_cCairo_ImageSurface;
58
+ break;
59
+ case CAIRO_SURFACE_TYPE_PDF:
60
+ klass = rb_cCairo_PDFSurface;
61
+ break;
62
+ case CAIRO_SURFACE_TYPE_PS:
63
+ klass = rb_cCairo_PSSurface;
64
+ break;
65
+ case CAIRO_SURFACE_TYPE_SVG:
66
+ klass = rb_cCairo_SVGSurface;
67
+ break;
68
+ case CAIRO_SURFACE_TYPE_WIN32:
69
+ klass = rb_cCairo_WIN32Surface;
70
+ break;
71
+ default:
72
+ rb_raise (rb_eArgError, "unknown source type: %d", type);
73
+ break;
84
74
  }
85
75
 
86
76
  return klass;
@@ -224,12 +214,11 @@ cairo_surface_t *
224
214
  rb_cairo_surface_from_ruby_object (VALUE obj)
225
215
  {
226
216
  cairo_surface_t *surface;
227
- if (!RTEST (rb_obj_is_kind_of (obj, rb_cCairo_Surface)))
217
+ if (!rb_cairo__is_kind_of (obj, rb_cCairo_Surface))
228
218
  {
229
219
  rb_raise (rb_eTypeError, "not a cairo surface");
230
220
  }
231
221
  Data_Get_Struct (obj, cairo_surface_t, surface);
232
- cr_surface_set_klass (surface, rb_obj_class (obj));
233
222
  return surface;
234
223
  }
235
224
 
@@ -247,7 +236,8 @@ rb_cairo_surface_to_ruby_object (cairo_surface_t *surface)
247
236
  {
248
237
  if (surface)
249
238
  {
250
- VALUE klass = cr_surface_get_klass (surface);
239
+ VALUE klass;
240
+ klass = cr_surface_get_klass (surface);
251
241
  cairo_surface_reference (surface);
252
242
  return Data_Wrap_Struct (klass, NULL, cr_surface_free, surface);
253
243
  }
@@ -264,6 +254,25 @@ cr_surface_allocate (VALUE klass)
264
254
  }
265
255
 
266
256
  /* Surface manipulation */
257
+ static void
258
+ yield_and_finish (VALUE self)
259
+ {
260
+ cairo_surface_t *surface;
261
+ cairo_status_t status;
262
+
263
+ rb_yield (self);
264
+
265
+ surface = _SELF;
266
+ if (cairo_surface_status (surface))
267
+ return;
268
+ cairo_surface_finish (surface);
269
+ status = cairo_surface_status (surface);
270
+ if (status == CAIRO_STATUS_SUCCESS || status == CAIRO_STATUS_SURFACE_FINISHED)
271
+ return;
272
+
273
+ cr_surface_check_status (surface);
274
+ }
275
+
267
276
  static VALUE
268
277
  cr_surface_create_similar (VALUE self, VALUE content,
269
278
  VALUE width, VALUE height)
@@ -274,7 +283,6 @@ cr_surface_create_similar (VALUE self, VALUE content,
274
283
  RVAL2CRCONTENT (content),
275
284
  NUM2INT (width), NUM2INT (height));
276
285
  cr_surface_check_status (surface);
277
- cr_surface_set_klass (surface, rb_obj_class (self));
278
286
  return CRSURFACE2RVAL (surface);
279
287
  }
280
288
 
@@ -293,12 +301,6 @@ cr_surface_finish (VALUE self)
293
301
  return self;
294
302
  }
295
303
 
296
- static VALUE
297
- cr_surface_get_type (VALUE self)
298
- {
299
- return INT2NUM (cairo_surface_get_type (_SELF));
300
- }
301
-
302
304
  static VALUE
303
305
  cr_surface_get_content (VALUE self)
304
306
  {
@@ -460,7 +462,6 @@ cr_image_surface_create_from_png_generic (VALUE klass, VALUE target)
460
462
  surface = cr_image_surface_create_from_png (target);
461
463
 
462
464
  cr_surface_check_status (surface);
463
- cr_surface_set_klass (surface, klass);
464
465
  rb_surface = cr_surface_allocate (klass);
465
466
  DATA_PTR (rb_surface) = surface;
466
467
  return rb_surface;
@@ -518,6 +519,8 @@ cr_image_surface_initialize (int argc, VALUE *argv, VALUE self)
518
519
 
519
520
  cr_surface_check_status (surface);
520
521
  DATA_PTR (self) = surface;
522
+ if (rb_block_given_p ())
523
+ yield_and_finish (self);
521
524
  return Qnil;
522
525
  }
523
526
 
@@ -609,6 +612,8 @@ cr_ ## type ## _surface_initialize (VALUE self, VALUE target, \
609
612
  \
610
613
  cr_surface_check_status (surface); \
611
614
  DATA_PTR (self) = surface; \
615
+ if (rb_block_given_p ()) \
616
+ yield_and_finish (self); \
612
617
  return Qnil; \
613
618
  }
614
619
 
@@ -717,6 +722,114 @@ cr_svg_version_to_string (VALUE self, VALUE version)
717
722
  }
718
723
  #endif
719
724
 
725
+ #if CAIRO_HAS_WIN32_SURFACE
726
+ /* WIN32-surface functions */
727
+
728
+ /* from dl/dl.h (ruby 1.9) */
729
+ #if SIZEOF_LONG == SIZEOF_VOIDP
730
+ # define PTR2NUM(x) (ULONG2NUM((unsigned long)(x)))
731
+ # define NUM2PTR(x) ((void *)(NUM2ULONG(x)))
732
+ #else
733
+ # define PTR2NUM(x) (ULL2NUM((unsigned long long)(x)))
734
+ # define NUM2PTR(x) ((void *)(NUM2ULL(x)))
735
+ #endif
736
+
737
+ static VALUE
738
+ cr_win32_surface_initialize (int argc, VALUE *argv, VALUE self)
739
+ {
740
+ cairo_surface_t *surface = NULL;
741
+ VALUE arg1, arg2, arg3, arg4;
742
+ VALUE hdc, format, width, height;
743
+
744
+ rb_scan_args (argc, argv, "13", &arg1, &arg2, &arg3, &arg4);
745
+
746
+ switch (argc)
747
+ {
748
+ case 1:
749
+ hdc = arg1;
750
+ surface = cairo_win32_surface_create (NUM2PTR (hdc));
751
+ break;
752
+ case 2:
753
+ width = arg1;
754
+ height = arg2;
755
+ surface = cairo_win32_surface_create_with_dib (CAIRO_FORMAT_ARGB32,
756
+ NUM2INT (width),
757
+ NUM2INT (height));
758
+ break;
759
+ case 3:
760
+ if (NIL_P (arg1) ||
761
+ (rb_cairo__is_kind_of (arg1, rb_cNumeric) &&
762
+ NUM2INT (arg1) != CAIRO_FORMAT_RGB24))
763
+ {
764
+ hdc = arg1;
765
+ width = arg2;
766
+ height = arg3;
767
+ HDC win32_hdc = NIL_P (hdc) ? NULL : NUM2PTR (hdc);
768
+ surface = cairo_win32_surface_create_with_ddb (win32_hdc,
769
+ CAIRO_FORMAT_RGB24,
770
+ NUM2INT (width),
771
+ NUM2INT (height));
772
+ }
773
+ else
774
+ {
775
+ format = arg1;
776
+ width = arg2;
777
+ height = arg3;
778
+ surface = cairo_win32_surface_create_with_dib (RVAL2CRFORMAT (format),
779
+ NUM2INT (width),
780
+ NUM2INT (height));
781
+ }
782
+ break;
783
+ case 4:
784
+ {
785
+ HDC win32_hdc;
786
+ hdc = arg1;
787
+ format = arg2;
788
+ width = arg3;
789
+ height = arg4;
790
+ win32_hdc = NIL_P (hdc) ? NULL : (HDC) NUM2UINT (hdc);
791
+ surface = cairo_win32_surface_create_with_ddb (win32_hdc,
792
+ RVAL2CRFORMAT (format),
793
+ NUM2INT (width),
794
+ NUM2INT (height));
795
+ }
796
+ break;
797
+ }
798
+
799
+ if (!surface)
800
+ rb_cairo_check_status (CAIRO_STATUS_INVALID_FORMAT);
801
+ cr_surface_check_status (surface);
802
+ DATA_PTR (self) = surface;
803
+ if (rb_block_given_p ())
804
+ yield_and_finish (self);
805
+ return Qnil;
806
+ }
807
+
808
+ static VALUE
809
+ cr_win32_surface_get_hdc (VALUE self)
810
+ {
811
+ HDC hdc;
812
+
813
+ hdc = cairo_win32_surface_get_dc (_SELF);
814
+ if (!hdc)
815
+ return Qnil;
816
+ else
817
+ return PTR2NUM (hdc);
818
+ }
819
+
820
+ static VALUE
821
+ cr_win32_surface_get_image (VALUE self)
822
+ {
823
+ cairo_surface_t *surface;
824
+
825
+ surface = cairo_win32_surface_get_image (_SELF);
826
+ if (!surface)
827
+ return Qnil;
828
+ rb_cairo_check_status (cairo_surface_status (surface));
829
+ return CRSURFACE2RVAL (surface);
830
+ }
831
+ #endif
832
+
720
833
 
721
834
  void
722
835
  Init_cairo_surface (void)
@@ -732,7 +845,6 @@ Init_cairo_surface (void)
732
845
  rb_define_method (rb_cCairo_Surface, "create_similar",
733
846
  cr_surface_create_similar, 3);
734
847
  rb_define_method (rb_cCairo_Surface, "finish", cr_surface_finish, 0);
735
- rb_define_method (rb_cCairo_Surface, "type", cr_surface_get_type, 0);
736
848
  rb_define_method (rb_cCairo_Surface, "content", cr_surface_get_content, 0);
737
849
 
738
850
  rb_define_method (rb_cCairo_Surface, "font_options",
@@ -817,11 +929,6 @@ Init_cairo_surface (void)
817
929
  /* SVG-surface */
818
930
  INIT_SURFACE(svg, SVG)
819
931
 
820
- rb_define_const (rb_cCairo_SVGSurface, "VERSION_1_1",
821
- rb_const_get (rb_mCairo, rb_intern ("SVG_VERSION_1_1")));
822
- rb_define_const (rb_cCairo_SVGSurface, "VERSION_1_2",
823
- rb_const_get (rb_mCairo, rb_intern ("SVG_VERSION_1_2")));
824
-
825
932
  rb_define_singleton_method (rb_cCairo_SVGSurface, "versions",
826
933
  cr_svg_get_versions, 0);
827
934
  rb_define_singleton_method (rb_cCairo_SVGSurface, "version_to_string",
@@ -834,4 +941,19 @@ Init_cairo_surface (void)
834
941
  #else
835
942
  rb_cCairo_SVGSurface = Qnil;
836
943
  #endif
944
+
945
+ #if CAIRO_HAS_WIN32_SURFACE
946
+ /* WIN32-surface */
947
+ rb_cCairo_WIN32Surface =
948
+ rb_define_class_under (rb_mCairo, "WIN32Surface", rb_cCairo_Surface);
949
+
950
+ rb_define_method (rb_cCairo_WIN32Surface, "initialize",
951
+ cr_win32_surface_initialize, -1);
952
+ rb_define_method (rb_cCairo_WIN32Surface, "hdc",
953
+ cr_win32_surface_get_hdc, 0);
954
+ rb_define_method (rb_cCairo_WIN32Surface, "image",
955
+ cr_win32_surface_get_image, 0);
956
+ #else
957
+ rb_cCairo_WIN32Surface = Qnil;
958
+ #endif
837
959
  }
@@ -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: 2007/05/03 02:47:39 $
7
7
  *
8
8
  * Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
9
9
  * Copyright 2004-2005 MenTaLguY <mental@rydia.com>
@@ -13,6 +13,7 @@
13
13
  */
14
14
 
15
15
  #include "rb_cairo.h"
16
+ #include "rb_cairo_private.h"
16
17
 
17
18
  VALUE rb_cCairo_TextExtents;
18
19
 
@@ -22,7 +23,7 @@ cairo_text_extents_t *
22
23
  rb_cairo_text_extents_from_ruby_object (VALUE obj)
23
24
  {
24
25
  cairo_text_extents_t *extents;
25
- if (!RTEST (rb_obj_is_kind_of (obj, rb_cCairo_TextExtents)))
26
+ if (!rb_cairo__is_kind_of (obj, rb_cCairo_TextExtents))
26
27
  {
27
28
  rb_raise (rb_eTypeError, "not a cairo text_extents");
28
29
  }
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: cairo
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.4.1
7
- date: 2007-04-13 00:00:00 +09:00
6
+ version: 1.5.0
7
+ date: 2007-05-27 00:00:00 +09:00
8
8
  summary: Ruby bindings for cairo
9
9
  require_paths:
10
10
  - src/lib
@@ -42,7 +42,10 @@ files:
42
42
  - README
43
43
  - Rakefile
44
44
  - extconf.rb
45
+ - misc/update-colors.rb
45
46
  - pkg-config.rb
47
+ - samples/.#blur.rb.1.1
48
+ - samples/blur.rb
46
49
  - samples/pac.rb
47
50
  - samples/pac2.rb
48
51
  - samples/png.rb
@@ -51,11 +54,17 @@ files:
51
54
  - samples/text2.rb
52
55
  - src/cairo.def
53
56
  - src/lib/cairo.rb
57
+ - src/lib/cairo/color.rb
58
+ - src/lib/cairo/colors.rb
59
+ - src/lib/cairo/constants.rb
54
60
  - src/lib/cairo/context.rb
61
+ - src/lib/cairo/context/blur.rb
55
62
  - src/lib/cairo/context/circle.rb
63
+ - src/lib/cairo/context/color.rb
56
64
  - src/lib/cairo/context/path.rb
57
- - src/lib/cairo/context/quad.rb
58
65
  - src/lib/cairo/context/rectangle.rb
66
+ - src/lib/cairo/path.rb
67
+ - src/lib/cairo/point.rb
59
68
  - src/rb_cairo.c
60
69
  - src/rb_cairo.h
61
70
  - src/rb_cairo_constants.c
@@ -75,8 +84,9 @@ files:
75
84
  - src/rb_cairo_text_extents.c
76
85
  test_files: []
77
86
 
78
- rdoc_options: []
79
-
87
+ rdoc_options:
88
+ - --main
89
+ - README.txt
80
90
  extra_rdoc_files: []
81
91
 
82
92
  executables: []