prawn-core 0.5.1 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/HACKING +46 -0
  2. data/README +9 -3
  3. data/Rakefile +7 -6
  4. data/examples/bounding_box/stretched_nesting.rb +67 -0
  5. data/examples/general/margin.rb +36 -0
  6. data/examples/general/multi_page_layout.rb +3 -1
  7. data/examples/general/page_numbering.rb +15 -0
  8. data/examples/general/stamp.rb +45 -0
  9. data/examples/graphics/stroke_cap_and_join.rb +45 -0
  10. data/examples/graphics/stroke_dash.rb +42 -0
  11. data/examples/graphics/transparency.rb +26 -0
  12. data/examples/text/text_box_returning_excess.rb +51 -0
  13. data/lib/prawn/byte_string.rb +7 -0
  14. data/lib/prawn/core.rb +7 -8
  15. data/lib/prawn/document/annotations.rb +3 -2
  16. data/lib/prawn/document/bounding_box.rb +15 -10
  17. data/lib/prawn/document/column_box.rb +1 -3
  18. data/lib/prawn/document/destinations.rb +11 -10
  19. data/lib/prawn/document/internals.rb +62 -19
  20. data/lib/prawn/document/snapshot.rb +71 -0
  21. data/lib/prawn/document/text/box.rb +7 -0
  22. data/lib/prawn/document/text/wrapping.rb +3 -0
  23. data/lib/prawn/document/text.rb +9 -2
  24. data/lib/prawn/document.rb +141 -25
  25. data/lib/prawn/errors.rb +12 -0
  26. data/lib/prawn/font/afm.rb +1 -1
  27. data/lib/prawn/font/ttf.rb +5 -5
  28. data/lib/prawn/font.rb +8 -5
  29. data/lib/prawn/graphics/cap_style.rb +35 -0
  30. data/lib/prawn/graphics/dash.rb +69 -0
  31. data/lib/prawn/graphics/join_style.rb +35 -0
  32. data/lib/prawn/graphics/transparency.rb +56 -0
  33. data/lib/prawn/graphics.rb +9 -1
  34. data/lib/prawn/images.rb +4 -4
  35. data/lib/prawn/name_tree.rb +2 -1
  36. data/lib/prawn/object_store.rb +63 -0
  37. data/lib/prawn/pdf_object.rb +4 -0
  38. data/lib/prawn/reference.rb +18 -5
  39. data/lib/prawn/stamp.rb +87 -0
  40. data/spec/bounding_box_spec.rb +9 -0
  41. data/spec/document_spec.rb +58 -5
  42. data/spec/images_spec.rb +1 -1
  43. data/spec/name_tree_spec.rb +14 -5
  44. data/spec/object_store_spec.rb +42 -0
  45. data/spec/pdf_object_spec.rb +5 -0
  46. data/spec/reference_spec.rb +40 -0
  47. data/spec/snapshot_spec.rb +115 -0
  48. data/spec/spec_helper.rb +1 -4
  49. data/spec/stamp_spec.rb +98 -0
  50. data/spec/stroke_styles_spec.rb +152 -0
  51. data/spec/text_box_spec.rb +26 -0
  52. data/spec/text_spec.rb +8 -1
  53. data/spec/transparency_spec.rb +61 -0
  54. data/vendor/pdf-inspector/lib/pdf/inspector/extgstate.rb +18 -0
  55. data/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +40 -1
  56. data/vendor/pdf-inspector/lib/pdf/inspector/page.rb +12 -3
  57. data/vendor/pdf-inspector/lib/pdf/inspector.rb +2 -1
  58. metadata +26 -2
data/HACKING ADDED
@@ -0,0 +1,46 @@
1
+ = Hacking on Prawn
2
+
3
+ A stub file that'll eventually get bigger
4
+
5
+ == NOTES
6
+
7
+ Install test-spec, pdf-reader, and mocha from RubyGems
8
+
9
+ Be sure to load in the necessary git submodules as well:
10
+
11
+ git submodule init
12
+ git submodule update
13
+
14
+ If you are running on Ruby 1.9.1, you will need Test::Unit 1.2.3
15
+
16
+ gem install test-unit -v 1.2.3
17
+
18
+ == Patch process
19
+
20
+ 1. File a ticket in the tracker that contains the code your issue is
21
+ related to:
22
+
23
+ http://github.com/sandal/prawn/issues
24
+ http://github.com/sandal/prawn-layout/issues
25
+ http://github.com/sandal/prawn-format/issues
26
+
27
+ 2. Fork any necessary repositories on Github, make your changes
28
+ 3. Submit pull request so Gregory is notified
29
+ 4. Include your ticket number in commit messages
30
+
31
+ If you are working on a ticket that has already been created, skip step 1.
32
+
33
+ All feature enhancements should come with an example in the examples/ dir,
34
+ and preferably, some specs.
35
+
36
+ All bug reports should have a reproducible example in bugs/ and preferably,
37
+ some specs.
38
+
39
+ == Support
40
+
41
+ Find us in #prawn on irc.freenode.net
42
+ <sandal> - Gregory Brown
43
+ <yob> - James Healy
44
+
45
+ Otherwise, use the mailing list:
46
+ http://groups.google.com/group/prawn-ruby
data/README CHANGED
@@ -27,8 +27,8 @@ But prawn can do a lot more:
27
27
 
28
28
  ...gives you an _really_ big page.
29
29
 
30
- Prawn::Document.new(:size => [11.32, 8.49],
31
- :page_orientation => :portrait)
30
+ Prawn::Document.new(:page_size => [11.32, 8.49],
31
+ :page_layout => :portrait)
32
32
 
33
33
  ...giving you a postage stamp.
34
34
 
@@ -107,19 +107,25 @@ For inline styling and advanced formatting:
107
107
 
108
108
  http://github.com/sandal/prawn-format/tree/stable/examples
109
109
 
110
- (or gem unpack prawn-core, prawn-format, and prawn-layout if you want to run them locally)
110
+ For encryption, password protection, and permissions:
111
+
112
+ http://github.com/madriska/prawn-security/tree/stable/examples
113
+
114
+ (or gem unpack prawn-core, prawn-format, prawn-security and prawn-layout if you want to run them locally)
111
115
 
112
116
  === Bug Tracker / Wiki:
113
117
 
114
118
  http://github.com/sandal/prawn/issues
115
119
  http://github.com/sandal/prawn-layout/issues
116
120
  http://github.com/sandal/prawn-format/issues
121
+ http://github.com/madriska/prawn-security/issues
117
122
 
118
123
  === Source Code:
119
124
 
120
125
  http://github.com/sandal/prawn
121
126
  http://github.com/sandal/prawn-layout
122
127
  http://github.com/sandal/prawn-format
128
+ http://github.com/madriska/prawn-security
123
129
 
124
130
  === Mailing List:
125
131
 
data/Rakefile CHANGED
@@ -4,15 +4,16 @@ require 'rake/testtask'
4
4
  require "rake/rdoctask"
5
5
  require "rake/gempackagetask"
6
6
 
7
- PRAWN_VERSION = "0.5.1"
7
+ PRAWN_VERSION = "0.6.1"
8
8
 
9
9
  task :default => [:test]
10
10
 
11
- desc "Run all tests, test-spec and mocha required"
11
+ desc "Run all tests, test-spec, mocha, and pdf-reader required"
12
12
  Rake::TestTask.new do |test|
13
- test.libs << "spec"
14
- test.test_files = Dir[ "spec/*_spec.rb" ]
15
- test.verbose = true
13
+ # test.ruby_opts << "-w" # .should == true triggers a lot of warnings
14
+ test.libs << "spec"
15
+ test.test_files = Dir[ "spec/*_spec.rb" ]
16
+ test.verbose = true
16
17
  end
17
18
 
18
19
  desc "Show library's code statistics"
@@ -56,7 +57,7 @@ spec = Gem::Specification.new do |spec|
56
57
 
57
58
  spec.test_files = Dir[ "test/*_test.rb" ]
58
59
  spec.has_rdoc = true
59
- spec.extra_rdoc_files = %w{README LICENSE COPYING}
60
+ spec.extra_rdoc_files = %w{HACKING README LICENSE COPYING}
60
61
  spec.rdoc_options << '--title' << 'Prawn Documentation' <<
61
62
  '--main' << 'README' << '-q'
62
63
  spec.author = "Gregory Brown"
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This example demonstrates how nested bounding boxes work when the outer box is
4
+ # stretchy and includes several inner boxes of different sizes.
5
+
6
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
7
+
8
+ Prawn::Document.generate("stretched_nesting.pdf", :page_layout => :landscape) do
9
+
10
+ def stroke_dashed_bounds
11
+ dash(1)
12
+ stroke_bounds
13
+ undash
14
+ end
15
+
16
+ bounding_box [100,400], :width => 500 do
17
+
18
+ bounding_box [0, bounds.top], :width => 200, :height => 100 do
19
+ stroke_bounds
20
+ end
21
+
22
+ bounding_box [200, bounds.top], :width => 150 do
23
+ indent(5) do
24
+ text "This box is longest, so it stretches the parent box. \n"*5
25
+ end
26
+ end
27
+
28
+ bounding_box [350, bounds.top], :width => 150 do
29
+ text "I AM SANTA CLAUS!!!"
30
+ end
31
+
32
+ stroke_dashed_bounds
33
+
34
+ end
35
+
36
+ bounding_box [100, 250], :width => 500 do
37
+
38
+ bounding_box [0, bounds.top], :width => 100, :height => 100 do
39
+ text "1"
40
+ stroke_bounds
41
+ end
42
+
43
+ bounding_box [125, bounds.top], :width => 50, :height => 25 do
44
+ text "2"
45
+ stroke_bounds
46
+ end
47
+
48
+ bounding_box [200, bounds.top - 50], :width => 50, :height => 125 do
49
+ text "3"
50
+ stroke_bounds
51
+ end
52
+
53
+ bounding_box [350, bounds.top - 100], :width => 20, :height => 20 do
54
+ text "4"
55
+ stroke_bounds
56
+ end
57
+
58
+ bounding_box [400, bounds.height - 150], :width => 100, :height => 100 do
59
+ text "5"
60
+ stroke_bounds
61
+ end
62
+
63
+ stroke_dashed_bounds
64
+
65
+ end
66
+
67
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This demonstrates the Prawn options for document and page margin, similar to CSS shorthand.
4
+ #
5
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
6
+
7
+ LOREM = ("Lorem ipsum dolor sit amet, consectetur adipisicing elit, "+
8
+ "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "+
9
+ "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris "+
10
+ "nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in "+
11
+ "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla "+
12
+ "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in " +
13
+ "culpa qui officia deserunt mollit anim id est laborum. ") * 20
14
+
15
+ Prawn::Document.generate("margin.pdf", :margin => 100) do |pdf|
16
+
17
+ pdf.text "100 on all sides", :style => :bold
18
+ pdf.text LOREM
19
+
20
+ pdf.start_new_page(:margin => 100, :left_margin => 0)
21
+ pdf.text "100 on all sides but 0 on the left", :style => :bold
22
+ pdf.text LOREM
23
+
24
+ pdf.start_new_page(:margin => [100, 0])
25
+ pdf.text "100 top and bottom, 0 left and right.", :style => :bold
26
+ pdf.text LOREM
27
+
28
+ pdf.start_new_page(:margin => [100, 0, 50])
29
+ pdf.text "100 top, 0 left and right, 50 bottom.", :style => :bold
30
+ pdf.text LOREM
31
+
32
+ pdf.start_new_page(:margin => [0, 50, 100, 150])
33
+ pdf.text "0 top, 50 right, 100 bottom, 150 left.", :style => :bold
34
+ pdf.text LOREM
35
+
36
+ end
@@ -13,4 +13,6 @@ Prawn::Document.generate("multi-layout.pdf", :page_layout => :landscape) do |pdf
13
13
  pdf.text "This is on legal paper size"
14
14
  pdf.start_new_page(:left_margin => 150, :right_margin => 150)
15
15
  pdf.text "This page has very wide left and right margins, causing a squeeze"
16
- end
16
+ pdf.start_new_page(:margin => 300, :right_margin => 0)
17
+ pdf.text "This page has even wider margins on all sides except for the right side, where it's 0"
18
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This example demonstrates how to add a "page k of n"
4
+ # template to your documents.
5
+ #
6
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
7
+
8
+ Prawn::Document.generate("page_with_numbering.pdf") do
9
+ text "Hai"
10
+ start_new_page
11
+ text "bai"
12
+ start_new_page
13
+ text "-- Hai again"
14
+ number_pages "<page> in a total of <total>", [bounds.right - 50, 0]
15
+ end
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Demonstrate use of stamps
4
+ #
5
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
6
+
7
+ Prawn::Document.generate("stamp.pdf") do
8
+
9
+ create_stamp("page_template") do
10
+ text "This is my page template", :at => [0, bounds.top - 4 * font.height]
11
+ text "This is also in my page template", :at => [0, 0]
12
+ end
13
+
14
+ create_stamp("odd_page_template") do
15
+ text "This is the odd page template",
16
+ :at => [0, bounds.top - 4 * font.height]
17
+ text "This is also in the odd page template", :at => [0, 0]
18
+ end
19
+
20
+ create_stamp("even_page_template") do
21
+ text "This is the even page template",
22
+ :at => [0, bounds.top - 4 * font.height]
23
+ text "This is also in the even page template", :at => [0, 0]
24
+ end
25
+
26
+ stamp("odd_page_template")
27
+
28
+ create_stamp("MyStamp") do
29
+ fill_color("ff0000")
30
+ fill_circle_at([0, 0], :radius => 20)
31
+ fill_color("000000")
32
+ fill_circle_at([10, 10], :radius => 20)
33
+ end
34
+
35
+ 10.times do |i|
36
+ 10.times do |j|
37
+ stamp_at("MyStamp", [100 + j * 50, bounds.top - 100 - i * 50])
38
+ end
39
+ end
40
+
41
+ 4.times do |i|
42
+ start_new_page
43
+ stamp("#{i % 2 == 0 ? 'even' : 'odd'}_page_template")
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Stroke dashing can be applied to any line or curve
4
+
5
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
6
+
7
+ Prawn::Document.generate("stroke_cap_and_join.pdf") do
8
+ self.line_width = 25
9
+ x0 = bounds.left + 100
10
+ x1 = bounds.left + 200
11
+ x2 = bounds.left + 300
12
+
13
+ y = bounds.top - 125
14
+
15
+ 3.times do |i|
16
+ case i
17
+ when 0
18
+ self.join_style = :miter
19
+ when 1
20
+ self.join_style = :round
21
+ when 2
22
+ self.join_style = :bevel
23
+ end
24
+ stroke do
25
+ move_to(x0, y)
26
+ line_to(x1, y + 100)
27
+ line_to(x2, y)
28
+ end
29
+ y -= 100
30
+ end
31
+
32
+
33
+ 3.times do |i|
34
+ case i
35
+ when 0
36
+ self.cap_style = :butt
37
+ when 1
38
+ self.cap_style = :round
39
+ when 2
40
+ self.cap_style = :projecting_square
41
+ end
42
+ stroke_line([x0, y, x2, y])
43
+ y -= 30
44
+ end
45
+ end
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Stroke dashing can be applied to any line or curve
4
+
5
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
6
+
7
+ Prawn::Document.generate("stroke_dash.pdf") do
8
+ self.line_width = 1
9
+ base_y = bounds.top
10
+
11
+ 100.times do |i|
12
+ length = i / 4 + 1
13
+ # space between dashes same length as dash
14
+ space = length
15
+ # start with dash
16
+ phase = 0
17
+ case i % 4
18
+ when 0
19
+ base_y -= 10
20
+ when 1
21
+ # start with space between dashes
22
+ phase = length
23
+ when 2
24
+ base_y -= 10
25
+ # space between dashes half as long as dash
26
+ space = length * 0.5
27
+ when 3
28
+ # space between dashes half as long as dash
29
+ space = length * 0.5
30
+ # start with space between dashes
31
+ phase = length
32
+ end
33
+ dash(length, :space => space, :phase => phase)
34
+ points = [bounds.left, base_y - 2 * i, bounds.right, base_y - 2 * i]
35
+ stroke_line(points)
36
+ end
37
+ i = 100
38
+ base_y -= 10
39
+ undash
40
+ points = [bounds.left, base_y - 2 * i, bounds.right, base_y - 2 * i]
41
+ stroke_line(points)
42
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Demonstrate use of transparency
4
+ #
5
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
6
+
7
+ Prawn::Document.generate("transparency.pdf") do
8
+ fill_color("ff0000")
9
+ fill_circle_at([200, 200], :radius => 200)
10
+ transparent(0.5, 1) do
11
+ fill_color("000000")
12
+ stroke_color("ffffff")
13
+ fill_and_stroke_circle_at([300, 300], :radius => 200)
14
+ fill_color("ffffff")
15
+ text "transparency " * 150, :size => 18
16
+ end
17
+
18
+ start_new_page
19
+
20
+ fill_color("000000")
21
+ fill_rectangle([0, bounds.top], 200, 100)
22
+ transparent(0.5) do
23
+ fill_color("ff0000")
24
+ fill_rectangle([100, bounds.top - 50], 200, 100)
25
+ end
26
+ end
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ #
3
+ # A text box is positioned by a top-left corner, width, and height and is
4
+ # essentially an invisible rectangle that the text will flow within. If the
5
+ # text exceeds the boundaries, it is either truncated, replaced with some
6
+ # ellipses, or set to expand beyond the bottom boundary.
7
+ #
8
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
9
+
10
+ Prawn::Document.generate("text_box_returning_excess.pdf") do
11
+
12
+ # Note that without the initial space in p_break, newlines may be eaten by
13
+ # the wrap/unwrap process that happens inside the text box.
14
+ p_break = " \n\n"
15
+ callout = "Lorem ipsum dolor sit amet"
16
+ lorem = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.#{p_break}Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.#{p_break}Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
17
+
18
+ box_height = font.height * 5
19
+
20
+ # Add a callout box that the rest of the text should flow around
21
+ font_size(18) do
22
+ text_box callout, {
23
+ :width => 100,
24
+ :height => font.height * 3,
25
+ :overflow => :truncate,
26
+ :at => [100, bounds.top - box_height - 4]
27
+ }
28
+ end
29
+
30
+ excess_text = text_box lorem + p_break + lorem, {
31
+ :width => 300,
32
+ :height => box_height,
33
+ :overflow => :truncate,
34
+ :at => [100, bounds.top],
35
+ }
36
+
37
+ excess_text = text_box excess_text, {
38
+ :width => 200,
39
+ :height => box_height,
40
+ :overflow => :truncate,
41
+ :at => [200, bounds.top - box_height],
42
+ }
43
+
44
+ text_box excess_text, {
45
+ :width => 300,
46
+ :height => box_height,
47
+ :overflow => :expand,
48
+ :at => [100, bounds.top - box_height * 2],
49
+ }
50
+
51
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ module Prawn
3
+ # This is used to differentiate strings that must be encoded as
4
+ # a byte string, such as binary data from encrypted strings.
5
+ class ByteString < String #:nodoc:
6
+ end
7
+ end
data/lib/prawn/core.rb CHANGED
@@ -1,11 +1,9 @@
1
1
  # encoding: utf-8
2
- #
3
2
  # Prawn : A library for PDF generation in Ruby
4
3
  #
5
4
  # Copyright April 2008, Gregory Brown. All Rights Reserved.
6
5
  #
7
6
  # This is free software. Please see the LICENSE and COPYING files for details.
8
-
9
7
  %w[ttfunk/lib].each do |dep|
10
8
  $LOAD_PATH.unshift(File.dirname(__FILE__) + "/../../vendor/#{dep}")
11
9
  end
@@ -27,7 +25,7 @@ module Prawn
27
25
  # The base source directory for Prawn as installed on the system
28
26
  BASEDIR = File.expand_path(File.join(dir, '..', '..'))
29
27
 
30
- VERSION = "0.5.1"
28
+ VERSION = "0.6.1"
31
29
 
32
30
  extend self
33
31
 
@@ -35,11 +33,10 @@ module Prawn
35
33
  # are used. Off by default.
36
34
  #
37
35
  # Example:
38
- #
39
- # >> Prawn::Document.new(:tomato => "Juicy")
40
- # Prawn::Errors::UnknownOption:
41
- # Detected unknown option(s): [:tomato]
42
- # Accepted options are: [:page_size, :page_layout, :left_margin, ...]
36
+ # >> Prawn::Document.new(:tomato => "Juicy")
37
+ # Prawn::Errors::UnknownOption:
38
+ # Detected unknown option(s): [:tomato]
39
+ # Accepted options are: [:page_size, :page_layout, :left_margin, ...]
43
40
  #
44
41
  attr_accessor :debug
45
42
 
@@ -75,10 +72,12 @@ end
75
72
  require "prawn/compatibility"
76
73
  require "prawn/errors"
77
74
  require "prawn/pdf_object"
75
+ require "prawn/object_store"
78
76
  require "prawn/graphics"
79
77
  require "prawn/images"
80
78
  require "prawn/images/jpg"
81
79
  require "prawn/images/png"
80
+ require "prawn/stamp"
82
81
  require "prawn/document"
83
82
  require "prawn/reference"
84
83
  require "prawn/font"
@@ -14,15 +14,16 @@ module Prawn
14
14
  # Provides very low-level support for annotations. These extensions are
15
15
  # mainly for use by prawn-format, so be sure to check that out if all
16
16
  # you need is basic internal or external links.
17
+ #
17
18
  module Annotations
18
19
 
19
20
  # Adds a new annotation (section 8.4 in PDF spec) to the current page.
20
21
  # +options+ must be a Hash describing the annotation.
21
22
  #
22
23
  def annotate(options)
23
- @current_page.data[:Annots] ||= []
24
+ current_page.data[:Annots] ||= []
24
25
  options = sanitize_annotation_hash(options)
25
- @current_page.data[:Annots] << ref(options)
26
+ current_page.data[:Annots] << ref(options)
26
27
  return options
27
28
  end
28
29
 
@@ -25,7 +25,7 @@ module Prawn
25
25
  # Usage:
26
26
  #
27
27
  # * Bounding box 100pt x 100pt in the absolute bottom left of the
28
- # containing box:
28
+ # containing box:
29
29
  #
30
30
  # pdf.bounding_box([0,100], :width => 100, :height => 100)
31
31
  # stroke_bounds
@@ -56,10 +56,10 @@ module Prawn
56
56
  # "and return to the margin_box"
57
57
  # end
58
58
  #
59
- # Note that this is a low level tool and is designed primarily for
60
- # building other abstractions. If you just want to flow some text on
61
- # a page, look into span() or text_box()
62
- #
59
+ # Note, this is a low level tool and is designed primarily for building
60
+ # other abstractions. If you just need to flow text on the page, you
61
+ # will want to look at span() and text_box() instead
62
+ #
63
63
  # ==Translating Coordinates
64
64
  #
65
65
  # When translating coordinates, the idea is to allow the user to draw
@@ -122,8 +122,8 @@ module Prawn
122
122
  # ==Stretchyness
123
123
  #
124
124
  # If you do not specify a height to a bounding box, it will become stretchy
125
- # and its height will be calculated according to the last drawing position
126
- # within the bounding box:
125
+ # and its height will be calculated automatically as you stretch the box
126
+ # downwards.
127
127
  #
128
128
  # pdf.bounding_box([100,400], :width => 400) do
129
129
  # pdf.text("The height of this box is #{pdf.bounds.height}")
@@ -141,8 +141,8 @@ module Prawn
141
141
  # pdf.bounding_box([50,500], :width => 200, :height => 300) do
142
142
  # pdf.stroke_bounds
143
143
  # pdf.canvas do
144
+ # Positioned outside the containing box at the 'real' (300,450)
144
145
  # pdf.bounding_box([300,450], :width => 200, :height => 200) do
145
- # # Positioned outside the containing box at the 'real' (300,450)
146
146
  # pdf.stroke_bounds
147
147
  # end
148
148
  # end
@@ -185,7 +185,9 @@ module Prawn
185
185
  user_block.call
186
186
  self.y = @bounding_box.absolute_bottom unless options[:hold_position]
187
187
 
188
- @bounding_box = parent_box
188
+ created_box, @bounding_box = @bounding_box, parent_box
189
+
190
+ return created_box
189
191
  end
190
192
 
191
193
  # Low level layout helper that simplifies coordinate math.
@@ -369,8 +371,11 @@ module Prawn
369
371
  # the box to the current drawing position.
370
372
  #
371
373
  def height
372
- @height || absolute_top - @parent.y
374
+ return @height if @height
375
+ @stretched_height = [(absolute_top - @parent.y), @stretched_height.to_f].max
373
376
  end
377
+
378
+ alias_method :update_height, :height
374
379
 
375
380
  # Returns +false+ when the box has a defined height, +true+ when the height
376
381
  # is being calculated on the fly based on the current vertical position.
@@ -89,9 +89,7 @@ module Prawn
89
89
  absolute_right - (width_of_column * columns_from_right)
90
90
  end
91
91
 
92
- # Wrap position to the next column, starting a new page if necessary
93
- #
94
- def move_past_bottom
92
+ def move_past_bottom #:nodoc:
95
93
  @current_column = (@current_column + 1) % @columns
96
94
  @parent.y = @y
97
95
  if 0 == @current_column