class Magick::Draw

def affine(sx, rx, ry, sy, tx, ty)

and translation (t). Angles are specified in radians.
Apply coordinate transformations to support scaling (s), rotation (r),
def affine(sx, rx, ry, sy, tx, ty)
    primitive "affine " + sprintf("%g,%g,%g,%g,%g,%g", sx, rx, ry, sy, tx, ty)
end

def arc(startX, startY, endX, endY, startDegrees, endDegrees)

Draw an arc.
def arc(startX, startY, endX, endY, startDegrees, endDegrees)
    primitive "arc " + sprintf("%g,%g %g,%g %g,%g",
                startX, startY, endX, endY, startDegrees, endDegrees)
end

def bezier(*points)

Draw a bezier curve.
def bezier(*points)
    if points.length == 0
        Kernel.raise ArgumentError, "no points specified"
    elsif points.length % 2 != 0
        Kernel.raise ArgumentError, "odd number of arguments specified"
    end
    primitive "bezier " + points.join(',')
end

def circle(originX, originY, perimX, perimY)

Draw a circle
def circle(originX, originY, perimX, perimY)
    primitive "circle " + sprintf("%g,%g %g,%g", originX, originY, perimX, perimY)
end

def clip_path(name)

Invoke a clip-path defined by def_clip_path.
def clip_path(name)
    primitive "clip-path #{name}"
end

def clip_rule(rule)

Define the clipping rule.
def clip_rule(rule)
    if ( not ["evenodd", "nonzero"].include?(rule.downcase) )
        Kernel.raise ArgumentError, "Unknown clipping rule #{rule}"
    end
    primitive "clip-rule #{rule}"
end

def clip_units(unit)

Define the clip units
def clip_units(unit)
    if ( not ["userspace", "userspaceonuse", "objectboundingbox"].include?(unit.downcase) )
        Kernel.raise ArgumentError, "Unknown clip unit #{unit}"
    end
    primitive "clip-units #{unit}"
end

def color(x, y, method)

point, replace, floodfill, filltoborder,reset
Set color in image according to specified colorization rule. Rule is one of
def color(x, y, method)
    if ( not PAINT_METHOD_NAMES.has_key?(method.to_i) )
        Kernel.raise ArgumentError, "Unknown PaintMethod: #{method}"
    end
    primitive "color #{x},#{y},#{PAINT_METHOD_NAMES[method.to_i]}"
end

def decorate(decoration)

line-through) OR the text solid background color (any color name or spec)
Specify EITHER the text decoration (none, underline, overline,
def decorate(decoration)
    if ( DECORATION_TYPE_NAMES.has_key?(decoration.to_i) )
        primitive "decorate #{DECORATION_TYPE_NAMES[decoration.to_i]}"
    else
        primitive "decorate #{enquote(decoration)}"
    end
end

def define_clip_path(name)

(pop) graphic-context".
the clip-path primitives with "push(pop) defs" and "push
primitives. Upon advice from the IM guys, we also bracket
bracketed by the "push clip-path " and "pop clip-path"
Define a clip-path. A clip-path is a sequence of primitives
def define_clip_path(name)
    begin
        push('defs')
        push('clip-path', name)
        push('graphic-context')
        yield
    ensure
        pop('graphic-context')
        pop('clip-path')
        pop('defs')
    end
end

def ellipse(originX, originY, width, height, arcStart, arcEnd)

Draw an ellipse
def ellipse(originX, originY, width, height, arcStart, arcEnd)
    primitive "ellipse " + sprintf("%g,%g %g,%g %g,%g",
                    originX, originY, width, height, arcStart, arcEnd)
end

def encoding(encoding)

is "UTF-8". All others are apparently ignored.
Let anything through, but the only defined argument
def encoding(encoding)
    primitive "encoding #{encoding}"
end

def enquote(str)

def enquote(str)
    if str.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(str)
        return str
    else
        return '"' + str + '"'
    end
end

def fill(colorspec)

Specify object fill, a color name or pattern name
def fill(colorspec)
    primitive "fill #{enquote(colorspec)}"
end

def fill_opacity(opacity)

Specify fill opacity (use "xx%" to indicate percentage)
def fill_opacity(opacity)
    primitive "fill-opacity #{opacity}"
end

def fill_rule(rule)

def fill_rule(rule)
    if ( not ["evenodd", "nonzero"].include?(rule.downcase) )
        Kernel.raise ArgumentError, "Unknown fill rule #{rule}"
    end
    primitive "fill-rule #{rule}"
end

def font(name)

Specify text drawing font
def font(name)
    primitive "font #{name}"
end

def font_family(name)

def font_family(name)
    primitive "font-family \'#{name}\'"
end

def font_stretch(stretch)

def font_stretch(stretch)
    if ( not STRETCH_TYPE_NAMES.has_key?(stretch.to_i) )
        Kernel.raise ArgumentError, "Unknown stretch type"
    end
    primitive "font-stretch #{STRETCH_TYPE_NAMES[stretch.to_i]}"
end

def font_style(style)

def font_style(style)
    if ( not STYLE_TYPE_NAMES.has_key?(style.to_i) )
        Kernel.raise ArgumentError, "Unknown style type"
    end
    primitive "font-style #{STYLE_TYPE_NAMES[style.to_i]}"
end

def font_weight(weight)

constant or [100,200,...,900]
The font weight argument can be either a font weight
def font_weight(weight)
    if ( FONT_WEIGHT_NAMES.has_key?(weight.to_i) )
        primitive "font-weight #{FONT_WEIGHT_NAMES[weight.to_i]}"
    else
        primitive "font-weight #{weight}"
    end
end

def gravity(grav)

NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast
Specify the text positioning gravity, one of:
def gravity(grav)
    if ( not GRAVITY_NAMES.has_key?(grav.to_i) )
        Kernel.raise ArgumentError, "Unknown text positioning gravity"
    end
    primitive "gravity #{GRAVITY_NAMES[grav.to_i]}"
end

def line(startX, startY, endX, endY)

Draw a line
def line(startX, startY, endX, endY)
    primitive "line " + sprintf("%g,%g %g,%g", startX, startY, endX, endY)
end

def matte(x, y, method)

colorization rule
Set matte (make transparent) in image according to the specified
def matte(x, y, method)
    if ( not PAINT_METHOD_NAMES.has_key?(method.to_i) )
        Kernel.raise ArgumentError, "Unknown paint method"
    end
    primitive "matte #{x},#{y} #{PAINT_METHOD_NAMES[method.to_i]}"
end

def opacity(opacity)

ending with a %, the number will be multiplied by 0.01.
Specify drawing fill and stroke opacities. If the value is a string
def opacity(opacity)
    if (Numeric === opacity)
        if (opacity < 0 || opacity > 1.0)
            Kernel.raise ArgumentError, "opacity must be >= 0 and <= 1.0"
        end
    end
    primitive "opacity #{opacity}"
end

def path(cmds)

apostrophes. Here we simply use apostrophes.
primitive requires that the commands be surrounded by quotes or
Draw using SVG-compatible path drawing commands. Note that the
def path(cmds)
    primitive "path '" + cmds + "'"
end

def pattern(name, x, y, width, height)

as the argument to the 'fill' or 'stroke' methods
draw the pattern. Reference the pattern by using its name
Define a pattern. In the block, call primitive methods to
def pattern(name, x, y, width, height)
    begin
        push('defs')
        push("pattern #{name} #{x} #{y} #{width} #{height}")
        push('graphic-context')
        yield
    ensure
        pop('graphic-context')
        pop('pattern')
        pop('defs')
    end
end

def point(x, y)

Set point to fill color.
def point(x, y)
    primitive "point #{x},#{y}"
end

def pointsize(points)

in other places this value is called the "pointsize". Give it both names.
Specify the font size in points. Yes, the primitive is "font-size" but
def pointsize(points)
    primitive "font-size #{points}"
end

def polygon(*points)

Draw a polygon
def polygon(*points)
    if points.length == 0
        Kernel.raise ArgumentError, "no points specified"
    elsif points.length % 2 != 0
        Kernel.raise ArgumentError, "odd number of points specified"
    end
    primitive "polygon " + points.join(',')
end

def polyline(*points)

Draw a polyline
def polyline(*points)
    if points.length == 0
        Kernel.raise ArgumentError, "no points specified"
    elsif points.length % 2 != 0
        Kernel.raise ArgumentError, "odd number of points specified"
    end
    primitive "polyline " + points.join(',')
end

def pop(*what)

def pop(*what)
    if what.length == 0
        primitive "pop graphic-context"
    else
        # to_s allows a Symbol to be used instead of a String
        primitive "pop " + what.map {|w| w.to_s}.join(' ')
    end
end

def push(*what)

push('pattern')
push('gradient')
push('defs')
push('graphic-context') (the default if no arguments)
Push the current set of drawing options. Also you can use
def push(*what)
    if what.length == 0
        primitive "push graphic-context"
    else
        # to_s allows a Symbol to be used instead of a String
        primitive "push " + what.map {|w| w.to_s}.join(' ')
    end
end

def rectangle(upper_left_x, upper_left_y, lower_right_x, lower_right_y)

Draw a rectangle
def rectangle(upper_left_x, upper_left_y, lower_right_x, lower_right_y)
    primitive "rectangle " + sprintf("%g,%g %g,%g",
            upper_left_x, upper_left_y, lower_right_x, lower_right_y)
end

def rotate(angle)

Specify coordinate space rotation. "angle" is measured in degrees
def rotate(angle)
    primitive "rotate #{angle}"
end

def roundrectangle(center_x, center_y, width, height, corner_width, corner_height)

Draw a rectangle with rounded corners
def roundrectangle(center_x, center_y, width, height, corner_width, corner_height)
    primitive "roundrectangle " + sprintf("%g,%g,%g,%g,%g,%g",
        center_x, center_y, width, height, corner_width, corner_height)
end

def scale(x, y)

Specify scaling to be applied to coordinate space on subsequent drawing commands.
def scale(x, y)
    primitive "scale #{x},#{y}"
end

def skewx(angle)

def skewx(angle)
    primitive "skewX #{angle}"
end

def skewy(angle)

def skewy(angle)
    primitive "skewY #{angle}"
end

def stroke(colorspec)

Specify the object stroke, a color name or pattern name.
def stroke(colorspec)
    primitive "stroke #{enquote(colorspec)}"
end

def stroke_antialias(bool)

Specify if stroke should be antialiased or not
def stroke_antialias(bool)
    bool = bool ? '1' : '0'
    primitive "stroke-antialias #{bool}"
end

def stroke_dasharray(*list)

Specify a stroke dash pattern
def stroke_dasharray(*list)
    if list.length == 0
        primitive "stroke-dasharray none"
    else
        list.each { |x|
            if x <= 0 then
                Kernel.raise ArgumentError, "dash array elements must be > 0 (#{x} given)"
            end
        }
        primitive "stroke-dasharray #{list.join(',')}"
    end
end

def stroke_dashoffset(value=0)

Specify the initial offset in the dash pattern
def stroke_dashoffset(value=0)
    primitive "stroke-dashoffset #{value}"
end

def stroke_linecap(value)

def stroke_linecap(value)
    if ( not ["butt", "round", "square"].include?(value.downcase) )
        Kernel.raise ArgumentError, "Unknown linecap type: #{value}"
    end
    primitive "stroke-linecap #{value}"
end

def stroke_linejoin(value)

def stroke_linejoin(value)
    if ( not ["round", "miter", "bevel"].include?(value.downcase) )
        Kernel.raise ArgumentError, "Unknown linejoin type: #{value}"
    end
    primitive "stroke-linejoin #{value}"
end

def stroke_miterlimit(value)

def stroke_miterlimit(value)
    if (value < 1)
        Kernel.raise ArgumentError, "miterlimit must be >= 1"
    end
    primitive "stroke-miterlimit #{value}"
end

def stroke_opacity(value)

(use "xx%" to indicate percentage)
Specify opacity of stroke drawing color
def stroke_opacity(value)
    primitive "stroke-opacity #{value}"
end

def stroke_width(pixels)

Specify stroke (outline) width in pixels.
def stroke_width(pixels)
    primitive "stroke-width #{pixels}"
end

def text(x, y, text)

Draw text at position x,y. Add quotes to text that is not already quoted.
def text(x, y, text)
    if text.to_s.empty?
        Kernel.raise ArgumentError, "missing text argument"
    end
    if text.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(text)
        ; # text already quoted
    elsif !text['\'']
        text = '\''+text+'\''
    elsif !text['"']
        text = '"'+text+'"'
    elsif !(text['{'] || text['}'])
        text = '{'+text+'}'
    else
        # escape existing braces, surround with braces
        text = '{' +  text.gsub(/[}]/) { |b| '\\' + b } + '}'
    end
    primitive "text #{x},#{y} #{text}"
end

def text_align(alignment)

Specify text alignment relative to a given point
def text_align(alignment)
    if ( not ALIGN_TYPE_NAMES.has_key?(alignment.to_i) )
        Kernel.raise ArgumentError, "Unknown alignment constant: #{alignment}"
    end
    primitive "text-align #{ALIGN_TYPE_NAMES[alignment.to_i]}"
end

def text_anchor(anchor)

SVG-compatible version of text_align
def text_anchor(anchor)
    if ( not ANCHOR_TYPE_NAMES.has_key?(anchor.to_i) )
        Kernel.raise ArgumentError, "Unknown anchor constant: #{anchor}"
    end
    primitive "text-anchor #{ANCHOR_TYPE_NAMES[anchor.to_i]}"
end

def text_antialias(boolean)

Specify if rendered text is to be antialiased.
def text_antialias(boolean)
    boolean = boolean ? '1' : '0'
    primitive "text-antialias #{boolean}"
end

def text_undercolor(color)

Specify color underneath text
def text_undercolor(color)
    primitive "text-undercolor #{enquote(color)}"
end

def translate(x, y)

commands.
Specify center of coordinate space to use for subsequent drawing
def translate(x, y)
    primitive "translate #{x},#{y}"
end