rmagick 2.13.4 → 2.16.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rmagick might be problematic. Click here for more details.

Files changed (281) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +14 -0
  3. data/.hound.yml +2 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +340 -0
  6. data/.simplecov +27 -0
  7. data/.travis.yml +29 -12
  8. data/CHANGELOG.md +915 -0
  9. data/CODE_OF_CONDUCT.md +13 -0
  10. data/CONTRIBUTING.md +31 -3
  11. data/Gemfile +3 -0
  12. data/README.textile +94 -4
  13. data/Rakefile +57 -45
  14. data/before_install_linux.sh +26 -6
  15. data/deprecated/RMagick.rb +6 -0
  16. data/doc/comtasks.html +1 -1
  17. data/doc/draw.html +7 -4
  18. data/doc/ex/InitialCoords.rb +16 -17
  19. data/doc/ex/NewCoordSys.rb +21 -23
  20. data/doc/ex/OrigCoordSys.rb +8 -10
  21. data/doc/ex/PreserveAspectRatio.rb +182 -183
  22. data/doc/ex/RotateScale.rb +27 -28
  23. data/doc/ex/Skew.rb +27 -27
  24. data/doc/ex/Use01.rb +7 -8
  25. data/doc/ex/Use02.rb +11 -12
  26. data/doc/ex/Use03.rb +7 -7
  27. data/doc/ex/ViewBox.rb +16 -18
  28. data/doc/ex/adaptive_threshold.rb +4 -5
  29. data/doc/ex/add_noise.rb +4 -5
  30. data/doc/ex/affine.rb +4 -4
  31. data/doc/ex/affine_transform.rb +4 -4
  32. data/doc/ex/arc.rb +10 -10
  33. data/doc/ex/arcpath.rb +7 -8
  34. data/doc/ex/arcs01.rb +10 -10
  35. data/doc/ex/arcs02.rb +36 -38
  36. data/doc/ex/average.rb +5 -5
  37. data/doc/ex/axes.rb +4 -4
  38. data/doc/ex/baseline_shift01.rb +11 -12
  39. data/doc/ex/bilevel_channel.rb +2 -3
  40. data/doc/ex/blur_image.rb +2 -2
  41. data/doc/ex/border.rb +2 -2
  42. data/doc/ex/bounding_box.rb +9 -11
  43. data/doc/ex/cbezier1.rb +3 -4
  44. data/doc/ex/cbezier2.rb +3 -4
  45. data/doc/ex/cbezier3.rb +3 -4
  46. data/doc/ex/cbezier4.rb +3 -4
  47. data/doc/ex/cbezier5.rb +2 -3
  48. data/doc/ex/cbezier6.rb +3 -3
  49. data/doc/ex/channel.rb +10 -11
  50. data/doc/ex/charcoal.rb +2 -2
  51. data/doc/ex/chop.rb +2 -2
  52. data/doc/ex/circle.rb +3 -3
  53. data/doc/ex/circle01.rb +6 -7
  54. data/doc/ex/clip_path.rb +12 -12
  55. data/doc/ex/coalesce.rb +32 -35
  56. data/doc/ex/color_fill_to_border.rb +6 -6
  57. data/doc/ex/color_floodfill.rb +2 -2
  58. data/doc/ex/color_histogram.rb +17 -18
  59. data/doc/ex/color_reset.rb +2 -2
  60. data/doc/ex/colorize.rb +2 -2
  61. data/doc/ex/colors.rb +30 -30
  62. data/doc/ex/compose_mask.rb +8 -9
  63. data/doc/ex/composite.rb +14 -16
  64. data/doc/ex/composite_layers.rb +15 -15
  65. data/doc/ex/composite_tiled.rb +5 -7
  66. data/doc/ex/contrast.rb +12 -12
  67. data/doc/ex/crop.rb +3 -3
  68. data/doc/ex/crop_with_gravity.rb +13 -17
  69. data/doc/ex/cubic01.rb +18 -20
  70. data/doc/ex/cubic02.rb +64 -67
  71. data/doc/ex/cycle_colormap.rb +2 -2
  72. data/doc/ex/dissolve.rb +2 -3
  73. data/doc/ex/drawcomp.rb +34 -34
  74. data/doc/ex/drop_shadow.rb +8 -8
  75. data/doc/ex/edge.rb +2 -2
  76. data/doc/ex/ellipse.rb +4 -4
  77. data/doc/ex/ellipse01.rb +10 -11
  78. data/doc/ex/emboss.rb +2 -2
  79. data/doc/ex/enhance.rb +2 -2
  80. data/doc/ex/equalize.rb +2 -2
  81. data/doc/ex/evenodd.rb +31 -32
  82. data/doc/ex/fill_pattern.rb +12 -15
  83. data/doc/ex/flatten_images.rb +13 -13
  84. data/doc/ex/flip.rb +2 -2
  85. data/doc/ex/flop.rb +2 -2
  86. data/doc/ex/font_styles.rb +21 -23
  87. data/doc/ex/fonts.rb +14 -14
  88. data/doc/ex/frame.rb +3 -3
  89. data/doc/ex/gaussian_blur.rb +2 -2
  90. data/doc/ex/get_multiline_type_metrics.rb +6 -7
  91. data/doc/ex/get_pixels.rb +13 -14
  92. data/doc/ex/get_type_metrics.rb +26 -31
  93. data/doc/ex/gradientfill.rb +12 -12
  94. data/doc/ex/grav.rb +4 -5
  95. data/doc/ex/gravity.rb +61 -60
  96. data/doc/ex/group.rb +16 -16
  97. data/doc/ex/hatchfill.rb +10 -10
  98. data/doc/ex/image.rb +29 -31
  99. data/doc/ex/implode.rb +17 -17
  100. data/doc/ex/level.rb +2 -2
  101. data/doc/ex/level_colors.rb +4 -4
  102. data/doc/ex/line.rb +4 -5
  103. data/doc/ex/line01.rb +11 -13
  104. data/doc/ex/mask.rb +7 -8
  105. data/doc/ex/matte_fill_to_border.rb +2 -3
  106. data/doc/ex/matte_floodfill.rb +2 -3
  107. data/doc/ex/matte_replace.rb +2 -3
  108. data/doc/ex/median_filter.rb +2 -2
  109. data/doc/ex/modulate.rb +2 -2
  110. data/doc/ex/mono.rb +4 -4
  111. data/doc/ex/morph.rb +7 -8
  112. data/doc/ex/mosaic.rb +15 -15
  113. data/doc/ex/motion_blur.rb +2 -2
  114. data/doc/ex/negate.rb +2 -2
  115. data/doc/ex/negate_channel.rb +2 -2
  116. data/doc/ex/nested_rvg.rb +11 -11
  117. data/doc/ex/nonzero.rb +31 -32
  118. data/doc/ex/normalize.rb +2 -2
  119. data/doc/ex/oil_paint.rb +2 -2
  120. data/doc/ex/opacity.rb +3 -3
  121. data/doc/ex/ordered_dither.rb +2 -2
  122. data/doc/ex/path.rb +4 -5
  123. data/doc/ex/pattern1.rb +10 -10
  124. data/doc/ex/pattern2.rb +7 -7
  125. data/doc/ex/polaroid.rb +13 -14
  126. data/doc/ex/polygon.rb +6 -7
  127. data/doc/ex/polygon01.rb +10 -12
  128. data/doc/ex/polyline.rb +4 -5
  129. data/doc/ex/polyline01.rb +11 -13
  130. data/doc/ex/posterize.rb +2 -2
  131. data/doc/ex/preview.rb +3 -4
  132. data/doc/ex/qbezierpath.rb +5 -5
  133. data/doc/ex/quad01.rb +23 -25
  134. data/doc/ex/quantize-m.rb +5 -5
  135. data/doc/ex/radial_blur.rb +2 -2
  136. data/doc/ex/raise.rb +2 -2
  137. data/doc/ex/random_threshold_channel.rb +2 -2
  138. data/doc/ex/rect01.rb +6 -7
  139. data/doc/ex/rect02.rb +9 -11
  140. data/doc/ex/rectangle.rb +3 -4
  141. data/doc/ex/reduce_noise.rb +2 -2
  142. data/doc/ex/remap.rb +7 -8
  143. data/doc/ex/remap_images.rb +9 -11
  144. data/doc/ex/resize_to_fill.rb +3 -5
  145. data/doc/ex/resize_to_fit.rb +3 -5
  146. data/doc/ex/roll.rb +2 -2
  147. data/doc/ex/rotate.rb +6 -7
  148. data/doc/ex/rotate_f.rb +2 -2
  149. data/doc/ex/roundrect.rb +4 -5
  150. data/doc/ex/rubyname.rb +11 -11
  151. data/doc/ex/rvg_clippath.rb +5 -7
  152. data/doc/ex/rvg_linecap.rb +25 -26
  153. data/doc/ex/rvg_linejoin.rb +25 -26
  154. data/doc/ex/rvg_opacity.rb +10 -11
  155. data/doc/ex/rvg_pattern.rb +15 -15
  156. data/doc/ex/rvg_stroke_dasharray.rb +6 -7
  157. data/doc/ex/segment.rb +2 -2
  158. data/doc/ex/sepiatone.rb +2 -3
  159. data/doc/ex/shade.rb +2 -2
  160. data/doc/ex/shadow.rb +2 -3
  161. data/doc/ex/shave.rb +2 -2
  162. data/doc/ex/shear.rb +3 -3
  163. data/doc/ex/sketch.rb +2 -3
  164. data/doc/ex/skewx.rb +4 -5
  165. data/doc/ex/skewy.rb +3 -3
  166. data/doc/ex/smile.rb +113 -113
  167. data/doc/ex/solarize.rb +2 -2
  168. data/doc/ex/sparse_color.rb +29 -30
  169. data/doc/ex/splice.rb +2 -3
  170. data/doc/ex/spread.rb +2 -2
  171. data/doc/ex/stegano.rb +34 -34
  172. data/doc/ex/stroke_dasharray.rb +4 -5
  173. data/doc/ex/stroke_fill.rb +4 -5
  174. data/doc/ex/stroke_linecap.rb +3 -3
  175. data/doc/ex/stroke_linejoin.rb +3 -3
  176. data/doc/ex/stroke_width.rb +3 -3
  177. data/doc/ex/swirl.rb +2 -2
  178. data/doc/ex/text.rb +4 -4
  179. data/doc/ex/text01.rb +7 -8
  180. data/doc/ex/text_align.rb +2 -2
  181. data/doc/ex/text_antialias.rb +9 -10
  182. data/doc/ex/text_styles.rb +11 -13
  183. data/doc/ex/text_undercolor.rb +2 -2
  184. data/doc/ex/texture_fill_to_border.rb +6 -6
  185. data/doc/ex/texture_floodfill.rb +2 -2
  186. data/doc/ex/texturefill.rb +10 -11
  187. data/doc/ex/threshold.rb +2 -2
  188. data/doc/ex/to_blob.rb +4 -5
  189. data/doc/ex/translate.rb +6 -6
  190. data/doc/ex/transparent.rb +5 -5
  191. data/doc/ex/transpose.rb +2 -2
  192. data/doc/ex/transverse.rb +2 -2
  193. data/doc/ex/tref01.rb +11 -12
  194. data/doc/ex/triangle01.rb +5 -6
  195. data/doc/ex/trim.rb +1 -2
  196. data/doc/ex/tspan01.rb +8 -9
  197. data/doc/ex/tspan02.rb +9 -11
  198. data/doc/ex/tspan03.rb +9 -11
  199. data/doc/ex/unsharp_mask.rb +2 -2
  200. data/doc/ex/viewex.rb +19 -21
  201. data/doc/ex/vignette.rb +2 -2
  202. data/doc/ex/watermark.rb +15 -16
  203. data/doc/ex/wave.rb +2 -2
  204. data/doc/ex/wet_floor.rb +17 -18
  205. data/doc/ex/writing_mode01.rb +8 -9
  206. data/doc/ex/writing_mode02.rb +8 -8
  207. data/doc/ilist.html +1 -1
  208. data/doc/usage.html +8 -8
  209. data/examples/constitute.rb +6 -6
  210. data/examples/crop_with_gravity.rb +13 -17
  211. data/examples/demo.rb +305 -305
  212. data/examples/describe.rb +27 -28
  213. data/examples/find_similar_region.rb +16 -16
  214. data/examples/histogram.rb +228 -232
  215. data/examples/identify.rb +165 -167
  216. data/examples/image_opacity.rb +4 -4
  217. data/examples/import_export.rb +10 -10
  218. data/examples/pattern_fill.rb +9 -9
  219. data/examples/rotating_text.rb +13 -14
  220. data/examples/spinner.rb +18 -19
  221. data/examples/thumbnail.rb +13 -14
  222. data/examples/vignette.rb +8 -9
  223. data/ext/RMagick/extconf.rb +489 -367
  224. data/ext/RMagick/rmagick.c +11 -4
  225. data/ext/RMagick/rmagick.h +4 -0
  226. data/ext/RMagick/rmdraw.c +49 -18
  227. data/ext/RMagick/rmenum.c +18 -7
  228. data/ext/RMagick/rmfill.c +4 -1
  229. data/ext/RMagick/rmilist.c +49 -13
  230. data/ext/RMagick/rmimage.c +196 -59
  231. data/ext/RMagick/rminfo.c +33 -10
  232. data/ext/RMagick/rmmain.c +18 -6
  233. data/ext/RMagick/rmmontage.c +12 -4
  234. data/ext/RMagick/rmpixel.c +18 -5
  235. data/ext/RMagick/rmstruct.c +108 -31
  236. data/ext/RMagick/rmutil.c +50 -26
  237. data/lib/rmagick/version.rb +4 -3
  238. data/lib/rmagick_internal.rb +1159 -1176
  239. data/lib/rvg/clippath.rb +36 -39
  240. data/lib/rvg/container.rb +115 -124
  241. data/lib/rvg/deep_equal.rb +46 -50
  242. data/lib/rvg/describable.rb +41 -47
  243. data/lib/rvg/embellishable.rb +384 -410
  244. data/lib/rvg/misc.rb +697 -714
  245. data/lib/rvg/paint.rb +42 -47
  246. data/lib/rvg/pathdata.rb +120 -125
  247. data/lib/rvg/rvg.rb +213 -213
  248. data/lib/rvg/stretchable.rb +159 -162
  249. data/lib/rvg/stylable.rb +109 -117
  250. data/lib/rvg/text.rb +9 -24
  251. data/lib/rvg/transformable.rb +120 -127
  252. data/lib/rvg/units.rb +58 -61
  253. data/rmagick.gemspec +46 -15
  254. data/spec/rmagick/ImageList1_spec.rb +24 -0
  255. data/spec/rmagick/draw_spec.rb +156 -0
  256. data/spec/rmagick/image/blue_shift_spec.rb +16 -0
  257. data/spec/rmagick/image/composite_spec.rb +140 -0
  258. data/spec/rmagick/image/constitute_spec.rb +15 -0
  259. data/spec/rmagick/image/dispatch_spec.rb +18 -0
  260. data/spec/rmagick/image/from_blob_spec.rb +14 -0
  261. data/spec/rmagick/image/ping_spec.rb +14 -0
  262. data/spec/rmagick/image/properties_spec.rb +29 -0
  263. data/spec/spec_helper.rb +4 -0
  264. data/test/Image1.rb +529 -727
  265. data/test/Image2.rb +1291 -1299
  266. data/test/Image3.rb +978 -981
  267. data/test/ImageList1.rb +7 -9
  268. data/test/ImageList2.rb +346 -350
  269. data/test/Image_attributes.rb +683 -686
  270. data/test/Import_Export.rb +25 -30
  271. data/test/Info.rb +339 -343
  272. data/test/Magick.rb +250 -253
  273. data/test/Pixel.rb +107 -110
  274. data/test/Preview.rb +48 -53
  275. data/test/test_all_basic.rb +15 -11
  276. data/test/tmpnam_test.rb +3 -3
  277. data/wercker.yml +10 -0
  278. metadata +77 -10
  279. data/ChangeLog +0 -816
  280. data/lib/RMagick.rb +0 -1
  281. data/test/Draw.rb +0 -121
data/lib/rvg/rvg.rb CHANGED
@@ -27,8 +27,7 @@
27
27
  # OSI Certified is a certification mark of the Open Source Initiative.
28
28
  #
29
29
  #++############################################################################
30
-
31
- require 'RMagick'
30
+ require 'rmagick'
32
31
  require 'rvg/misc'
33
32
  require 'rvg/describable'
34
33
  require 'rvg/stylable'
@@ -47,237 +46,238 @@ require 'pp' if ENV['debug_rvg']
47
46
  # RVG is the main class in this library. All graphic elements
48
47
  # must be contained within an RVG object.
49
48
  module Magick
50
- class RVG
51
-
52
- include Stylable
53
- include Transformable
54
- include Stretchable
55
- include Embellishable
56
- include Describable
57
- include Duplicatable
49
+ class RVG
50
+ include Stylable
51
+ include Transformable
52
+ include Stretchable
53
+ include Embellishable
54
+ include Describable
55
+ include Duplicatable
58
56
 
59
- private
57
+ private
60
58
 
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
59
+ # background_fill defaults to 'none'. If background_fill has been set to something
60
+ # else, combine it with the background_fill_opacity.
61
+ def bgfill
62
+ if @background_fill.nil?
63
+ color = Magick::Pixel.new(0,0,0,Magick::TransparentOpacity)
64
+ else
65
+ color = @background_fill
66
+ color.opacity = (1.0 - @background_fill_opacity) * Magick::TransparentOpacity
67
+ end
68
+ color
69
+ end
72
70
 
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
71
+ def new_canvas
72
+ if @background_pattern
73
+ canvas = Magick::Image.new(@width, @height, @background_pattern)
74
+ elsif @background_image
75
+ if @width != @background_image.columns || @height != @background_image.rows
76
+ canvas = case @background_position
77
+ when :scaled
78
+ @background_image.resize(@width, @height)
79
+ when :tiled
80
+ Magick::Image.new(@width, @height, Magick::TextureFill.new(@background_image))
81
+ when :fit
82
+ width = @width
83
+ height = @height
84
+ bgcolor = bgfill
85
+ @background_image.change_geometry(Magick::Geometry.new(width, height)) do |new_cols, new_rows|
86
+ bg_image = @background_image.resize(new_cols, new_rows)
87
+ if bg_image.columns != width || bg_image.rows != height
88
+ bg = Magick::Image.new(width, height) { self.background_color = bgcolor }
89
+ bg_image = bg.composite!(bg_image, Magick::CenterGravity, Magick::OverCompositeOp)
97
90
  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
91
+ bg_image
92
+ end
93
+ end
94
+ else
95
+ canvas = @background_image.copy
106
96
  end
97
+ else
98
+ bgcolor = bgfill
99
+ canvas = Magick::Image.new(Integer(@width), Integer(@height)) { self.background_color = bgcolor }
100
+ end
101
+ canvas[:desc] = @desc if @desc
102
+ canvas[:title] = @title if @title
103
+ canvas[:metadata] = @metadata if @metadata
104
+ canvas
105
+ end
107
106
 
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
107
+ if ENV['debug_prim']
108
+ def print_gc(gc)
109
+ primitives = gc.inspect.split(/\n/)
110
+ indent = 0
111
+ primitives.each do |cmd|
112
+ indent -= 1 if cmd['pop ']
113
+ print((' '*indent), cmd, "\n")
114
+ indent += 1 if cmd['push ']
118
115
  end
116
+ end
117
+ end
119
118
 
120
- public
119
+ public
121
120
 
122
- WORD_SEP = / / # Regexp to separate words
121
+ WORD_SEP = / / # Regexp to separate words
123
122
 
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
123
+ # The background image specified by background_image=
124
+ attr_reader :background_image
125
+ # The background image layout specified by background_position=
126
+ attr_reader :background_position
127
+ # The background fill color specified by background_fill=
128
+ attr_reader :background_fill
129
+ # The background fill color opacity specified by background_fill_opacity=
130
+ attr_reader :background_fill_opacity
131
+ # The image after drawing has completed
132
+ attr_reader :canvas
133
+ # For embedded RVG objects, the x-axis coordinate of the upper-left corner
134
+ attr_reader :x
135
+ # For embedded RVG objects, the x-axis coordinate of the upper-left corner
136
+ attr_reader :y
137
+ attr_reader :width, :height
139
138
 
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
139
+ # Sets an image to use as the canvas background. See background_position= for layout options.
140
+ def background_image=(bg_image)
141
+ warn 'background_image= has no effect in nested RVG objects' if @nested
142
+ if bg_image && !bg_image.is_a?(Magick::Image)
143
+ fail ArgumentError, "background image must be an Image (got #{bg_image.class})"
144
+ end
145
+ @background_image = bg_image
146
+ end
148
147
 
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
148
+ # Sets an object to use to fill the canvas background.
149
+ # The object must have a <tt>fill</tt> method. See the <b>Fill Classes</b>
150
+ # section in the RMagick doc for more information.
151
+ def background_pattern=(filler)
152
+ warn 'background_pattern= has no effect in nested RVG objects' if @nested
153
+ @background_pattern = filler
154
+ end
156
155
 
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
156
+ # How to position the background image on the canvas. One of the following symbols:
157
+ # [:scaled] Scale the image to the canvas width and height.
158
+ # [:tiled] Tile the image across the canvas.
159
+ # [:fit] Scale the image to fit within the canvas while retaining the
160
+ # image proportions. Center the image on the canvas. Color any part of
161
+ # the canvas not covered by the image with the background color.
162
+ def background_position=(pos)
163
+ warn 'background_position= has no effect in nested RVG objects' if @nested
164
+ bg_pos = pos.to_s.downcase
165
+ unless ['scaled', 'tiled', 'fit'].include?(bg_pos)
166
+ fail ArgumentError, "background position must be `scaled', `tiled', or `fit' (#{pos} given)"
167
+ end
168
+ @background_position = bg_pos.to_sym
169
+ end
171
170
 
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
171
+ # Sets the canvas background color. Either a Magick::Pixel or a color name.
172
+ # The default fill is "none", that is, transparent black.
173
+ def background_fill=(color)
174
+ warn 'background_fill= has no effect in nested RVG objects' if @nested
175
+ if !color.is_a?(Magick::Pixel)
176
+ begin
177
+ @background_fill = Magick::Pixel.from_color(color)
178
+ rescue Magick::ImageMagickError
179
+ raise ArgumentError, "unknown color `#{color}'"
180
+ rescue TypeError
181
+ raise TypeError, "cannot convert #{color.class} into Pixel"
182
+ rescue
183
+ raise ArgumentError, "argument must be a color name or a Pixel (got #{color.class})"
189
184
  end
185
+ else
186
+ @background_fill = color
187
+ end
188
+ end
190
189
 
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
190
+ # Opacity of the background fill color, a number between 0.0 (transparent) and
191
+ # 1.0 (opaque). The default is 1.0 when the background_fill= attribute has been set.
192
+ def background_fill_opacity=(opacity)
193
+ warn 'background_fill_opacity= has no effect in nested RVG objects' if @nested
194
+ begin
195
+ @background_fill_opacity = Float(opacity)
196
+ rescue ArgumentError
197
+ raise ArgumentError, "background_fill_opacity must be a number between 0 and 1 (#{opacity} given)"
198
+ end
199
+ end
201
200
 
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
201
+ # Draw a +width+ x +height+ image. The image is specified by calling
202
+ # one or more drawing methods on the RVG object.
203
+ # You can group the drawing method calls in the optional associated block.
204
+ # The +x+ and +y+ arguments have no meaning for the outermost RVG object.
205
+ # On nested RVG objects [+x+, +y+] is the coordinate of the upper-left
206
+ # corner in the containing canvas on which the nested RVG object is placed.
207
+ #
208
+ # Drawing occurs on a +canvas+ created by the #draw method. By default the
209
+ # canvas is transparent. You can specify a different canvas with the
210
+ # #background_fill= or #background_image= methods.
211
+ #
212
+ # RVG objects are _containers_. That is, styles and transforms defined
213
+ # on the object are used by contained objects such as shapes, text, and
214
+ # groups unless overridden by an inner container or the object itself.
215
+ def initialize(width = nil, height = nil)
216
+ super
217
+ @width = width
218
+ @height = 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 = 0.0
226
+ @y = 0.0
227
+ @nested = false
228
+ yield(self) if block_given?
229
+ end
242
230
 
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
231
+ # Construct a canvas or reuse an existing canvas.
232
+ # Execute drawing commands. Return the canvas.
233
+ def draw
234
+ fail StandardError, 'draw not permitted in nested RVG objects' if @nested
235
+ @canvas ||= new_canvas # allow drawing over existing canvas
236
+ gc = Utility::GraphicContext.new
237
+ add_outermost_primitives(gc)
238
+ pp(self) if ENV['debug_rvg']
239
+ print_gc(gc) if ENV['debug_prim']
240
+ gc.draw(@canvas)
241
+ @canvas
242
+ end
250
243
 
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
244
+ # Accept #use arguments. Use (x,y) to generate an additional translate.
245
+ # Override @width and @height if new values are supplied.
246
+ def ref(x, y, rw, rh) #:nodoc:
247
+ translate(x, y) if x != 0 || y != 0
248
+ @width = rw if rw
249
+ @height = rh if rh
250
+ end
257
251
 
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
252
+ # Used by Magick::Embellishable.rvg to set non-0 x- and y-coordinates
253
+ def corner(x, y) #:nodoc:
254
+ @nested = true
255
+ @x = Float(x)
256
+ @y = Float(y)
257
+ translate(@x, @y) if @x != 0.0 || @y != 0.0
258
+ end
268
259
 
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
260
+ # Primitives for the outermost RVG object
261
+ def add_outermost_primitives(gc) #:nodoc:
262
+ add_transform_primitives(gc)
263
+ gc.push
264
+ add_viewbox_primitives(@width, @height, gc)
265
+ add_style_primitives(gc)
266
+ @content.each { |element| element.add_primitives(gc) }
267
+ gc.pop
268
+ self
269
+ end
280
270
 
281
- end # end class RVG
271
+ # Primitives for nested RVG objects
272
+ def add_primitives(gc) #:nodoc:
273
+ if @width.nil? || @height.nil?
274
+ fail ArgumentError, 'RVG width or height undefined'
275
+ elsif @width == 0 || @height == 0
276
+ return self
277
+ end
278
+ gc.push
279
+ add_outermost_primitives(gc)
280
+ gc.pop
281
+ end
282
+ end # end class RVG
282
283
  end # end module Magick
283
-