sandal / prawn
- Source
- Commits
- Network (94)
- Issues (12)
- Downloads (20)
- Wiki (7)
- Graphs
-
Branch:
master
Brad Ediger (author)
Thu Dec 17 16:54:46 -0800 2009
| 3454efc9 » | sandal | 2008-12-15 | 1 | # encoding: utf-8 | |
| 2 | # | ||||
| 3 | # This example demonstrates the basic functionality of Prawn's bounding boxes. | ||||
| 4 | # Note that top level bounding boxes are positioned relative to the margin_box. | ||||
| 5 | # | ||||
| 3f99ef7f » | sandal | 2009-07-19 | 6 | require "#{File.dirname(__FILE__)}/../example_helper.rb" | |
| 3454efc9 » | sandal | 2008-12-15 | 7 | ||
| 8 | Prawn::Document.generate("bounding_boxes.pdf") do | ||||
| 9 | |||||
| 10 | # Generates a box with a top-left of [100,600] and a top-right of [300,600] | ||||
| 11 | # The box automatically expands as the cursor moves down the page. Notice | ||||
| 12 | # that the final coordinates are outlined by a top and bottom line drawn | ||||
| 13 | # relatively using calculations from +bounds+. | ||||
| 14 | # | ||||
| 15 | bounding_box [100,600], :width => 200 do | ||||
| 16 | move_down 10 | ||||
| 17 | text "The rain in spain falls mainly on the plains " * 5 | ||||
| 18 | move_down 20 | ||||
| 19 | stroke do | ||||
| 20 | line bounds.top_left, bounds.top_right | ||||
| 21 | line bounds.bottom_left, bounds.bottom_right | ||||
| 22 | end | ||||
| 23 | end | ||||
| 24 | |||||
| 25 | # Generates a bounding box from [100, cursor], [300, cursor - 200], | ||||
| 26 | # where cursor is the current y position. | ||||
| 27 | # | ||||
| 28 | bounding_box [100,cursor], :width => 200, :height => 200 do | ||||
| 29 | stroke do | ||||
| 30 | circle_at [100,100], :radius => 100 | ||||
| 31 | line bounds.top_left, bounds.bottom_right | ||||
| 32 | line bounds.top_right, bounds.bottom_left | ||||
| 33 | end | ||||
| 34 | |||||
| 35 | # Generates a nested bonding box and strokes its boundaries. Note that | ||||
| 36 | # this box is anchored relative to its parent bounding box, not the | ||||
| 37 | # margin_box | ||||
| 38 | bounding_box [50,150], :width => 100, :height => 100 do | ||||
| 39 | stroke_bounds | ||||
| 40 | end | ||||
| 41 | end | ||||
| 42 | |||||
| 43 | end | ||||
