Created
June 8, 2010 15:16
-
-
Save practicingruby/430169 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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