rmagick 1.7.4 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rmagick might be problematic. Click here for more details.
- data/ChangeLog +10 -2
- data/README.html +284 -290
- data/README.txt +298 -307
- data/configure +180 -11
- data/configure.ac +18 -2
- data/doc/comtasks.html +1 -1
- data/doc/constants.html +15 -10
- data/doc/css/ref.css +67 -0
- data/doc/draw.html +1 -1
- data/doc/ex/InitialCoords.rb +24 -0
- data/doc/ex/NewCoordSys.rb +33 -0
- data/doc/ex/OrigCoordSys.rb +19 -0
- data/doc/ex/PreserveAspectRatio.rb +206 -0
- data/doc/ex/RotateScale.rb +38 -0
- data/doc/ex/Skew.rb +39 -0
- data/doc/ex/Use01.rb +17 -0
- data/doc/ex/Use02.rb +22 -0
- data/doc/ex/Use03.rb +17 -0
- data/doc/ex/ViewBox.rb +34 -0
- data/doc/ex/arcs01.rb +29 -0
- data/doc/ex/arcs02.rb +62 -0
- data/doc/ex/baseline_shift01.rb +19 -0
- data/doc/ex/bounding_box.rb +31 -37
- data/doc/ex/circle01.rb +18 -0
- data/doc/ex/cubic01.rb +46 -0
- data/doc/ex/cubic02.rb +95 -0
- data/doc/ex/drop_shadow.rb +1 -1
- data/doc/ex/ellipse01.rb +23 -0
- data/doc/ex/evenodd.rb +44 -0
- data/doc/ex/font_styles.rb +29 -0
- data/doc/ex/group.rb +27 -0
- data/doc/ex/image.rb +47 -0
- data/doc/ex/images/big-duck.gif +0 -0
- data/doc/ex/images/duck.gif +0 -0
- data/doc/ex/images/duck0.gif +0 -0
- data/doc/ex/images/duck1.gif +0 -0
- data/doc/ex/images/duck10.gif +0 -0
- data/doc/ex/images/duck11.gif +0 -0
- data/doc/ex/images/duck12.gif +0 -0
- data/doc/ex/images/duck13.gif +0 -0
- data/doc/ex/images/duck14.gif +0 -0
- data/doc/ex/images/duck15.gif +0 -0
- data/doc/ex/images/duck2.gif +0 -0
- data/doc/ex/images/duck3.gif +0 -0
- data/doc/ex/images/duck4.gif +0 -0
- data/doc/ex/images/duck5.gif +0 -0
- data/doc/ex/images/duck6.gif +0 -0
- data/doc/ex/images/duck7.gif +0 -0
- data/doc/ex/images/duck8.gif +0 -0
- data/doc/ex/images/duck9.gif +0 -0
- data/doc/ex/line01.rb +24 -0
- data/doc/ex/nested_rvg.rb +22 -0
- data/doc/ex/nonzero.rb +44 -0
- data/doc/ex/polygon01.rb +24 -0
- data/doc/ex/polyline01.rb +24 -0
- data/doc/ex/quad01.rb +37 -0
- data/doc/ex/rect01.rb +16 -0
- data/doc/ex/rect02.rb +23 -0
- data/doc/ex/rvg_clippath.rb +15 -0
- data/doc/ex/rvg_linecap.rb +44 -0
- data/doc/ex/rvg_linejoin.rb +42 -0
- data/doc/ex/rvg_opacity.rb +20 -0
- data/doc/ex/rvg_pattern.rb +27 -0
- data/doc/ex/rvg_stroke_dasharray.rb +13 -0
- data/doc/ex/sepiatone.rb +15 -0
- data/doc/ex/shadow.rb +37 -0
- data/doc/ex/smile.rb +9 -9
- data/doc/ex/stroke_fill.rb +12 -0
- data/doc/ex/text01.rb +18 -0
- data/doc/ex/text_styles.rb +22 -0
- data/doc/ex/texture_fill_to_border.rb +3 -3
- data/doc/ex/texture_floodfill.rb +3 -2
- data/doc/ex/tref01.rb +26 -0
- data/doc/ex/triangle01.rb +17 -0
- data/doc/ex/tspan01.rb +19 -0
- data/doc/ex/tspan02.rb +20 -0
- data/doc/ex/tspan03.rb +22 -0
- data/doc/ex/writing_mode01.rb +28 -0
- data/doc/ex/writing_mode02.rb +27 -0
- data/doc/ilist.html +1 -1
- data/doc/image1.html +66 -30
- data/doc/image2.html +1 -1
- data/doc/image3.html +274 -49
- data/doc/imageattrs.html +87 -10
- data/doc/imusage.html +1 -1
- data/doc/index.html +80 -39
- data/doc/info.html +149 -13
- data/doc/magick.html +1 -1
- data/doc/rvg.html +890 -0
- data/doc/rvgclip.html +249 -0
- data/doc/rvggroup.html +305 -0
- data/doc/rvgimage.html +288 -0
- data/doc/rvgpattern.html +456 -0
- data/doc/rvgshape.html +376 -0
- data/doc/rvgstyle.html +269 -0
- data/doc/rvgtext.html +464 -0
- data/doc/rvgtspan.html +237 -0
- data/doc/rvgtut.html +512 -0
- data/doc/rvguse.html +145 -0
- data/doc/rvgxform.html +294 -0
- data/doc/struct.html +9 -71
- data/doc/usage.html +22 -7
- data/ext/RMagick/MANIFEST +94 -2
- data/ext/RMagick/rmagick.h +10 -4
- data/ext/RMagick/rmagick_config.h.in +8 -2
- data/ext/RMagick/rmdraw.c +2 -2
- data/ext/RMagick/rmfill.c +2 -2
- data/ext/RMagick/rmilist.c +3 -3
- data/ext/RMagick/rmimage.c +152 -5
- data/ext/RMagick/rminfo.c +208 -2
- data/ext/RMagick/rmmain.c +14 -5
- data/ext/RMagick/rmutil.c +83 -22
- data/lib/RMagick.rb +2 -2
- data/lib/rvg/clippath.rb +46 -0
- data/lib/rvg/container.rb +129 -0
- data/lib/rvg/deep_equal.rb +54 -0
- data/lib/rvg/describable.rb +51 -0
- data/lib/rvg/embellishable.rb +395 -0
- data/lib/rvg/misc.rb +729 -0
- data/lib/rvg/paint.rb +48 -0
- data/lib/rvg/pathdata.rb +129 -0
- data/lib/rvg/rvg.rb +279 -0
- data/lib/rvg/stretchable.rb +150 -0
- data/lib/rvg/stylable.rb +116 -0
- data/lib/rvg/text.rb +185 -0
- data/lib/rvg/transformable.rb +131 -0
- data/lib/rvg/units.rb +64 -0
- data/rmagick.gemspec +1 -1
- data/uninstall.rb +3 -2
- metadata +96 -3
data/lib/rvg/paint.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#--
|
2
|
+
# $Id: paint.rb,v 1.1 2005/03/12 17:02:00 rmagick Exp $
|
3
|
+
# Copyright (C) 2005 Timothy P. Hunter
|
4
|
+
#++
|
5
|
+
# Defines paint server classes.
|
6
|
+
# Eventually this will include gradients.
|
7
|
+
|
8
|
+
class Magick::RVG
|
9
|
+
|
10
|
+
class Pattern
|
11
|
+
include StructureConstructors
|
12
|
+
include UseConstructors
|
13
|
+
include ShapeConstructors
|
14
|
+
include TextConstructors
|
15
|
+
include ImageConstructors
|
16
|
+
include Stretchable
|
17
|
+
include Duplicatable
|
18
|
+
include Stylable
|
19
|
+
|
20
|
+
# Create a pattern that can be used with the :fill or :stroke styles.
|
21
|
+
# The +width+ and +height+ arguments define the viewport.
|
22
|
+
# The pattern will be repeated at <tt>x+m*width</tt> and <tt>y+n*height</tt>
|
23
|
+
# offsets.
|
24
|
+
#
|
25
|
+
# Define the pattern in the block.
|
26
|
+
# The pattern can be composed of shapes (rectangle, circles, etc.), text,
|
27
|
+
# raster images and container objects. You can include graphic objects by
|
28
|
+
# referring to them with #use.
|
29
|
+
def initialize(width=0, height=0, x=0, y=0)
|
30
|
+
super()
|
31
|
+
@width, @height, @x, @y = RVG.convert_to_float(width, height, x, y)
|
32
|
+
@content = Content.new
|
33
|
+
yield(self) if block_given?
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_primitives(gc, style) #:nodoc:
|
37
|
+
name = __id__.to_s
|
38
|
+
gc.pattern(name, @x, @y, @width, @height) do
|
39
|
+
add_viewbox_primitives(@width, @height, gc)
|
40
|
+
@content.each { |element| element.add_primitives(gc) }
|
41
|
+
end
|
42
|
+
gc.__send__(style, name)
|
43
|
+
end
|
44
|
+
|
45
|
+
end # class Pattern
|
46
|
+
|
47
|
+
end # module Magick::RVG
|
48
|
+
|
data/lib/rvg/pathdata.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
#--
|
2
|
+
# $Id: pathdata.rb,v 1.1 2005/03/12 17:02:00 rmagick Exp $
|
3
|
+
# Copyright (C) 2005 Timothy P. Hunter
|
4
|
+
#++
|
5
|
+
|
6
|
+
class Magick::RVG
|
7
|
+
|
8
|
+
# The PathData class provides an object-oriented way to produce an SVG
|
9
|
+
# path. Each of the methods corresponds to a path command. Construct a
|
10
|
+
# path by calling one or more methods. The path object can be passed
|
11
|
+
# as an argument to the RVG::ShapeConstructors#path method.
|
12
|
+
class PathData
|
13
|
+
|
14
|
+
private
|
15
|
+
def add_points(req, *coords)
|
16
|
+
if coords
|
17
|
+
if coords.length % req != 0
|
18
|
+
raise ArgumentError, "wrong number of coordinates specified. A multiple of #{req} required, #{req+coords.length} given."
|
19
|
+
end
|
20
|
+
coords.each {|c| @path << ("%g" % c)}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
public
|
25
|
+
|
26
|
+
# Construct an empty path
|
27
|
+
def initialize
|
28
|
+
@path = ''
|
29
|
+
end
|
30
|
+
|
31
|
+
# Convert the path to its string equivalent.
|
32
|
+
def to_s
|
33
|
+
@path
|
34
|
+
end
|
35
|
+
|
36
|
+
def deep_copy(h=nil) #:nodoc:
|
37
|
+
@path.dup
|
38
|
+
end
|
39
|
+
|
40
|
+
# Add a <tt>moveto</tt> command. If <tt>abs</tt> is
|
41
|
+
# <tt>true</tt> the coordinates are absolute, otherwise
|
42
|
+
# the coordinates are relative.
|
43
|
+
def moveto(abs, x, y, *coords)
|
44
|
+
@path << sprintf("%s%g,%g ", (abs ? 'M' : 'm'), x, y)
|
45
|
+
# "subsequent pairs are treated as implicit lineto commands"
|
46
|
+
add_points(2, *coords)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Add a <tt>closepath</tt> command. The <tt>abs</tt> argument
|
50
|
+
# is ignored.
|
51
|
+
def closepath(abs=true)
|
52
|
+
@path << 'Z' # ignore `abs'
|
53
|
+
end
|
54
|
+
|
55
|
+
# Add a <tt>lineto</tt> command. Any number of x,y coordinate
|
56
|
+
# pairs may be specified. If <tt>abs</tt> is
|
57
|
+
# <tt>true</tt> the coordinates are absolute, otherwise
|
58
|
+
# the coordinates are relative.
|
59
|
+
def lineto(abs, x, y, *coords)
|
60
|
+
@path << sprintf("%s%g,%g ", (abs ? 'L' : 'l'), x, y)
|
61
|
+
# "a number of coordinate pairs may be specified to draw a polyline"
|
62
|
+
add_points(2, *coords)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Add a <tt>horizontal lineto</tt> command. If <tt>abs</tt> is
|
66
|
+
# <tt>true</tt> the coordinates are absolute, otherwise
|
67
|
+
# the coordinates are relative.
|
68
|
+
def hlineto(abs, x)
|
69
|
+
@path << sprintf("%s%g ", (abs ? 'H' : 'h'), x)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Add a <tt>vertical lineto</tt> command. If <tt>abs</tt> is
|
73
|
+
# <tt>true</tt> the coordinates are absolute, otherwise
|
74
|
+
# the coordinates are relative.
|
75
|
+
def vlineto(abs, y)
|
76
|
+
@path << sprintf("%s%g ", (abs ? 'V' : 'v'), y)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Add a <tt>curveto</tt> (<em>cubic Bezier</em>) command.
|
80
|
+
# If <tt>abs</tt> is
|
81
|
+
# <tt>true</tt> the coordinates are absolute, otherwise
|
82
|
+
# the coordinates are relative.
|
83
|
+
def curveto(abs, x1, y1, x2, y2, x, y, *coords)
|
84
|
+
@path << sprintf("%s%g,%g %g,%g %g,%g ", (abs ? 'C' : 'c'), x1, y1, x2, y2, x, y)
|
85
|
+
# "multiple sets of coordinates may be specified to draw a polybezier"
|
86
|
+
add_points(6, *coords)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Add a <tt>smooth curveto</tt> (<em>cubic Bezier</em>) command.
|
90
|
+
# If <tt>abs</tt> is
|
91
|
+
# <tt>true</tt> the coordinates are absolute, otherwise
|
92
|
+
# the coordinates are relative.
|
93
|
+
def smooth_curveto(abs, x2, y2, x, y, *coords)
|
94
|
+
@path << sprintf("%s%g,%g %g,%g ", (abs ? 'S' : 's'), x2, y2, x, y)
|
95
|
+
# "multiple sets of coordinates may be specified to draw a polybezier"
|
96
|
+
add_points(4, *coords)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Add a <tt>quadratic Bezier curveto</tt> command.
|
100
|
+
# If <tt>abs</tt> is
|
101
|
+
# <tt>true</tt> the coordinates are absolute, otherwise
|
102
|
+
# the coordinates are relative.
|
103
|
+
def quadratic_curveto(abs, x1, y1, x, y, *coords)
|
104
|
+
@path << sprintf("%s%g,%g %g,%g ", (abs ? 'Q' : 'q'), x1, y1, x, y)
|
105
|
+
add_points(4, *coords)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Add a <tt>smooth quadratic Bezier curveto</tt> command.
|
109
|
+
# If <tt>abs</tt> is
|
110
|
+
# <tt>true</tt> the coordinates are absolute, otherwise
|
111
|
+
# the coordinates are relative.
|
112
|
+
def smooth_quadratic_curveto(abs, x, y, *coords)
|
113
|
+
@path << sprintf("%s%g,%g ", (abs ? 'T' : 't'), x, y)
|
114
|
+
add_points(2, *coords)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Add an <tt>arc</tt> command.
|
118
|
+
# If <tt>abs</tt> is
|
119
|
+
# <tt>true</tt> the coordinates are absolute, otherwise
|
120
|
+
# the coordinates are relative.
|
121
|
+
|
122
|
+
def arc(abs, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y)
|
123
|
+
@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)
|
124
|
+
end
|
125
|
+
|
126
|
+
end # class PathData
|
127
|
+
|
128
|
+
end # class Magick::RVG
|
129
|
+
|
data/lib/rvg/rvg.rb
ADDED
@@ -0,0 +1,279 @@
|
|
1
|
+
#--############################################################################
|
2
|
+
# $Id: rvg.rb,v 1.3 2005/04/19 23:27:01 rmagick Exp $
|
3
|
+
#
|
4
|
+
# Copyright (C) 2005 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
|
+
class Magick::RVG
|
50
|
+
|
51
|
+
include Stylable
|
52
|
+
include Transformable
|
53
|
+
include Stretchable
|
54
|
+
include Embellishable
|
55
|
+
include Describable
|
56
|
+
include Duplicatable
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# background_fill defaults to 'none'. If background_fill has been set to something
|
61
|
+
# else, combine it with the background_fill_opacity.
|
62
|
+
def bgfill()
|
63
|
+
if @background_fill.nil?
|
64
|
+
color = Pixel.new(0,0,0,TransparentOpacity)
|
65
|
+
else
|
66
|
+
color = @background_fill
|
67
|
+
color.opacity = (1.0 - @background_fill_opacity) * ::Magick::TransparentOpacity
|
68
|
+
end
|
69
|
+
return color
|
70
|
+
end
|
71
|
+
|
72
|
+
def new_canvas
|
73
|
+
if @background_pattern
|
74
|
+
canvas = ::Magick::Image.new(@width, @height, @background_pattern)
|
75
|
+
elsif @background_image
|
76
|
+
if @width != @background_image.columns || @height != @background_image.rows
|
77
|
+
canvas = case @background_position
|
78
|
+
when :scaled
|
79
|
+
@background_image.resize(@width, @height)
|
80
|
+
when :tiled
|
81
|
+
::Magick::Image.new(@width, @height, TextureFill.new(@background_image))
|
82
|
+
when :fit
|
83
|
+
width, height = @width, @height
|
84
|
+
bgcolor = bgfill()
|
85
|
+
@background_image.change_geometry(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, CenterGravity, OverCompositeOp)
|
90
|
+
end
|
91
|
+
bg_image
|
92
|
+
end
|
93
|
+
end
|
94
|
+
else
|
95
|
+
canvas = @background_image.copy
|
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
|
+
return canvas
|
105
|
+
end
|
106
|
+
|
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 ']
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
public
|
120
|
+
|
121
|
+
WORD_SEP = / / # Regexp to separate words
|
122
|
+
|
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
|
138
|
+
|
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.kind_of?(::Magick::Image)
|
143
|
+
raise ArgumentError, "background image must be an Image (got #{bg_image.class})"
|
144
|
+
end
|
145
|
+
@background_image = bg_image
|
146
|
+
end
|
147
|
+
|
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
|
155
|
+
|
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
|
+
if ! ['scaled', 'tiled', 'fit'].include?(bg_pos)
|
166
|
+
raise ArgumentError, "background position must be `scaled', `tiled', or `fit' (#{pos} given)"
|
167
|
+
end
|
168
|
+
@background_position = bg_pos.to_sym
|
169
|
+
end
|
170
|
+
|
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.kind_of?(Pixel)
|
176
|
+
begin
|
177
|
+
@background_fill = 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})"
|
184
|
+
end
|
185
|
+
else
|
186
|
+
@background_fill = color
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
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
|
200
|
+
|
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, @height = width, height
|
218
|
+
@content = Content.new
|
219
|
+
@canvas = nil
|
220
|
+
@background_fill = nil
|
221
|
+
@background_fill_opacity = 1.0 # applies only if background_fill= is used
|
222
|
+
@background_position = :scaled
|
223
|
+
@background_pattern, @background_image, @desc, @title, @metadata = nil
|
224
|
+
@x, @y = 0.0
|
225
|
+
@nested = false
|
226
|
+
yield(self) if block_given?
|
227
|
+
end
|
228
|
+
|
229
|
+
# Construct a canvas or reuse an existing canvas.
|
230
|
+
# Execute drawing commands. Return the canvas.
|
231
|
+
def draw
|
232
|
+
raise StandardError, "draw not permitted in nested RVG objects" if @nested
|
233
|
+
@canvas ||= new_canvas # allow drawing over existing canvas
|
234
|
+
gc = Utility::GraphicContext.new
|
235
|
+
add_outermost_primitives(gc)
|
236
|
+
pp(self) if ENV['debug_rvg']
|
237
|
+
print_gc(gc) if ENV['debug_prim']
|
238
|
+
gc.draw(@canvas)
|
239
|
+
return @canvas
|
240
|
+
end
|
241
|
+
|
242
|
+
# Accept #use arguments. Use (x,y) to generate an additional translate.
|
243
|
+
# Override @width and @height if new values are supplied.
|
244
|
+
def ref(x, y, rw, rh) #:nodoc:
|
245
|
+
translate(x, y) if (x != 0 || y != 0)
|
246
|
+
@width = rw if rw
|
247
|
+
@height = rh if rh
|
248
|
+
end
|
249
|
+
|
250
|
+
# Used by ::Magick::Embellishable.rvg to set non-0 x- and y-coordinates
|
251
|
+
def corner(x, y) #:nodoc:
|
252
|
+
@nested = true
|
253
|
+
@x, @y = Float(x), Float(y)
|
254
|
+
translate(@x, @y) if (@x != 0.0 || @y != 0.0)
|
255
|
+
end
|
256
|
+
|
257
|
+
# Primitives for the outermost RVG object
|
258
|
+
def add_outermost_primitives(gc) #:nodoc:
|
259
|
+
add_transform_primitives(gc)
|
260
|
+
add_viewbox_primitives(@width, @height, gc)
|
261
|
+
add_style_primitives(gc)
|
262
|
+
@content.each { |element| element.add_primitives(gc) }
|
263
|
+
self
|
264
|
+
end
|
265
|
+
|
266
|
+
# Primitives for nested RVG objects
|
267
|
+
def add_primitives(gc) #:nodoc:
|
268
|
+
if @width.nil? || @height.nil?
|
269
|
+
raise ArgumentError, "RVG width or height undefined"
|
270
|
+
elsif @width == 0 || @height == 0
|
271
|
+
return self
|
272
|
+
end
|
273
|
+
gc.push
|
274
|
+
add_outermost_primitives(gc)
|
275
|
+
gc.pop
|
276
|
+
end
|
277
|
+
|
278
|
+
end # end class Magick::RVG
|
279
|
+
|