prawn 0.11.1.pre → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. data/COPYING +2 -340
  2. data/HACKING +1 -1
  3. data/LICENSE +3 -3
  4. data/Rakefile +17 -6
  5. data/data/encodings/win_ansi.txt +1 -1
  6. data/data/images/prawn.png +0 -0
  7. data/data/pdfs/form.pdf +820 -0
  8. data/data/pdfs/multipage_template.pdf +127 -0
  9. data/examples/bounding_box/bounding_boxes.rb +4 -3
  10. data/examples/bounding_box/indentation.rb +2 -1
  11. data/examples/bounding_box/russian_boxes.rb +3 -2
  12. data/examples/bounding_box/stretched_nesting.rb +2 -1
  13. data/examples/general/background.rb +2 -1
  14. data/examples/general/canvas.rb +2 -1
  15. data/examples/general/context_sensitive_headers.rb +2 -1
  16. data/examples/general/float.rb +2 -1
  17. data/examples/general/margin.rb +2 -1
  18. data/examples/general/measurement_units.rb +2 -1
  19. data/examples/general/metadata-info.rb +2 -1
  20. data/examples/general/multi_page_layout.rb +2 -1
  21. data/examples/general/outlines.rb +2 -1
  22. data/examples/general/page_geometry.rb +2 -1
  23. data/examples/general/page_numbering.rb +27 -2
  24. data/examples/general/page_templates.rb +20 -0
  25. data/examples/general/repeaters.rb +2 -1
  26. data/examples/general/stamp.rb +4 -3
  27. data/examples/general/templates.rb +2 -1
  28. data/examples/graphics/basic_images.rb +2 -1
  29. data/examples/graphics/cmyk.rb +2 -1
  30. data/examples/graphics/curves.rb +4 -3
  31. data/examples/graphics/gradient.rb +23 -0
  32. data/examples/graphics/hexagon.rb +3 -2
  33. data/examples/graphics/image_fit.rb +3 -2
  34. data/examples/graphics/image_flow.rb +2 -1
  35. data/examples/graphics/image_position.rb +3 -2
  36. data/examples/graphics/line.rb +2 -1
  37. data/examples/graphics/png_types.rb +3 -2
  38. data/examples/graphics/polygons.rb +3 -2
  39. data/examples/graphics/remote_images.rb +2 -1
  40. data/examples/graphics/rounded_polygons.rb +2 -1
  41. data/examples/graphics/rounded_rectangle.rb +2 -1
  42. data/examples/graphics/ruport_style_helpers.rb +3 -2
  43. data/examples/graphics/stroke_bounds.rb +2 -1
  44. data/examples/graphics/stroke_cap_and_join.rb +2 -1
  45. data/examples/graphics/stroke_dash.rb +2 -1
  46. data/examples/graphics/transformations.rb +2 -1
  47. data/examples/graphics/transparency.rb +4 -3
  48. data/examples/grid/bounding_boxes.rb +2 -1
  49. data/examples/grid/column_gutter_grid.rb +2 -1
  50. data/examples/grid/multi_boxes.rb +2 -1
  51. data/examples/grid/show_grid.rb +2 -1
  52. data/examples/grid/simple_grid.rb +2 -1
  53. data/examples/m17n/chinese_text_wrapping.rb +2 -1
  54. data/examples/m17n/euro.rb +3 -2
  55. data/examples/m17n/full_win_ansi_character_list.rb +20 -0
  56. data/examples/m17n/sjis.rb +2 -1
  57. data/examples/m17n/utf8.rb +3 -2
  58. data/examples/m17n/win_ansi_charset.rb +2 -1
  59. data/examples/security/hello_foo.rb +2 -1
  60. data/examples/table/bill.rb +2 -1
  61. data/examples/table/borders.rb +25 -0
  62. data/examples/table/cell.rb +3 -2
  63. data/examples/table/checkerboard.rb +2 -1
  64. data/examples/table/header.rb +3 -2
  65. data/examples/table/inline_format_table.rb +2 -1
  66. data/examples/table/multi_page_table.rb +2 -1
  67. data/examples/table/simple_table.rb +2 -1
  68. data/examples/table/subtable.rb +2 -1
  69. data/examples/table/widths.rb +2 -1
  70. data/examples/text/alignment.rb +2 -1
  71. data/examples/text/character_spacing.rb +2 -1
  72. data/examples/text/dfont.rb +2 -1
  73. data/examples/text/family_based_styling.rb +3 -2
  74. data/examples/text/font_calculations.rb +2 -1
  75. data/examples/text/font_size.rb +2 -1
  76. data/examples/text/hyphenation.rb +2 -2
  77. data/examples/text/indent_paragraphs.rb +7 -5
  78. data/examples/text/inline_format.rb +7 -6
  79. data/examples/text/kerning.rb +2 -1
  80. data/examples/text/rendering_mode.rb +21 -0
  81. data/examples/text/rotated.rb +2 -1
  82. data/examples/text/shaped_text_box.rb +2 -1
  83. data/examples/text/simple_text.rb +2 -1
  84. data/examples/text/simple_text_ttf.rb +2 -1
  85. data/examples/text/span.rb +3 -2
  86. data/examples/text/text_box.rb +7 -5
  87. data/examples/text/text_box_returning_excess.rb +4 -3
  88. data/examples/text/text_flow.rb +2 -1
  89. data/lib/prawn.rb +1 -1
  90. data/lib/prawn/core/object_store.rb +42 -14
  91. data/lib/prawn/core/page.rb +22 -8
  92. data/lib/prawn/core/text.rb +141 -13
  93. data/lib/prawn/core/text/formatted/arranger.rb +39 -12
  94. data/lib/prawn/core/text/formatted/line_wrap.rb +205 -60
  95. data/lib/prawn/core/text/formatted/wrap.rb +72 -35
  96. data/lib/prawn/document.rb +174 -70
  97. data/lib/prawn/document/bounding_box.rb +122 -83
  98. data/lib/prawn/document/column_box.rb +113 -0
  99. data/lib/prawn/document/graphics_state.rb +90 -2
  100. data/lib/prawn/document/internals.rb +5 -3
  101. data/lib/prawn/errors.rb +5 -0
  102. data/lib/prawn/font.rb +4 -4
  103. data/lib/prawn/font/afm.rb +11 -0
  104. data/lib/prawn/font/ttf.rb +5 -0
  105. data/lib/prawn/graphics.rb +77 -14
  106. data/lib/prawn/graphics/cap_style.rb +13 -5
  107. data/lib/prawn/graphics/color.rb +54 -35
  108. data/lib/prawn/graphics/dash.rb +27 -16
  109. data/lib/prawn/graphics/gradient.rb +84 -0
  110. data/lib/prawn/graphics/join_style.rb +12 -3
  111. data/lib/prawn/graphics/transparency.rb +4 -4
  112. data/lib/prawn/images.rb +18 -160
  113. data/lib/prawn/images/jpg.rb +39 -0
  114. data/lib/prawn/images/png.rb +130 -0
  115. data/lib/prawn/repeater.rb +6 -13
  116. data/lib/prawn/security.rb +6 -1
  117. data/lib/prawn/stamp.rb +12 -4
  118. data/lib/prawn/table.rb +36 -4
  119. data/lib/prawn/table/cell.rb +224 -63
  120. data/lib/prawn/table/cell/text.rb +20 -10
  121. data/lib/prawn/table/cells.rb +23 -6
  122. data/lib/prawn/text.rb +54 -91
  123. data/lib/prawn/text/box.rb +29 -283
  124. data/lib/prawn/text/formatted/box.rb +349 -24
  125. data/lib/prawn/text/formatted/fragment.rb +63 -2
  126. data/lib/prawn/text/formatted/parser.rb +2 -1
  127. data/prawn.gemspec +21 -5
  128. data/spec/bounding_box_spec.rb +61 -28
  129. data/spec/cell_spec.rb +168 -30
  130. data/spec/document_spec.rb +187 -3
  131. data/spec/extensions/mocha.rb +45 -0
  132. data/spec/font_spec.rb +32 -1
  133. data/spec/formatted_text_arranger_spec.rb +35 -40
  134. data/spec/formatted_text_box_spec.rb +287 -443
  135. data/spec/formatted_text_fragment_spec.rb +87 -0
  136. data/spec/graphics_spec.rb +128 -12
  137. data/spec/grid_spec.rb +1 -1
  138. data/spec/images_spec.rb +11 -3
  139. data/spec/inline_formatted_text_parser_spec.rb +8 -0
  140. data/spec/line_wrap_spec.rb +200 -208
  141. data/spec/object_store_spec.rb +10 -0
  142. data/spec/outline_spec.rb +7 -3
  143. data/spec/repeater_spec.rb +58 -10
  144. data/spec/security_spec.rb +6 -0
  145. data/spec/spec_helper.rb +12 -8
  146. data/spec/stamp_spec.rb +52 -1
  147. data/spec/stroke_styles_spec.rb +30 -0
  148. data/spec/table_spec.rb +93 -3
  149. data/spec/template_spec.rb +132 -6
  150. data/spec/text_at_spec.rb +14 -4
  151. data/spec/text_box_spec.rb +309 -70
  152. data/spec/text_rendering_mode_spec.rb +45 -0
  153. data/spec/text_spec.rb +60 -17
  154. data/spec/text_with_inline_formatting_spec.rb +4 -162
  155. metadata +241 -241
  156. data/lib/prawn/core/text/line_wrap.rb +0 -211
  157. data/lib/prawn/core/text/wrap.rb +0 -82
  158. data/vendor/pdf-inspector/README +0 -18
  159. data/vendor/pdf-inspector/lib/pdf/inspector.rb +0 -26
  160. data/vendor/pdf-inspector/lib/pdf/inspector/extgstate.rb +0 -18
  161. data/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +0 -131
  162. data/vendor/pdf-inspector/lib/pdf/inspector/page.rb +0 -25
  163. data/vendor/pdf-inspector/lib/pdf/inspector/text.rb +0 -46
  164. data/vendor/pdf-inspector/lib/pdf/inspector/xobject.rb +0 -19
  165. data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
  166. data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
  167. data/vendor/ttfunk/example.rb +0 -45
  168. data/vendor/ttfunk/lib/ttfunk.rb +0 -102
  169. data/vendor/ttfunk/lib/ttfunk/directory.rb +0 -17
  170. data/vendor/ttfunk/lib/ttfunk/encoding/mac_roman.rb +0 -88
  171. data/vendor/ttfunk/lib/ttfunk/encoding/windows_1252.rb +0 -69
  172. data/vendor/ttfunk/lib/ttfunk/reader.rb +0 -44
  173. data/vendor/ttfunk/lib/ttfunk/resource_file.rb +0 -78
  174. data/vendor/ttfunk/lib/ttfunk/subset.rb +0 -18
  175. data/vendor/ttfunk/lib/ttfunk/subset/base.rb +0 -141
  176. data/vendor/ttfunk/lib/ttfunk/subset/mac_roman.rb +0 -50
  177. data/vendor/ttfunk/lib/ttfunk/subset/unicode.rb +0 -48
  178. data/vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb +0 -63
  179. data/vendor/ttfunk/lib/ttfunk/subset/windows_1252.rb +0 -55
  180. data/vendor/ttfunk/lib/ttfunk/subset_collection.rb +0 -72
  181. data/vendor/ttfunk/lib/ttfunk/table.rb +0 -46
  182. data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +0 -34
  183. data/vendor/ttfunk/lib/ttfunk/table/cmap/format00.rb +0 -54
  184. data/vendor/ttfunk/lib/ttfunk/table/cmap/format04.rb +0 -126
  185. data/vendor/ttfunk/lib/ttfunk/table/cmap/subtable.rb +0 -79
  186. data/vendor/ttfunk/lib/ttfunk/table/glyf.rb +0 -64
  187. data/vendor/ttfunk/lib/ttfunk/table/glyf/compound.rb +0 -81
  188. data/vendor/ttfunk/lib/ttfunk/table/glyf/simple.rb +0 -37
  189. data/vendor/ttfunk/lib/ttfunk/table/head.rb +0 -44
  190. data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +0 -41
  191. data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +0 -47
  192. data/vendor/ttfunk/lib/ttfunk/table/kern.rb +0 -79
  193. data/vendor/ttfunk/lib/ttfunk/table/kern/format0.rb +0 -62
  194. data/vendor/ttfunk/lib/ttfunk/table/loca.rb +0 -43
  195. data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +0 -40
  196. data/vendor/ttfunk/lib/ttfunk/table/name.rb +0 -125
  197. data/vendor/ttfunk/lib/ttfunk/table/os2.rb +0 -78
  198. data/vendor/ttfunk/lib/ttfunk/table/post.rb +0 -91
  199. data/vendor/ttfunk/lib/ttfunk/table/post/format10.rb +0 -43
  200. data/vendor/ttfunk/lib/ttfunk/table/post/format20.rb +0 -35
  201. data/vendor/ttfunk/lib/ttfunk/table/post/format25.rb +0 -23
  202. data/vendor/ttfunk/lib/ttfunk/table/post/format30.rb +0 -17
  203. data/vendor/ttfunk/lib/ttfunk/table/post/format40.rb +0 -17
  204. data/vendor/ttfunk/lib/ttfunk/table/simple.rb +0 -14
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  #
3
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
3
+ require File.expand_path(File.join(File.dirname(__FILE__),
4
+ %w[.. example_helper]))
4
5
 
5
6
  Prawn::Document.generate("multi_page_table.pdf") do
6
7
 
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  #
3
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
3
+ require File.expand_path(File.join(File.dirname(__FILE__),
4
+ %w[.. example_helper]))
4
5
 
5
6
  Prawn::Document.generate("simple_table.pdf") do
6
7
 
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  #
3
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
3
+ require File.expand_path(File.join(File.dirname(__FILE__),
4
+ %w[.. example_helper]))
4
5
 
5
6
  Prawn::Document.generate("subtable.pdf") do |pdf|
6
7
 
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  #
3
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
3
+ require File.expand_path(File.join(File.dirname(__FILE__),
4
+ %w[.. example_helper]))
4
5
 
5
6
  Prawn::Document.generate("widths.pdf") do
6
7
 
@@ -3,7 +3,8 @@
3
3
  # This example demonstrates usage of Document#text with the :align option.
4
4
  # Available options are :left, :right, and :center, with :left as default.
5
5
  #
6
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
6
+ require File.expand_path(File.join(File.dirname(__FILE__),
7
+ %w[.. example_helper]))
7
8
 
8
9
  Prawn::Document.generate("alignment.pdf") do
9
10
  text "This text should be left aligned"
@@ -3,7 +3,8 @@
3
3
  # Example of character spacing
4
4
  #
5
5
  #
6
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
6
+ require File.expand_path(File.join(File.dirname(__FILE__),
7
+ %w[.. example_helper]))
7
8
 
8
9
  Prawn::Document.generate "character_spacing.pdf" do |pdf|
9
10
  string = "hello world " * 50
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
3
+ require File.expand_path(File.join(File.dirname(__FILE__),
4
+ %w[.. example_helper]))
4
5
 
5
6
  DFONT_FILE = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
6
7
  puts "There are #{Prawn::Font::DFont.font_count(DFONT_FILE)} fonts in #{DFONT_FILE}:"
@@ -4,7 +4,8 @@
4
4
  # If you are working with TTF fonts, you'll want to check out the
5
5
  # documentation for Document#font_families and register your fonts with it.
6
6
  #
7
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
7
+ require File.expand_path(File.join(File.dirname(__FILE__),
8
+ %w[.. example_helper]))
8
9
 
9
10
  Prawn::Document.generate("family_style.pdf") do
10
11
  ["Courier","Helvetica","Times-Roman"].each do |f|
@@ -21,4 +22,4 @@ Prawn::Document.generate("family_style.pdf") do
21
22
  text "Bold Italic", :style => :bold_italic
22
23
  text "Italic", :style => :italic
23
24
  text "Normal"
24
- end
25
+ end
@@ -4,7 +4,8 @@
4
4
  # meant to assist those that need to do advanced positioning calculations.
5
5
  # Run the example for a clearer picture of how things work
6
6
  #
7
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
7
+ require File.expand_path(File.join(File.dirname(__FILE__),
8
+ %w[.. example_helper]))
8
9
 
9
10
  Prawn::Document.generate('font_calculations.pdf') do
10
11
 
@@ -2,7 +2,8 @@
2
2
  #
3
3
  # This example shows the many ways of setting font sizes in Prawn
4
4
  #
5
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
5
+ require File.expand_path(File.join(File.dirname(__FILE__),
6
+ %w[.. example_helper]))
6
7
 
7
8
  Prawn::Document.generate "font_size.pdf", :page_size => "A4" do
8
9
 
@@ -1,7 +1,8 @@
1
1
  # encoding: utf-8
2
2
  #
3
3
 
4
- require 'examples/example_helper'
4
+ require File.expand_path(File.join(File.dirname(__FILE__),
5
+ %w[.. example_helper]))
5
6
 
6
7
  Prawn::Document.generate("hyphenation.pdf") do
7
8
  def get_string(i)
@@ -18,7 +19,6 @@ Prawn::Document.generate("hyphenation.pdf") do
18
19
  options = {
19
20
  :width => bounds.width * 0.3,
20
21
  :height => bounds.width * 0.3,
21
- :overflow => :ellipses,
22
22
  :at => [0, 0],
23
23
  :align => :left,
24
24
  :document => self
@@ -3,20 +3,22 @@
3
3
  # Example of two ways of indenting paragraphs
4
4
  #
5
5
  #
6
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
6
+ require File.expand_path(File.join(File.dirname(__FILE__),
7
+ %w[.. example_helper]))
7
8
 
8
9
  Prawn::Document.generate "indent_paragraphs.pdf" do |pdf|
9
10
  hello = "hello " * 50
10
11
  world = "world " * 50
11
- pdf.text(hello + "\n" + world, :indent_paragraphs => 60)
12
+ string = hello + "©\n" + world + "©"
13
+ pdf.text(string, :indent_paragraphs => 60, :align => :justify)
12
14
 
13
15
  pdf.move_cursor_to(pdf.font.height)
14
- pdf.text(hello + "\n" + world, :indent_paragraphs => 60)
16
+ pdf.text(string, :indent_paragraphs => 60, :align => :justify)
15
17
 
16
18
  pdf.move_cursor_to(pdf.font.height * 3)
17
- pdf.text(hello + "\n" + world, :indent_paragraphs => 60)
19
+ pdf.text(string, :indent_paragraphs => 60, :align => :justify)
18
20
 
19
21
  # can also indent using a non-breaking space
20
22
  nbsp = Prawn::Text::NBSP
21
- pdf.text("\n" * 10 + hello + "\n#{nbsp * 10}" + world)
23
+ pdf.text("\n\n\n\n#{nbsp * 10}" + hello + "\n#{nbsp * 10}" + world, :align => :justify)
22
24
  end
@@ -2,7 +2,8 @@
2
2
  #
3
3
  # This example shows how to use inline formatting
4
4
  #
5
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
5
+ require File.expand_path(File.join(File.dirname(__FILE__),
6
+ %w[.. example_helper]))
6
7
 
7
8
  Prawn::Document.generate("inline_format.pdf") do |pdf|
8
9
 
@@ -13,7 +14,7 @@ Prawn::Document.generate("inline_format.pdf") do |pdf|
13
14
  pdf.text("right: " + "hello <b>world how <i>are</i></b> you? " * 2,
14
15
  :inline_format => true,
15
16
  :align => :right)
16
- pdf.text("center: " + "hello <b>world how <i>are</i></b> you? " * 2,
17
+ pdf.text("center: " + "hello <b>world <font size='48'>ho<sub>w</sub> <i>are</i></font></b> you? " * 2,
17
18
  :inline_format => true,
18
19
  :align => :center)
19
20
  pdf.text("\njustify: " + "hello <b>world <i>goodbye</i></b> " * 12 + "the end ",
@@ -78,10 +79,10 @@ Prawn::Document.generate("inline_format.pdf") do |pdf|
78
79
  @document.stroke_polygon(fragment.top_left, fragment.top_right,
79
80
  fragment.bottom_right, fragment.bottom_left)
80
81
  end
81
- @document.stroke_circle_at(fragment.top_left, :radius => @radius)
82
- @document.stroke_circle_at(fragment.top_right, :radius => @radius)
83
- @document.stroke_circle_at(fragment.bottom_right, :radius => @radius)
84
- @document.stroke_circle_at(fragment.bottom_left, :radius => @radius)
82
+ @document.stroke_circle(fragment.top_left, @radius)
83
+ @document.stroke_circle(fragment.top_right, @radius)
84
+ @document.stroke_circle(fragment.bottom_right, @radius)
85
+ @document.stroke_circle(fragment.bottom_left, @radius)
85
86
  end
86
87
  end
87
88
 
@@ -2,7 +2,8 @@
2
2
  #
3
3
  # Demonstration of enabling and disabling kerning support
4
4
  #
5
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
5
+ require File.expand_path(File.join(File.dirname(__FILE__),
6
+ %w[.. example_helper]))
6
7
 
7
8
  Prawn::Document.generate "kerning.pdf" do
8
9
  draw_text "To kern?", :at => [200,720], :size => 24, :kerning => true
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Example of character spacing
4
+ #
5
+ #
6
+ require File.expand_path(File.join(File.dirname(__FILE__),
7
+ %w[.. example_helper]))
8
+
9
+ Prawn::Document.generate "rendering_mode.pdf" do |pdf|
10
+ pdf.fill_color "00ff00"
11
+ pdf.stroke_color "0000ff"
12
+
13
+ # inline rendering mode
14
+ pdf.text("Inline mode", :mode => :stroke, :size => 40)
15
+
16
+ # block rendering mode
17
+ pdf.text_rendering_mode(:stroke) do
18
+ pdf.text("Block", :size => 30)
19
+ pdf.text("Mode", :size => 30)
20
+ end
21
+ end
@@ -2,7 +2,8 @@
2
2
  #
3
3
  # Demonstrates transformations
4
4
  #
5
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
5
+ require File.expand_path(File.join(File.dirname(__FILE__),
6
+ %w[.. example_helper]))
6
7
 
7
8
  Prawn::Document.generate "rotated_text.pdf" do |pdf|
8
9
  pdf.line_width = 1
@@ -2,7 +2,8 @@
2
2
  #
3
3
  # Demonstrates extending Text::Box
4
4
  #
5
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
5
+ require File.expand_path(File.join(File.dirname(__FILE__),
6
+ %w[.. example_helper]))
6
7
 
7
8
  Prawn::Document.generate "shaped_text_box.pdf" do |pdf|
8
9
  module ShapedBox
@@ -3,7 +3,8 @@
3
3
  # An early example of basic text generation at absolute positions.
4
4
  # Mostly kept for nostalgia.
5
5
  #
6
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
6
+ require File.expand_path(File.join(File.dirname(__FILE__),
7
+ %w[.. example_helper]))
7
8
 
8
9
  Prawn::Document.generate "simple_text.pdf" do
9
10
  fill_color "0000ff"
@@ -2,7 +2,8 @@
2
2
  #
3
3
  # An early example of TTF font embedding. Mostly kept for nostalgia's sake.
4
4
  #
5
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
5
+ require File.expand_path(File.join(File.dirname(__FILE__),
6
+ %w[.. example_helper]))
6
7
 
7
8
  Prawn::Document.generate "simple_text_ttf.pdf" do
8
9
  fill_color "0000ff"
@@ -3,7 +3,8 @@
3
3
  # Demonstration of Document#span, which is used for generating flowing
4
4
  # columns of text.
5
5
  #
6
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
6
+ require File.expand_path(File.join(File.dirname(__FILE__),
7
+ %w[.. example_helper]))
7
8
 
8
9
  Prawn::Document.generate("span.pdf") do
9
10
 
@@ -26,4 +27,4 @@ Prawn::Document.generate("span.pdf") do
26
27
  text "The rain in spain falls mainly on the plains. " * 300
27
28
  end
28
29
  end
29
- end
30
+ end
@@ -1,7 +1,8 @@
1
1
  # encoding: utf-8
2
2
  #
3
3
 
4
- require 'examples/example_helper'
4
+ require File.expand_path(File.join(File.dirname(__FILE__),
5
+ %w[.. example_helper]))
5
6
 
6
7
  Prawn::Document.generate("text_box.pdf") do
7
8
  def get_string(i, j)
@@ -31,7 +32,6 @@ Prawn::Document.generate("text_box.pdf") do
31
32
  options = {
32
33
  :width => bounds.width * 0.3,
33
34
  :height => bounds.width * 0.3,
34
- :overflow => :ellipses,
35
35
  :at => [0, 0],
36
36
  :align => :left,
37
37
  :document => self
@@ -66,21 +66,23 @@ Prawn::Document.generate("text_box.pdf") do
66
66
  options[:at][1] = bounds.top - (bounds.height - options[:height]) * 0.33 * j
67
67
  box = Prawn::Text::Box.new(get_string(i, j), options)
68
68
 
69
- fill_color("ffeeee")
70
- if i == 1
69
+ if j >= 2
71
70
  # bound with a box of a particular size, regardless of how
72
71
  # much text it contains
72
+ fill_color("ffeeee")
73
73
  fill_and_stroke_rectangle(options[:at],
74
74
  options[:width],
75
75
  options[:height])
76
76
  else
77
77
  # bound with a box that exactly fits the printed text using
78
78
  # dry_run look-ahead
79
+ fill_color("eeeeff")
79
80
  box.render(:dry_run => true)
80
- fill_and_stroke_rectangle(options[:at],
81
+ fill_and_stroke_rectangle(box.at,
81
82
  options[:width],
82
83
  box.height)
83
84
  end
85
+
84
86
  fill_color("000000")
85
87
  box.render
86
88
  end
@@ -2,10 +2,11 @@
2
2
  #
3
3
  # A text box is positioned by a top-left corner, width, and height and is
4
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.
5
+ # text exceeds the boundaries, it is either truncated, shrunk-to-fit, or set
6
+ # to expand beyond the bottom boundary.
7
7
  #
8
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
8
+ require File.expand_path(File.join(File.dirname(__FILE__),
9
+ %w[.. example_helper]))
9
10
 
10
11
  Prawn::Document.generate("text_box_returning_excess.pdf") do
11
12
 
@@ -3,7 +3,8 @@
3
3
  # Basic text flowing example including the use of bounding boxes. A somewhat
4
4
  # old example, mostly retained for nostalgia.
5
5
  #
6
- require "#{File.dirname(__FILE__)}/../example_helper.rb"
6
+ require File.expand_path(File.join(File.dirname(__FILE__),
7
+ %w[.. example_helper]))
7
8
 
8
9
  content = <<-EOS
9
10
  How does
data/lib/prawn.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # into the lib/prawn/core/* source tree.
6
6
  #
7
7
  module Prawn #:nodoc:
8
- VERSION = "0.11.1.pre"
8
+ VERSION = "0.11.1"
9
9
  end
10
10
 
11
11
  require "prawn/core"
@@ -129,6 +129,37 @@ module Prawn
129
129
  flat_page_ids[k]
130
130
  end
131
131
 
132
+ # imports all objects required to render a page from another PDF. The
133
+ # objects are added to the current object store, but NOT linked
134
+ # anywhere.
135
+ #
136
+ # The object ID of the root Page object is returned, it's up to the
137
+ # calling code to link that into the document structure somewhere. If
138
+ # this isn't done the imported objects will just be removed when the
139
+ # store is compacted.
140
+ #
141
+ # Imports nothing and returns nil if the requested page number doesn't
142
+ # exist. page_num is 1 indexed, so 1 indicates the first page.
143
+ #
144
+ def import_page(filename, page_num)
145
+ @loaded_objects = {}
146
+ unless File.file?(filename)
147
+ raise ArgumentError, "#{filename} does not exist"
148
+ end
149
+
150
+ hash = PDF::Reader::ObjectHash.new(filename)
151
+ ref = hash.page_references[page_num - 1]
152
+
153
+ ref.nil? ? nil : load_object_graph(hash, ref).identifier
154
+
155
+ rescue PDF::Reader::MalformedPDFError, PDF::Reader::InvalidObjectError
156
+ msg = "Error reading template file. If you are sure it's a valid PDF, it may be a bug."
157
+ raise Prawn::Errors::TemplateError, msg
158
+ rescue PDF::Reader::UnsupportedFeatureError
159
+ msg = "Template file contains unsupported PDF features"
160
+ raise Prawn::Errors::TemplateError, msg
161
+ end
162
+
132
163
  private
133
164
 
134
165
  # returns a nested array of object IDs for all pages in this object store.
@@ -143,19 +174,16 @@ module Prawn
143
174
 
144
175
  # takes a source PDF and uses it as a template for this document.
145
176
  #
146
- def load_file(filename)
147
- unless File.file?(filename)
148
- raise ArgumentError, "#{filename} does not exist"
149
- end
150
-
151
- unless PDF.const_defined?("Hash")
152
- raise "PDF::Hash not found. Is PDF::Reader > 0.8?"
177
+ def load_file(template)
178
+ unless (template.respond_to?(:seek) && template.respond_to?(:read)) ||
179
+ File.file?(template)
180
+ raise ArgumentError, "#{template} does not exist"
153
181
  end
154
182
 
155
- hash = PDF::Hash.new(filename)
183
+ hash = PDF::Reader::ObjectHash.new(template)
156
184
  src_info = hash.trailer[:Info]
157
185
  src_root = hash.trailer[:Root]
158
- @min_version = hash.version.to_f
186
+ @min_version = hash.pdf_version.to_f
159
187
 
160
188
  if hash.trailer[:Encrypt]
161
189
  msg = "Template file is an encrypted PDF, it can't be used as a template"
@@ -177,16 +205,16 @@ module Prawn
177
205
  raise Prawn::Errors::TemplateError, msg
178
206
  end
179
207
 
180
- # recurse down an object graph from a source PDF, importing all the indirect
181
- # objects we find.
208
+ # recurse down an object graph from a source PDF, importing all the
209
+ # indirect objects we find.
182
210
  #
183
- # hash is the PDF::Hash to extract objects from, object is the object to
184
- # extract.
211
+ # hash is the PDF::Reader::ObjectHash to extract objects from, object is
212
+ # the object to extract.
185
213
  #
186
214
  def load_object_graph(hash, object)
187
215
  @loaded_objects ||= {}
188
216
  case object
189
- when Hash then
217
+ when ::Hash then
190
218
  object.each { |key,value| object[key] = load_object_graph(hash, value) }
191
219
  object
192
220
  when Array then