prawn 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. data/README +6 -10
  2. data/Rakefile +4 -13
  3. data/data/encodings/win_ansi.txt +29 -0
  4. data/data/images/fractal.jpg +0 -0
  5. data/data/images/letterhead.jpg +0 -0
  6. data/examples/bounding_box/bounding_boxes.rb +44 -0
  7. data/examples/bounding_box/lazy_bounding_boxes.rb +28 -0
  8. data/examples/bounding_box/padded_box.rb +24 -0
  9. data/examples/{russian_boxes.rb → bounding_box/russian_boxes.rb} +9 -6
  10. data/examples/general/background.rb +20 -0
  11. data/examples/{canvas.rb → general/canvas.rb} +6 -2
  12. data/examples/general/measurement_units.rb +52 -0
  13. data/examples/{multi_page_layout.rb → general/multi_page_layout.rb} +6 -3
  14. data/examples/{page_geometry.rb → general/page_geometry.rb} +6 -2
  15. data/examples/{image.rb → graphics/basic_images.rb} +8 -4
  16. data/examples/graphics/cmyk.rb +13 -0
  17. data/examples/graphics/curves.rb +12 -0
  18. data/examples/{hexagon.rb → graphics/hexagon.rb} +5 -5
  19. data/examples/graphics/image_fit.rb +16 -0
  20. data/examples/graphics/image_flow.rb +38 -0
  21. data/examples/graphics/image_position.rb +18 -0
  22. data/examples/{line.rb → graphics/line.rb} +4 -2
  23. data/examples/{png_types.rb → graphics/png_types.rb} +4 -4
  24. data/examples/{polygons.rb → graphics/polygons.rb} +5 -4
  25. data/examples/graphics/remote_images.rb +12 -0
  26. data/examples/{ruport_helpers.rb → graphics/ruport_style_helpers.rb} +8 -5
  27. data/examples/graphics/stroke_bounds.rb +23 -0
  28. data/examples/{chinese_text_wrapping.rb → m17n/chinese_text_wrapping.rb} +7 -4
  29. data/examples/m17n/euro.rb +16 -0
  30. data/examples/m17n/sjis.rb +29 -0
  31. data/examples/m17n/utf8.rb +14 -0
  32. data/examples/m17n/win_ansi_charset.rb +55 -0
  33. data/examples/{addressbook.csv → table/addressbook.csv} +0 -0
  34. data/examples/{cell.rb → table/cell.rb} +8 -6
  35. data/examples/{currency.csv → table/currency.csv} +0 -0
  36. data/examples/{fancy_table.rb → table/fancy_table.rb} +9 -6
  37. data/examples/{ruport_formatter.rb → table/ruport_formatter.rb} +6 -3
  38. data/examples/{table.rb → table/table.rb} +6 -2
  39. data/examples/table/table_alignment.rb +18 -0
  40. data/examples/table/table_border_color.rb +17 -0
  41. data/examples/table/table_colspan.rb +19 -0
  42. data/examples/table/table_header_color.rb +19 -0
  43. data/examples/table/table_header_underline.rb +15 -0
  44. data/examples/{alignment.rb → text/alignment.rb} +5 -2
  45. data/examples/text/family_based_styling.rb +25 -0
  46. data/examples/{flowing_text_with_header_and_footer.rb → text/flowing_text_with_header_and_footer.rb} +19 -8
  47. data/examples/text/font_calculations.rb +91 -0
  48. data/examples/text/font_size.rb +34 -0
  49. data/examples/{kerning.rb → text/kerning.rb} +5 -1
  50. data/examples/text/simple_text.rb +18 -0
  51. data/examples/text/simple_text_ttf.rb +18 -0
  52. data/examples/{span.rb → text/span.rb} +5 -2
  53. data/examples/text/text_box.rb +26 -0
  54. data/examples/{text_flow.rb → text/text_flow.rb} +5 -2
  55. data/lib/prawn.rb +26 -20
  56. data/lib/prawn/compatibility.rb +5 -8
  57. data/lib/prawn/document.rb +29 -13
  58. data/lib/prawn/document/annotations.rb +63 -0
  59. data/lib/prawn/document/bounding_box.rb +18 -3
  60. data/lib/prawn/document/destinations.rb +81 -0
  61. data/lib/prawn/document/internals.rb +16 -2
  62. data/lib/prawn/document/page_geometry.rb +58 -57
  63. data/lib/prawn/document/span.rb +8 -0
  64. data/lib/prawn/document/table.rb +81 -31
  65. data/lib/prawn/document/text.rb +66 -21
  66. data/lib/prawn/document/text/box.rb +77 -0
  67. data/lib/prawn/encoding.rb +121 -0
  68. data/lib/prawn/errors.rb +4 -0
  69. data/lib/prawn/font.rb +70 -42
  70. data/lib/prawn/font/metrics.rb +64 -119
  71. data/lib/prawn/graphics.rb +105 -87
  72. data/lib/prawn/graphics/cell.rb +55 -28
  73. data/lib/prawn/graphics/color.rb +8 -0
  74. data/lib/prawn/images.rb +55 -12
  75. data/lib/prawn/images/jpg.rb +2 -1
  76. data/lib/prawn/images/png.rb +2 -1
  77. data/lib/prawn/literal_string.rb +14 -0
  78. data/lib/prawn/measurement_extensions.rb +46 -0
  79. data/lib/prawn/measurements.rb +71 -0
  80. data/lib/prawn/name_tree.rb +165 -0
  81. data/lib/prawn/pdf_object.rb +8 -1
  82. data/spec/annotations_spec.rb +90 -0
  83. data/spec/destinations_spec.rb +15 -0
  84. data/spec/document_spec.rb +39 -2
  85. data/spec/font_spec.rb +22 -0
  86. data/spec/graphics_spec.rb +99 -87
  87. data/spec/images_spec.rb +29 -1
  88. data/spec/measurement_units_spec.rb +23 -0
  89. data/spec/metrics_spec.rb +3 -2
  90. data/spec/name_tree_spec.rb +103 -0
  91. data/spec/pdf_object_spec.rb +15 -5
  92. data/spec/png_spec.rb +14 -14
  93. data/spec/spec_helper.rb +8 -6
  94. data/spec/table_spec.rb +40 -0
  95. data/spec/text_spec.rb +6 -4
  96. data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
  97. data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
  98. data/vendor/ttfunk/example.rb +5 -0
  99. data/vendor/ttfunk/lib/ttfunk.rb +48 -0
  100. data/vendor/ttfunk/lib/ttfunk/table.rb +27 -0
  101. data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +94 -0
  102. data/vendor/ttfunk/lib/ttfunk/table/directory.rb +25 -0
  103. data/vendor/ttfunk/lib/ttfunk/table/head.rb +25 -0
  104. data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +27 -0
  105. data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +20 -0
  106. data/vendor/ttfunk/lib/ttfunk/table/kern.rb +48 -0
  107. data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +17 -0
  108. data/vendor/ttfunk/lib/ttfunk/table/name.rb +52 -0
  109. metadata +93 -62
  110. data/examples/bounding_boxes.rb +0 -30
  111. data/examples/curves.rb +0 -10
  112. data/examples/family_based_styling.rb +0 -21
  113. data/examples/font_size.rb +0 -19
  114. data/examples/image2.rb +0 -13
  115. data/examples/image_flow.rb +0 -29
  116. data/examples/lazy_bounding_boxes.rb +0 -19
  117. data/examples/remote_images.rb +0 -7
  118. data/examples/simple_text.rb +0 -15
  119. data/examples/simple_text_ttf.rb +0 -16
  120. data/examples/sjis.rb +0 -21
  121. data/examples/utf8.rb +0 -12
  122. data/vendor/font_ttf/ttf.rb +0 -20
  123. data/vendor/font_ttf/ttf/datatypes.rb +0 -189
  124. data/vendor/font_ttf/ttf/encodings.rb +0 -140
  125. data/vendor/font_ttf/ttf/exceptions.rb +0 -28
  126. data/vendor/font_ttf/ttf/file.rb +0 -290
  127. data/vendor/font_ttf/ttf/fontchunk.rb +0 -77
  128. data/vendor/font_ttf/ttf/table/cmap.rb +0 -408
  129. data/vendor/font_ttf/ttf/table/cvt.rb +0 -49
  130. data/vendor/font_ttf/ttf/table/fpgm.rb +0 -48
  131. data/vendor/font_ttf/ttf/table/gasp.rb +0 -88
  132. data/vendor/font_ttf/ttf/table/glyf.rb +0 -452
  133. data/vendor/font_ttf/ttf/table/head.rb +0 -86
  134. data/vendor/font_ttf/ttf/table/hhea.rb +0 -96
  135. data/vendor/font_ttf/ttf/table/hmtx.rb +0 -98
  136. data/vendor/font_ttf/ttf/table/kern.rb +0 -186
  137. data/vendor/font_ttf/ttf/table/loca.rb +0 -75
  138. data/vendor/font_ttf/ttf/table/maxp.rb +0 -81
  139. data/vendor/font_ttf/ttf/table/name.rb +0 -222
  140. data/vendor/font_ttf/ttf/table/os2.rb +0 -172
  141. data/vendor/font_ttf/ttf/table/post.rb +0 -120
  142. data/vendor/font_ttf/ttf/table/prep.rb +0 -27
  143. data/vendor/font_ttf/ttf/table/vhea.rb +0 -45
  144. data/vendor/font_ttf/ttf/table/vmtx.rb +0 -36
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Demonstrates the :underline_header border style for Document#table.
4
+ #
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
6
+ require "prawn"
7
+
8
+ Prawn::Document.generate "table_header_underline.pdf" do
9
+ table [ ['01/01/2008', 'John Doe', '4.2', '125.00', '525.00'],
10
+ ['01/12/2008', 'Jane Doe', '3.2', '75.50', '241.60'] ] * 5,
11
+ :position => :center,
12
+ :headers => ['Date', 'Employee', 'Hours', 'Rate', 'Total'],
13
+ :widths => { 0 => 75, 1 => 100, 2 => 50, 3 => 50, 4 => 50},
14
+ :border_style => :underline_header
15
+ end
@@ -1,6 +1,9 @@
1
1
  # encoding: utf-8
2
-
3
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
2
+ #
3
+ # This example demonstrates usage of Document#text with the :align option.
4
+ # Available options are :left, :right, and :center, with :left as default.
5
+ #
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
4
7
  require "prawn"
5
8
 
6
9
  Prawn::Document.generate("alignment.pdf") do
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This example demonstrates using the :style option for Document#text.
4
+ # If you are working with TTF fonts, you'll want to check out the
5
+ # documentation for Document#font_families and register your fonts with it.
6
+ #
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
8
+ require "prawn"
9
+
10
+ Prawn::Document.generate("family_style.pdf") do
11
+ ["Courier","Helvetica","Times-Roman"].each do |f|
12
+ [:bold,:bold_italic,:italic,:normal].each do |s|
13
+ font f, :style => s
14
+ text "I'm writing in #{f} (#{s})"
15
+ end
16
+ end
17
+
18
+ font "Helvetica"
19
+
20
+ text "Normal"
21
+ text "Bold", :style => :bold
22
+ text "Bold Italic", :style => :bold_italic
23
+ text "Italic", :style => :italic
24
+ text "Normal"
25
+ end
@@ -1,18 +1,30 @@
1
1
  # encoding: utf-8
2
-
3
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
2
+ #
3
+ # Multi-faceted example that demonstrates a document flowing between header
4
+ # and footer regions. At the moment, headers and footers in Prawn are run
5
+ # using the current font settings (among other things), for each page. THhis
6
+ # means that it is important to non-destructively set your desired styling
7
+ # within your headers and footers, as shown below.
8
+ #
9
+ # Future versions of Prawn may make this more convenient somehow.
10
+ #
11
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
4
12
  require "prawn"
5
13
 
6
14
  Prawn::Document.generate("flow_with_headers_and_footers.pdf") do
7
15
 
8
16
  header margin_box.top_left do
9
- text "Here's My Fancy Header", :size => 25, :align => :center
10
- stroke_horizontal_rule
17
+ font "Helvetica" do
18
+ text "Here's My Fancy Header", :size => 25, :align => :center
19
+ stroke_horizontal_rule
20
+ end
11
21
  end
12
22
 
13
23
  footer [margin_box.left, margin_box.bottom + 25] do
14
- stroke_horizontal_rule
15
- text "And here's a sexy footer", :size => 16
24
+ font "Helvetica" do
25
+ stroke_horizontal_rule
26
+ text "And here's a sexy footer", :size => 16
27
+ end
16
28
  end
17
29
 
18
30
  bounding_box([bounds.left, bounds.top - 50],
@@ -68,5 +80,4 @@ Prawn::Document.generate("flow_with_headers_and_footers.pdf") do
68
80
 
69
81
  end
70
82
 
71
- end
72
-
83
+ end
@@ -0,0 +1,91 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This example is a demonstration of how Prawn does its text positioning,
4
+ # meant to assist those that need to do advanced positioning calculations.
5
+ # Run the example for a clearer picture of how things work
6
+ #
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
8
+ require 'prawn'
9
+
10
+ Prawn::Document.generate('font_calculations.pdf') do
11
+
12
+ def demonstration(pos)
13
+ move_down 10
14
+
15
+ stroke_horizontal_rule
16
+
17
+ text "When using flowing text, Prawn will position text\n" +
18
+ "starting font.#{pos} below the baseline, and leave\n" +
19
+ "the y-cursor at the baseline of the next line of text"
20
+
21
+ stroke_horizontal_rule
22
+
23
+ move_down 20
24
+
25
+ bl = y - bounds.absolute_bottom
26
+
27
+ stroke_horizontal_rule
28
+ text "When using text positioned with :at, the baseline is used", :at => [0, bl]
29
+
30
+ text "(and the Y-cursor is not moved)", :at => [350, bl]
31
+
32
+ colors = { :ascender => "ff0000",
33
+ :descender => "00ff00",
34
+ :line_gap => "0000ff",
35
+ :font_height => "005500" }
36
+
37
+
38
+ pad(20) do
39
+ text "Calculations Demo", :size => 16
40
+ end
41
+
42
+ fill_color colors[:ascender]
43
+ text "ASCENDER"
44
+
45
+ fill_color colors[:descender]
46
+ text "DESCENDER"
47
+
48
+ fill_color colors[:line_gap]
49
+ text "LINEGAP"
50
+
51
+ fill_color colors[:font_height]
52
+ text "FONT_HEIGHT"
53
+
54
+ fill_color "000000"
55
+ font.size = 20
56
+
57
+ move_down 40
58
+
59
+ bl = y - bounds.absolute_bottom
60
+ text "The quick brown fox jumps over the lazy dog.", :at => [0, bl]
61
+
62
+ stroke_color colors[:ascender]
63
+ stroke_line [0, bl], [0, bl + font.ascender]
64
+ stroke_line [0, bl + font.ascender], [bounds.width, bl + font.ascender]
65
+
66
+ stroke_color colors[:descender]
67
+ stroke_line [0,bl], [0, bl + font.descender]
68
+ stroke_line [0, bl + font.descender], [bounds.width, bl + font.descender]
69
+
70
+ stroke_color colors[:line_gap]
71
+ stroke_line [0, bl + font.descender], [0,bl + font.descender - font.line_gap]
72
+ stroke_line [0, bl + font.descender - font.line_gap],
73
+ [bounds.width,bl + font.descender - font.line_gap]
74
+
75
+ stroke_color colors[:font_height]
76
+ stroke_line [bounds.width, bl + font.ascender],
77
+ [bounds.width, bl + font.descender - font.line_gap]
78
+
79
+ stroke_color "000000"
80
+ fill_color "000000"
81
+ end
82
+
83
+ text "Using AFM", :size => 20
84
+ demonstration("height")
85
+
86
+ move_down 75
87
+ font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
88
+ text "Using TTF", :size => 20
89
+ demonstration("ascender")
90
+
91
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This example shows the many ways of setting font sizes in Prawn
4
+ #
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
6
+ require "prawn"
7
+
8
+ Prawn::Document.generate "font_size.pdf", :page_size => "A4" do
9
+
10
+ # Explicit global changes
11
+ font 'Helvetica'
12
+ font.size = 16
13
+
14
+ text 'Font at 16 point'
15
+
16
+ # Transactional changes rolled back after block exit
17
+ font.size 9 do
18
+ text 'Font at 9 point'
19
+ # single line changes, not persisted.
20
+ text 'Font at manual override 20 point', :size => 20
21
+ text 'Font at 9 point'
22
+ end
23
+
24
+ # Transactional changes rolled back after block exit on full fonts.
25
+ font("Times-Roman", :style => :italic, :size => 12) do
26
+ text "Font in times at 12"
27
+ font.size(16) { text "Font in Times at 16" }
28
+ end
29
+
30
+ text 'Font at 16 point'
31
+
32
+ font "Courier", :size => 40
33
+ text "40 pt!"
34
+ end
@@ -1,4 +1,8 @@
1
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
1
+ # encoding: utf-8
2
+ #
3
+ # Demonstration of enabling and disabling kerning support
4
+ #
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
2
6
  require "prawn"
3
7
 
4
8
  Prawn::Document.generate "kerning.pdf" do
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ #
3
+ # An early example of basic text generation at absolute positions.
4
+ # Mostly kept for nostalgia.
5
+ #
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
7
+ require "prawn"
8
+
9
+ Prawn::Document.generate "simple_text.pdf" do
10
+ fill_color "0000ff"
11
+ text "Hello World", :at => [200,420], :size => 32, :rotate => 45
12
+ font "Times-Roman"
13
+ fill_color "ff0000"
14
+ text "Using Another Font", :at => [5,5]
15
+ start_new_page
16
+ font "Courier"
17
+ text "Goodbye World", :at => [288,50]
18
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ #
3
+ # An early example of TTF font embedding. Mostly kept for nostalgia's sake.
4
+ #
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
6
+ require "prawn"
7
+
8
+ Prawn::Document.generate "simple_text_ttf.pdf" do
9
+ fill_color "0000ff"
10
+ font "#{Prawn::BASEDIR}/data/fonts/comicsans.ttf"
11
+ text "Hello World", :at => [200,720], :size => 32
12
+
13
+ font "#{Prawn::BASEDIR}/data/fonts/Chalkboard.ttf"
14
+
15
+ pad(20) do
16
+ text "This is chalkboard wrapping " * 20
17
+ end
18
+ end
@@ -1,6 +1,9 @@
1
1
  # encoding: utf-8
2
-
3
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
2
+ #
3
+ # Demonstration of Document#span, which is used for generating flowing
4
+ # columns of text.
5
+ #
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
4
7
  require "prawn"
5
8
 
6
9
  Prawn::Document.generate("span.pdf") do
@@ -0,0 +1,26 @@
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 wil lflow 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
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
9
+ require 'prawn'
10
+
11
+ Prawn::Document.generate("text_box.pdf") do
12
+
13
+ text_box "Oh hai text box. " * 200,
14
+ :width => 300, :height => font.height * 5,
15
+ :overflow => :ellipses,
16
+ :at => [100,bounds.top]
17
+
18
+ text_box "Oh hai text box. " * 200,
19
+ :width => 250, :height => font.height * 10,
20
+ :overflow => :truncate,
21
+ :at => [50, 300]
22
+
23
+ move_down 20
24
+
25
+ text_box "Oh hai text box. " * 100, :overflow => :expand
26
+ end
@@ -1,6 +1,9 @@
1
1
  # encoding: utf-8
2
-
3
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
2
+ #
3
+ # Basic text flowing example including the use of bounding boxes. A somewhat
4
+ # old example, mostly retained for nostalgia.
5
+ #
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
4
7
  require "prawn"
5
8
 
6
9
  content = <<-EOS
@@ -1,37 +1,41 @@
1
1
  # encoding: utf-8
2
-
2
+
3
3
  # prawn.rb : A library for PDF generation in Ruby
4
4
  #
5
- # Copyright April 2008, Gregory Brown. All Rights Reserved.
5
+ # Copyright April 2008, Gregory Brown. All Rights Reserved.
6
6
  #
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
 
9
- %w[font_ttf].each do |dep|
9
+ %w[ttfunk/lib].each do |dep|
10
10
  $LOAD_PATH.unshift(File.dirname(__FILE__) + "/../vendor/#{dep}")
11
11
  end
12
-
13
- require 'ttf'
14
-
15
- module Prawn
12
+
13
+ require 'ttfunk'
14
+
15
+ module Prawn
16
16
  file = __FILE__
17
17
  file = File.readlink(file) if File.symlink?(file)
18
18
  dir = File.dirname(file)
19
19
 
20
20
  # The base source directory for Prawn as installed on the system
21
- BASEDIR = File.expand_path(File.join(dir, '..'))
21
+ BASEDIR = File.expand_path(File.join(dir, '..'))
22
22
 
23
- VERSION = "0.2.3"
23
+ VERSION = "0.3.0"
24
24
 
25
25
  extend self
26
26
 
27
- def verify_options(accepted,actual) #:nodoc:
27
+ attr_accessor :debug
28
+
29
+ def verify_options(accepted,actual) #:nodoc:
30
+ return unless debug || $DEBUG
28
31
  require "set"
29
32
  unless (act=Set[*actual.keys]).subset?(acc=Set[*accepted])
30
- raise Prawn::Errors::UnknownOption,
33
+ raise Prawn::Errors::UnknownOption,
31
34
  "\nDetected unknown option(s): #{(act - acc).to_a.inspect}\n" <<
32
35
  "Accepted options are: #{accepted.inspect}"
33
- end
34
- end
36
+ end
37
+ yield if block_given?
38
+ end
35
39
 
36
40
  module Configurable #:nodoc:
37
41
  def configuration(*args)
@@ -41,16 +45,16 @@ module Prawn
41
45
  elsif args.length > 1
42
46
  @config.values_at(*args)
43
47
  elsif args.length == 1
44
- @config[args[0]]
45
- else
46
- @config
48
+ @config[args[0]]
49
+ else
50
+ @config
47
51
  end
48
- end
52
+ end
49
53
 
50
54
  alias_method :C, :configuration
51
55
  end
52
- end
53
-
56
+ end
57
+
54
58
  require "prawn/compatibility"
55
59
  require "prawn/errors"
56
60
  require "prawn/pdf_object"
@@ -60,4 +64,6 @@ require "prawn/images/jpg"
60
64
  require "prawn/images/png"
61
65
  require "prawn/document"
62
66
  require "prawn/reference"
63
- require "prawn/font"
67
+ require "prawn/font"
68
+ require "prawn/encoding"
69
+ require "prawn/measurements"
@@ -1,3 +1,6 @@
1
+ # Why would we ever use Ruby 1.8.7 when we can backport with something
2
+ # as simple as this?
3
+ #
1
4
  # encoding: utf-8
2
5
 
3
6
  if RUBY_VERSION < "1.9"
@@ -14,7 +17,7 @@ if RUBY_VERSION < "1.9"
14
17
  end
15
18
 
16
19
  class File #:nodoc:
17
- def self.read_binary(file)
20
+ def self.binread(file)
18
21
  File.open(file,"rb") { |f| f.read }
19
22
  end
20
23
  end
@@ -27,13 +30,7 @@ if RUBY_VERSION < "1.9"
27
30
  false
28
31
  end
29
32
 
30
- else
31
-
32
- class File #:nodoc:
33
- def self.read_binary(file)
34
- File.open(file,"rb:BINARY") { |f| f.read }
35
- end
36
- end
33
+ else
37
34
 
38
35
  def ruby_18 #:nodoc:
39
36
  false
@@ -9,19 +9,23 @@
9
9
  require "stringio"
10
10
  require "prawn/document/page_geometry"
11
11
  require "prawn/document/bounding_box"
12
- require "prawn/document/text"
12
+ require "prawn/document/text"
13
13
  require "prawn/document/table"
14
14
  require "prawn/document/internals"
15
15
  require "prawn/document/span"
16
+ require "prawn/document/annotations"
17
+ require "prawn/document/destinations"
16
18
 
17
19
  module Prawn
18
20
  class Document
19
21
 
20
22
  include Prawn::Document::Internals
21
- include Prawn::Graphics
23
+ include Prawn::Document::Annotations
24
+ include Prawn::Document::Destinations
25
+ include Prawn::Graphics
22
26
  include Prawn::Images
23
- include Text
24
- include PageGeometry
27
+ include Text
28
+ include PageGeometry
25
29
 
26
30
  attr_accessor :y, :margin_box
27
31
  attr_reader :margins, :page_size, :page_layout
@@ -59,14 +63,13 @@ module Prawn
59
63
  #
60
64
  # <tt>:page_size</tt>:: One of the Document::PageGeometry::SIZES [LETTER]
61
65
  # <tt>:page_layout</tt>:: Either <tt>:portrait</tt> or <tt>:landscape</tt>
62
- # <tt>:on_page_start</tt>:: Optional proc run at each page start
63
- # <tt>:on_page_stop</tt>:: Optional proc run at each page stop
64
66
  # <tt>:left_margin</tt>:: Sets the left margin in points [ 0.5 inch]
65
67
  # <tt>:right_margin</tt>:: Sets the right margin in points [ 0.5 inch]
66
68
  # <tt>:top_margin</tt>:: Sets the top margin in points [ 0.5 inch]
67
69
  # <tt>:bottom_margin</tt>:: Sets the bottom margin in points [0.5 inch]
68
70
  # <tt>:skip_page_creation</tt>:: Creates a document without starting the first page [false]
69
71
  # <tt>:compress</tt>:: Compresses content streams before rendering them [false]
72
+ # <tt>:background</tt>:: An image path to be used as background on all pages [nil]
70
73
  #
71
74
  # Usage:
72
75
  #
@@ -76,19 +79,23 @@ module Prawn
76
79
  # # New document, A4 paper, landscaped
77
80
  # pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
78
81
  #
82
+ # # New document, with background
83
+ # pdf = Prawn::Document.new(:background => "#{Prawn::BASEDIR}/data/images/pigs.jpg")
84
+ #
79
85
  def initialize(options={},&block)
80
- Prawn.verify_options [:page_size, :page_layout, :on_page_start,
81
- :on_page_stop, :left_margin, :right_margin, :top_margin,
82
- :bottom_margin, :skip_page_creation, :compress, :skip_encoding, :text_options ], options
86
+ Prawn.verify_options [:page_size, :page_layout, :left_margin,
87
+ :right_margin, :top_margin, :bottom_margin, :skip_page_creation,
88
+ :compress, :skip_encoding, :text_options, :background ], options
83
89
 
84
90
  @objects = []
85
91
  @info = ref(:Creator => "Prawn", :Producer => "Prawn")
86
- @pages = ref(:Type => :Pages, :Count => 0, :Kids => [])
87
- @root = ref(:Type => :Catalog, :Pages => @pages)
92
+ @pages = ref(:Type => :Pages, :Count => 0, :Kids => [])
93
+ @root = ref(:Type => :Catalog, :Pages => @pages)
88
94
  @page_size = options[:page_size] || "LETTER"
89
95
  @page_layout = options[:page_layout] || :portrait
90
96
  @compress = options[:compress] || false
91
97
  @skip_encoding = options[:skip_encoding]
98
+ @background = options[:background]
92
99
 
93
100
  text_options.update(options[:text_options] || {})
94
101
 
@@ -134,7 +141,9 @@ module Prawn
134
141
 
135
142
  add_content "q"
136
143
 
137
- @y = @bounding_box.absolute_top
144
+ @y = @bounding_box.absolute_top
145
+
146
+ image(@background, :at => [0,@y]) if @background
138
147
  end
139
148
 
140
149
  # Returns the number of pages in the document
@@ -147,6 +156,13 @@ module Prawn
147
156
  def page_count
148
157
  @pages.data[:Count]
149
158
  end
159
+
160
+ # The current y drawing position relative to the innermost bounding box,
161
+ # or to the page margins at the top level.
162
+ #
163
+ def cursor
164
+ y - bounds.absolute_bottom
165
+ end
150
166
 
151
167
  # Renders the PDF document to string
152
168
  #
@@ -270,7 +286,7 @@ module Prawn
270
286
  :Parent => @pages,
271
287
  :MediaBox => page_dimensions,
272
288
  :Contents => @page_content)
273
- font.add_to_current_page if @font_name
289
+ font.add_to_current_page if @font
274
290
  update_colors
275
291
  end
276
292