Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Created June 8, 2010 15:16
Show Gist options
  • Select an option

  • Save practicingruby/430169 to your computer and use it in GitHub Desktop.

Select an option

Save practicingruby/430169 to your computer and use it in GitHub Desktop.
module Prawn
class Canvas
include Prawn::Chunkable
def initialize
@chunks = []
end
attr_accessor :chunks
chunk_methods :move_to, :line_to, :line, :stroke, :curve_to
def move_to!(params)
chunk(:move_to, params) do |c|
"%.3f %.3f m" % c[:point]
end
end
def line_to!(params)
chunk(:line_to, params) do |c|
"%.3f %.3f l" % c[:point]
end
end
def curve_to!(params={})
params[:bounds] or raise Prawn::Errors::InvalidGraphicsPath,
"Bounding points for bezier curve must be specified "+
"as :bounds => [[x1,y1],[x2,y2]]"
chunk(:curve_to, params) do |c|
"%.3f %.3f %.3f %.3f %.3f %.3f c" % (c[:bounds] + [c[:point]]).flatten
end
end
def line!(params)
chunk(:line, params) do |c|
[ move_to!(:point => c.params[:point1]),
line_to!(:point => c.params[:point2]) ]
end
end
def stroke!
chunk(:stroke) { "S" }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment