Class: Rasem::SVGPath

Inherits:
SVGTagWithParent show all
Defined in:
lib/rasem/svg_image.rb

Overview

SVG Path element, with ruby methods to describe the path

Instance Attribute Summary

Attributes inherited from SVGTagWithParent

#img

Attributes inherited from SVGTag

#attributes, #children, #tag

Instance Method Summary collapse

Methods inherited from SVGTag

#append_child, #linearGradient, #matrix, #merge_defaults, #method_missing, #path, #pop_defaults, #push_defaults, #radialGradient, #raw, #rotate, #scale, #skewX, #skewY, #spawn_child, #to_s, #translate, #use, #validate_attribute, #validate_attributes, #validate_child_name, #validate_tag, #with_style, #write, #write_points, #write_styles, #write_transforms

Constructor Details

#initialize(img = nil, attributes = {}, &block) ⇒ SVGPath

Returns a new instance of SVGPath.



532
533
534
535
# File 'lib/rasem/svg_image.rb', line 532

def initialize(img = nil, attributes={}, &block)
  attributes.merge!(:d => "") unless attributes.has_key? :d
  super(img, "path", attributes)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rasem::SVGTag

Instance Method Details

#arcTo(dx, dy, rx, ry, axis_rotation, large_arc_flag, sweep_flag) ⇒ Object

elliptical arc commands

Draws an elliptical arc from the current point to the point x,y. rx and ry are the elliptical radius in x and y direction. The x-rotation determines how much the arc is to be rotated around the x-axis. It only seems to have an effect when rx and ry have different values. The large-arc-flag doesn’t seem to be used (can be either 0 or 1). Neither value (0 or 1) changes the arc. The sweep-flag determines the direction to draw the arc in.



683
684
685
# File 'lib/rasem/svg_image.rb', line 683

def arcTo(dx, dy, rx, ry, axis_rotation, large_arc_flag, sweep_flag)
  add_d("a#{rx},#{ry} #{axis_rotation} #{large_arc_flag},#{sweep_flag} #{dx},#{dy}")
end

#arcToA(dx, dy, rx, ry, axis_rotation, large_arc_flag, sweep_flag) ⇒ Object



688
689
690
# File 'lib/rasem/svg_image.rb', line 688

def arcToA(dx, dy, rx, ry, axis_rotation, large_arc_flag, sweep_flag)
  add_d("A#{rx},#{ry} #{axis_rotation} #{large_arc_flag},#{sweep_flag} #{dx},#{dy}")
end

#closeObject

close path command

Closes the path by drawing a line from current point to first point.



699
700
701
# File 'lib/rasem/svg_image.rb', line 699

def close
  add_d("Z")
end

#curveTo(dx, dy, x1, y1, x2, y2) ⇒ Object

curveTo commands

Draws a cubic Bezier curve from current pen point to dx,dy. x1,y1 and x2,y2 are start and end control points of the curve, controlling how it bends.



609
610
611
# File 'lib/rasem/svg_image.rb', line 609

def curveTo(dx, dy, x1, y1, x2, y2)
  add_d("c#{x1},#{y1} #{x2},#{y2} #{dx},#{dy}")
end

#curveToA(dx, dy, x1, y1, x2, y2) ⇒ Object



614
615
616
# File 'lib/rasem/svg_image.rb', line 614

def curveToA(dx, dy, x1, y1, x2, y2)
  add_d("C#{x1},#{y1} #{x2},#{y2} #{dx},#{dy}")
end

#hlineTo(x) ⇒ Object

horizontal lineTo commands

Draws a horizontal line to the point defined by x.



576
577
578
# File 'lib/rasem/svg_image.rb', line 576

def hlineTo(x)
  add_d("h#{x}")
end

#hlineToA(x) ⇒ Object



581
582
583
# File 'lib/rasem/svg_image.rb', line 581

def hlineToA(x)
  add_d("H#{x}")
end

#lineTo(x, y) ⇒ Object

lineTo commands

Draws a line from current pen location to specified point x,y.



560
561
562
# File 'lib/rasem/svg_image.rb', line 560

def lineTo(x, y)
  add_d("l#{x},#{y}")
end

#lineToA(x, y) ⇒ Object



565
566
567
# File 'lib/rasem/svg_image.rb', line 565

def lineToA(x, y)
  add_d("L#{x},#{y}")
end

#moveTo(x, y) ⇒ Object

moveTo commands

Moves pen to specified point x,y without drawing.



544
545
546
# File 'lib/rasem/svg_image.rb', line 544

def moveTo(x, y)
  add_d("m#{x},#{y}")
end

#moveToA(x, y) ⇒ Object



549
550
551
# File 'lib/rasem/svg_image.rb', line 549

def moveToA(x, y)
  add_d("M#{x},#{y}")
end

#qcurveTo(dx, dy, x1, y1) ⇒ Object

quadratic Bezier curveTo commands

Draws a quadratic Bezier curve from current pen point to dx,dy. x1,y1 is the control point controlling how the curve bends.



644
645
646
# File 'lib/rasem/svg_image.rb', line 644

def qcurveTo(dx, dy, x1, y1)
  add_d("q#{x1},#{y1} #{dx},#{dy}")
end

#qcurveToA(dx, dy, x1, y1) ⇒ Object



649
650
651
# File 'lib/rasem/svg_image.rb', line 649

def qcurveToA(dx, dy, x1, y1)
  add_d("Q#{x1},#{y1} #{dx},#{dy}")
end

#scurveTo(dx, dy, x2, y2) ⇒ Object

smooth curveTo commands

Draws a cubic Bezier curve from current pen point to dx,dy. x2,y2 is the end control point. The start control point is is assumed to be the same as the end control point of the previous curve.



627
628
629
# File 'lib/rasem/svg_image.rb', line 627

def scurveTo(dx, dy, x2, y2)
  add_d("s#{x2},#{y2} #{dx},#{dy}")
end

#scurveToA(dx, dy, x2, y2) ⇒ Object



632
633
634
# File 'lib/rasem/svg_image.rb', line 632

def scurveToA(dx, dy, x2, y2)
  add_d("S#{x2},#{y2} #{dx},#{dy}")
end

#sqcurveTo(dx, dy) ⇒ Object

smooth quadratic Bezier curveTo commands

Draws a quadratic Bezier curve from current pen point to dx,dy. The control point is assumed to be the same as the last control point used.



661
662
663
# File 'lib/rasem/svg_image.rb', line 661

def sqcurveTo(dx, dy)
  add_d("t#{dx},#{dy}")
end

#sqcurveToA(dx, dy) ⇒ Object



666
667
668
# File 'lib/rasem/svg_image.rb', line 666

def sqcurveToA(dx, dy)
  add_d("T#{dx},#{dy}")
end

#vlineTo(y) ⇒ Object

vertical lineTo commands

Draws a vertical line to the point defined by y.



592
593
594
# File 'lib/rasem/svg_image.rb', line 592

def vlineTo(y)
  add_d("v#{y}")
end

#vlineToA(y) ⇒ Object



597
598
599
# File 'lib/rasem/svg_image.rb', line 597

def vlineToA(y)
  add_d("V#{y}")
end