rubyquartz 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. data/COPYRIGHT +24 -0
  2. data/History.txt +9 -0
  3. data/Manifest.txt +95 -0
  4. data/README.txt +71 -0
  5. data/Rakefile +51 -0
  6. data/ext/ExportedSymbols.txt +1 -0
  7. data/ext/bitmap.c +129 -0
  8. data/ext/bitmap.h +38 -0
  9. data/ext/bitmap_context.c +67 -0
  10. data/ext/bitmap_context.h +31 -0
  11. data/ext/color.c +145 -0
  12. data/ext/color.h +34 -0
  13. data/ext/colorspace.c +94 -0
  14. data/ext/colorspace.h +33 -0
  15. data/ext/context.c +393 -0
  16. data/ext/context.h +33 -0
  17. data/ext/extconf.rb +48 -0
  18. data/ext/font.c +148 -0
  19. data/ext/font.h +32 -0
  20. data/ext/function.c +124 -0
  21. data/ext/function.h +32 -0
  22. data/ext/image.c +140 -0
  23. data/ext/image.h +31 -0
  24. data/ext/image_source.c +143 -0
  25. data/ext/image_source.h +31 -0
  26. data/ext/pdf_document.c +91 -0
  27. data/ext/pdf_document.h +31 -0
  28. data/ext/pdf_page.c +79 -0
  29. data/ext/pdf_page.h +31 -0
  30. data/ext/point.c +42 -0
  31. data/ext/point.h +32 -0
  32. data/ext/rect.c +45 -0
  33. data/ext/rect.h +32 -0
  34. data/ext/rubyquartz.c +80 -0
  35. data/ext/rubyquartz.h +29 -0
  36. data/ext/rubyquartz_prefix.h +45 -0
  37. data/ext/shading.c +68 -0
  38. data/ext/shading.h +32 -0
  39. data/ext/size.c +42 -0
  40. data/ext/size.h +32 -0
  41. data/ext/text.c +258 -0
  42. data/ext/text.h +39 -0
  43. data/ext/utilities.c +181 -0
  44. data/ext/utilities.h +43 -0
  45. data/lib/rubyquartz.rb +59 -0
  46. data/lib/rubyquartz/bitmap.rb +62 -0
  47. data/lib/rubyquartz/bitmap_context.rb +50 -0
  48. data/lib/rubyquartz/color.rb +68 -0
  49. data/lib/rubyquartz/colorspace.rb +42 -0
  50. data/lib/rubyquartz/context.rb +116 -0
  51. data/lib/rubyquartz/font.rb +48 -0
  52. data/lib/rubyquartz/function.rb +57 -0
  53. data/lib/rubyquartz/image.rb +48 -0
  54. data/lib/rubyquartz/image_source.rb +50 -0
  55. data/lib/rubyquartz/pdf_document.rb +47 -0
  56. data/lib/rubyquartz/pdf_page.rb +54 -0
  57. data/lib/rubyquartz/point.rb +63 -0
  58. data/lib/rubyquartz/rect.rb +127 -0
  59. data/lib/rubyquartz/shading.rb +48 -0
  60. data/lib/rubyquartz/size.rb +39 -0
  61. data/lib/rubyquartz/text.rb +50 -0
  62. data/test/images/TestContext.test_begin_path.png +0 -0
  63. data/test/images/TestContext.test_draw_image.png +0 -0
  64. data/test/images/TestContext.test_draw_path.png +0 -0
  65. data/test/images/TestContext.test_draw_pdf.png +0 -0
  66. data/test/images/TestContext.test_draw_shading_axial.png +0 -0
  67. data/test/images/TestContext.test_draw_text.png +0 -0
  68. data/test/images/TestContext.test_draw_text_baseline_aligned.png +0 -0
  69. data/test/images/TestContext.test_draw_text_flipped.png +0 -0
  70. data/test/images/TestContext.test_draw_text_flipped_non_zero_point.png +0 -0
  71. data/test/images/TestContext.test_draw_text_non_zero_point.png +0 -0
  72. data/test/images/TestContext.test_fill.png +0 -0
  73. data/test/images/TestContext.test_gsave.png +0 -0
  74. data/test/images/TestContext.test_gsave_block.png +0 -0
  75. data/test/images/TestContext.test_line_width.png +0 -0
  76. data/test/images/TestContext.test_lineto.png +0 -0
  77. data/test/images/TestContext.test_rotate.png +0 -0
  78. data/test/images/TestContext.test_rounded_rect.png +0 -0
  79. data/test/images/TestContext.test_scale.png +0 -0
  80. data/test/images/TestContext.test_set_line_dash.png +0 -0
  81. data/test/images/TestContext.test_shadow.png +0 -0
  82. data/test/images/TestContext.test_stroke_rect.png +0 -0
  83. data/test/images/TestContext.test_text_bounds.png +0 -0
  84. data/test/images/TestContext.test_translate.png +0 -0
  85. data/test/inputs/circle.pdf +0 -0
  86. data/test/inputs/wash.png +0 -0
  87. data/test/rubyquartz_test.rb +51 -0
  88. data/test/tc_bitmap_context.rb +43 -0
  89. data/test/tc_color.rb +43 -0
  90. data/test/tc_context.rb +315 -0
  91. data/test/tc_font.rb +54 -0
  92. data/test/tc_image_source.rb +69 -0
  93. data/test/tc_pdf_document.rb +63 -0
  94. data/test/tc_pdf_page.rb +53 -0
  95. data/test/tc_text.rb +39 -0
  96. metadata +156 -0
data/ext/image.h ADDED
@@ -0,0 +1,31 @@
1
+ /*
2
+ Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
3
+
4
+ OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
5
+
6
+ Omni Source Code software is available from The Omni Group on their web
7
+ site at www.omnigroup.com.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a
10
+ copy of this software and associated documentation files (the "Software"),
11
+ to deal in the Software without restriction, including without limitation
12
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
13
+ and/or sell copies of the Software, and to permit persons to whom the
14
+ Software is furnished to do so, subject to the following conditions:
15
+
16
+ Any original copyright notices and this permission notice shall be included
17
+ in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25
+ DEALINGS IN THE SOFTWARE.
26
+ */
27
+
28
+
29
+ extern void Init_image(void);
30
+ extern VALUE image_class;
31
+ extern CGImageRef image_get(VALUE self);
@@ -0,0 +1,143 @@
1
+ /*
2
+ Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
3
+
4
+ OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
5
+
6
+ Omni Source Code software is available from The Omni Group on their web
7
+ site at www.omnigroup.com.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a
10
+ copy of this software and associated documentation files (the "Software"),
11
+ to deal in the Software without restriction, including without limitation
12
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
13
+ and/or sell copies of the Software, and to permit persons to whom the
14
+ Software is furnished to do so, subject to the following conditions:
15
+
16
+ Any original copyright notices and this permission notice shall be included
17
+ in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25
+ DEALINGS IN THE SOFTWARE.
26
+ */
27
+
28
+
29
+ #include "image_source.h"
30
+
31
+ VALUE image_source_class;
32
+
33
+ CGImageSourceRef image_source_get(VALUE self)
34
+ {
35
+ return (CGImageSourceRef)_cftype_get(self, CGImageSourceGetTypeID(), "CGImageSourceRef");
36
+ }
37
+
38
+ static void image_source_set(VALUE self, CGImageSourceRef image_source)
39
+ {
40
+ _cftype_set(self, CGImageSourceGetTypeID(), "CGImageSourceRef", image_source);
41
+ }
42
+
43
+ // TODO: Add arguments for other options or add an options has with a Hash<->CFDictionaryRef conversion function
44
+ static VALUE image_source_initialize_with_path(VALUE self, VALUE path)
45
+ {
46
+ CFURLRef url = _create_url_for_path(path);
47
+ CFDictionaryRef options = NULL;
48
+
49
+ CGImageSourceRef src = CGImageSourceCreateWithURL(url, options);
50
+ CFRelease(url);
51
+
52
+ if (!src)
53
+ rb_raise(rb_eException, "Unable to create an image source from the path");
54
+ image_source_set(self, src);
55
+ CFRelease(src);
56
+
57
+ return self;
58
+ }
59
+
60
+ static VALUE image_source_initialize_with_data(VALUE self, VALUE data_value)
61
+ {
62
+ // Have to copy here since the entire data won't have been consumed by the time CGImageSourceCreateWithData returns
63
+ CFDataRef data = _create_data_from_string(data_value, true/*copy*/);
64
+ CFDictionaryRef options = NULL;
65
+
66
+ CGImageSourceRef src = CGImageSourceCreateWithData(data, options);
67
+ CFRelease(data);
68
+
69
+ if (!src)
70
+ rb_raise(rb_eException, "Unable to create an image source from the data");
71
+ image_source_set(self, src);
72
+ CFRelease(src);
73
+
74
+ return self;
75
+ }
76
+
77
+ static VALUE image_source_get_type_identifiers(VALUE self)
78
+ {
79
+ CFArrayRef typeIdentifiers = CGImageSourceCopyTypeIdentifiers();
80
+ CFIndex typeIdentifierIndex = CFArrayGetCount(typeIdentifiers);
81
+
82
+ VALUE strings = rb_ary_new();
83
+ while (typeIdentifierIndex--) {
84
+ CFStringRef typeIdentifier = CFArrayGetValueAtIndex(typeIdentifiers, typeIdentifierIndex);
85
+ VALUE str = _value_for_string(typeIdentifier);
86
+ rb_ary_unshift(strings, str);
87
+ }
88
+
89
+ CFRelease(typeIdentifiers);
90
+
91
+ return strings;
92
+ }
93
+
94
+ static VALUE image_source_name_for_type_identifier(VALUE self, VALUE type_value)
95
+ {
96
+ CFStringRef type = _copy_string_for_str(type_value);
97
+ CFStringRef name = UTTypeCopyDescription(type);
98
+ CFRelease(type);
99
+
100
+ if (!name)
101
+ rb_raise(rb_eException, "No name available for type");
102
+
103
+ VALUE result = _value_for_string(name);
104
+ CFRelease(name);
105
+ return result;
106
+ }
107
+
108
+ static VALUE image_source_get_type(VALUE self)
109
+ {
110
+ return _value_for_string(CGImageSourceGetType(image_source_get(self)));
111
+ }
112
+
113
+ static VALUE image_source_get_count(VALUE self)
114
+ {
115
+ return INT2NUM(CGImageSourceGetCount(image_source_get(self)));
116
+ }
117
+
118
+
119
+ // Not sure if this has any value
120
+ #if 0
121
+ static VALUE image_source_get_properties(VALUE self)
122
+ {
123
+ CFDictionaryRef options = NULL;
124
+ CFDictionaryRef properties = CGImageSourceCopyProperties(image_source_get(self), options);
125
+ return self;
126
+ }
127
+ #endif
128
+
129
+ void Init_image_source(void)
130
+ {
131
+ image_source_class = rb_define_class_under(module, "ImageSource", rb_cObject);
132
+ rb_define_alloc_func(image_source_class, _cftype_alloc);
133
+
134
+ rb_define_private_method(image_source_class, "_initialize_with_path", image_source_initialize_with_path, 1);
135
+ rb_define_private_method(image_source_class, "_initialize_with_data", image_source_initialize_with_data, 1);
136
+
137
+ rb_define_module_function(image_source_class, "type_identifiers", image_source_get_type_identifiers, 0);
138
+ rb_define_module_function(image_source_class, "name_for_type_identifier", image_source_name_for_type_identifier, 1);
139
+
140
+ rb_define_method(image_source_class, "type", image_source_get_type, 0);
141
+ rb_define_method(image_source_class, "size", image_source_get_count, 0);
142
+ //rb_define_method(image_source_class, "properties", image_source_get_properties, 0);
143
+ }
@@ -0,0 +1,31 @@
1
+ /*
2
+ Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
3
+
4
+ OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
5
+
6
+ Omni Source Code software is available from The Omni Group on their web
7
+ site at www.omnigroup.com.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a
10
+ copy of this software and associated documentation files (the "Software"),
11
+ to deal in the Software without restriction, including without limitation
12
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
13
+ and/or sell copies of the Software, and to permit persons to whom the
14
+ Software is furnished to do so, subject to the following conditions:
15
+
16
+ Any original copyright notices and this permission notice shall be included
17
+ in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25
+ DEALINGS IN THE SOFTWARE.
26
+ */
27
+
28
+
29
+ extern void Init_image_source(void);
30
+ extern VALUE image_source_class;
31
+ extern CGImageSourceRef image_source_get(VALUE self);
@@ -0,0 +1,91 @@
1
+ /*
2
+ Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
3
+
4
+ OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
5
+
6
+ Omni Source Code software is available from The Omni Group on their web
7
+ site at www.omnigroup.com.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a
10
+ copy of this software and associated documentation files (the "Software"),
11
+ to deal in the Software without restriction, including without limitation
12
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
13
+ and/or sell copies of the Software, and to permit persons to whom the
14
+ Software is furnished to do so, subject to the following conditions:
15
+
16
+ Any original copyright notices and this permission notice shall be included
17
+ in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25
+ DEALINGS IN THE SOFTWARE.
26
+ */
27
+
28
+
29
+ #include "pdf_document.h"
30
+
31
+ VALUE pdf_document_class;
32
+
33
+ CGPDFDocumentRef pdf_document_get(VALUE self)
34
+ {
35
+ return (CGPDFDocumentRef)_cftype_get(self, CGPDFDocumentGetTypeID(), "CGPDFDocumentRef");
36
+ }
37
+
38
+ static void pdf_document_set(VALUE self, CGPDFDocumentRef pdf_document)
39
+ {
40
+ _cftype_set(self, CGPDFDocumentGetTypeID(), "CGPDFDocumentRef", pdf_document);
41
+ }
42
+
43
+ static VALUE pdf_document_initialize_with_path(VALUE self, VALUE path)
44
+ {
45
+ CFURLRef url = _create_url_for_path(path);
46
+
47
+ CGPDFDocumentRef doc = CGPDFDocumentCreateWithURL(url);
48
+ CFRelease(url);
49
+
50
+ if (!doc)
51
+ rb_raise(rb_eException, "Unable to create an PDF document from the path");
52
+ pdf_document_set(self, doc);
53
+ CFRelease(doc);
54
+
55
+ return self;
56
+ }
57
+
58
+ static VALUE pdf_document_initialize_with_data(VALUE self, VALUE data_value)
59
+ {
60
+ // Have to copy here since the entire data won't have been consumed by the time CGPDFDocumentCreateWithProvider returns
61
+ CFDataRef data = _create_data_from_string(data_value, true/*copy*/);
62
+ CGDataProviderRef provider = CGDataProviderCreateWithCFData(data);
63
+ CFRelease(data);
64
+
65
+
66
+ CGPDFDocumentRef doc = CGPDFDocumentCreateWithProvider(provider);
67
+ CFRelease(provider);
68
+
69
+ if (!doc)
70
+ rb_raise(rb_eException, "Unable to create an PDF document from the data");
71
+ pdf_document_set(self, doc);
72
+ CFRelease(doc);
73
+
74
+ return self;
75
+ }
76
+
77
+ static VALUE pdf_document_get_count(VALUE self)
78
+ {
79
+ return INT2NUM(CGPDFDocumentGetNumberOfPages(pdf_document_get(self)));
80
+ }
81
+
82
+ void Init_pdf_document(void)
83
+ {
84
+ pdf_document_class = rb_define_class_under(module, "PDFDocument", rb_cObject);
85
+ rb_define_alloc_func(pdf_document_class, _cftype_alloc);
86
+
87
+ rb_define_private_method(pdf_document_class, "_initialize_with_path", pdf_document_initialize_with_path, 1);
88
+ rb_define_private_method(pdf_document_class, "_initialize_with_data", pdf_document_initialize_with_data, 1);
89
+
90
+ rb_define_method(pdf_document_class, "size", pdf_document_get_count, 0);
91
+ }
@@ -0,0 +1,31 @@
1
+ /*
2
+ Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
3
+
4
+ OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
5
+
6
+ Omni Source Code software is available from The Omni Group on their web
7
+ site at www.omnigroup.com.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a
10
+ copy of this software and associated documentation files (the "Software"),
11
+ to deal in the Software without restriction, including without limitation
12
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
13
+ and/or sell copies of the Software, and to permit persons to whom the
14
+ Software is furnished to do so, subject to the following conditions:
15
+
16
+ Any original copyright notices and this permission notice shall be included
17
+ in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25
+ DEALINGS IN THE SOFTWARE.
26
+ */
27
+
28
+
29
+ extern void Init_pdf_document(void);
30
+ extern VALUE pdf_document_class;
31
+ extern CGPDFDocumentRef pdf_document_get(VALUE self);
data/ext/pdf_page.c ADDED
@@ -0,0 +1,79 @@
1
+ /*
2
+ Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
3
+
4
+ OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
5
+
6
+ Omni Source Code software is available from The Omni Group on their web
7
+ site at www.omnigroup.com.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a
10
+ copy of this software and associated documentation files (the "Software"),
11
+ to deal in the Software without restriction, including without limitation
12
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
13
+ and/or sell copies of the Software, and to permit persons to whom the
14
+ Software is furnished to do so, subject to the following conditions:
15
+
16
+ Any original copyright notices and this permission notice shall be included
17
+ in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25
+ DEALINGS IN THE SOFTWARE.
26
+ */
27
+
28
+
29
+ #include "pdf_page.h"
30
+
31
+ #include "pdf_document.h"
32
+ #include "rect.h"
33
+
34
+ VALUE pdf_page_class;
35
+
36
+ CGPDFPageRef pdf_page_get(VALUE self)
37
+ {
38
+ return (CGPDFPageRef)_cftype_get(self, CGPDFPageGetTypeID(), "CGPDFPageRef");
39
+ }
40
+
41
+ static void pdf_page_set(VALUE self, CGPDFPageRef pdf_page)
42
+ {
43
+ _cftype_set(self, CGPDFPageGetTypeID(), "CGPDFPageRef", pdf_page);
44
+ }
45
+
46
+ static VALUE _initialize_with_document_at_index(VALUE self, VALUE document, VALUE index)
47
+ {
48
+ // Page numbers start at 1
49
+ CGPDFPageRef page = CGPDFDocumentGetPage(pdf_document_get(document), NUM2INT(index)+1);
50
+
51
+ if (!page)
52
+ rb_raise(rb_eException, "Unable to create page");
53
+
54
+ pdf_page_set(self, page);
55
+
56
+ return self;
57
+ }
58
+
59
+ static VALUE pdf_page_page_number(VALUE self)
60
+ {
61
+ return INT2NUM(CGPDFPageGetPageNumber(pdf_page_get(self)));
62
+ }
63
+
64
+ static VALUE pdf_page_box(VALUE self, VALUE box)
65
+ {
66
+ CGRect rect = CGPDFPageGetBoxRect(pdf_page_get(self), NUM2INT(box));
67
+ return rect_value_from_rect(rect);
68
+ }
69
+
70
+ void Init_pdf_page(void)
71
+ {
72
+ pdf_page_class = rb_define_class_under(module, "PDFPage", rb_cObject);
73
+ rb_define_alloc_func(pdf_page_class, _cftype_alloc);
74
+
75
+ rb_define_private_method(pdf_page_class, "_initialize_with_document_at_index", _initialize_with_document_at_index, 2);
76
+ rb_define_private_method(pdf_page_class, "_page_box", pdf_page_box, 1);
77
+
78
+ rb_define_method(pdf_document_class, "page_number", pdf_page_page_number, 0);
79
+ }
data/ext/pdf_page.h ADDED
@@ -0,0 +1,31 @@
1
+ /*
2
+ Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
3
+
4
+ OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
5
+
6
+ Omni Source Code software is available from The Omni Group on their web
7
+ site at www.omnigroup.com.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a
10
+ copy of this software and associated documentation files (the "Software"),
11
+ to deal in the Software without restriction, including without limitation
12
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
13
+ and/or sell copies of the Software, and to permit persons to whom the
14
+ Software is furnished to do so, subject to the following conditions:
15
+
16
+ Any original copyright notices and this permission notice shall be included
17
+ in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25
+ DEALINGS IN THE SOFTWARE.
26
+ */
27
+
28
+
29
+ extern void Init_pdf_page(void);
30
+ extern VALUE pdf_page_class;
31
+ extern CGPDFPageRef pdf_page_get(VALUE self);
data/ext/point.c ADDED
@@ -0,0 +1,42 @@
1
+ /*
2
+ Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
3
+
4
+ OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
5
+
6
+ Omni Source Code software is available from The Omni Group on their web
7
+ site at www.omnigroup.com.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a
10
+ copy of this software and associated documentation files (the "Software"),
11
+ to deal in the Software without restriction, including without limitation
12
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
13
+ and/or sell copies of the Software, and to permit persons to whom the
14
+ Software is furnished to do so, subject to the following conditions:
15
+
16
+ Any original copyright notices and this permission notice shall be included
17
+ in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25
+ DEALINGS IN THE SOFTWARE.
26
+ */
27
+
28
+
29
+ #include "point.h"
30
+
31
+ VALUE point_class;
32
+
33
+ VALUE point_value_from_point(CGPoint point)
34
+ {
35
+ VALUE xy[2] = {rb_float_new(point.x), rb_float_new(point.y)};
36
+ return rb_class_new_instance(2, xy, point_class);
37
+ }
38
+
39
+ void Init_point(void)
40
+ {
41
+ point_class = rb_define_class_under(module, "Point", rb_cObject);
42
+ }