rmagick4j 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/History.txt +84 -0
  2. data/LICENSE.txt +9 -0
  3. data/Manifest.txt +142 -0
  4. data/README.txt +25 -0
  5. data/Rakefile +109 -0
  6. data/lib/RMagick.rb +1861 -0
  7. data/lib/jhlabs-filters.jar +0 -0
  8. data/lib/magick4j.jar +0 -0
  9. data/lib/rmagick4j/constants.rb +21 -0
  10. data/lib/rmagick4j/draw.rb +86 -0
  11. data/lib/rmagick4j/enum.rb +120 -0
  12. data/lib/rmagick4j/gradient_fill.rb +14 -0
  13. data/lib/rmagick4j/image.rb +289 -0
  14. data/lib/rmagick4j/image_list.rb +21 -0
  15. data/lib/rmagick4j/pixel.rb +170 -0
  16. data/lib/rmagick4j/rmagick4j.rb +19 -0
  17. data/lib/rmagick4j/texture_fill.rb +14 -0
  18. data/lib/rmagick4j/type_metric.rb +8 -0
  19. data/lib/rmagick4j/version.rb +5 -0
  20. data/lib/rvg/clippath.rb +48 -0
  21. data/lib/rvg/container.rb +131 -0
  22. data/lib/rvg/deep_equal.rb +56 -0
  23. data/lib/rvg/describable.rb +53 -0
  24. data/lib/rvg/embellishable.rb +417 -0
  25. data/lib/rvg/misc.rb +739 -0
  26. data/lib/rvg/paint.rb +55 -0
  27. data/lib/rvg/pathdata.rb +131 -0
  28. data/lib/rvg/rvg.rb +283 -0
  29. data/lib/rvg/stretchable.rb +168 -0
  30. data/lib/rvg/stylable.rb +118 -0
  31. data/lib/rvg/text.rb +187 -0
  32. data/lib/rvg/transformable.rb +133 -0
  33. data/lib/rvg/units.rb +66 -0
  34. data/lib/svgsalamander.jar +0 -0
  35. data/test/RMagickTestSuite.rb +129 -0
  36. data/test/eyetests/bullseye.rb +150 -0
  37. data/test/eyetests/tests/draw_arc_basic.rb +16 -0
  38. data/test/eyetests/tests/draw_circle_affine.rb +19 -0
  39. data/test/eyetests/tests/draw_circle_basic.rb +16 -0
  40. data/test/eyetests/tests/draw_ellipse_affine.rb +19 -0
  41. data/test/eyetests/tests/draw_ellipse_basic.rb +16 -0
  42. data/test/eyetests/tests/draw_line_affine.rb +24 -0
  43. data/test/eyetests/tests/draw_line_basic.rb +20 -0
  44. data/test/eyetests/tests/draw_pattern_1.rb +35 -0
  45. data/test/eyetests/tests/draw_polygon_affine.rb +21 -0
  46. data/test/eyetests/tests/draw_polygon_basic.rb +19 -0
  47. data/test/eyetests/tests/draw_polyline_affine.rb +19 -0
  48. data/test/eyetests/tests/draw_polyline_basic.rb +18 -0
  49. data/test/eyetests/tests/draw_rectangle_affine.rb +16 -0
  50. data/test/eyetests/tests/draw_rectangle_basic.rb +16 -0
  51. data/test/eyetests/tests/draw_rmagick_test_01.rb +35 -0
  52. data/test/eyetests/tests/draw_rmagick_test_02.rb +40 -0
  53. data/test/eyetests/tests/draw_rmagick_test_03.rb +17 -0
  54. data/test/eyetests/tests/draw_rmagick_test_04.rb +21 -0
  55. data/test/eyetests/tests/draw_roundrectangle_affine.rb +19 -0
  56. data/test/eyetests/tests/draw_roundrectangle_basic.rb +16 -0
  57. data/test/eyetests/tests/gradient_fill_horizontal_diagonal_fill.rb +9 -0
  58. data/test/eyetests/tests/gradient_fill_horizontal_fill.rb +9 -0
  59. data/test/eyetests/tests/gradient_fill_point_fill.rb +9 -0
  60. data/test/eyetests/tests/gradient_fill_vertical_diagonal_fill.rb +9 -0
  61. data/test/eyetests/tests/gradient_fill_vertical_fill.rb +9 -0
  62. data/test/eyetests/tests/gruff_accumulator_bar.rb +29 -0
  63. data/test/eyetests/tests/gruff_area_1.rb +16 -0
  64. data/test/eyetests/tests/gruff_area_2.rb +27 -0
  65. data/test/eyetests/tests/gruff_bar_1.rb +29 -0
  66. data/test/eyetests/tests/gruff_bar_2.rb +19 -0
  67. data/test/eyetests/tests/gruff_line_1.rb +13 -0
  68. data/test/eyetests/tests/gruff_line_2.rb +20 -0
  69. data/test/eyetests/tests/gruff_net_1.rb +16 -0
  70. data/test/eyetests/tests/gruff_net_2.rb +16 -0
  71. data/test/eyetests/tests/gruff_pie_1.rb +21 -0
  72. data/test/eyetests/tests/gruff_pie_2.rb +22 -0
  73. data/test/eyetests/tests/gruff_scene_1.rb +14 -0
  74. data/test/eyetests/tests/gruff_scene_2.rb +14 -0
  75. data/test/eyetests/tests/gruff_sidebar.rb +32 -0
  76. data/test/eyetests/tests/gruff_sidestacked_bar_1.rb +26 -0
  77. data/test/eyetests/tests/gruff_sidestacked_bar_2.rb +26 -0
  78. data/test/eyetests/tests/gruff_spider_1.rb +22 -0
  79. data/test/eyetests/tests/gruff_spider_2.rb +15 -0
  80. data/test/eyetests/tests/gruff_stacked_bar_1.rb +23 -0
  81. data/test/eyetests/tests/gruff_stacked_bar_2.rb +26 -0
  82. data/test/eyetests/tests/hatch_fill.rb +9 -0
  83. data/test/eyetests/tests/image_list_flatten_images.rb +15 -0
  84. data/test/eyetests/tests/new_image.rb +24 -0
  85. data/test/eyetests/tests/path_a_command_01.rb +16 -0
  86. data/test/eyetests/tests/path_a_command_02.rb +19 -0
  87. data/test/eyetests/tests/path_c_command_01.rb +16 -0
  88. data/test/eyetests/tests/path_c_command_02.rb +16 -0
  89. data/test/eyetests/tests/path_complex_01.rb +16 -0
  90. data/test/eyetests/tests/path_espiral_01.rb +28 -0
  91. data/test/eyetests/tests/path_h_command_01.rb +16 -0
  92. data/test/eyetests/tests/path_h_command_02.rb +16 -0
  93. data/test/eyetests/tests/path_l_command_01.rb +16 -0
  94. data/test/eyetests/tests/path_l_command_02.rb +16 -0
  95. data/test/eyetests/tests/path_m_command_01.rb +16 -0
  96. data/test/eyetests/tests/path_m_command_02.rb +16 -0
  97. data/test/eyetests/tests/path_m_command_03.rb +16 -0
  98. data/test/eyetests/tests/path_q_command_01.rb +16 -0
  99. data/test/eyetests/tests/path_q_command_02.rb +16 -0
  100. data/test/eyetests/tests/path_q_command_03.rb +25 -0
  101. data/test/eyetests/tests/path_s_command_01.rb +16 -0
  102. data/test/eyetests/tests/path_s_command_02.rb +16 -0
  103. data/test/eyetests/tests/path_star_01.rb +16 -0
  104. data/test/eyetests/tests/path_t_command_01.rb +16 -0
  105. data/test/eyetests/tests/path_t_command_02.rb +16 -0
  106. data/test/eyetests/tests/path_v_command_01.rb +16 -0
  107. data/test/eyetests/tests/path_v_command_02.rb +16 -0
  108. data/test/eyetests/tests/store_pixel_smiley.rb +123 -0
  109. data/test/eyetests/tests/texture_fill.rb +11 -0
  110. data/test/gruff_tests/test/gruff_test_case.rb +120 -0
  111. data/test/gruff_tests/test/monkey_gruff.rb +7 -0
  112. data/test/gruff_tests/test/test_accumulator_bar.rb +50 -0
  113. data/test/gruff_tests/test/test_area.rb +134 -0
  114. data/test/gruff_tests/test/test_bar.rb +283 -0
  115. data/test/gruff_tests/test/test_base.rb +8 -0
  116. data/test/gruff_tests/test/test_bullet.rb +26 -0
  117. data/test/gruff_tests/test/test_legend.rb +71 -0
  118. data/test/gruff_tests/test/test_line.rb +493 -0
  119. data/test/gruff_tests/test/test_mini_bar.rb +32 -0
  120. data/test/gruff_tests/test/test_mini_pie.rb +20 -0
  121. data/test/gruff_tests/test/test_mini_side_bar.rb +37 -0
  122. data/test/gruff_tests/test/test_net.rb +230 -0
  123. data/test/gruff_tests/test/test_photo.rb +41 -0
  124. data/test/gruff_tests/test/test_pie.rb +154 -0
  125. data/test/gruff_tests/test/test_scene.rb +100 -0
  126. data/test/gruff_tests/test/test_side_bar.rb +12 -0
  127. data/test/gruff_tests/test/test_sidestacked_bar.rb +89 -0
  128. data/test/gruff_tests/test/test_spider.rb +216 -0
  129. data/test/gruff_tests/test/test_stacked_bar.rb +52 -0
  130. data/test/images/clown.jpg +0 -0
  131. data/test/images/texture.jpg +0 -0
  132. data/test/implemented_methods.rb +18 -0
  133. data/test/spec/draw_spec.rb +24 -0
  134. data/test/spec/image_constants.rb +76 -0
  135. data/test/spec/image_spec.rb +23 -0
  136. data/test/spec/pixel_spec.rb +84 -0
  137. data/test/spec/stories/geometry_runner.rb +13 -0
  138. data/test/spec/stories/geometry_steps.rb +24 -0
  139. data/test/spec/stories/geometry_story.rb +116 -0
  140. data/test/spec/stories/image_filling_runner.rb +13 -0
  141. data/test/spec/stories/image_filling_steps.rb +64 -0
  142. data/test/spec/stories/image_filling_story.rb +41 -0
  143. metadata +215 -0
@@ -0,0 +1,53 @@
1
+ #--
2
+ # $Id: describable.rb,v 1.4 2008/02/24 18:26:36 rmagick Exp $
3
+ # Copyright (C) 2008 Timothy P. Hunter
4
+ #++
5
+
6
+ module Magick
7
+ class RVG
8
+
9
+ #--
10
+ # Corresponds to SVG's Description.class
11
+ #++
12
+ # This module defines a number of metadata attributes.
13
+ module Describable
14
+
15
+ private
16
+
17
+ def initialize(*args, &block) #:nodoc:
18
+ super
19
+ @title, @desc, @metadata = nil
20
+ end
21
+
22
+ public
23
+
24
+ # Sets the object description
25
+ attr_writer :desc
26
+ # Sets the object title
27
+ attr_writer :title
28
+ # Sets the object metadata
29
+ attr_writer :metadata
30
+
31
+ # Returns the title of this object. The RVG object title is stored as
32
+ # the 'title' property on the image
33
+ def title
34
+ @title.to_s
35
+ end
36
+
37
+ # Returns the description of this object. The RVG object description is
38
+ # stored as the 'desc' property on the image
39
+ def desc
40
+ @desc.to_s
41
+ end
42
+
43
+ # Returns additional metadata of this object. The RVG object metadata
44
+ # are stored as the 'metadata' property on the image
45
+ def metadata
46
+ @metadata.to_s
47
+ end
48
+
49
+ end # module Describable
50
+
51
+ end # class RVG
52
+ end # module Magick
53
+
@@ -0,0 +1,417 @@
1
+ #--
2
+ # $Id: embellishable.rb,v 1.8 2008/02/24 18:26:36 rmagick Exp $
3
+ # Copyright (C) 2008 Timothy P. Hunter
4
+ #++
5
+
6
+ module Magick
7
+ class RVG
8
+
9
+ # Parent class of Circle, Ellipse, Text, etc.
10
+ class Shape #:nodoc:
11
+ include Stylable
12
+ include Transformable
13
+ include Duplicatable
14
+
15
+ # Each shape can have its own set of transforms and styles.
16
+ def add_primitives(gc)
17
+ gc.push
18
+ add_transform_primitives(gc)
19
+ add_style_primitives(gc)
20
+ gc.__send__(@primitive, *@args)
21
+ gc.pop
22
+ end
23
+
24
+ end # class Shape
25
+
26
+ class Circle < Shape
27
+
28
+ # Define a circle with radius +r+ and centered at [<tt>cx</tt>, <tt>cy</tt>].
29
+ # Use the RVG::ShapeConstructors#circle method to create Circle objects in a container.
30
+ def initialize(r, cx=0, cy=0)
31
+ super()
32
+ r, cx, cy = Magick::RVG.convert_to_float(r, cx, cy)
33
+ if r < 0
34
+ raise ArgumentError, "radius must be >= 0 (#{r} given)"
35
+ end
36
+ @primitive = :circle
37
+ @args = [cx, cy, cx+r, cy]
38
+ self
39
+ end
40
+
41
+ end # class Circle
42
+
43
+ class Ellipse < Shape
44
+
45
+ # Define an ellipse with a center at [<tt>cx</tt>, <tt>cy</tt>], a horizontal radius +rx+
46
+ # and a vertical radius +ry+.
47
+ # Use the RVG::ShapeConstructors#ellipse method to create Ellipse objects in a container.
48
+ def initialize(rx, ry, cx=0, cy=0)
49
+ super()
50
+ rx, ry, cx, cy = Magick::RVG.convert_to_float(rx, ry, cx, cy)
51
+ if rx < 0 || ry < 0
52
+ raise ArgumentError, "radii must be >= 0 (#{rx}, #{ry} given)"
53
+ end
54
+ @primitive = :ellipse
55
+ # Ellipses are always complete.
56
+ @args = [cx, cy, rx, ry, 0, 360]
57
+ end
58
+
59
+ end # class Ellipse
60
+
61
+ class Line < Shape
62
+
63
+ # Define a line from [<tt>x1</tt>, <tt>y1</tt>] to [<tt>x2</tt>, <tt>y2</tt>].
64
+ # Use the RVG::ShapeConstructors#line method to create Line objects in a container.
65
+ def initialize(x1=0, y1=0, x2=0, y2=0)
66
+ super()
67
+ @primitive = :line
68
+ @args = [x1, y1, x2, y2]
69
+ end
70
+
71
+ end # class Line
72
+
73
+ class Path < Shape
74
+
75
+ # Define an SVG path. The argument can be either a path string
76
+ # or a PathData object.
77
+ # Use the RVG::ShapeConstructors#path method to create Path objects in a container.
78
+ def initialize(path)
79
+ super()
80
+ @primitive = :path
81
+ @args = [path.to_s]
82
+ end
83
+
84
+ end # class Path
85
+
86
+ class Rect < Shape
87
+
88
+ # Define a width x height rectangle. The upper-left corner is at [<tt>x</tt>, <tt>y</tt>].
89
+ # If either <tt>width</tt> or <tt>height</tt> is 0, the rectangle is not rendered.
90
+ # Use the RVG::ShapeConstructors#rect method to create Rect objects in a container.
91
+ def initialize(width, height, x=0, y=0)
92
+ super()
93
+ width, height, x, y = Magick::RVG.convert_to_float(width, height, x, y)
94
+ if width < 0 || height < 0
95
+ raise ArgumentError, "width, height must be >= 0 (#{width}, #{height} given)"
96
+ end
97
+ @args = [x, y, x+width, y+height]
98
+ @primitive = :rectangle
99
+ end
100
+
101
+ # Specify optional rounded corners for a rectangle. The arguments
102
+ # are the x- and y-axis radii. If y is omitted it defaults to x.
103
+ def round(rx, ry=nil)
104
+ rx, ry = Magick::RVG.convert_to_float(rx, ry || rx)
105
+ if rx < 0 || ry < 0
106
+ raise ArgumentError, "rx, ry must be >= 0 (#{rx}, #{ry} given)"
107
+ end
108
+ @args << rx << ry
109
+ @primitive = :roundrectangle
110
+ self
111
+ end
112
+
113
+ end # class Rect
114
+
115
+ class PolyShape < Shape
116
+
117
+ def polypoints(points)
118
+ case points.length
119
+ when 1
120
+ points = Array(points[0])
121
+ when 2
122
+ x_coords = Array(points[0])
123
+ y_coords = Array(points[1])
124
+ unless x_coords.length > 0 && y_coords.length > 0
125
+ raise ArgumentError, "array arguments must contain at least one point"
126
+ end
127
+ n = x_coords.length - y_coords.length
128
+ short = n > 0 ? y_coords : x_coords
129
+ olen = short.length
130
+ n.abs.times {|x| short << short[x % olen]}
131
+ points = x_coords.zip(y_coords).flatten
132
+ end
133
+ n = points.length
134
+ if n < 4 || n % 2 != 0
135
+ raise ArgumentError, "insufficient/odd number of points specified: #{n}"
136
+ end
137
+ return Magick::RVG.convert_to_float(*points)
138
+ end
139
+
140
+ end # class PolyShape
141
+
142
+ class Polygon < PolyShape
143
+
144
+ # Draws a polygon. The arguments are [<tt>x</tt>, <tt>y</tt>] pairs that
145
+ # define the points that make up the polygon. At least two
146
+ # points must be specified. If the last point is not the
147
+ # same as the first, adds an additional point to close
148
+ # the polygon.
149
+ # Use the RVG::ShapeConstructors#polygon method to create Polygon objects in a container.
150
+ def initialize(*points)
151
+ super()
152
+ @primitive = :polygon
153
+ @args = polypoints(points)
154
+ end
155
+
156
+ end # class Polygon
157
+
158
+ class Polyline < PolyShape
159
+
160
+ # Draws a polyline. The arguments are [<tt>x</tt>, <tt>y</tt>] pairs that
161
+ # define the points that make up the polyline. At least two
162
+ # points must be specified.
163
+ # Use the RVG::ShapeConstructors#polyline method to create Polyline objects in a container.
164
+ def initialize(*points)
165
+ super()
166
+ points = polypoints(points)
167
+ @primitive = :polyline
168
+ @args = Magick::RVG.convert_to_float(*points)
169
+ end
170
+
171
+ end # class Polyline
172
+
173
+
174
+ class Image
175
+ include Stylable
176
+ include Transformable
177
+ include Describable
178
+ include PreserveAspectRatio
179
+ include Duplicatable
180
+
181
+ private
182
+ def align_to_viewport(scale)
183
+ tx = case @align
184
+ when 'none', /\AxMin/
185
+ 0
186
+ when NilClass, /\AxMid/
187
+ (@width - @image.columns*scale) / 2.0
188
+ when /\AxMax/
189
+ @width - @image.columns*scale
190
+ end
191
+
192
+ ty = case @align
193
+ when 'none', /YMin\z/
194
+ 0
195
+ when NilClass, /YMid\z/
196
+ (@height - @image.rows*scale) / 2.0
197
+ when /YMax\z/
198
+ @height - @image.rows*scale
199
+ end
200
+ return [tx, ty]
201
+ end
202
+
203
+ def add_composite_primitive(gc)
204
+ if @align == 'none'
205
+ # Let RMagick do the scaling
206
+ scale = 1.0
207
+ width, height = @width, @height
208
+ elsif @meet_or_slice == 'meet'
209
+ scale = [@width/@image.columns, @height/@image.rows].min
210
+ width, height = @image.columns, @image.rows
211
+ else
212
+ # Establish clipping path around the current viewport
213
+ name = __id__.to_s
214
+ gc.define_clip_path(name) do
215
+ gc.path("M#{@x},#{@y} l#{@width},0 l0,#{@height} l-#{@width},0 l0,-#{@height}z")
216
+ end
217
+
218
+ gc.clip_path(name)
219
+ scale = [@width/@image.columns, @height/@image.rows].max
220
+ width, height = @image.columns, @image.rows
221
+ end
222
+ tx, ty = align_to_viewport(scale)
223
+ gc.composite(@x+tx, @y+ty, width*scale, height*scale, @image)
224
+ end
225
+
226
+ def init_viewbox()
227
+ @align = nil
228
+ @vbx_width, @vbx_height = @image.columns, @image.rows
229
+ @meet_or_slice = 'meet'
230
+ end
231
+
232
+ public
233
+
234
+ # Composite a raster image in the viewport defined by [x,y] and
235
+ # +width+ and +height+.
236
+ # Use the RVG::ImageConstructors#image method to create Text objects in a container.
237
+ def initialize(image, width=nil, height=nil, x=0, y=0)
238
+ super() # run module initializers
239
+ @image = image.copy # use a copy of the image in case app. re-uses the argument
240
+ @x, @y, @width, @height = Magick::RVG.convert_to_float(x, y, width || @image.columns, height || @image.rows)
241
+ if @width < 0 || @height < 0
242
+ raise ArgumentError, "width, height must be >= 0"
243
+ end
244
+ init_viewbox()
245
+ end
246
+
247
+ def add_primitives(gc) #:nodoc:
248
+ # Do not render if width or height is 0
249
+ return if @width == 0 || @height == 0
250
+ gc.push
251
+ add_transform_primitives(gc)
252
+ add_style_primitives(gc)
253
+ add_composite_primitive(gc)
254
+ gc.pop
255
+ end
256
+
257
+ end # class Image
258
+
259
+
260
+ # Methods that construct basic shapes within a container
261
+ module ShapeConstructors
262
+
263
+ # Draws a circle whose center is [<tt>cx</tt>, <tt>cy</tt>] and radius is +r+.
264
+ def circle(r, cx=0, cy=0)
265
+ circle = Circle.new(r, cx, cy)
266
+ @content << circle
267
+ return circle
268
+ end
269
+
270
+ # Draws an ellipse whose center is [<tt>cx</tt>, <tt>cy</tt>] and having
271
+ # a horizontal radius +rx+ and vertical radius +ry+.
272
+ def ellipse(rx, ry, cx=0, cy=0)
273
+ ellipse = Ellipse.new(rx, ry, cx, cy)
274
+ @content << ellipse
275
+ return ellipse
276
+ end
277
+
278
+ # Draws a line from [<tt>x1</tt>, <tt>y1</tt>] to [<tt>x2</tt>, <tt>y2</tt>].
279
+ def line(x1=0, y1=0, x2=0, y2=0)
280
+ line = Line.new(x1, y1, x2, y2)
281
+ @content << line
282
+ return line
283
+ end
284
+
285
+ # Draws a path defined by an SVG path string or a PathData
286
+ # object.
287
+ def path(path)
288
+ path = Path.new(path)
289
+ @content << path
290
+ return path
291
+ end
292
+
293
+ # Draws a rectangle whose upper-left corner is [<tt>x</tt>, <tt>y</tt>] and
294
+ # with the specified +width+ and +height+. Unless otherwise
295
+ # specified the rectangle has square corners. Returns a
296
+ # Rectangle object.
297
+ #
298
+ # Draw a rectangle with rounded corners by calling the #round
299
+ # method on the Rectangle object. <tt>rx</tt> and <tt>ry</tt> are
300
+ # the corner radii in the x- and y-directions. For example:
301
+ # canvas.rect(width, height, x, y).round(8, 6)
302
+ # If <tt>ry</tt> is omitted it defaults to <tt>rx</tt>.
303
+ def rect(width, height, x=0, y=0)
304
+ rect = Rect.new(width, height, x, y)
305
+ @content << rect
306
+ return rect
307
+ end
308
+
309
+ # Draws a polygon. The arguments are [<tt>x</tt>, <tt>y</tt>] pairs that
310
+ # define the points that make up the polygon. At least two
311
+ # points must be specified. If the last point is not the
312
+ # same as the first, adds an additional point to close
313
+ # the polygon.
314
+ def polygon(*points)
315
+ polygon = Polygon.new(*points)
316
+ @content << polygon
317
+ return polygon
318
+ end
319
+
320
+ # Draws a polyline. The arguments are [<tt>x</tt>, <tt>y</tt>] pairs that
321
+ # define the points that make up the polyline. At least two
322
+ # points must be specified.
323
+ def polyline(*points)
324
+ polyline = Polyline.new(*points)
325
+ @content << polyline
326
+ return polyline
327
+ end
328
+
329
+ end # module ShapeContent
330
+
331
+ # Methods that reference ("use") other drawable objects within a container
332
+ module UseConstructors
333
+
334
+ # Reference an object to be inserted into the container's
335
+ # content. [<tt>x</tt>,<tt>y</tt>] is the offset from the upper-left
336
+ # corner. If the argument is an RVG or Image object and +width+ and +height+
337
+ # are specified, these values will override the +width+ and +height+
338
+ # attributes on the argument.
339
+ def use(obj, x=0, y=0, width=nil, height=nil)
340
+ use = Use.new(obj, x, y, width, height)
341
+ @content << use
342
+ return use
343
+ end
344
+
345
+ end # module UseConstructors
346
+
347
+ # Methods that construct container objects within a container
348
+ module StructureConstructors
349
+
350
+ # Establishes a new viewport. [<tt>x</tt>, <tt>y</tt>] is the coordinate of the
351
+ # upper-left corner within the containing viewport. This is a
352
+ # _container_ method. Styles and
353
+ # transforms specified on this object will be used by objects
354
+ # contained within, unless overridden by an inner container or
355
+ # the contained object itself.
356
+ def rvg(cols, rows, x=0, y=0, &block)
357
+ rvg = Magick::RVG.new(cols, rows, &block)
358
+ begin
359
+ x, y = Float(x), Float(y)
360
+ rescue ArgumentError
361
+ args = [cols, rows, x, y]
362
+ raise ArgumentError, "at least one argument is not convertable to Float (got #{args.collect {|a| a.class}.join(', ')})"
363
+ end
364
+ rvg.corner(x, y)
365
+ @content << rvg
366
+ return rvg
367
+ end
368
+
369
+ # Defines a group.
370
+ #
371
+ # This method constructs a new
372
+ # Group _container_ object. The styles and
373
+ # transforms specified on this object will be used by objects
374
+ # contained within, unless overridden by an inner container or
375
+ # the contained object itself.
376
+ # Define grouped elements by calling RVG::Embellishable
377
+ # methods within the associated block.
378
+ def g(&block)
379
+ group = Group.new(&block)
380
+ @content << group
381
+ return group
382
+ end
383
+
384
+ end # module StructureConstructors
385
+
386
+ # Methods that construct raster image objects within a container
387
+ module ImageConstructors
388
+
389
+ # Composite a raster image at [<tt>x</tt>,<tt>y</tt>]
390
+ # in a viewport of the specified <tt>width</tt> and <tt>height</tt>.
391
+ # If not specified, the width and height are the width and height
392
+ # of the image. Use the RVG::PreserveAspectRatio#preserve_aspect_ratio method to
393
+ # control the placement and scaling of the image within the
394
+ # viewport. By default, the image is scaled to fit inside the
395
+ # viewport and centered within the viewport.
396
+ def image(image, width=nil, height=nil, x=0, y=0)
397
+ img = Image.new(image, width, height, x, y)
398
+ @content << img
399
+ return img
400
+ end
401
+
402
+ end # module ImageConstructors
403
+
404
+ # Methods that create shapes, text, and other drawable objects
405
+ # within container objects such as ::Magick::RVG and
406
+ # ::Magick::RVG::Group
407
+ module Embellishable
408
+ include StructureConstructors
409
+ include ShapeConstructors
410
+ include TextConstructors
411
+ include UseConstructors
412
+ include ImageConstructors
413
+ end # module Embellishable
414
+
415
+ end # class RVG
416
+ end # module Magick
417
+