Module Prawn::Graphics
In: lib/prawn/graphics/color.rb
lib/prawn/graphics.rb

Implements the drawing facilities for Prawn::Document. Use this to draw the most beautiful imaginable things.

This file lifts and modifies several of PDF::Writer‘s graphics functions ruby-pdf.rubyforge.org

Methods

Included Modules

Color

Classes and Modules

Module Prawn::Graphics::Color

Constants

KAPPA = 4.0 * ((Math.sqrt(2) - 1.0) / 3.0)   This constant is used to approximate a symmetrical arc using a cubic Bezier curve.

Public Instance methods

Draws a circle of radius :radius with the centre-point at point as a complete subpath. The drawing point will be moved to the centre-point upon completion of the drawing the circle.

   pdf.circle_at [100,100], :radius => 25

Draws a Bezier curve between two points, bounded by two additional points

   pdf.curve [50,100], [100,100], :bounds => [[90,90],[75,75]]

Draws a Bezier curve from the current drawing position to the specified point, bounded by two additional points.

  pdf.curve_to [100,100], :bounds => [[90,90],[75,75]]

Draws an ellipse of x radius r1 and y radius r2 with the centre-point at point as a complete subpath. The drawing point will be moved to the centre-point upon completion of the drawing the ellipse.

   # draws an ellipse with x-radius 25 and y-radius 50
   pdf.ellipse_at [100,100], 25, 50

Fills and closes the current path. See Graphic::Color for color details

Fills, strokes, and closes the current path. See Graphic::Color for color details

Draws a horizontal line from x1 to x2 at the current y position, or the position specified by the :at option.

 # draw a line from [25, 75] to [100, 75]
 horizontal_line 25, 100, :at => 75

Draws a horizontal line from the left border to the right border of the bounding box at the current y position.

Draws a line from one point to another. Points may be specified as tuples or flattened argument list:

  pdf.line [100,100], [200,250]
  pdf.line(100,100,200,250)

Draws a line from the current drawing position to the specified point. The destination may be described as a tuple or a flattened list:

  pdf.line_to [50,50]
  pdf.line_to(50,50)

When called without an argument, returns the current line thickness. When called with an argument, sets the line thickness to the specified value (in PDF points)

  pdf.line_width #=> 1
  pdf.line_width(5)
  pdf.line_width #=> 5

Sets line thickness to the width specified.

Moves the drawing position to a given point. The point can be specified as a tuple or a flattened argument list

  pdf.move_to [100,50]
  pdf.move_to(100,50)

Draws a polygon from the specified points.

   # draws a snazzy triangle
   pdf.polygon [100,100], [100,200], [200,200]

Draws a rectangle given point, width and height. The rectangle is bounded by its upper-left corner.

   pdf.rectangle [300,300], 100, 200

Strokes and closes the current path. See Graphic::Color for color details

Draws and strokes a rectangle represented by the current bounding box

Draws a vertical line at the x cooordinate given by :at from y1 to y2.

  # draw a line from [25, 100] to [25, 300]
  vertical_line 100, 300, :at => 25

[Validate]