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, #lines, #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.


551
552
553
554
# File 'lib/rasem/svg_image.rb', line 551

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.


702
703
704
# File 'lib/rasem/svg_image.rb', line 702

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


707
708
709
# File 'lib/rasem/svg_image.rb', line 707

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.


718
719
720
# File 'lib/rasem/svg_image.rb', line 718

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.


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

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


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

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.


595
596
597
# File 'lib/rasem/svg_image.rb', line 595

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

#hlineToA(x) ⇒ Object


600
601
602
# File 'lib/rasem/svg_image.rb', line 600

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.


579
580
581
# File 'lib/rasem/svg_image.rb', line 579

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

#lineToA(x, y) ⇒ Object


584
585
586
# File 'lib/rasem/svg_image.rb', line 584

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.


563
564
565
# File 'lib/rasem/svg_image.rb', line 563

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

#moveToA(x, y) ⇒ Object


568
569
570
# File 'lib/rasem/svg_image.rb', line 568

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.


663
664
665
# File 'lib/rasem/svg_image.rb', line 663

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

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


668
669
670
# File 'lib/rasem/svg_image.rb', line 668

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.


646
647
648
# File 'lib/rasem/svg_image.rb', line 646

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

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


651
652
653
# File 'lib/rasem/svg_image.rb', line 651

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.


680
681
682
# File 'lib/rasem/svg_image.rb', line 680

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

#sqcurveToA(dx, dy) ⇒ Object


685
686
687
# File 'lib/rasem/svg_image.rb', line 685

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.


611
612
613
# File 'lib/rasem/svg_image.rb', line 611

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

#vlineToA(y) ⇒ Object


616
617
618
# File 'lib/rasem/svg_image.rb', line 616

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