prawn 0.11.1 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. data/GPLv2 +340 -0
  2. data/GPLv3 +674 -0
  3. data/README.md +96 -0
  4. data/Rakefile +0 -12
  5. data/examples/example_helper.rb +3 -0
  6. data/lib/prawn.rb +1 -1
  7. data/lib/prawn/core/page.rb +4 -2
  8. data/lib/prawn/core/pdf_object.rb +7 -7
  9. data/lib/prawn/core/text/formatted/arranger.rb +2 -1
  10. data/lib/prawn/core/text/formatted/line_wrap.rb +2 -1
  11. data/lib/prawn/core/text/formatted/wrap.rb +5 -1
  12. data/lib/prawn/document.rb +135 -112
  13. data/lib/prawn/document/bounding_box.rb +51 -5
  14. data/lib/prawn/document/column_box.rb +0 -19
  15. data/lib/prawn/document/internals.rb +1 -0
  16. data/lib/prawn/document/snapshot.rb +3 -0
  17. data/lib/prawn/font.rb +4 -3
  18. data/lib/prawn/font/afm.rb +11 -2
  19. data/lib/prawn/font/ttf.rb +15 -0
  20. data/lib/prawn/images.rb +1 -1
  21. data/lib/prawn/table.rb +23 -7
  22. data/lib/prawn/table/cell.rb +31 -9
  23. data/lib/prawn/table/cell/text.rb +2 -2
  24. data/prawn.gemspec +5 -6
  25. data/spec/bounding_box_spec.rb +157 -0
  26. data/spec/data/curves.pdf +66 -0
  27. data/spec/document_spec.rb +59 -4
  28. data/spec/extensions/mocha.rb +1 -3
  29. data/spec/font_spec.rb +23 -0
  30. data/spec/formatted_text_box_spec.rb +40 -0
  31. data/spec/images_spec.rb +7 -0
  32. data/spec/object_store_spec.rb +3 -3
  33. data/spec/snapshot_spec.rb +33 -0
  34. data/spec/table_spec.rb +75 -0
  35. data/spec/template_spec.rb +11 -5
  36. data/spec/text_spacing_spec.rb +18 -0
  37. data/spec/text_spec.rb +32 -0
  38. metadata +217 -283
  39. data/HACKING +0 -50
  40. data/README +0 -141
  41. data/examples/bounding_box/bounding_boxes.rb +0 -44
  42. data/examples/bounding_box/indentation.rb +0 -35
  43. data/examples/bounding_box/stretched_nesting.rb +0 -68
  44. data/examples/general/background.rb +0 -24
  45. data/examples/general/canvas.rb +0 -16
  46. data/examples/general/float.rb +0 -12
  47. data/examples/general/margin.rb +0 -37
  48. data/examples/general/measurement_units.rb +0 -52
  49. data/examples/general/metadata-info.rb +0 -17
  50. data/examples/general/multi_page_layout.rb +0 -19
  51. data/examples/general/outlines.rb +0 -67
  52. data/examples/general/page_geometry.rb +0 -32
  53. data/examples/general/page_numbering.rb +0 -40
  54. data/examples/general/page_templates.rb +0 -20
  55. data/examples/general/repeaters.rb +0 -48
  56. data/examples/general/stamp.rb +0 -42
  57. data/examples/general/templates.rb +0 -14
  58. data/examples/graphics/basic_images.rb +0 -24
  59. data/examples/graphics/curves.rb +0 -12
  60. data/examples/graphics/hexagon.rb +0 -14
  61. data/examples/graphics/image_fit.rb +0 -16
  62. data/examples/graphics/image_flow.rb +0 -38
  63. data/examples/graphics/image_position.rb +0 -18
  64. data/examples/graphics/line.rb +0 -33
  65. data/examples/graphics/polygons.rb +0 -17
  66. data/examples/graphics/rounded_polygons.rb +0 -20
  67. data/examples/graphics/rounded_rectangle.rb +0 -21
  68. data/examples/graphics/ruport_style_helpers.rb +0 -20
  69. data/examples/graphics/stroke_bounds.rb +0 -21
  70. data/examples/graphics/stroke_cap_and_join.rb +0 -46
  71. data/examples/graphics/stroke_dash.rb +0 -43
  72. data/examples/graphics/transformations.rb +0 -53
  73. data/examples/graphics/transparency.rb +0 -27
  74. data/examples/grid/bounding_boxes.rb +0 -22
  75. data/examples/grid/column_gutter_grid.rb +0 -21
  76. data/examples/grid/multi_boxes.rb +0 -52
  77. data/examples/grid/show_grid.rb +0 -14
  78. data/examples/grid/simple_grid.rb +0 -21
  79. data/examples/m17n/chinese_text_wrapping.rb +0 -18
  80. data/examples/m17n/euro.rb +0 -16
  81. data/examples/m17n/utf8.rb +0 -14
  82. data/examples/security/hello_foo.rb +0 -9
  83. data/examples/table/borders.rb +0 -25
  84. data/examples/table/cell.rb +0 -13
  85. data/examples/table/checkerboard.rb +0 -23
  86. data/examples/table/inline_format_table.rb +0 -13
  87. data/examples/table/multi_page_table.rb +0 -10
  88. data/examples/table/simple_table.rb +0 -25
  89. data/examples/table/subtable.rb +0 -13
  90. data/examples/table/widths.rb +0 -21
  91. data/examples/text/alignment.rb +0 -19
  92. data/examples/text/character_spacing.rb +0 -13
  93. data/examples/text/dfont.rb +0 -49
  94. data/examples/text/family_based_styling.rb +0 -25
  95. data/examples/text/font_size.rb +0 -34
  96. data/examples/text/inline_format.rb +0 -104
  97. data/examples/text/kerning.rb +0 -31
  98. data/examples/text/rendering_mode.rb +0 -21
  99. data/examples/text/rotated.rb +0 -99
  100. data/examples/text/shaped_text_box.rb +0 -32
  101. data/examples/text/simple_text.rb +0 -18
  102. data/examples/text/simple_text_ttf.rb +0 -18
  103. data/examples/text/span.rb +0 -30
  104. data/examples/text/text_box.rb +0 -90
  105. data/examples/text/text_box_returning_excess.rb +0 -52
  106. data/examples/text/text_flow.rb +0 -68
@@ -1,14 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Shows that Prawn works out of the box with UTF-8 text, so long as you use
4
- # a TTF file with the necessary glyphs for your content.
5
- #
6
- require File.expand_path(File.join(File.dirname(__FILE__),
7
- %w[.. example_helper]))
8
-
9
- Prawn::Document.generate("utf8.pdf") do
10
- font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
11
- text "ὕαλον ϕαγεῖν δύναμαι· τοῦτο οὔ με βλάπτει." * 20
12
- end
13
-
14
-
@@ -1,9 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__),
2
- %w[.. example_helper]))
3
-
4
- Prawn::Document.generate("security_hello_foo.pdf") do
5
- text "Hello, world!"
6
- encrypt_document :user_password => 'foo', :owner_password => 'bar',
7
- :permissions => { :print_document => false }
8
- end
9
-
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- require File.expand_path(File.join(File.dirname(__FILE__),
4
- %w[.. example_helper]))
5
-
6
- Prawn::Document.generate("borders.pdf") do |pdf|
7
- pdf.text "This example demonstrates alignment of the background and " +
8
- "borders, including proper corner alignment without overlap."
9
- pdf.move_down 20
10
-
11
- pdf.cell :content => "all borders", :background_color => 'ff0000'
12
- pdf.move_down 15
13
-
14
- [:top, :bottom, :left, :right].each do |border|
15
- y = pdf.cursor
16
- pdf.cell :content => "no #{border} border", :background_color => 'ff0000',
17
- :borders => ([:top, :bottom, :left, :right] - [border])
18
- pdf.cell :content => "#{border} border 0", :background_color => 'ff0000',
19
- :"border_#{border}_width" => 0, :at => [150, y]
20
- pdf.cell :content => "#{border} border 2", :background_color => 'ff0000',
21
- :"border_#{border}_width" => 2, :at => [300, y]
22
- pdf.move_down 15
23
- end
24
- end
25
-
@@ -1,13 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Low level cell and row implementation, which form the basic building
4
- # blocks for Prawn tables. Only necessary to know about if you plan on
5
- # building your own table implementation from scratch or heavily modify
6
- # the existing table system.
7
- #
8
- require File.expand_path(File.join(File.dirname(__FILE__),
9
- %w[.. example_helper]))
10
-
11
- Prawn::Document.generate("cell.pdf") do
12
- cell :content => "test", :padding => 10, :font_style => :bold, :size => 7
13
- end
@@ -1,23 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # Shows how to use the style() method with a block to style each cell with
4
- # custom code.
5
-
6
- require File.expand_path(File.join(File.dirname(__FILE__),
7
- %w[.. example_helper]))
8
-
9
- Prawn::Document.generate("checkerboard.pdf") do
10
-
11
- text "Here is a checkerboard:"
12
-
13
- table [[""] * 8] * 8 do |t|
14
- t.cells.style :width => 24, :height => 24
15
- t.cells.style do |c|
16
- c.background_color = ((c.row + c.column) % 2).zero? ? '000000' : 'ffffff'
17
- end
18
- end
19
-
20
- move_down 12
21
- text "Hope you enjoyed it!"
22
-
23
- end
@@ -1,13 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- require File.expand_path(File.join(File.dirname(__FILE__),
4
- %w[.. example_helper]))
5
-
6
- Prawn::Document.generate("inline_format_table.pdf") do
7
-
8
- table([%w[foo bar baz<b>baz</b>], %w[baz bar <i>foo</i>foo]],
9
- :cell_style => { :padding => 12, :inline_format => true },
10
- :width => bounds.width)
11
-
12
- end
13
-
@@ -1,10 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- require File.expand_path(File.join(File.dirname(__FILE__),
4
- %w[.. example_helper]))
5
-
6
- Prawn::Document.generate("multi_page_table.pdf") do
7
-
8
- table([%w[Some data in a table]] * 50)
9
-
10
- end
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- require File.expand_path(File.join(File.dirname(__FILE__),
4
- %w[.. example_helper]))
5
-
6
- Prawn::Document.generate("simple_table.pdf") do
7
-
8
- table([["foo", "bar " * 15, "baz"],
9
- ["baz", "bar", "foo " * 15]], :cell_style => { :padding => 12 }) do
10
- cells.borders = []
11
-
12
- # Use the row() and style() methods to select and style a row.
13
- style row(0), :border_width => 2, :borders => [:bottom]
14
-
15
- # The style method can take a block, allowing you to customize properties
16
- # per-cell.
17
- style(columns(0..1)) { |cell| cell.borders |= [:right] }
18
- end
19
-
20
- move_down 12
21
-
22
- table([%w[foo bar bazbaz], %w[baz bar foofoo]],
23
- :cell_style => { :padding => 12 }, :width => bounds.width)
24
-
25
- end
@@ -1,13 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- require File.expand_path(File.join(File.dirname(__FILE__),
4
- %w[.. example_helper]))
5
-
6
- Prawn::Document.generate("subtable.pdf") do |pdf|
7
-
8
- subtable = Prawn::Table.new([%w[one two], %w[three four]], pdf)
9
-
10
- pdf.table([["Subtable ->", subtable, "<-"]])
11
-
12
- end
13
-
@@ -1,21 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- require File.expand_path(File.join(File.dirname(__FILE__),
4
- %w[.. example_helper]))
5
-
6
- Prawn::Document.generate("widths.pdf") do
7
-
8
- text "Some 300-pt tables:"
9
-
10
- table([%w[A B C]], :width => 300)
11
- move_down 12
12
-
13
- table([%w[A B C], %w[D Everything\ under\ the\ sun F]], :width => 300)
14
- move_down 12
15
-
16
- # TODO: what should this be doing? Like the current prawn-layout, it does
17
- # not attempt to reflow the second column.
18
- # table([["A", "Blah " * 20, "C"]], :width => 300)
19
- # move_down 12
20
-
21
- end
@@ -1,19 +0,0 @@
1
- # encoding: utf-8
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
- require File.expand_path(File.join(File.dirname(__FILE__),
7
- %w[.. example_helper]))
8
-
9
- Prawn::Document.generate("alignment.pdf") do
10
- text "This text should be left aligned"
11
- text "This text should be centered", :align => :center
12
- text "This text should be right aligned", :align => :right
13
-
14
- pad(20) { text "This is Flowing from the left. " * 20 }
15
-
16
- pad(20) { text "This is Flowing from the center. " * 20, :align => :center }
17
-
18
- pad(20) { text "This is Flowing from the right. " * 20, :align => :right }
19
- end
@@ -1,13 +0,0 @@
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 "character_spacing.pdf" do |pdf|
10
- string = "hello world " * 50
11
- pdf.text(string, :character_spacing => 2.5)
12
- pdf.text(string)
13
- end
@@ -1,49 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path(File.join(File.dirname(__FILE__),
4
- %w[.. example_helper]))
5
-
6
- DFONT_FILE = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
7
- puts "There are #{Prawn::Font::DFont.font_count(DFONT_FILE)} fonts in #{DFONT_FILE}:"
8
- Prawn::Font::DFont.named_fonts(DFONT_FILE).each do |name|
9
- puts "* #{name}"
10
- end
11
-
12
- puts
13
- puts "generating sample document in 'dfont.pdf'..."
14
-
15
- Prawn::Document.generate "dfont.pdf" do
16
- fill_color "0000ff"
17
-
18
- font DFONT_FILE, :font => "ActionMan-Bold", :size => 24
19
- text "Introducing Action Man!"
20
-
21
- move_text_position 24
22
-
23
- font_families["Action Man"] = {
24
- :normal => { :file => DFONT_FILE, :font => "ActionMan" },
25
- :bold => { :file => DFONT_FILE, :font => "ActionMan-Bold" },
26
- :italic => { :file => DFONT_FILE, :font => "ActionMan-Italic" },
27
- :bold_italic => { :file => DFONT_FILE, :font => "ActionMan-BoldItalic" }
28
- }
29
-
30
- font "Action Man", :size => 16
31
- text "Action Man is feeling normal here."
32
-
33
- move_text_position 16
34
-
35
- font "Action Man", :style => :bold, :size => 16
36
- text "Action Man is feeling bold here!"
37
-
38
- move_text_position 16
39
-
40
- font "Action Man", :style => :italic, :size => 16
41
- text "Here, we see Action Man feeling italicized. Slick!"
42
-
43
- move_text_position 16
44
-
45
- font "Action Man", :style => :bold_italic, :size => 16
46
- text "Lastly, we observe Mr. Action Man being bold AND italicized. Excellent!"
47
- end
48
-
49
- puts "done"
@@ -1,25 +0,0 @@
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
- require File.expand_path(File.join(File.dirname(__FILE__),
8
- %w[.. example_helper]))
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,34 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # This example shows the many ways of setting font sizes in Prawn
4
- #
5
- require File.expand_path(File.join(File.dirname(__FILE__),
6
- %w[.. example_helper]))
7
-
8
- Prawn::Document.generate "font_size.pdf", :page_size => "A4" do
9
-
10
- # Explicit global changes
11
- font 'Helvetica'
12
- self.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,104 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # This example shows how to use inline formatting
4
- #
5
- require File.expand_path(File.join(File.dirname(__FILE__),
6
- %w[.. example_helper]))
7
-
8
- Prawn::Document.generate("inline_format.pdf") do |pdf|
9
-
10
- pdf.text("hello <strikethrough><b>world\nhow <i>are</i></b> you?</strikethrough> world, <u>how are you</u> now?",
11
- :inline_format => true)
12
- pdf.text("<font size='14'>left: </font>" + "hello <b>world <font name='Times-Roman' size='28'>how</font> <i>are</i></b> you? <font size='14'><b>Goodbye.</b></font> " * 8,
13
- :inline_format => true)
14
- pdf.text("right: " + "hello <b>world how <i>are</i></b> you? " * 2,
15
- :inline_format => true,
16
- :align => :right)
17
- pdf.text("center: " + "hello <b>world <font size='48'>ho<sub>w</sub> <i>are</i></font></b> you? " * 2,
18
- :inline_format => true,
19
- :align => :center)
20
- pdf.text("\njustify: " + "hello <b>world <i>goodbye</i></b> " * 12 + "the end ",
21
- :inline_format => true,
22
- :align => :justify)
23
- pdf.text("\njustify: " + "hello world goodbye " * 12 + "the end ",
24
- :inline_format => true,
25
- :align => :justify)
26
- pdf.text("\njustify: " + "hello world goodbye " * 12 + "the end ",
27
- :align => :justify)
28
-
29
-
30
- pdf.text("<color rgb='00ff00'>link: <font size='24' character_spacing='7.5'>please make</font> <color rgb='#0000ff'><u><link href='http://wiki.github.com/sandal/prawn/'>this</link></u></color> clickable.</color> Here we have A<color rgb='#0000ff'><sup><link href='http://wiki.github.com/sandal/prawn/'>superscript</link></sup></color> link and A<color rgb='#0000ff'><sub><link href='http://wiki.github.com/sandal/prawn/'> subscript</link></sub></color> link.",
31
- :inline_format => true)
32
-
33
- pdf.text("<color c='100' m='0' y='0' k='0'><font size='24'>CMYK</font></color>",
34
- :inline_format => true)
35
-
36
- file = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
37
- pdf.font_families["Action Man"] = {
38
- :normal => { :file => file, :font => "ActionMan" },
39
- :italic => { :file => file, :font => "ActionMan-Italic" },
40
- :bold => { :file => file, :font => "ActionMan-Bold" },
41
- :bold_italic => { :file => file, :font => "ActionMan-BoldItalic" }
42
- }
43
-
44
- pdf.font("Action Man")
45
- pdf.text("\nhello <b>world\nhow <i>are</i></b> you?",
46
- :inline_format => true)
47
-
48
-
49
- pdf.font("Helvetica")
50
-
51
-
52
-
53
- class Highlight
54
- def initialize(options)
55
- @color = options[:color]
56
- @document = options[:document]
57
- end
58
-
59
- def render_behind(fragment)
60
- original_color = @document.fill_color
61
- @document.fill_color = @color
62
- @document.fill_rectangle(fragment.top_left,
63
- fragment.width,
64
- fragment.height)
65
- @document.fill_color = original_color
66
- end
67
- end
68
-
69
- class FragmentBorder
70
- def initialize(options)
71
- @radius = options[:radius]
72
- @connect_corners = options[:connect_corners]
73
- @document = options[:document]
74
- end
75
-
76
- def render_in_front(fragment)
77
- box = fragment.bounding_box
78
- if @connect_corners
79
- @document.stroke_polygon(fragment.top_left, fragment.top_right,
80
- fragment.bottom_right, fragment.bottom_left)
81
- end
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)
86
- end
87
- end
88
-
89
- highlight_callback = Highlight.new(:color => 'ffff00', :document => pdf)
90
- border_callback = FragmentBorder.new(:radius => 2.5,
91
- :connect_corners => true,
92
- :document => pdf)
93
- pdf.formatted_text([
94
- { :text => "\n" },
95
- { :text => "hello ",
96
- :callback => highlight_callback },
97
- { :text => "world",
98
- :size => 24,
99
- :character_spacing => 0,
100
- :callback => [highlight_callback, border_callback] },
101
- { :text => " hello" }
102
- ], :indent_paragraphs => 40, :character_spacing => -2)
103
- end
104
-
@@ -1,31 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Demonstration of enabling and disabling kerning support
4
- #
5
- require File.expand_path(File.join(File.dirname(__FILE__),
6
- %w[.. example_helper]))
7
-
8
- Prawn::Document.generate "kerning.pdf" do
9
- draw_text "To kern?", :at => [200,720], :size => 24, :kerning => true
10
- draw_text "To not kern?", :at => [200,690], :size => 24, :kerning => false
11
-
12
- move_down 100
13
-
14
- pad(30) do
15
- text "To kern and wrap. " * 5, :size => 24, :kerning => true
16
- end
17
-
18
- text "To not kern and wrap. " * 5, :size => 24, :kerning => false
19
-
20
- font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
21
-
22
- draw_text "To kern?", :at => [200,660], :size => 24, :kerning => true
23
- draw_text "To not kern?", :at => [200,630], :size => 24, :kerning => false
24
-
25
- pad(30) do
26
- text "To kern and wrap. " * 5, :size => 24, :kerning => true
27
- end
28
-
29
- text "To not kern and wrap. " * 5, :size => 24, :kerning => false
30
-
31
- end