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
@@ -147,19 +147,19 @@ def pac(surface, width, height)
147
147
  cr.show_page
148
148
  end
149
149
 
150
- width = 841.889763779528
151
- height = 595.275590551181
150
+ paper = Cairo::Paper.parse(:a4_landscape)
152
151
 
153
- Cairo::ImageSurface.new(width, height) do |surface|
154
- cr = pac(surface, width, height)
152
+ size_in_points = paper.size("pt")
153
+ Cairo::ImageSurface.new(*size_in_points) do |surface|
154
+ cr = pac(surface, *size_in_points)
155
155
  cr.target.write_to_png("pac2.png")
156
156
  end
157
157
 
158
158
  scalable_surface_output = Proc.new do |surface_class_name, suffix|
159
159
  if Cairo.const_defined?(surface_class_name)
160
160
  surface_class = Cairo.const_get(surface_class_name)
161
- surface_class.new("pac2.#{suffix}", width, height) do |surface|
162
- pac(surface, width, height)
161
+ surface_class.new("pac2.#{suffix}", paper) do |surface|
162
+ pac(surface, *size_in_points)
163
163
  end
164
164
  else
165
165
  puts("#{surface_class_name} isn't supported.")
@@ -40,7 +40,6 @@ Cairo::ImageSurface.new(width, height) do |surface|
40
40
  stride = cr.target.stride
41
41
  end
42
42
 
43
- Cairo::ImageSurface.new(data, Cairo::FORMAT_ARGB32,
44
- width, height, stride) do |surface|
43
+ Cairo::ImageSurface.new(data, :argb32, width, height, stride) do |surface|
45
44
  surface.write_to_png("test-renew.png")
46
45
  end
@@ -19,14 +19,20 @@ def parse(args=ARGV)
19
19
  options.fade_out = false
20
20
 
21
21
  opts = OptionParser.new do |opts|
22
- opts.on("--width=WIDTH", Integer, "paper width") {|options.width|}
23
- opts.on("--height=HEIGHT", Integer, "paper height") {|options.height|}
22
+ opts.on("--width=WIDTH", Integer, "paper width") do |width|
23
+ options.width = width
24
+ end
25
+ opts.on("--height=HEIGHT", Integer, "paper height") do |height|
26
+ options.height = height
27
+ end
24
28
  opts.on("--font-description=DESCRIPTION",
25
29
  "font description (e.g. 'Monospace 14')") do |desc|
26
30
  options.font_description = desc
27
31
  end
28
32
  opts.on("--[no-]fade-out",
29
- "fade-out one-third of page") {|options.fade_out|}
33
+ "fade-out one-third of page") do |fade_out|
34
+ options.fade_out = fade_out
35
+ end
30
36
  end
31
37
 
32
38
  opts.parse!(args)
@@ -27,7 +27,9 @@ EXPORTS
27
27
  rb_cCairo_PSSurface DATA
28
28
  rb_cCairo_SVGSurface DATA
29
29
  rb_cCairo_Win32Surface DATA
30
+ rb_cCairo_Win32PrintingSurface DATA
30
31
  rb_cCairo_QuartzSurface DATA
32
+ rb_cCairo_QuartzImageSurface DATA
31
33
 
32
34
  rb_mCairo_Operator DATA
33
35
  rb_mCairo_Antialias DATA
@@ -45,9 +47,11 @@ EXPORTS
45
47
  rb_mCairo_Extend DATA
46
48
  rb_mCairo_Filter DATA
47
49
  rb_mCairo_SVGVersion DATA
50
+ rb_mCairo_PSLevel DATA
48
51
 
49
52
  rb_mCairo_Color DATA
50
53
  rb_cCairo_Color_Base DATA
54
+ rb_cCairo_Paper DATA
51
55
 
52
56
  rb_cairo_context_from_ruby_object
53
57
  rb_cairo_context_to_ruby_object
@@ -71,6 +75,7 @@ EXPORTS
71
75
  rb_cairo_glyph_to_ruby_object
72
76
  rb_cairo_surface_from_ruby_object
73
77
  rb_cairo_surface_to_ruby_object
78
+ rb_cairo_surface_to_ruby_object_with_destroy
74
79
  rb_cairo_operator_from_ruby_object
75
80
  rb_cairo_antialias_from_ruby_object
76
81
  rb_cairo_fill_rule_from_ruby_object
@@ -87,4 +92,5 @@ EXPORTS
87
92
  rb_cairo_extend_from_ruby_object
88
93
  rb_cairo_filter_from_ruby_object
89
94
  rb_cairo_svg_version_from_ruby_object
95
+ rb_cairo_ps_level_from_ruby_object
90
96
  rb_cairo_check_status
@@ -27,6 +27,7 @@ module Cairo
27
27
  end
28
28
 
29
29
  require 'cairo/color'
30
+ require 'cairo/paper'
30
31
 
31
32
  require 'cairo.so'
32
33
  require 'cairo/constants'
@@ -53,11 +54,39 @@ module Cairo
53
54
  end
54
55
  end
55
56
 
56
- class SVGSurface
57
- class << self
58
- def versions_as_string
59
- versions.collect do |version|
60
- version_to_string(version)
57
+ if const_defined?("PSLevel")
58
+ module PSLevel
59
+ class << self
60
+ def names
61
+ list.collect {|version| name(version)}
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ if const_defined?("SVGVersion")
68
+ module SVGVersion
69
+ class << self
70
+ def names
71
+ list.collect {|version| name(version)}
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ if const_defined?("SVGSurface")
78
+ class SVGSurface
79
+ class << self
80
+ def versions_as_string
81
+ SVGVersion.names
82
+ end
83
+
84
+ def versions
85
+ SVGVersion.list
86
+ end
87
+
88
+ def version_to_string(version)
89
+ SVGVersion.name(version)
61
90
  end
62
91
  end
63
92
  end
@@ -91,6 +120,7 @@ end
91
120
 
92
121
  require 'cairo/point'
93
122
  require 'cairo/colors'
123
+ require 'cairo/papers'
94
124
  require 'cairo/context'
95
125
  require 'cairo/path'
96
126
 
@@ -0,0 +1,183 @@
1
+ module Cairo
2
+ class Paper
3
+ class ParseError < ArgumentError
4
+ end
5
+
6
+ class UnknownPaperName < ParseError
7
+ attr_reader :name
8
+ def initialize(name)
9
+ @name = name
10
+ super("unknown paper name: #{name}")
11
+ end
12
+ end
13
+
14
+ class UnknownUnit < ParseError
15
+ attr_reader :unit
16
+ def initialize(unit)
17
+ @unit = unit
18
+ super("unknown unit: #{unit}")
19
+ end
20
+ end
21
+
22
+ class UnrecognizedPaperDescription < ParseError
23
+ attr_reader :description
24
+ def initialize(description)
25
+ @description = description
26
+ super("unrecognized paper description: #{description.inspect}")
27
+ end
28
+ end
29
+
30
+ class << self
31
+ def parse(paper_description, robust=false)
32
+ case paper_description
33
+ when Paper
34
+ return paper_description.dup
35
+ when Symbol
36
+ paper = resolve_constant(paper_description)
37
+ return paper.dup if paper
38
+ raise UnknownPaperName.new(paper_description)
39
+ when String
40
+ paper = resolve_constant(paper_description)
41
+ paper ||= parse_size(paper_description)
42
+ return paper.dup if paper
43
+ when Array
44
+ return new(*paper_description)
45
+ end
46
+
47
+ raise UnrecognizedPaperDescription.new(paper_description) if robust
48
+ nil
49
+ end
50
+
51
+ @@default_unit = nil
52
+ def default_unit
53
+ @@default_unit
54
+ end
55
+
56
+ def default_unit=(unit)
57
+ @@default_unit = unit
58
+ end
59
+
60
+ @@unit_resolvers = {}
61
+ def register_unit_resolver(from_units, to_units, &resolver)
62
+ from_units = [from_units] unless from_units.is_a?(Array)
63
+ to_units = [to_units] unless to_units.is_a?(Array)
64
+ from_units.each do |from_unit|
65
+ @@unit_resolvers[from_unit] ||= []
66
+ to_units.each do |unit|
67
+ @@unit_resolvers[from_unit] << [unit, resolver]
68
+ end
69
+ end
70
+ end
71
+
72
+ def resolve_unit(size, from_unit, to_unit)
73
+ from_unit ||= default_unit
74
+ return size if from_unit == to_unit
75
+ from_units = @@unit_resolvers[from_unit] || []
76
+ raise UnknownUnit.new(from_unit) if from_units.empty?
77
+ from_units.each do |unit, resolver|
78
+ return resolver.call(size) if to_unit == unit
79
+ end
80
+ raise UnknownUnit.new(to_unit)
81
+ end
82
+
83
+ private
84
+ def resolve_constant(name)
85
+ name = name.to_s.upcase.gsub(/\s+|-/, '_')
86
+ if /\A[A-Z]/ =~ name and const_defined?(name)
87
+ const_get(name)
88
+ else
89
+ nil
90
+ end
91
+ end
92
+
93
+ def parse_size(size)
94
+ size_re = /(\d+(\.\d*)?)/
95
+ unit_re = /([a-zA-Z]+?)/
96
+ if /\A#{size_re}#{unit_re}?x#{size_re}#{unit_re}?(?:#(.*))?\z/ !~ size
97
+ return nil
98
+ end
99
+
100
+ width = $1
101
+ width_fractional = $2
102
+ width_unit = $3
103
+ height = $4
104
+ height_fractional = $5
105
+ height_unit = $6
106
+ name = $7
107
+ width = width_fractional ? Float(width) : Integer(width)
108
+ height = height_fractional ? Float(height) : Integer(height)
109
+ new(resolve_unit(width, width_unit, "pt"),
110
+ resolve_unit(height, height_unit, "pt"),
111
+ nil, name)
112
+ end
113
+ end
114
+
115
+ self.default_unit = "pt"
116
+ register_unit_resolver("pt", ["in", "inch"]) {|size| size / 72.0}
117
+ register_unit_resolver(["in", "inch"], "pt") {|size| size * 72}
118
+ register_unit_resolver("pt", "mm") {|size| size * 25.4 / 72.0}
119
+ register_unit_resolver("mm", "pt") {|size| size / 25.4 * 72}
120
+ register_unit_resolver("pt", "cm") {|size| size * 2.54 / 72.0}
121
+ register_unit_resolver("cm", "pt") {|size| size / 2.54 * 72}
122
+ register_unit_resolver("pt", "m") {|size| size * 0.0254 / 72.0}
123
+ register_unit_resolver("m", "pt") {|size| size / 0.0254 * 72}
124
+
125
+ attr_reader :unit
126
+ attr_writer :width, :height
127
+ attr_accessor :name
128
+ def initialize(width, height, unit=nil, name=nil)
129
+ @width = width
130
+ @height = height
131
+ @unit = unit
132
+ @name = name
133
+ end
134
+
135
+ def unit=(unit)
136
+ if @unit != unit
137
+ @width = self.class.resolve_unit(width, @unit, unit)
138
+ @height = self.class.resolve_unit(height, @unit, unit)
139
+ end
140
+ @unit = unit
141
+ end
142
+
143
+ def width(unit=nil)
144
+ return @width if unit.nil?
145
+ self.class.resolve_unit(@width, @unit, unit)
146
+ end
147
+
148
+ def height(unit=nil)
149
+ return @height if unit.nil?
150
+ self.class.resolve_unit(@height, @unit, unit)
151
+ end
152
+
153
+ def size(unit=nil)
154
+ [width(unit), height(unit)]
155
+ end
156
+
157
+ def ==(other)
158
+ other.is_a?(self.class) and @name == other.name and
159
+ width_in_delta?(other.width(@unit)) and
160
+ height_in_delta?(other.height(@unit))
161
+ end
162
+
163
+ def to_s
164
+ string = "#{@width}#{@unit}x#{@height}#{@unit}"
165
+ string << "\##{@name}" if @name
166
+ string
167
+ end
168
+
169
+ private
170
+ def width_in_delta?(value, delta=nil)
171
+ in_delta?(@width, delta, value)
172
+ end
173
+
174
+ def height_in_delta?(value, delta=nil)
175
+ in_delta?(@height, delta, value)
176
+ end
177
+
178
+ def in_delta?(value, delta, other)
179
+ delta ||= 0.001
180
+ value - delta < other and other < value + delta
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,41 @@
1
+ require 'cairo/paper'
2
+
3
+ module Cairo
4
+ class Paper
5
+ [
6
+ [841, 1189, "A0"],
7
+ [594, 841, "A1"],
8
+ [420, 594, "A2"],
9
+ [297, 420, "A3"],
10
+ [210, 297, "A4"],
11
+ [148, 210, "A5"],
12
+ [105, 148, "A6"],
13
+ [74, 105, "A7"],
14
+ [52, 74, "A8"],
15
+ [37, 52, "A9"],
16
+ [26, 37, "A10"],
17
+
18
+ [1030, 1456, "B0"],
19
+ [728, 1030, "B1"],
20
+ [515, 728, "B2"],
21
+ [364, 515, "B3"],
22
+ [257, 364, "B4"],
23
+ [182, 257, "B5"],
24
+ [128, 182, "B6"],
25
+ [91, 128, "B7"],
26
+ [64, 91, "B8"],
27
+ [45, 64, "B9"],
28
+ [32, 45, "B10"],
29
+
30
+ [215.9, 279.4, "letter"],
31
+ [215.9, 355.6, "legal"],
32
+ [279.9, 431.8, "tabloid"],
33
+ [100, 148, "Japanese postcard"],
34
+ ].each do |width, height, name|
35
+ constant_name = name.upcase.gsub(/ +/, '_')
36
+ const_set(constant_name, new(width, height, "mm", name))
37
+ const_set("#{constant_name}_LANDSCAPE",
38
+ new(height, width, "mm", "#{name} (landscape)"))
39
+ end
40
+ end
41
+ end
@@ -3,7 +3,7 @@
3
3
  * Ruby Cairo Binding
4
4
  *
5
5
  * $Author: kou $
6
- * $Date: 2007/05/27 02:46:01 $
6
+ * $Date: 2008-04-11 03:08:57 $
7
7
  *
8
8
  * Copyright 2006-2007 Kouhei Sutou <kou@cozmixng.org>
9
9
  * Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
@@ -17,7 +17,7 @@
17
17
  #include "rb_cairo.h"
18
18
  #include "rb_cairo_private.h"
19
19
 
20
- VALUE rb_mCairo, rb_mCairo_Color, rb_cCairo_Color_Base;
20
+ VALUE rb_mCairo, rb_mCairo_Color, rb_cCairo_Color_Base, rb_cCairo_Paper;
21
21
 
22
22
  static ID id__add_one_arg_setter;
23
23
 
@@ -58,10 +58,11 @@ Init_cairo ()
58
58
 
59
59
  rb_define_const (rb_mCairo, "BINDINGS_VERSION",
60
60
  rb_ary_new3 (4,
61
- INT2FIX (1), INT2FIX (5), INT2FIX (1), Qnil));
61
+ INT2FIX (1), INT2FIX (6), INT2FIX (0), Qnil));
62
62
 
63
63
  rb_mCairo_Color = rb_const_get (rb_mCairo, rb_intern ("Color"));
64
64
  rb_cCairo_Color_Base = rb_const_get (rb_mCairo_Color, rb_intern ("Base"));
65
+ rb_cCairo_Paper = rb_const_get (rb_mCairo, rb_intern ("Paper"));
65
66
 
66
67
  Init_cairo_private ();
67
68
  Init_cairo_constants ();
@@ -3,7 +3,7 @@
3
3
  * Ruby Cairo Binding
4
4
  *
5
5
  * $Author: kou $
6
- * $Date: 2008-01-11 12:18:34 $
6
+ * $Date: 2008-04-11 03:01:33 $
7
7
  *
8
8
  * Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
9
9
  * Copyright 2004-2005 MenTaLguY <mental@rydia.com>
@@ -104,9 +104,11 @@ RB_CAIRO_VAR VALUE rb_cCairo_PDFSurface;
104
104
  RB_CAIRO_VAR VALUE rb_cCairo_PSSurface;
105
105
  RB_CAIRO_VAR VALUE rb_cCairo_SVGSurface;
106
106
  RB_CAIRO_VAR VALUE rb_cCairo_Win32Surface;
107
+ RB_CAIRO_VAR VALUE rb_cCairo_Win32PrintingSurface;
107
108
  /* For backward compatibility*/
108
109
  #define rb_cCairo_WIN32Surface rb_cCairo_Win32Surface
109
110
  RB_CAIRO_VAR VALUE rb_cCairo_QuartzSurface;
111
+ RB_CAIRO_VAR VALUE rb_cCairo_QuartzImageSurface;
110
112
 
111
113
  RB_CAIRO_VAR VALUE rb_mCairo_Operator;
112
114
  RB_CAIRO_VAR VALUE rb_mCairo_Antialias;
@@ -129,6 +131,7 @@ RB_CAIRO_VAR VALUE rb_mCairo_Filter;
129
131
  RB_CAIRO_VAR VALUE rb_mCairo_SVGVersion;
130
132
  RB_CAIRO_VAR VALUE rb_mCairo_Color;
131
133
  RB_CAIRO_VAR VALUE rb_cCairo_Color_Base;
134
+ RB_CAIRO_VAR VALUE rb_cCairo_Paper;
132
135
 
133
136
 
134
137
  #define RVAL2CRCONTEXT(obj) (rb_cairo_context_from_ruby_object(obj))
@@ -163,6 +166,8 @@ RB_CAIRO_VAR VALUE rb_cCairo_Color_Base;
163
166
 
164
167
  #define RVAL2CRSURFACE(obj) (rb_cairo_surface_from_ruby_object(obj))
165
168
  #define CRSURFACE2RVAL(surface) (rb_cairo_surface_to_ruby_object(surface))
169
+ #define CRSURFACE2RVAL_WITH_DESTROY(surface) \
170
+ (rb_cairo_surface_to_ruby_object_with_destroy(surface))
166
171
 
167
172
  cairo_t *rb_cairo_context_from_ruby_object (VALUE obj);
168
173
  VALUE rb_cairo_context_to_ruby_object (cairo_t *cr);
@@ -196,6 +201,8 @@ VALUE rb_cairo_glyph_to_ruby_object (cairo_glyph_t *gly
196
201
 
197
202
  cairo_surface_t *rb_cairo_surface_from_ruby_object (VALUE obj);
198
203
  VALUE rb_cairo_surface_to_ruby_object (cairo_surface_t *surface);
204
+ VALUE rb_cairo_surface_to_ruby_object_with_destroy
205
+ (cairo_surface_t *surface);
199
206
 
200
207
 
201
208
  #define RVAL2CROPERATOR(obj) (rb_cairo_operator_from_ruby_object(obj))
@@ -216,6 +223,11 @@ VALUE rb_cairo_surface_to_ruby_object (cairo_surface_t *s
216
223
  #if CAIRO_HAS_SVG_SURFACE
217
224
  #define RVAL2CRSVGVERSION(obj) (rb_cairo_svg_version_from_ruby_object(obj))
218
225
  #endif
226
+ #if CAIRO_HAS_PS_SURFACE
227
+ # if CAIRO_CHECK_VERSION(1, 5, 2)
228
+ #define RVAL2CRPSLEVEL(obj) (rb_cairo_ps_level_from_ruby_object(obj))
229
+ # endif
230
+ #endif
219
231
 
220
232
  cairo_operator_t rb_cairo_operator_from_ruby_object (VALUE obj);
221
233
  cairo_antialias_t rb_cairo_antialias_from_ruby_object (VALUE obj);
@@ -235,6 +247,11 @@ cairo_filter_t rb_cairo_filter_from_ruby_object (VALUE obj);
235
247
  #if CAIRO_HAS_SVG_SURFACE
236
248
  cairo_svg_version_t rb_cairo_svg_version_from_ruby_object (VALUE obj);
237
249
  #endif
250
+ #if CAIRO_HAS_PS_SURFACE
251
+ # if CAIRO_CHECK_VERSION(1, 5, 2)
252
+ cairo_ps_level_t rb_cairo_ps_level_from_ruby_object (VALUE obj);
253
+ # endif
254
+ #endif
238
255
 
239
256
  void rb_cairo_check_status (cairo_status_t status);
240
257