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

circle_at curve curve_to ellipse_at fill fill_and_stroke horizontal_line horizontal_rule line line_to line_width line_width= move_to polygon rectangle stroke stroke_bounds vertical_line

### 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

circle_at(point, options)

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

curve(origin,dest, options={})

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

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

curve_to(dest,options={})

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]]

ellipse_at(point, r1, r2 = r1)

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

fill() {|if block_given?| ...}

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

fill_and_stroke() {|if block_given?| ...}

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

horizontal_line(x1,x2,options={})

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

horizontal_rule()

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

line(*points)

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)

line_to(*point)

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)

line_width(width=nil)

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

line_width=(width)

Sets line thickness to the `width` specified.

move_to(*point)

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)

polygon(*points)

Draws a polygon from the specified points.

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

rectangle(point,width,height)

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

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

stroke() {|if block_given?| ...}

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

stroke_bounds()

Draws and strokes a rectangle represented by the current bounding box

vertical_line(y1,y2,params)

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]