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.
- data/COPYING +2 -340
- data/HACKING +1 -1
- data/LICENSE +3 -3
- data/Rakefile +17 -6
- data/data/encodings/win_ansi.txt +1 -1
- data/data/images/prawn.png +0 -0
- data/data/pdfs/form.pdf +820 -0
- data/data/pdfs/multipage_template.pdf +127 -0
- data/examples/bounding_box/bounding_boxes.rb +4 -3
- data/examples/bounding_box/indentation.rb +2 -1
- data/examples/bounding_box/russian_boxes.rb +3 -2
- data/examples/bounding_box/stretched_nesting.rb +2 -1
- data/examples/general/background.rb +2 -1
- data/examples/general/canvas.rb +2 -1
- data/examples/general/context_sensitive_headers.rb +2 -1
- data/examples/general/float.rb +2 -1
- data/examples/general/margin.rb +2 -1
- data/examples/general/measurement_units.rb +2 -1
- data/examples/general/metadata-info.rb +2 -1
- data/examples/general/multi_page_layout.rb +2 -1
- data/examples/general/outlines.rb +2 -1
- data/examples/general/page_geometry.rb +2 -1
- data/examples/general/page_numbering.rb +27 -2
- data/examples/general/page_templates.rb +20 -0
- data/examples/general/repeaters.rb +2 -1
- data/examples/general/stamp.rb +4 -3
- data/examples/general/templates.rb +2 -1
- data/examples/graphics/basic_images.rb +2 -1
- data/examples/graphics/cmyk.rb +2 -1
- data/examples/graphics/curves.rb +4 -3
- data/examples/graphics/gradient.rb +23 -0
- data/examples/graphics/hexagon.rb +3 -2
- data/examples/graphics/image_fit.rb +3 -2
- data/examples/graphics/image_flow.rb +2 -1
- data/examples/graphics/image_position.rb +3 -2
- data/examples/graphics/line.rb +2 -1
- data/examples/graphics/png_types.rb +3 -2
- data/examples/graphics/polygons.rb +3 -2
- data/examples/graphics/remote_images.rb +2 -1
- data/examples/graphics/rounded_polygons.rb +2 -1
- data/examples/graphics/rounded_rectangle.rb +2 -1
- data/examples/graphics/ruport_style_helpers.rb +3 -2
- data/examples/graphics/stroke_bounds.rb +2 -1
- data/examples/graphics/stroke_cap_and_join.rb +2 -1
- data/examples/graphics/stroke_dash.rb +2 -1
- data/examples/graphics/transformations.rb +2 -1
- data/examples/graphics/transparency.rb +4 -3
- data/examples/grid/bounding_boxes.rb +2 -1
- data/examples/grid/column_gutter_grid.rb +2 -1
- data/examples/grid/multi_boxes.rb +2 -1
- data/examples/grid/show_grid.rb +2 -1
- data/examples/grid/simple_grid.rb +2 -1
- data/examples/m17n/chinese_text_wrapping.rb +2 -1
- data/examples/m17n/euro.rb +3 -2
- data/examples/m17n/full_win_ansi_character_list.rb +20 -0
- data/examples/m17n/sjis.rb +2 -1
- data/examples/m17n/utf8.rb +3 -2
- data/examples/m17n/win_ansi_charset.rb +2 -1
- data/examples/security/hello_foo.rb +2 -1
- data/examples/table/bill.rb +2 -1
- data/examples/table/borders.rb +25 -0
- data/examples/table/cell.rb +3 -2
- data/examples/table/checkerboard.rb +2 -1
- data/examples/table/header.rb +3 -2
- data/examples/table/inline_format_table.rb +2 -1
- data/examples/table/multi_page_table.rb +2 -1
- data/examples/table/simple_table.rb +2 -1
- data/examples/table/subtable.rb +2 -1
- data/examples/table/widths.rb +2 -1
- data/examples/text/alignment.rb +2 -1
- data/examples/text/character_spacing.rb +2 -1
- data/examples/text/dfont.rb +2 -1
- data/examples/text/family_based_styling.rb +3 -2
- data/examples/text/font_calculations.rb +2 -1
- data/examples/text/font_size.rb +2 -1
- data/examples/text/hyphenation.rb +2 -2
- data/examples/text/indent_paragraphs.rb +7 -5
- data/examples/text/inline_format.rb +7 -6
- data/examples/text/kerning.rb +2 -1
- data/examples/text/rendering_mode.rb +21 -0
- data/examples/text/rotated.rb +2 -1
- data/examples/text/shaped_text_box.rb +2 -1
- data/examples/text/simple_text.rb +2 -1
- data/examples/text/simple_text_ttf.rb +2 -1
- data/examples/text/span.rb +3 -2
- data/examples/text/text_box.rb +7 -5
- data/examples/text/text_box_returning_excess.rb +4 -3
- data/examples/text/text_flow.rb +2 -1
- data/lib/prawn.rb +1 -1
- data/lib/prawn/core/object_store.rb +42 -14
- data/lib/prawn/core/page.rb +22 -8
- data/lib/prawn/core/text.rb +141 -13
- data/lib/prawn/core/text/formatted/arranger.rb +39 -12
- data/lib/prawn/core/text/formatted/line_wrap.rb +205 -60
- data/lib/prawn/core/text/formatted/wrap.rb +72 -35
- data/lib/prawn/document.rb +174 -70
- data/lib/prawn/document/bounding_box.rb +122 -83
- data/lib/prawn/document/column_box.rb +113 -0
- data/lib/prawn/document/graphics_state.rb +90 -2
- data/lib/prawn/document/internals.rb +5 -3
- data/lib/prawn/errors.rb +5 -0
- data/lib/prawn/font.rb +4 -4
- data/lib/prawn/font/afm.rb +11 -0
- data/lib/prawn/font/ttf.rb +5 -0
- data/lib/prawn/graphics.rb +77 -14
- data/lib/prawn/graphics/cap_style.rb +13 -5
- data/lib/prawn/graphics/color.rb +54 -35
- data/lib/prawn/graphics/dash.rb +27 -16
- data/lib/prawn/graphics/gradient.rb +84 -0
- data/lib/prawn/graphics/join_style.rb +12 -3
- data/lib/prawn/graphics/transparency.rb +4 -4
- data/lib/prawn/images.rb +18 -160
- data/lib/prawn/images/jpg.rb +39 -0
- data/lib/prawn/images/png.rb +130 -0
- data/lib/prawn/repeater.rb +6 -13
- data/lib/prawn/security.rb +6 -1
- data/lib/prawn/stamp.rb +12 -4
- data/lib/prawn/table.rb +36 -4
- data/lib/prawn/table/cell.rb +224 -63
- data/lib/prawn/table/cell/text.rb +20 -10
- data/lib/prawn/table/cells.rb +23 -6
- data/lib/prawn/text.rb +54 -91
- data/lib/prawn/text/box.rb +29 -283
- data/lib/prawn/text/formatted/box.rb +349 -24
- data/lib/prawn/text/formatted/fragment.rb +63 -2
- data/lib/prawn/text/formatted/parser.rb +2 -1
- data/prawn.gemspec +21 -5
- data/spec/bounding_box_spec.rb +61 -28
- data/spec/cell_spec.rb +168 -30
- data/spec/document_spec.rb +187 -3
- data/spec/extensions/mocha.rb +45 -0
- data/spec/font_spec.rb +32 -1
- data/spec/formatted_text_arranger_spec.rb +35 -40
- data/spec/formatted_text_box_spec.rb +287 -443
- data/spec/formatted_text_fragment_spec.rb +87 -0
- data/spec/graphics_spec.rb +128 -12
- data/spec/grid_spec.rb +1 -1
- data/spec/images_spec.rb +11 -3
- data/spec/inline_formatted_text_parser_spec.rb +8 -0
- data/spec/line_wrap_spec.rb +200 -208
- data/spec/object_store_spec.rb +10 -0
- data/spec/outline_spec.rb +7 -3
- data/spec/repeater_spec.rb +58 -10
- data/spec/security_spec.rb +6 -0
- data/spec/spec_helper.rb +12 -8
- data/spec/stamp_spec.rb +52 -1
- data/spec/stroke_styles_spec.rb +30 -0
- data/spec/table_spec.rb +93 -3
- data/spec/template_spec.rb +132 -6
- data/spec/text_at_spec.rb +14 -4
- data/spec/text_box_spec.rb +309 -70
- data/spec/text_rendering_mode_spec.rb +45 -0
- data/spec/text_spec.rb +60 -17
- data/spec/text_with_inline_formatting_spec.rb +4 -162
- metadata +241 -241
- data/lib/prawn/core/text/line_wrap.rb +0 -211
- data/lib/prawn/core/text/wrap.rb +0 -82
- data/vendor/pdf-inspector/README +0 -18
- data/vendor/pdf-inspector/lib/pdf/inspector.rb +0 -26
- data/vendor/pdf-inspector/lib/pdf/inspector/extgstate.rb +0 -18
- data/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +0 -131
- data/vendor/pdf-inspector/lib/pdf/inspector/page.rb +0 -25
- data/vendor/pdf-inspector/lib/pdf/inspector/text.rb +0 -46
- data/vendor/pdf-inspector/lib/pdf/inspector/xobject.rb +0 -19
- data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
- data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
- data/vendor/ttfunk/example.rb +0 -45
- data/vendor/ttfunk/lib/ttfunk.rb +0 -102
- data/vendor/ttfunk/lib/ttfunk/directory.rb +0 -17
- data/vendor/ttfunk/lib/ttfunk/encoding/mac_roman.rb +0 -88
- data/vendor/ttfunk/lib/ttfunk/encoding/windows_1252.rb +0 -69
- data/vendor/ttfunk/lib/ttfunk/reader.rb +0 -44
- data/vendor/ttfunk/lib/ttfunk/resource_file.rb +0 -78
- data/vendor/ttfunk/lib/ttfunk/subset.rb +0 -18
- data/vendor/ttfunk/lib/ttfunk/subset/base.rb +0 -141
- data/vendor/ttfunk/lib/ttfunk/subset/mac_roman.rb +0 -50
- data/vendor/ttfunk/lib/ttfunk/subset/unicode.rb +0 -48
- data/vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb +0 -63
- data/vendor/ttfunk/lib/ttfunk/subset/windows_1252.rb +0 -55
- data/vendor/ttfunk/lib/ttfunk/subset_collection.rb +0 -72
- data/vendor/ttfunk/lib/ttfunk/table.rb +0 -46
- data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +0 -34
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format00.rb +0 -54
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format04.rb +0 -126
- data/vendor/ttfunk/lib/ttfunk/table/cmap/subtable.rb +0 -79
- data/vendor/ttfunk/lib/ttfunk/table/glyf.rb +0 -64
- data/vendor/ttfunk/lib/ttfunk/table/glyf/compound.rb +0 -81
- data/vendor/ttfunk/lib/ttfunk/table/glyf/simple.rb +0 -37
- data/vendor/ttfunk/lib/ttfunk/table/head.rb +0 -44
- data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +0 -41
- data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +0 -47
- data/vendor/ttfunk/lib/ttfunk/table/kern.rb +0 -79
- data/vendor/ttfunk/lib/ttfunk/table/kern/format0.rb +0 -62
- data/vendor/ttfunk/lib/ttfunk/table/loca.rb +0 -43
- data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +0 -40
- data/vendor/ttfunk/lib/ttfunk/table/name.rb +0 -125
- data/vendor/ttfunk/lib/ttfunk/table/os2.rb +0 -78
- data/vendor/ttfunk/lib/ttfunk/table/post.rb +0 -91
- data/vendor/ttfunk/lib/ttfunk/table/post/format10.rb +0 -43
- data/vendor/ttfunk/lib/ttfunk/table/post/format20.rb +0 -35
- data/vendor/ttfunk/lib/ttfunk/table/post/format25.rb +0 -23
- data/vendor/ttfunk/lib/ttfunk/table/post/format30.rb +0 -17
- data/vendor/ttfunk/lib/ttfunk/table/post/format40.rb +0 -17
- data/vendor/ttfunk/lib/ttfunk/table/simple.rb +0 -14
data/examples/table/subtable.rb
CHANGED
data/examples/table/widths.rb
CHANGED
data/examples/text/alignment.rb
CHANGED
@@ -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
|
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
|
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
|
data/examples/text/dfont.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require
|
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
|
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
|
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
|
|
data/examples/text/font_size.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
#
|
3
3
|
# This example shows the many ways of setting font sizes in Prawn
|
4
4
|
#
|
5
|
-
require
|
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
|
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
|
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
|
-
|
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(
|
16
|
+
pdf.text(string, :indent_paragraphs => 60, :align => :justify)
|
15
17
|
|
16
18
|
pdf.move_cursor_to(pdf.font.height * 3)
|
17
|
-
pdf.text(
|
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
|
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
|
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
|
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.
|
82
|
-
@document.
|
83
|
-
@document.
|
84
|
-
@document.
|
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
|
|
data/examples/text/kerning.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
#
|
3
3
|
# Demonstration of enabling and disabling kerning support
|
4
4
|
#
|
5
|
-
require
|
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
|
data/examples/text/rotated.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
#
|
3
3
|
# Demonstrates extending Text::Box
|
4
4
|
#
|
5
|
-
require
|
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
|
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
|
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"
|
data/examples/text/span.rb
CHANGED
@@ -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
|
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
|
data/examples/text/text_box.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#
|
3
3
|
|
4
|
-
require
|
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
|
-
|
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(
|
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,
|
6
|
-
#
|
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
|
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
|
|
data/examples/text/text_flow.rb
CHANGED
@@ -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
|
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
@@ -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(
|
147
|
-
unless
|
148
|
-
|
149
|
-
|
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::
|
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.
|
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
|
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::
|
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
|