| Class | Magick::RVG::PathData |
| In: |
lib/rvg/pathdata.rb
|
| Parent: | Object |
The PathData class provides an object-oriented way to produce an SVG path. Each of the methods corresponds to a path command. Construct a path by calling one or more methods. The path object can be passed as an argument to the RVG::ShapeConstructors#path method.
Construct an empty path
# File lib/rvg/pathdata.rb, line 27
27: def initialize
28: @path = ''
29: end
Add an arc command. If abs is true the coordinates are absolute, otherwise the coordinates are relative.
# File lib/rvg/pathdata.rb, line 122
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
Add a closepath command. The abs argument is ignored.
# File lib/rvg/pathdata.rb, line 51
51: def closepath(abs=true)
52: @path << 'Z' # ignore `abs'
53: end
Add a curveto (cubic Bezier) command. If abs is true the coordinates are absolute, otherwise the coordinates are relative.
# File lib/rvg/pathdata.rb, line 83
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
Add a horizontal lineto command. If abs is true the coordinates are absolute, otherwise the coordinates are relative.
# File lib/rvg/pathdata.rb, line 68
68: def hlineto(abs, x)
69: @path << sprintf("%s%g ", (abs ? 'H' : 'h'), x)
70: end
Add a lineto command. Any number of x,y coordinate pairs may be specified. If abs is true the coordinates are absolute, otherwise the coordinates are relative.
# File lib/rvg/pathdata.rb, line 59
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
Add a moveto command. If abs is true the coordinates are absolute, otherwise the coordinates are relative.
# File lib/rvg/pathdata.rb, line 43
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
Add a quadratic Bezier curveto command. If abs is true the coordinates are absolute, otherwise the coordinates are relative.
# File lib/rvg/pathdata.rb, line 103
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
Add a smooth curveto (cubic Bezier) command. If abs is true the coordinates are absolute, otherwise the coordinates are relative.
# File lib/rvg/pathdata.rb, line 93
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
Add a smooth quadratic Bezier curveto command. If abs is true the coordinates are absolute, otherwise the coordinates are relative.
# File lib/rvg/pathdata.rb, line 112
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
Convert the path to its string equivalent.
# File lib/rvg/pathdata.rb, line 32
32: def to_s
33: @path
34: end
Add a vertical lineto command. If abs is true the coordinates are absolute, otherwise the coordinates are relative.
# File lib/rvg/pathdata.rb, line 75
75: def vlineto(abs, y)
76: @path << sprintf("%s%g ", (abs ? 'V' : 'v'), y)
77: end
# File lib/rvg/pathdata.rb, line 15
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