module Magick::RVG::Transformable
def add_transform_primitives(gc)
def add_transform_primitives(gc) @transforms.each { |transform| gc.__send__(transform[0], *transform[1]) } end
def initialize(*args, &block)
def initialize(*args, &block) super() @transforms = Transforms.new end
def matrix(sx, rx, ry, sy, tx, ty)
def matrix(sx, rx, ry, sy, tx, ty) begin @transforms << [:affine, [Float(sx), Float(rx), Float(ry), Float(sy), Float(tx), Float(ty)]] rescue ArgumentError raise ArgumentError, "arguments must be convertable to float (got #{sx.class}, #{rx.class}, #{ry.class}, #{sy.class}, #{sx.class}, #{sx.class}, #{tx.class}, #{ty.class})" end yield(self) if block_given? self end
def rotate(angle, *args)
[rotate(angle, cx, cy)] rotate by angle degrees about
[rotate(angle)] rotate by angle degrees
This method can take either of two argument lists:
def rotate(angle, *args) begin case args.length when 0 @transforms << [:rotate, [Float(angle)]] when 2 cx = Float(args[0]) cy = Float(args[1]) @transforms << [:translate, [cx, cy]] @transforms << [:rotate, [angle]] @transforms << [:translate, [-cx, -cy]] else fail ArgumentError, "wrong number of arguments (#{args.length} for 1 or 3)" end rescue ArgumentError raise ArgumentError, "arguments must be convertable to float (got #{[angle, *args].collect {|a| a.class}.join(', ')})" end yield(self) if block_given? self end
def scale(sx, sy = nil)
Multiply the x-coordinates by sx and the y-coordinates
def scale(sx, sy = nil) sy ||= sx begin @transforms << [:scale, [Float(sx), Float(sy)]] rescue ArgumentError raise ArgumentError, "arguments must be convertable to float (got #{sx.class}, #{sy.class})" end yield(self) if block_given? self end
def skewX(angle)
def skewX(angle) begin @transforms << [:skewx, [Float(angle)]] rescue ArgumentError raise ArgumentError, "argument must be convertable to float (got #{angle.class})" end yield(self) if block_given? self end
def skewY(angle)
def skewY(angle) begin @transforms << [:skewy, [Float(angle)]] rescue ArgumentError raise ArgumentError, "argument must be convertable to float (got #{angle.class})" end yield(self) if block_given? self end
def translate(tx, ty = nil)
to all y-coordinates. If ty is omitted it defaults
Add tx to all x-coordinates and ty
def translate(tx, ty = nil) ty ||= tx begin @transforms << [:translate, [Float(tx), Float(ty)]] rescue ArgumentError raise ArgumentError, "arguments must be convertable to float (got #{tx.class}, #{ty.class})" end yield(self) if block_given? self end