Class Magick::RVG::PathData
In: lib/rvg/pathdata.rb
Parent: Object
Enum GeometryValue Stylable RVG\n[lib/rvg/clippath.rb\nlib/rvg/container.rb\nlib/rvg/deep_equal.rb\nlib/rvg/describable.rb\nlib/rvg/embellishable.rb\nlib/rvg/misc.rb\nlib/rvg/paint.rb\nlib/rvg/pathdata.rb\nlib/rvg/rvg.rb\nlib/rvg/stretchable.rb\nlib/rvg/stylable.rb\nlib/rvg/text.rb\nlib/rvg/transformable.rb\nlib/rvg/units.rb] Transformable Stretchable Embellishable Describable Duplicatable Comparable Image ImageList Enumerable Geometry HatchFill Draw lib/RMagick.rb lib/rvg/misc.rb ObjectData Application Pre_ObjectData_Descriptor Envelope Post_ObjectData_Descriptor IPTC Magick dot/m_14_0.png

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.

Methods

Public Class methods

Construct an empty path

[Source]

    # File lib/rvg/pathdata.rb, line 28
28:             def initialize
29:                 @path = ''
30:             end

Public Instance methods

Add an arc command. If abs is true the coordinates are absolute, otherwise the coordinates are relative.

[Source]

     # File lib/rvg/pathdata.rb, line 123
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

Add a closepath command. The abs argument is ignored.

[Source]

    # File lib/rvg/pathdata.rb, line 52
52:             def closepath(abs=true)
53:                 @path << 'Z'    # ignore `abs'
54:             end

Add a curveto (cubic Bezier) command. If abs is true the coordinates are absolute, otherwise the coordinates are relative.

[Source]

    # File lib/rvg/pathdata.rb, line 84
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

Add a horizontal lineto command. If abs is true the coordinates are absolute, otherwise the coordinates are relative.

[Source]

    # File lib/rvg/pathdata.rb, line 69
69:             def hlineto(abs, x)
70:                 @path << sprintf("%s%g ", (abs ? 'H' : 'h'), x)
71:             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.

[Source]

    # File lib/rvg/pathdata.rb, line 60
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

Add a moveto command. If abs is true the coordinates are absolute, otherwise the coordinates are relative.

[Source]

    # File lib/rvg/pathdata.rb, line 44
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

Add a quadratic Bezier curveto command. If abs is true the coordinates are absolute, otherwise the coordinates are relative.

[Source]

     # File lib/rvg/pathdata.rb, line 104
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

Add a smooth curveto (cubic Bezier) command. If abs is true the coordinates are absolute, otherwise the coordinates are relative.

[Source]

    # File lib/rvg/pathdata.rb, line 94
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

Add a smooth quadratic Bezier curveto command. If abs is true the coordinates are absolute, otherwise the coordinates are relative.

[Source]

     # File lib/rvg/pathdata.rb, line 113
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

Convert the path to its string equivalent.

[Source]

    # File lib/rvg/pathdata.rb, line 33
33:             def to_s
34:                 @path
35:             end

Add a vertical lineto command. If abs is true the coordinates are absolute, otherwise the coordinates are relative.

[Source]

    # File lib/rvg/pathdata.rb, line 76
76:             def vlineto(abs, y)
77:                 @path << sprintf("%s%g ", (abs ? 'V' : 'v'), y)
78:             end

Private Instance methods

[Source]

    # File lib/rvg/pathdata.rb, line 16
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

[Validate]