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
data/lib/rvg/paint.rb ADDED
@@ -0,0 +1,55 @@
1
+ #--
2
+ # $Id: paint.rb,v 1.5 2008/02/24 18:26:36 rmagick Exp $
3
+ # Copyright (C) 2008 Timothy P. Hunter
4
+ #++
5
+ # Defines paint server classes.
6
+ # Eventually this will include gradients.
7
+
8
+ module Magick
9
+ class RVG
10
+
11
+ class Pattern
12
+ include StructureConstructors
13
+ include UseConstructors
14
+ include ShapeConstructors
15
+ include TextConstructors
16
+ include ImageConstructors
17
+ include Stretchable
18
+ include Duplicatable
19
+ include Stylable
20
+
21
+ # Return upper-left corner, width, height of viewport in user coordinates.
22
+ # Usually these are the values specified when the Pattern object is
23
+ # created, but they can be changed by a call to the viewbox method.
24
+ attr_reader :x, :y, :width, :height
25
+
26
+ # Create a pattern that can be used with the :fill or :stroke styles.
27
+ # The +width+ and +height+ arguments define the viewport.
28
+ # The pattern will be repeated at <tt>x+m*width</tt> and <tt>y+n*height</tt>
29
+ # offsets.
30
+ #
31
+ # Define the pattern in the block.
32
+ # The pattern can be composed of shapes (rectangle, circles, etc.), text,
33
+ # raster images and container objects. You can include graphic objects by
34
+ # referring to them with #use.
35
+ def initialize(width=0, height=0, x=0, y=0)
36
+ super()
37
+ @width, @height, @x, @y = Magick::RVG.convert_to_float(width, height, x, y)
38
+ @content = Content.new
39
+ yield(self) if block_given?
40
+ end
41
+
42
+ def add_primitives(gc, style) #:nodoc:
43
+ name = __id__.to_s
44
+ gc.pattern(name, @x, @y, @width, @height) do
45
+ add_viewbox_primitives(@width, @height, gc)
46
+ @content.each { |element| element.add_primitives(gc) }
47
+ end
48
+ gc.__send__(style, name)
49
+ end
50
+
51
+ end # class Pattern
52
+
53
+ end # class RVG
54
+ end # module Magick
55
+
@@ -0,0 +1,131 @@
1
+ #--
2
+ # $Id: pathdata.rb,v 1.4 2008/02/24 18:26:37 rmagick Exp $
3
+ # Copyright (C) 2008 Timothy P. Hunter
4
+ #++
5
+
6
+ module Magick
7
+ class RVG
8
+
9
+ # The PathData class provides an object-oriented way to produce an SVG
10
+ # path. Each of the methods corresponds to a path command. Construct a
11
+ # path by calling one or more methods. The path object can be passed
12
+ # as an argument to the RVG::ShapeConstructors#path method.
13
+ class PathData
14
+
15
+ private
16
+ def add_points(req, *coords)
17
+ if coords
18
+ if coords.length % req != 0
19
+ raise ArgumentError, "wrong number of coordinates specified. A multiple of #{req} required, #{req+coords.length} given."
20
+ end
21
+ coords.each {|c| @path << ("%g" % c)}
22
+ end
23
+ end
24
+
25
+ public
26
+
27
+ # Construct an empty path
28
+ def initialize
29
+ @path = ''
30
+ end
31
+
32
+ # Convert the path to its string equivalent.
33
+ def to_s
34
+ @path
35
+ end
36
+
37
+ def deep_copy(h=nil) #:nodoc:
38
+ @path.dup
39
+ end
40
+
41
+ # Add a <tt>moveto</tt> command. If <tt>abs</tt> is
42
+ # <tt>true</tt> the coordinates are absolute, otherwise
43
+ # the coordinates are relative.
44
+ def moveto(abs, x, y, *coords)
45
+ @path << sprintf("%s%g,%g ", (abs ? 'M' : 'm'), x, y)
46
+ # "subsequent pairs are treated as implicit lineto commands"
47
+ add_points(2, *coords)
48
+ end
49
+
50
+ # Add a <tt>closepath</tt> command. The <tt>abs</tt> argument
51
+ # is ignored.
52
+ def closepath(abs=true)
53
+ @path << 'Z' # ignore `abs'
54
+ end
55
+
56
+ # Add a <tt>lineto</tt> command. Any number of x,y coordinate
57
+ # pairs may be specified. If <tt>abs</tt> is
58
+ # <tt>true</tt> the coordinates are absolute, otherwise
59
+ # the coordinates are relative.
60
+ def lineto(abs, x, y, *coords)
61
+ @path << sprintf("%s%g,%g ", (abs ? 'L' : 'l'), x, y)
62
+ # "a number of coordinate pairs may be specified to draw a polyline"
63
+ add_points(2, *coords)
64
+ end
65
+
66
+ # Add a <tt>horizontal lineto</tt> command. If <tt>abs</tt> is
67
+ # <tt>true</tt> the coordinates are absolute, otherwise
68
+ # the coordinates are relative.
69
+ def hlineto(abs, x)
70
+ @path << sprintf("%s%g ", (abs ? 'H' : 'h'), x)
71
+ end
72
+
73
+ # Add a <tt>vertical lineto</tt> command. If <tt>abs</tt> is
74
+ # <tt>true</tt> the coordinates are absolute, otherwise
75
+ # the coordinates are relative.
76
+ def vlineto(abs, y)
77
+ @path << sprintf("%s%g ", (abs ? 'V' : 'v'), y)
78
+ end
79
+
80
+ # Add a <tt>curveto</tt> (<em>cubic Bezier</em>) command.
81
+ # If <tt>abs</tt> is
82
+ # <tt>true</tt> the coordinates are absolute, otherwise
83
+ # the coordinates are relative.
84
+ def curveto(abs, x1, y1, x2, y2, x, y, *coords)
85
+ @path << sprintf("%s%g,%g %g,%g %g,%g ", (abs ? 'C' : 'c'), x1, y1, x2, y2, x, y)
86
+ # "multiple sets of coordinates may be specified to draw a polybezier"
87
+ add_points(6, *coords)
88
+ end
89
+
90
+ # Add a <tt>smooth curveto</tt> (<em>cubic Bezier</em>) command.
91
+ # If <tt>abs</tt> is
92
+ # <tt>true</tt> the coordinates are absolute, otherwise
93
+ # the coordinates are relative.
94
+ def smooth_curveto(abs, x2, y2, x, y, *coords)
95
+ @path << sprintf("%s%g,%g %g,%g ", (abs ? 'S' : 's'), x2, y2, x, y)
96
+ # "multiple sets of coordinates may be specified to draw a polybezier"
97
+ add_points(4, *coords)
98
+ end
99
+
100
+ # Add a <tt>quadratic Bezier curveto</tt> command.
101
+ # If <tt>abs</tt> is
102
+ # <tt>true</tt> the coordinates are absolute, otherwise
103
+ # the coordinates are relative.
104
+ def quadratic_curveto(abs, x1, y1, x, y, *coords)
105
+ @path << sprintf("%s%g,%g %g,%g ", (abs ? 'Q' : 'q'), x1, y1, x, y)
106
+ add_points(4, *coords)
107
+ end
108
+
109
+ # Add a <tt>smooth quadratic Bezier curveto</tt> command.
110
+ # If <tt>abs</tt> is
111
+ # <tt>true</tt> the coordinates are absolute, otherwise
112
+ # the coordinates are relative.
113
+ def smooth_quadratic_curveto(abs, x, y, *coords)
114
+ @path << sprintf("%s%g,%g ", (abs ? 'T' : 't'), x, y)
115
+ add_points(2, *coords)
116
+ end
117
+
118
+ # Add an <tt>arc</tt> command.
119
+ # If <tt>abs</tt> is
120
+ # <tt>true</tt> the coordinates are absolute, otherwise
121
+ # the coordinates are relative.
122
+
123
+ def arc(abs, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y)
124
+ @path << sprintf("%s%g,%g %g %d %d %g,%g ", (abs ? 'A' : 'a'), rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y)
125
+ end
126
+
127
+ end # class PathData
128
+
129
+ end # class RVG
130
+ end # module Magick
131
+
data/lib/rvg/rvg.rb ADDED
@@ -0,0 +1,283 @@
1
+ #--############################################################################
2
+ # $Id: rvg.rb,v 1.9 2008/02/24 21:15:24 rmagick Exp $
3
+ #
4
+ # Copyright (C) 2008 by Timothy P. Hunter
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a
7
+ # copy of this software and associated documentation files (the
8
+ # "Software"), to deal in the Software without restriction, including
9
+ # without limitation the rights to use, copy, modify, merge, publish,
10
+ # distribute, sublicense, and/or sell copies of the Software, and to
11
+ # permit persons to whom the Software is furnished to do so, subject to
12
+ # the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included
15
+ # in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ #
25
+ #
26
+ # This software is OSI Certified Open Source Software.
27
+ # OSI Certified is a certification mark of the Open Source Initiative.
28
+ #
29
+ #++############################################################################
30
+
31
+ require 'RMagick'
32
+ require 'rvg/misc'
33
+ require 'rvg/describable'
34
+ require 'rvg/stylable'
35
+ require 'rvg/transformable'
36
+ require 'rvg/stretchable'
37
+ require 'rvg/text'
38
+ require 'rvg/embellishable'
39
+ require 'rvg/container'
40
+ require 'rvg/pathdata'
41
+ require 'rvg/clippath'
42
+ require 'rvg/paint'
43
+ require 'rvg/units'
44
+
45
+ require 'pp' if ENV['debug_rvg']
46
+
47
+ # RVG is the main class in this library. All graphic elements
48
+ # must be contained within an RVG object.
49
+ module Magick
50
+ class RVG
51
+
52
+ include Stylable
53
+ include Transformable
54
+ include Stretchable
55
+ include Embellishable
56
+ include Describable
57
+ include Duplicatable
58
+
59
+ private
60
+
61
+ # background_fill defaults to 'none'. If background_fill has been set to something
62
+ # else, combine it with the background_fill_opacity.
63
+ def bgfill()
64
+ if @background_fill.nil?
65
+ color = Magick::Pixel.new(0,0,0,Magick::TransparentOpacity)
66
+ else
67
+ color = @background_fill
68
+ color.opacity = (1.0 - @background_fill_opacity) * Magick::TransparentOpacity
69
+ end
70
+ return color
71
+ end
72
+
73
+ def new_canvas
74
+ if @background_pattern
75
+ canvas = Magick::Image.new(@width, @height, @background_pattern)
76
+ elsif @background_image
77
+ if @width != @background_image.columns || @height != @background_image.rows
78
+ canvas = case @background_position
79
+ when :scaled
80
+ @background_image.resize(@width, @height)
81
+ when :tiled
82
+ Magick::Image.new(@width, @height, Magick::TextureFill.new(@background_image))
83
+ when :fit
84
+ width, height = @width, @height
85
+ bgcolor = bgfill()
86
+ @background_image.change_geometry(Magick::Geometry.new(width, height)) do |new_cols, new_rows|
87
+ bg_image = @background_image.resize(new_cols, new_rows)
88
+ if bg_image.columns != width || bg_image.rows != height
89
+ bg = Magick::Image.new(width, height) { self.background_color = bgcolor }
90
+ bg_image = bg.composite!(bg_image, Magick::CenterGravity, Magick::OverCompositeOp)
91
+ end
92
+ bg_image
93
+ end
94
+ end
95
+ else
96
+ canvas = @background_image.copy
97
+ end
98
+ else
99
+ bgcolor = bgfill()
100
+ canvas = Magick::Image.new(Integer(@width), Integer(@height)) { self.background_color = bgcolor }
101
+ end
102
+ canvas[:desc] = @desc if @desc
103
+ canvas[:title] = @title if @title
104
+ canvas[:metadata] = @metadata if @metadata
105
+ return canvas
106
+ end
107
+
108
+ if ENV['debug_prim']
109
+ def print_gc(gc)
110
+ primitives = gc.inspect.split(/\n/)
111
+ indent = 0
112
+ primitives.each do |cmd|
113
+ indent -= 1 if cmd['pop ']
114
+ print((' '*indent), cmd, "\n")
115
+ indent += 1 if cmd['push ']
116
+ end
117
+ end
118
+ end
119
+
120
+ public
121
+
122
+ WORD_SEP = / / # Regexp to separate words
123
+
124
+ # The background image specified by background_image=
125
+ attr_reader :background_image
126
+ # The background image layout specified by background_position=
127
+ attr_reader :background_position
128
+ # The background fill color specified by background_fill=
129
+ attr_reader :background_fill
130
+ # The background fill color opacity specified by background_fill_opacity=
131
+ attr_reader :background_fill_opacity
132
+ # The image after drawing has completed
133
+ attr_reader :canvas
134
+ # For embedded RVG objects, the x-axis coordinate of the upper-left corner
135
+ attr_reader :x
136
+ # For embedded RVG objects, the x-axis coordinate of the upper-left corner
137
+ attr_reader :y
138
+ attr_reader :width, :height
139
+
140
+ # Sets an image to use as the canvas background. See background_position= for layout options.
141
+ def background_image=(bg_image)
142
+ warn "background_image= has no effect in nested RVG objects" if @nested
143
+ if bg_image && ! bg_image.kind_of?(Magick::Image)
144
+ raise ArgumentError, "background image must be an Image (got #{bg_image.class})"
145
+ end
146
+ @background_image = bg_image
147
+ end
148
+
149
+ # Sets an object to use to fill the canvas background.
150
+ # The object must have a <tt>fill</tt> method. See the <b>Fill Classes</b>
151
+ # section in the RMagick doc for more information.
152
+ def background_pattern=(filler)
153
+ warn "background_pattern= has no effect in nested RVG objects" if @nested
154
+ @background_pattern = filler
155
+ end
156
+
157
+ # How to position the background image on the canvas. One of the following symbols:
158
+ # [:scaled] Scale the image to the canvas width and height.
159
+ # [:tiled] Tile the image across the canvas.
160
+ # [:fit] Scale the image to fit within the canvas while retaining the
161
+ # image proportions. Center the image on the canvas. Color any part of
162
+ # the canvas not covered by the image with the background color.
163
+ def background_position=(pos)
164
+ warn "background_position= has no effect in nested RVG objects" if @nested
165
+ bg_pos = pos.to_s.downcase
166
+ if ! ['scaled', 'tiled', 'fit'].include?(bg_pos)
167
+ raise ArgumentError, "background position must be `scaled', `tiled', or `fit' (#{pos} given)"
168
+ end
169
+ @background_position = bg_pos.to_sym
170
+ end
171
+
172
+ # Sets the canvas background color. Either a Magick::Pixel or a color name.
173
+ # The default fill is "none", that is, transparent black.
174
+ def background_fill=(color)
175
+ warn "background_fill= has no effect in nested RVG objects" if @nested
176
+ if ! color.kind_of?(Magick::Pixel)
177
+ begin
178
+ @background_fill = Magick::Pixel.from_color(color)
179
+ rescue Magick::ImageMagickError
180
+ raise ArgumentError, "unknown color `#{color}'"
181
+ rescue TypeError
182
+ raise TypeError, "cannot convert #{color.class} into Pixel"
183
+ rescue
184
+ raise ArgumentError, "argument must be a color name or a Pixel (got #{color.class})"
185
+ end
186
+ else
187
+ @background_fill = color
188
+ end
189
+ end
190
+
191
+ # Opacity of the background fill color, a number between 0.0 (transparent) and
192
+ # 1.0 (opaque). The default is 1.0 when the background_fill= attribute has been set.
193
+ def background_fill_opacity=(opacity)
194
+ warn "background_fill_opacity= has no effect in nested RVG objects" if @nested
195
+ begin
196
+ @background_fill_opacity = Float(opacity)
197
+ rescue ArgumentError
198
+ raise ArgumentError, "background_fill_opacity must be a number between 0 and 1 (#{opacity} given)"
199
+ end
200
+ end
201
+
202
+ # Draw a +width+ x +height+ image. The image is specified by calling
203
+ # one or more drawing methods on the RVG object.
204
+ # You can group the drawing method calls in the optional associated block.
205
+ # The +x+ and +y+ arguments have no meaning for the outermost RVG object.
206
+ # On nested RVG objects [+x+, +y+] is the coordinate of the upper-left
207
+ # corner in the containing canvas on which the nested RVG object is placed.
208
+ #
209
+ # Drawing occurs on a +canvas+ created by the #draw method. By default the
210
+ # canvas is transparent. You can specify a different canvas with the
211
+ # #background_fill= or #background_image= methods.
212
+ #
213
+ # RVG objects are _containers_. That is, styles and transforms defined
214
+ # on the object are used by contained objects such as shapes, text, and
215
+ # groups unless overridden by an inner container or the object itself.
216
+ def initialize(width=nil, height=nil)
217
+ super
218
+ @width, @height = width, height
219
+ @content = Content.new
220
+ @canvas = nil
221
+ @background_fill = nil
222
+ @background_fill_opacity = 1.0 # applies only if background_fill= is used
223
+ @background_position = :scaled
224
+ @background_pattern, @background_image, @desc, @title, @metadata = nil
225
+ @x, @y = 0.0, 0.0
226
+ @nested = false
227
+ yield(self) if block_given?
228
+ end
229
+
230
+ # Construct a canvas or reuse an existing canvas.
231
+ # Execute drawing commands. Return the canvas.
232
+ def draw
233
+ raise StandardError, "draw not permitted in nested RVG objects" if @nested
234
+ @canvas ||= new_canvas # allow drawing over existing canvas
235
+ gc = Utility::GraphicContext.new
236
+ add_outermost_primitives(gc)
237
+ pp(self) if ENV['debug_rvg']
238
+ print_gc(gc) if ENV['debug_prim']
239
+ gc.draw(@canvas)
240
+ return @canvas
241
+ end
242
+
243
+ # Accept #use arguments. Use (x,y) to generate an additional translate.
244
+ # Override @width and @height if new values are supplied.
245
+ def ref(x, y, rw, rh) #:nodoc:
246
+ translate(x, y) if (x != 0 || y != 0)
247
+ @width = rw if rw
248
+ @height = rh if rh
249
+ end
250
+
251
+ # Used by Magick::Embellishable.rvg to set non-0 x- and y-coordinates
252
+ def corner(x, y) #:nodoc:
253
+ @nested = true
254
+ @x, @y = Float(x), Float(y)
255
+ translate(@x, @y) if (@x != 0.0 || @y != 0.0)
256
+ end
257
+
258
+ # Primitives for the outermost RVG object
259
+ def add_outermost_primitives(gc) #:nodoc:
260
+ add_transform_primitives(gc)
261
+ gc.push
262
+ add_viewbox_primitives(@width, @height, gc)
263
+ add_style_primitives(gc)
264
+ @content.each { |element| element.add_primitives(gc) }
265
+ gc.pop
266
+ self
267
+ end
268
+
269
+ # Primitives for nested RVG objects
270
+ def add_primitives(gc) #:nodoc:
271
+ if @width.nil? || @height.nil?
272
+ raise ArgumentError, "RVG width or height undefined"
273
+ elsif @width == 0 || @height == 0
274
+ return self
275
+ end
276
+ gc.push
277
+ add_outermost_primitives(gc)
278
+ gc.pop
279
+ end
280
+
281
+ end # end class RVG
282
+ end # end module Magick
283
+