class Magick::RVG::Utility::GraphicContext

def self.degrees_to_radians(deg)

def self.degrees_to_radians(deg)
  Math::PI * (deg % 360.0) / 180.0
end

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

def affine(sx, rx, ry, sy, tx, ty)
  sx, rx, ry, sy, tx, ty = Magick::RVG.convert_to_float(sx, rx, ry, sy, tx, ty)
  @gc.affine(sx, rx, ry, sy, tx, ty)
  @text_attrs.set_affine(sx, rx, ry, sy, tx, ty)
  nil
end

def baseline_shift(value)

def baseline_shift(value)
  @text_attrs.baseline_shift = case value
                               when 'baseline', 'sub', 'super'
                                 value.to_sym
                               when /[-+]?\d+%/, Numeric
                                 value
                               else
                                 :baseline
                               end
  nil
end

def concat_matrix

def concat_matrix
  curr = @text_attrs.affine
  sx = curr.sx * @sx + curr.ry * @rx
  rx = curr.rx * @sx + curr.sy * @rx
  ry = curr.sx * @ry + curr.ry * @sy
  sy = curr.rx * @ry + curr.sy * @sy
  tx = curr.sx * @tx + curr.ry * @ty + curr.tx
  ty = curr.rx * @tx + curr.sy * @ty + curr.ty
  @text_attrs.set_affine(sx, rx, ry, sy, tx, ty)
  init_matrix
end

def font(name)

def font(name)
  @gc.font(name)
  @shadow[-1].font = name
  nil
end

def font_family(name)

def font_family(name)
  @gc.font_family(name)
  @shadow[-1].font_family = name
  nil
end

def font_size(points)

def font_size(points)
  @gc.font_size(points)
  @shadow[-1].pointsize = points
  nil
end

def font_stretch(stretch)

def font_stretch(stretch)
  stretch = FONT_STRETCH.fetch(stretch.to_sym, Magick::NormalStretch)
  @gc.font_stretch(stretch)
  @shadow[-1].font_stretch = stretch
  nil
end

def font_style(style)

def font_style(style)
  style = FONT_STYLE.fetch(style.to_sym, Magick::NormalStyle)
  @gc.font_style(style)
  @shadow[-1].font_style = style
  nil
end

def font_weight(weight)

def font_weight(weight)
  # If the arg is not in the hash use it directly. Handles numeric values.
  weight = FONT_WEIGHT.fetch(weight) { |key| key }
  @gc.font_weight(weight)
  @shadow[-1].font_weight = weight
  nil
end

def glyph_orientation_horizontal(deg)

def glyph_orientation_horizontal(deg)
  deg = Magick::RVG.convert_one_to_float(deg)
  @text_attrs.glyph_orientation_horizontal = (deg % 360) / 90 * 90
  nil
end

def glyph_orientation_vertical(deg)

def glyph_orientation_vertical(deg)
  deg = Magick::RVG.convert_one_to_float(deg)
  @text_attrs.glyph_orientation_vertical = (deg % 360) / 90 * 90
  nil
end

def init_matrix

def init_matrix
  @rx = @ry = 0
  @sx = @sy = 1
  @tx = @ty = 0
end

def initialize

def initialize
  @gc = Magick::Draw.new
  @shadow = []
  @shadow << Magick::Draw.new
  @text_attrs = TextAttributes.new
  init_matrix
end

def inspect

def inspect
  @gc.inspect
end

def letter_spacing(value)

def letter_spacing(value)
  @text_attrs.letter_spacing = Magick::RVG.convert_one_to_float(value)
  nil
end

def method_missing(meth_id, *args, &block)

def method_missing(meth_id, *args, &block)
  @gc.__send__(meth_id, *args, &block)
end

def pop

def pop
  @gc.pop
  @shadow.pop
  @text_attrs.pop
  nil
end

def push

def push
  @gc.push
  @shadow.push(@shadow.last.dup)
  @text_attrs.push
  nil
end

def rotate(degrees)

def rotate(degrees)
  degrees = Magick::RVG.convert_one_to_float(degrees)
  @gc.rotate(degrees)
  @sx =  Math.cos(GraphicContext.degrees_to_radians(degrees))
  @rx =  Math.sin(GraphicContext.degrees_to_radians(degrees))
  @ry = -Math.sin(GraphicContext.degrees_to_radians(degrees))
  @sy =  Math.cos(GraphicContext.degrees_to_radians(degrees))
  concat_matrix
  nil
end

def scale(sx, sy)

def scale(sx, sy)
  sx, sy = Magick::RVG.convert_to_float(sx, sy)
  @gc.scale(sx, sy)
  @sx = sx
  @sy = sy
  concat_matrix
  nil
end

def shadow

def shadow
  @shadow.last
end

def skewX(degrees)

def skewX(degrees)
  degrees = Magick::RVG.convert_one_to_float(degrees)
  @gc.skewX(degrees)
  @ry = Math.tan(GraphicContext.degrees_to_radians(degrees))
  concat_matrix
  nil
end

def skewY(degrees)

def skewY(degrees)
  degrees = Magick::RVG.convert_one_to_float(degrees)
  @gc.skewY(degrees)
  @rx = Math.tan(GraphicContext.degrees_to_radians(degrees))
  concat_matrix
  nil
end

def stroke_width(width)

def stroke_width(width)
  width = Magick::RVG.convert_one_to_float(width)
  @gc.stroke_width(width)
  @shadow[-1].stroke_width = width
  nil
end

def text(x, y, text)

def text(x, y, text)
  return if text.length.zero?
  text_renderer = if @text_attrs.non_default?
                    TEXT_STRATEGIES[@text_attrs.writing_mode].new(self)
                  else
                    DefaultTextStrategy.new(self)
                  end
  text_renderer.render(x, y, text)
end

def text_anchor(anchor)

def text_anchor(anchor)
  anchor = anchor.to_sym
  anchor_enum = TEXT_ANCHOR.fetch(anchor, Magick::StartAnchor)
  @gc.text_anchor(anchor_enum)
  align = ANCHOR_TO_ALIGN.fetch(anchor, Magick::LeftAlign)
  @shadow[-1].align = align
  @text_attrs.text_anchor = anchor
  nil
end

def text_decoration(decoration)

def text_decoration(decoration)
  decoration = TEXT_DECORATION.fetch(decoration.to_sym, Magick::NoDecoration)
  @gc.decorate(decoration)
  @shadow[-1].decorate = decoration
  nil
end

def translate(tx, ty)

def translate(tx, ty)
  tx, ty = Magick::RVG.convert_to_float(tx, ty)
  @gc.translate(tx, ty)
  @tx = tx
  @ty = ty
  concat_matrix
  nil
end

def word_spacing(value)

def word_spacing(value)
  @text_attrs.word_spacing = Magick::RVG.convert_one_to_float(value)
  nil
end

def writing_mode(mode)

def writing_mode(mode)
  @text_attrs.writing_mode = mode
  nil
end