Class: Magick::RVG::PathData
- Inherits:
-
Object
- Object
- Magick::RVG::PathData
- Defined in:
- lib/rvg/pathdata.rb
Overview
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.
Instance Method Summary collapse
-
#arc(abs, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y) ⇒ Object
Add an
arc
command. -
#closepath(abs = true) ⇒ Object
Add a
closepath
command. -
#curveto(abs, x1, y1, x2, y2, x, y, *coords) ⇒ Object
Add a
curveto
(cubic Bezier) command. -
#deep_copy(h = nil) ⇒ Object
:nodoc:.
-
#hlineto(abs, x) ⇒ Object
Add a
horizontal lineto
command. -
#initialize ⇒ PathData
constructor
Construct an empty path.
-
#lineto(abs, x, y, *coords) ⇒ Object
Add a
lineto
command. -
#moveto(abs, x, y, *coords) ⇒ Object
Add a
moveto
command. -
#quadratic_curveto(abs, x1, y1, x, y, *coords) ⇒ Object
Add a
quadratic Bezier curveto
command. -
#smooth_curveto(abs, x2, y2, x, y, *coords) ⇒ Object
Add a
smooth curveto
(cubic Bezier) command. -
#smooth_quadratic_curveto(abs, x, y, *coords) ⇒ Object
Add a
smooth quadratic Bezier curveto
command. -
#to_s ⇒ Object
Convert the path to its string equivalent.
-
#vlineto(abs, y) ⇒ Object
Add a
vertical lineto
command.
Constructor Details
#initialize ⇒ PathData
Construct an empty path
26 27 28 |
# File 'lib/rvg/pathdata.rb', line 26 def initialize @path = '' end |
Instance Method Details
#arc(abs, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y) ⇒ Object
Add an arc
command. If abs
is true
the coordinates are absolute, otherwise the coordinates are relative.
121 122 123 |
# File 'lib/rvg/pathdata.rb', line 121 def arc(abs, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y) @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) end |
#closepath(abs = true) ⇒ Object
Add a closepath
command. The abs
argument is ignored.
50 51 52 |
# File 'lib/rvg/pathdata.rb', line 50 def closepath(abs = true) @path << 'Z' # ignore `abs' end |
#curveto(abs, x1, y1, x2, y2, x, y, *coords) ⇒ Object
Add a curveto
(cubic Bezier) command. If abs
is true
the coordinates are absolute, otherwise the coordinates are relative.
82 83 84 85 86 |
# File 'lib/rvg/pathdata.rb', line 82 def curveto(abs, x1, y1, x2, y2, x, y, *coords) @path << sprintf('%s%g,%g %g,%g %g,%g ', (abs ? 'C' : 'c'), x1, y1, x2, y2, x, y) # "multiple sets of coordinates may be specified to draw a polybezier" add_points(6, *coords) end |
#deep_copy(h = nil) ⇒ Object
:nodoc:
35 36 37 |
# File 'lib/rvg/pathdata.rb', line 35 def deep_copy(h = nil) #:nodoc: @path.dup end |
#hlineto(abs, x) ⇒ Object
Add a horizontal lineto
command. If abs
is true
the coordinates are absolute, otherwise the coordinates are relative.
67 68 69 |
# File 'lib/rvg/pathdata.rb', line 67 def hlineto(abs, x) @path << sprintf('%s%g ', (abs ? 'H' : 'h'), x) end |
#lineto(abs, x, y, *coords) ⇒ Object
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.
58 59 60 61 62 |
# File 'lib/rvg/pathdata.rb', line 58 def lineto(abs, x, y, *coords) @path << sprintf('%s%g,%g ', (abs ? 'L' : 'l'), x, y) # "a number of coordinate pairs may be specified to draw a polyline" add_points(2, *coords) end |
#moveto(abs, x, y, *coords) ⇒ Object
Add a moveto
command. If abs
is true
the coordinates are absolute, otherwise the coordinates are relative.
42 43 44 45 46 |
# File 'lib/rvg/pathdata.rb', line 42 def moveto(abs, x, y, *coords) @path << sprintf('%s%g,%g ', (abs ? 'M' : 'm'), x, y) # "subsequent pairs are treated as implicit lineto commands" add_points(2, *coords) end |
#quadratic_curveto(abs, x1, y1, x, y, *coords) ⇒ Object
Add a quadratic Bezier curveto
command. If abs
is true
the coordinates are absolute, otherwise the coordinates are relative.
102 103 104 105 |
# File 'lib/rvg/pathdata.rb', line 102 def quadratic_curveto(abs, x1, y1, x, y, *coords) @path << sprintf('%s%g,%g %g,%g ', (abs ? 'Q' : 'q'), x1, y1, x, y) add_points(4, *coords) end |
#smooth_curveto(abs, x2, y2, x, y, *coords) ⇒ Object
Add a smooth curveto
(cubic Bezier) command. If abs
is true
the coordinates are absolute, otherwise the coordinates are relative.
92 93 94 95 96 |
# File 'lib/rvg/pathdata.rb', line 92 def smooth_curveto(abs, x2, y2, x, y, *coords) @path << sprintf('%s%g,%g %g,%g ', (abs ? 'S' : 's'), x2, y2, x, y) # "multiple sets of coordinates may be specified to draw a polybezier" add_points(4, *coords) end |
#smooth_quadratic_curveto(abs, x, y, *coords) ⇒ Object
Add a smooth quadratic Bezier curveto
command. If abs
is true
the coordinates are absolute, otherwise the coordinates are relative.
111 112 113 114 |
# File 'lib/rvg/pathdata.rb', line 111 def smooth_quadratic_curveto(abs, x, y, *coords) @path << sprintf('%s%g,%g ', (abs ? 'T' : 't'), x, y) add_points(2, *coords) end |
#to_s ⇒ Object
Convert the path to its string equivalent.
31 32 33 |
# File 'lib/rvg/pathdata.rb', line 31 def to_s @path end |
#vlineto(abs, y) ⇒ Object
Add a vertical lineto
command. If abs
is true
the coordinates are absolute, otherwise the coordinates are relative.
74 75 76 |
# File 'lib/rvg/pathdata.rb', line 74 def vlineto(abs, y) @path << sprintf('%s%g ', (abs ? 'V' : 'v'), y) end |