prawn 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYING +2 -2
- data/Gemfile +18 -0
- data/LICENSE +1 -1
- data/README.md +17 -4
- data/Rakefile +18 -22
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/pdfs/nested_pages.pdf +13 -13
- data/lib/pdf/core.rb +35 -0
- data/lib/{prawn → pdf}/core/annotations.rb +6 -7
- data/lib/{prawn → pdf}/core/byte_string.rb +1 -1
- data/lib/{prawn → pdf}/core/destinations.rb +23 -23
- data/lib/{prawn → pdf}/core/document_state.rb +8 -8
- data/lib/pdf/core/filter_list.rb +51 -0
- data/lib/pdf/core/filters.rb +36 -0
- data/lib/pdf/core/graphics_state.rb +68 -0
- data/lib/{prawn → pdf}/core/literal_string.rb +1 -1
- data/lib/{prawn → pdf}/core/name_tree.rb +14 -2
- data/lib/{prawn → pdf}/core/object_store.rb +80 -24
- data/lib/pdf/core/outline.rb +315 -0
- data/lib/{prawn → pdf}/core/page.rb +23 -26
- data/lib/{prawn/document → pdf/core}/page_geometry.rb +11 -21
- data/lib/{prawn → pdf}/core/pdf_object.rb +48 -32
- data/lib/{prawn → pdf}/core/reference.rb +35 -44
- data/lib/pdf/core/stream.rb +98 -0
- data/lib/{prawn → pdf}/core/text.rb +24 -17
- data/lib/prawn.rb +95 -17
- data/lib/prawn/compatibility.rb +66 -26
- data/lib/prawn/document.rb +48 -30
- data/lib/prawn/document/bounding_box.rb +3 -3
- data/lib/prawn/document/column_box.rb +46 -8
- data/lib/prawn/document/graphics_state.rb +10 -73
- data/lib/prawn/document/internals.rb +24 -23
- data/lib/prawn/document/snapshot.rb +6 -7
- data/lib/prawn/document/span.rb +10 -10
- data/lib/prawn/encoding.rb +7 -7
- data/lib/prawn/errors.rb +18 -29
- data/lib/prawn/font.rb +64 -28
- data/lib/prawn/font/afm.rb +32 -74
- data/lib/prawn/font/dfont.rb +2 -2
- data/lib/prawn/font/ttf.rb +28 -57
- data/lib/prawn/font_metric_cache.rb +45 -0
- data/lib/prawn/graphics.rb +307 -41
- data/lib/prawn/graphics/cap_style.rb +3 -3
- data/lib/prawn/graphics/color.rb +12 -5
- data/lib/prawn/graphics/dash.rb +52 -31
- data/lib/prawn/graphics/join_style.rb +7 -7
- data/lib/prawn/graphics/patterns.rb +137 -0
- data/lib/prawn/graphics/transformation.rb +9 -9
- data/lib/prawn/graphics/transparency.rb +1 -1
- data/lib/prawn/image_handler.rb +30 -0
- data/lib/prawn/images.rb +86 -105
- data/lib/prawn/images/image.rb +48 -0
- data/lib/prawn/images/jpg.rb +14 -10
- data/lib/prawn/images/png.rb +50 -37
- data/lib/prawn/layout.rb +2 -2
- data/lib/prawn/layout/grid.rb +51 -51
- data/lib/prawn/measurement_extensions.rb +5 -5
- data/lib/prawn/measurements.rb +25 -21
- data/lib/prawn/outline.rb +4 -308
- data/lib/prawn/repeater.rb +8 -8
- data/lib/prawn/security.rb +50 -36
- data/lib/prawn/soft_mask.rb +94 -0
- data/lib/prawn/stamp.rb +3 -3
- data/lib/prawn/table.rb +292 -118
- data/lib/prawn/table/cell.rb +272 -45
- data/lib/prawn/table/cell/image.rb +70 -0
- data/lib/prawn/table/cell/in_table.rb +2 -2
- data/lib/prawn/table/cell/span_dummy.rb +92 -0
- data/lib/prawn/table/cell/subtable.rb +2 -2
- data/lib/prawn/table/cell/text.rb +42 -24
- data/lib/prawn/table/cells.rb +137 -48
- data/lib/prawn/text.rb +35 -23
- data/lib/prawn/text/box.rb +18 -5
- data/lib/prawn/text/formatted.rb +5 -4
- data/lib/prawn/text/formatted/arranger.rb +292 -0
- data/lib/prawn/text/formatted/box.rb +52 -13
- data/lib/prawn/text/formatted/fragment.rb +37 -22
- data/lib/prawn/text/formatted/line_wrap.rb +286 -0
- data/lib/prawn/text/formatted/parser.rb +14 -6
- data/lib/prawn/text/formatted/wrap.rb +151 -0
- data/lib/prawn/utilities.rb +44 -0
- data/manual/basic_concepts/adding_pages.rb +27 -0
- data/manual/basic_concepts/basic_concepts.rb +34 -0
- data/manual/basic_concepts/creation.rb +39 -0
- data/manual/basic_concepts/cursor.rb +33 -0
- data/manual/basic_concepts/measurement.rb +25 -0
- data/manual/basic_concepts/origin.rb +38 -0
- data/manual/basic_concepts/other_cursor_helpers.rb +40 -0
- data/manual/bounding_box/bounding_box.rb +39 -0
- data/manual/bounding_box/bounds.rb +49 -0
- data/manual/bounding_box/canvas.rb +24 -0
- data/manual/bounding_box/creation.rb +23 -0
- data/manual/bounding_box/indentation.rb +46 -0
- data/manual/bounding_box/nesting.rb +45 -0
- data/manual/bounding_box/russian_boxes.rb +40 -0
- data/manual/bounding_box/stretchy.rb +31 -0
- data/manual/document_and_page_options/background.rb +27 -0
- data/manual/document_and_page_options/document_and_page_options.rb +31 -0
- data/manual/document_and_page_options/metadata.rb +23 -0
- data/manual/document_and_page_options/page_margins.rb +38 -0
- data/manual/document_and_page_options/page_size.rb +34 -0
- data/manual/example_file.rb +116 -0
- data/manual/example_helper.rb +411 -0
- data/manual/example_package.rb +53 -0
- data/manual/example_section.rb +46 -0
- data/manual/graphics/circle_and_ellipse.rb +22 -0
- data/manual/graphics/color.rb +24 -0
- data/manual/graphics/common_lines.rb +28 -0
- data/manual/graphics/fill_and_stroke.rb +42 -0
- data/manual/graphics/fill_rules.rb +37 -0
- data/manual/graphics/gradients.rb +37 -0
- data/manual/graphics/graphics.rb +58 -0
- data/manual/graphics/helper.rb +24 -0
- data/manual/graphics/line_width.rb +35 -0
- data/manual/graphics/lines_and_curves.rb +41 -0
- data/manual/graphics/polygon.rb +29 -0
- data/manual/graphics/rectangle.rb +21 -0
- data/manual/graphics/rotate.rb +28 -0
- data/manual/graphics/scale.rb +41 -0
- data/manual/graphics/soft_masks.rb +46 -0
- data/manual/graphics/stroke_cap.rb +31 -0
- data/manual/graphics/stroke_dash.rb +48 -0
- data/manual/graphics/stroke_join.rb +30 -0
- data/manual/graphics/translate.rb +29 -0
- data/manual/graphics/transparency.rb +35 -0
- data/manual/images/absolute_position.rb +23 -0
- data/manual/images/fit.rb +21 -0
- data/manual/images/horizontal.rb +25 -0
- data/manual/images/images.rb +40 -0
- data/manual/images/plain_image.rb +18 -0
- data/manual/images/scale.rb +22 -0
- data/manual/images/vertical.rb +28 -0
- data/manual/images/width_and_height.rb +25 -0
- data/manual/layout/boxes.rb +27 -0
- data/manual/layout/content.rb +25 -0
- data/manual/layout/layout.rb +28 -0
- data/manual/layout/simple_grid.rb +23 -0
- data/manual/manual/cover.rb +35 -0
- data/manual/manual/foreword.rb +85 -0
- data/manual/manual/how_to_read_this_manual.rb +41 -0
- data/manual/manual/manual.rb +35 -0
- data/manual/outline/add_subsection_to.rb +61 -0
- data/manual/outline/insert_section_after.rb +47 -0
- data/manual/outline/outline.rb +32 -0
- data/manual/outline/sections_and_pages.rb +67 -0
- data/manual/repeatable_content/page_numbering.rb +54 -0
- data/manual/repeatable_content/repeatable_content.rb +31 -0
- data/manual/repeatable_content/repeater.rb +55 -0
- data/manual/repeatable_content/stamp.rb +41 -0
- data/manual/security/encryption.rb +31 -0
- data/manual/security/permissions.rb +38 -0
- data/manual/security/security.rb +28 -0
- data/manual/syntax_highlight.rb +52 -0
- data/manual/table/basic_block.rb +53 -0
- data/manual/table/before_rendering_page.rb +26 -0
- data/manual/table/cell_border_lines.rb +24 -0
- data/manual/table/cell_borders_and_bg.rb +31 -0
- data/manual/table/cell_dimensions.rb +30 -0
- data/manual/table/cell_text.rb +38 -0
- data/manual/table/column_widths.rb +30 -0
- data/manual/table/content_and_subtables.rb +39 -0
- data/manual/table/creation.rb +27 -0
- data/manual/table/filtering.rb +36 -0
- data/manual/table/flow_and_header.rb +17 -0
- data/manual/table/image_cells.rb +33 -0
- data/manual/table/position.rb +29 -0
- data/manual/table/row_colors.rb +20 -0
- data/manual/table/span.rb +30 -0
- data/manual/table/style.rb +22 -0
- data/manual/table/table.rb +52 -0
- data/manual/table/width.rb +27 -0
- data/manual/templates/full_template.rb +25 -0
- data/manual/templates/page_template.rb +48 -0
- data/manual/templates/templates.rb +27 -0
- data/manual/text/alignment.rb +44 -0
- data/manual/text/color.rb +24 -0
- data/manual/text/column_box.rb +32 -0
- data/manual/text/fallback_fonts.rb +37 -0
- data/manual/text/font.rb +41 -0
- data/manual/text/font_size.rb +45 -0
- data/manual/text/font_style.rb +23 -0
- data/manual/text/formatted_callbacks.rb +60 -0
- data/manual/text/formatted_text.rb +54 -0
- data/manual/text/free_flowing_text.rb +51 -0
- data/manual/text/group.rb +29 -0
- data/manual/text/inline.rb +43 -0
- data/manual/text/kerning_and_character_spacing.rb +39 -0
- data/manual/text/leading.rb +25 -0
- data/manual/text/line_wrapping.rb +41 -0
- data/manual/text/paragraph_indentation.rb +26 -0
- data/manual/text/positioned_text.rb +38 -0
- data/manual/text/registering_families.rb +48 -0
- data/manual/text/rendering_and_color.rb +37 -0
- data/manual/text/right_to_left_text.rb +43 -0
- data/manual/text/rotation.rb +43 -0
- data/manual/text/single_usage.rb +37 -0
- data/manual/text/text.rb +75 -0
- data/manual/text/text_box_excess.rb +32 -0
- data/manual/text/text_box_extensions.rb +45 -0
- data/manual/text/text_box_overflow.rb +44 -0
- data/manual/text/utf8.rb +28 -0
- data/{examples/m17n → manual/text}/win_ansi_charset.rb +14 -10
- data/prawn.gemspec +18 -12
- data/spec/acceptance/png.rb +23 -0
- data/spec/annotations_spec.rb +16 -32
- data/spec/bounding_box_spec.rb +128 -15
- data/spec/cell_spec.rb +169 -38
- data/spec/column_box_spec.rb +33 -0
- data/spec/destinations_spec.rb +5 -5
- data/spec/document_spec.rb +150 -104
- data/spec/extensions/encoding_helpers.rb +10 -0
- data/spec/extensions/mocha.rb +1 -0
- data/spec/filters_spec.rb +34 -0
- data/spec/font_metric_cache_spec.rb +52 -0
- data/spec/font_spec.rb +183 -97
- data/spec/formatted_text_arranger_spec.rb +43 -43
- data/spec/formatted_text_box_spec.rb +30 -20
- data/spec/formatted_text_fragment_spec.rb +8 -8
- data/spec/graphics_spec.rb +158 -69
- data/spec/grid_spec.rb +15 -15
- data/spec/image_handler_spec.rb +42 -0
- data/spec/images_spec.rb +49 -24
- data/spec/inline_formatted_text_parser_spec.rb +73 -19
- data/spec/jpg_spec.rb +4 -4
- data/spec/line_wrap_spec.rb +26 -26
- data/spec/measurement_units_spec.rb +6 -6
- data/spec/name_tree_spec.rb +21 -21
- data/spec/object_store_spec.rb +39 -39
- data/spec/outline_spec.rb +93 -53
- data/spec/pdf_object_spec.rb +88 -86
- data/spec/png_spec.rb +31 -28
- data/spec/reference_spec.rb +32 -32
- data/spec/repeater_spec.rb +25 -11
- data/spec/security_spec.rb +44 -12
- data/spec/snapshot_spec.rb +8 -9
- data/spec/soft_mask_spec.rb +117 -0
- data/spec/span_spec.rb +10 -15
- data/spec/spec_helper.rb +25 -8
- data/spec/stamp_spec.rb +29 -30
- data/spec/stream_spec.rb +58 -0
- data/spec/stroke_styles_spec.rb +36 -18
- data/spec/table/span_dummy_spec.rb +17 -0
- data/spec/table_spec.rb +697 -105
- data/spec/template_spec.rb +108 -54
- data/spec/text_at_spec.rb +18 -17
- data/spec/text_box_spec.rb +111 -62
- data/spec/text_rendering_mode_spec.rb +5 -5
- data/spec/text_spacing_spec.rb +4 -4
- data/spec/text_spec.rb +57 -49
- data/spec/transparency_spec.rb +5 -5
- metadata +421 -213
- data/data/fonts/Action Man.dfont +0 -0
- data/data/fonts/Activa.ttf +0 -0
- data/data/fonts/Chalkboard.ttf +0 -0
- data/data/fonts/DejaVuSans.ttf +0 -0
- data/data/fonts/Dustismo_Roman.ttf +0 -0
- data/data/fonts/comicsans.ttf +0 -0
- data/data/fonts/gkai00mp.ttf +0 -0
- data/data/images/rails.dat +0 -0
- data/data/images/rails.png +0 -0
- data/examples/bounding_box/russian_boxes.rb +0 -37
- data/examples/example_helper.rb +0 -11
- data/examples/general/context_sensitive_headers.rb +0 -38
- data/examples/graphics/cmyk.rb +0 -13
- data/examples/graphics/gradient.rb +0 -23
- data/examples/graphics/png_types.rb +0 -23
- data/examples/graphics/remote_images.rb +0 -13
- data/examples/m17n/full_win_ansi_character_list.rb +0 -20
- data/examples/m17n/sjis.rb +0 -29
- data/examples/table/bill.rb +0 -54
- data/examples/table/header.rb +0 -15
- data/examples/text/font_calculations.rb +0 -92
- data/examples/text/hyphenation.rb +0 -45
- data/examples/text/indent_paragraphs.rb +0 -24
- data/lib/prawn/core.rb +0 -85
- data/lib/prawn/core/text/formatted/arranger.rb +0 -294
- data/lib/prawn/core/text/formatted/line_wrap.rb +0 -273
- data/lib/prawn/core/text/formatted/wrap.rb +0 -153
- data/lib/prawn/graphics/gradient.rb +0 -84
- data/lib/prawn/security/arcfour.rb +0 -51
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
describe "A column box" do
|
6
|
+
it "has sensible left and right values" do
|
7
|
+
create_pdf
|
8
|
+
@pdf.column_box [0, @pdf.cursor], :width => @pdf.bounds.width,
|
9
|
+
:height => 200, :columns => 3, :spacer => 25 do
|
10
|
+
left = @pdf.bounds.left
|
11
|
+
right = @pdf.bounds.right
|
12
|
+
|
13
|
+
@pdf.bounds.move_past_bottom # next column
|
14
|
+
|
15
|
+
@pdf.bounds.left.should be > left
|
16
|
+
@pdf.bounds.left.should be > right
|
17
|
+
@pdf.bounds.right.should be > @pdf.bounds.left
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "includes spacers between columns but not at the end" do
|
22
|
+
create_pdf
|
23
|
+
@pdf.column_box [0, @pdf.cursor], :width => 500,
|
24
|
+
:height => 200, :columns => 3, :spacer => 25 do
|
25
|
+
@pdf.bounds.width.should == 150 # (500 - (25 * 2)) / 3
|
26
|
+
|
27
|
+
@pdf.bounds.move_past_bottom
|
28
|
+
@pdf.bounds.move_past_bottom
|
29
|
+
|
30
|
+
@pdf.bounds.right.should == 500
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/destinations_spec.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
describe "When creating destinations" do
|
4
6
|
|
5
|
-
describe "When creating destinations" do
|
6
|
-
|
7
7
|
before(:each) { create_pdf }
|
8
|
-
|
9
|
-
it "should add entry to Dests name tree" do
|
8
|
+
|
9
|
+
it "should add entry to Dests name tree" do
|
10
10
|
@pdf.dests.data.empty?.should == true
|
11
11
|
@pdf.add_dest "candy", "chocolate"
|
12
12
|
@pdf.dests.data.size.should == 1
|
data/spec/document_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "tempfile"
|
3
3
|
|
4
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
5
5
|
|
6
6
|
describe "Prawn::Document.new" do
|
7
7
|
it "should not modify its argument" do
|
@@ -12,12 +12,12 @@ describe "Prawn::Document.new" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "The cursor" do
|
15
|
-
it "should
|
15
|
+
it "should == pdf.y - bounds.absolute_bottom" do
|
16
16
|
pdf = Prawn::Document.new
|
17
17
|
pdf.cursor.should == pdf.bounds.top
|
18
|
-
|
18
|
+
|
19
19
|
pdf.y = 300
|
20
|
-
pdf.cursor.should == pdf.y - pdf.bounds.absolute_bottom
|
20
|
+
pdf.cursor.should == pdf.y - pdf.bounds.absolute_bottom
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should be able to move relative to the bottom margin" do
|
@@ -27,14 +27,40 @@ describe "The cursor" do
|
|
27
27
|
pdf.cursor.should == 10
|
28
28
|
pdf.y.should == pdf.cursor + pdf.bounds.absolute_bottom
|
29
29
|
end
|
30
|
-
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "when generating a document with a custom text formatter" do
|
33
|
+
it "should use the provided text formatter" do
|
34
|
+
class TestTextFormatter
|
35
|
+
def self.format(string)
|
36
|
+
[
|
37
|
+
{
|
38
|
+
text: string.gsub("Dr. Who?", "Just 'The Doctor'."),
|
39
|
+
styles: [],
|
40
|
+
color: nil,
|
41
|
+
link: nil,
|
42
|
+
anchor: nil,
|
43
|
+
local: nil,
|
44
|
+
font: nil,
|
45
|
+
size: nil,
|
46
|
+
character_spacing: nil
|
47
|
+
}
|
48
|
+
]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
pdf = Prawn::Document.new text_formatter: TestTextFormatter
|
52
|
+
pdf.text "Dr. Who?", inline_format: true
|
53
|
+
text = PDF::Inspector::Text.analyze(pdf.render)
|
54
|
+
text.strings.first.should == "Just 'The Doctor'."
|
55
|
+
end
|
56
|
+
end
|
31
57
|
|
32
58
|
describe "when generating a document from a subclass" do
|
33
59
|
it "should be an instance of the subclass" do
|
34
60
|
custom_document = Class.new(Prawn::Document)
|
35
|
-
custom_document.generate(Tempfile.new("generate_test").path) do |e|
|
61
|
+
custom_document.generate(Tempfile.new("generate_test").path) do |e|
|
36
62
|
e.class.should == custom_document
|
37
|
-
e.should
|
63
|
+
e.should be_a_kind_of(Prawn::Document)
|
38
64
|
end
|
39
65
|
end
|
40
66
|
|
@@ -45,51 +71,51 @@ describe "when generating a document from a subclass" do
|
|
45
71
|
Prawn::Document.extensions << mod1 << mod2
|
46
72
|
|
47
73
|
custom_document = Class.new(Prawn::Document)
|
48
|
-
|
74
|
+
custom_document.extensions.should == [mod1, mod2]
|
49
75
|
|
50
76
|
# remove the extensions we added to prawn document
|
51
77
|
Prawn::Document.extensions.delete(mod1)
|
52
78
|
Prawn::Document.extensions.delete(mod2)
|
53
79
|
|
54
|
-
|
55
|
-
|
80
|
+
Prawn::Document.new.respond_to?(:test_extensions1).should be_false
|
81
|
+
Prawn::Document.new.respond_to?(:test_extensions2).should be_false
|
56
82
|
|
57
83
|
# verify these still exist on custom class
|
58
|
-
|
84
|
+
custom_document.extensions.should == [mod1, mod2]
|
59
85
|
|
60
|
-
|
61
|
-
|
86
|
+
custom_document.new.respond_to?(:test_extensions1).should be_true
|
87
|
+
custom_document.new.respond_to?(:test_extensions2).should be_true
|
62
88
|
end
|
63
89
|
|
64
90
|
end
|
65
91
|
|
66
|
-
|
67
|
-
describe "When creating multi-page documents" do
|
68
|
-
|
92
|
+
|
93
|
+
describe "When creating multi-page documents" do
|
94
|
+
|
69
95
|
before(:each) { create_pdf }
|
70
|
-
|
71
|
-
it "should initialize with a single page" do
|
96
|
+
|
97
|
+
it "should initialize with a single page" do
|
72
98
|
page_counter = PDF::Inspector::Page.analyze(@pdf.render)
|
73
|
-
|
74
|
-
page_counter.pages.size.should == 1
|
75
|
-
@pdf.page_count.should == 1
|
99
|
+
|
100
|
+
page_counter.pages.size.should == 1
|
101
|
+
@pdf.page_count.should == 1
|
76
102
|
end
|
77
|
-
|
103
|
+
|
78
104
|
it "should provide an accurate page_count" do
|
79
|
-
3.times { @pdf.start_new_page }
|
105
|
+
3.times { @pdf.start_new_page }
|
80
106
|
page_counter = PDF::Inspector::Page.analyze(@pdf.render)
|
81
|
-
|
107
|
+
|
82
108
|
page_counter.pages.size.should == 4
|
83
109
|
@pdf.page_count.should == 4
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
87
113
|
|
88
114
|
describe "When beginning each new page" do
|
89
115
|
|
90
116
|
describe "Background template feature" do
|
91
117
|
before(:each) do
|
92
|
-
@filename = "#{Prawn::
|
118
|
+
@filename = "#{Prawn::DATADIR}/images/pigs.jpg"
|
93
119
|
@pdf = Prawn::Document.new(:background => @filename)
|
94
120
|
end
|
95
121
|
it "should place a background image if it is in options block" do
|
@@ -102,11 +128,11 @@ describe "When beginning each new page" do
|
|
102
128
|
@pdf.instance_variable_defined?(:@background).should == true
|
103
129
|
@pdf.instance_variable_get(:@background).should == @filename
|
104
130
|
end
|
105
|
-
|
106
|
-
|
131
|
+
|
132
|
+
|
107
133
|
end
|
108
|
-
|
109
|
-
|
134
|
+
|
135
|
+
|
110
136
|
end
|
111
137
|
|
112
138
|
describe "Prawn::Document#float" do
|
@@ -119,7 +145,7 @@ describe "Prawn::Document#float" do
|
|
119
145
|
|
120
146
|
it "should teleport across pages if necessary" do
|
121
147
|
create_pdf
|
122
|
-
|
148
|
+
|
123
149
|
@pdf.float do
|
124
150
|
@pdf.text "Foo"
|
125
151
|
@pdf.start_new_page
|
@@ -156,7 +182,7 @@ end
|
|
156
182
|
|
157
183
|
describe "on_page_create callback" do
|
158
184
|
before do
|
159
|
-
create_pdf
|
185
|
+
create_pdf
|
160
186
|
end
|
161
187
|
|
162
188
|
it "should be invoked with document" do
|
@@ -177,34 +203,34 @@ describe "on_page_create callback" do
|
|
177
203
|
|
178
204
|
5.times { @pdf.start_new_page }
|
179
205
|
end
|
180
|
-
|
206
|
+
|
181
207
|
it "should be replaceable" do
|
182
208
|
trigger1 = mock()
|
183
209
|
trigger1.expects(:fire).times(1)
|
184
|
-
|
210
|
+
|
185
211
|
trigger2 = mock()
|
186
212
|
trigger2.expects(:fire).times(1)
|
187
213
|
|
188
214
|
@pdf.on_page_create { trigger1.fire }
|
189
|
-
|
215
|
+
|
190
216
|
@pdf.start_new_page
|
191
|
-
|
217
|
+
|
192
218
|
@pdf.on_page_create { trigger2.fire }
|
193
|
-
|
219
|
+
|
194
220
|
@pdf.start_new_page
|
195
221
|
end
|
196
|
-
|
222
|
+
|
197
223
|
it "should be clearable by calling on_page_create without a block" do
|
198
224
|
trigger = mock()
|
199
225
|
trigger.expects(:fire).times(1)
|
200
226
|
|
201
227
|
@pdf.on_page_create { trigger.fire }
|
202
228
|
|
203
|
-
@pdf.start_new_page
|
204
|
-
|
229
|
+
@pdf.start_new_page
|
230
|
+
|
205
231
|
@pdf.on_page_create
|
206
|
-
|
207
|
-
@pdf.start_new_page
|
232
|
+
|
233
|
+
@pdf.start_new_page
|
208
234
|
end
|
209
235
|
|
210
236
|
end
|
@@ -214,8 +240,8 @@ describe "Document compression" do
|
|
214
240
|
it "should not compress the page content stream if compression is disabled" do
|
215
241
|
|
216
242
|
pdf = Prawn::Document.new(:compress => false)
|
217
|
-
pdf.page.content.stubs(:
|
218
|
-
pdf.page.content.expects(:
|
243
|
+
pdf.page.content.stream.stubs(:compress!).returns(true)
|
244
|
+
pdf.page.content.stream.expects(:compress!).never
|
219
245
|
|
220
246
|
pdf.text "Hi There" * 20
|
221
247
|
pdf.render
|
@@ -224,8 +250,8 @@ describe "Document compression" do
|
|
224
250
|
it "should compress the page content stream if compression is enabled" do
|
225
251
|
|
226
252
|
pdf = Prawn::Document.new(:compress => true)
|
227
|
-
pdf.page.content.stubs(:
|
228
|
-
pdf.page.content.expects(:
|
253
|
+
pdf.page.content.stream.stubs(:compress!).returns(true)
|
254
|
+
pdf.page.content.stream.expects(:compress!).once
|
229
255
|
|
230
256
|
pdf.text "Hi There" * 20
|
231
257
|
pdf.render
|
@@ -235,14 +261,14 @@ describe "Document compression" do
|
|
235
261
|
doc_uncompressed = Prawn::Document.new
|
236
262
|
doc_compressed = Prawn::Document.new(:compress => true)
|
237
263
|
[doc_compressed, doc_uncompressed].each do |pdf|
|
238
|
-
pdf.font "#{Prawn::
|
264
|
+
pdf.font "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
|
239
265
|
pdf.text "更可怕的是,同质化竞争对手可以按照URL中后面这个ID来遍历" * 10
|
240
266
|
end
|
241
267
|
|
242
|
-
doc_compressed.render.length.should
|
243
|
-
end
|
268
|
+
doc_compressed.render.length.should be < doc_uncompressed.render.length
|
269
|
+
end
|
244
270
|
|
245
|
-
end
|
271
|
+
end
|
246
272
|
|
247
273
|
describe "Document metadata" do
|
248
274
|
it "should output strings as UTF-16 with a byte order mark" do
|
@@ -262,11 +288,10 @@ describe "When reopening pages" do
|
|
262
288
|
pdf.go_to_page 1
|
263
289
|
pdf.text "More for page 1"
|
264
290
|
end
|
265
|
-
|
266
|
-
#
|
267
|
-
#
|
268
|
-
|
269
|
-
should.not.raise(PDF::Reader::MalformedPDFError)
|
291
|
+
|
292
|
+
# Indirectly verify that the actual length does not match dictionary length.
|
293
|
+
# If it isn't, a MalformedPDFError will be raised
|
294
|
+
PDF::Inspector::Page.analyze(@pdf.render)
|
270
295
|
end
|
271
296
|
|
272
297
|
it "should insert pages after the current page when calling start_new_page" do
|
@@ -298,21 +323,21 @@ describe "When setting page size" do
|
|
298
323
|
it "should default to LETTER" do
|
299
324
|
@pdf = Prawn::Document.new
|
300
325
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
301
|
-
pages.first[:size].should ==
|
302
|
-
end
|
303
|
-
|
304
|
-
(
|
326
|
+
pages.first[:size].should == PDF::Core::PageGeometry::SIZES["LETTER"]
|
327
|
+
end
|
328
|
+
|
329
|
+
(PDF::Core::PageGeometry::SIZES.keys - ["LETTER"]).each do |k|
|
305
330
|
it "should provide #{k} geometry" do
|
306
331
|
@pdf = Prawn::Document.new(:page_size => k)
|
307
|
-
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
308
|
-
pages.first[:size].should ==
|
332
|
+
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
333
|
+
pages.first[:size].should == PDF::Core::PageGeometry::SIZES[k]
|
309
334
|
end
|
310
335
|
end
|
311
|
-
|
312
|
-
it "should allow custom page size" do
|
336
|
+
|
337
|
+
it "should allow custom page size" do
|
313
338
|
@pdf = Prawn::Document.new(:page_size => [1920, 1080] )
|
314
|
-
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
315
|
-
pages.first[:size].should == [1920, 1080]
|
339
|
+
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
340
|
+
pages.first[:size].should == [1920, 1080]
|
316
341
|
end
|
317
342
|
|
318
343
|
|
@@ -321,25 +346,25 @@ describe "When setting page size" do
|
|
321
346
|
@pdf.start_new_page
|
322
347
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
323
348
|
pages.each do |page|
|
324
|
-
page[:size].should ==
|
349
|
+
page[:size].should == PDF::Core::PageGeometry::SIZES["LEGAL"]
|
325
350
|
end
|
326
351
|
end
|
327
352
|
|
328
|
-
end
|
353
|
+
end
|
329
354
|
|
330
355
|
describe "When setting page layout" do
|
331
356
|
it "should reverse coordinates for landscape" do
|
332
357
|
@pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
|
333
|
-
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
334
|
-
pages.first[:size].should ==
|
335
|
-
end
|
358
|
+
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
359
|
+
pages.first[:size].should == PDF::Core::PageGeometry::SIZES["A4"].reverse
|
360
|
+
end
|
336
361
|
|
337
362
|
it "should retain page layout by default when starting a new page" do
|
338
363
|
@pdf = Prawn::Document.new(:page_layout => :landscape)
|
339
364
|
@pdf.start_new_page(:trace => true)
|
340
365
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
341
366
|
pages.each do |page|
|
342
|
-
page[:size].should ==
|
367
|
+
page[:size].should == PDF::Core::PageGeometry::SIZES["LETTER"].reverse
|
343
368
|
end
|
344
369
|
end
|
345
370
|
|
@@ -358,11 +383,11 @@ describe "The mask() feature" do
|
|
358
383
|
@pdf.mask(:y, :line_width) do
|
359
384
|
@pdf.y = y + 1
|
360
385
|
@pdf.line_width = line_width + 1
|
361
|
-
@pdf.y.
|
362
|
-
@pdf.line_width.
|
386
|
+
@pdf.y.should_not == y
|
387
|
+
@pdf.line_width.should_not == line_width
|
363
388
|
end
|
364
389
|
@pdf.y.should == y
|
365
|
-
@pdf.line_width.should == line_width
|
390
|
+
@pdf.line_width.should == line_width
|
366
391
|
end
|
367
392
|
end
|
368
393
|
|
@@ -391,14 +416,14 @@ describe "The group() feature" do
|
|
391
416
|
pages[1][:strings].should == ["Hello", "World"]
|
392
417
|
end
|
393
418
|
|
394
|
-
it "should
|
419
|
+
it "should raise_error CannotGroup if the content is too tall" do
|
395
420
|
lambda {
|
396
421
|
Prawn::Document.new do
|
397
422
|
group do
|
398
423
|
100.times { text "Too long" }
|
399
424
|
end
|
400
425
|
end.render
|
401
|
-
}.should
|
426
|
+
}.should raise_error(Prawn::Errors::CannotGroup)
|
402
427
|
end
|
403
428
|
|
404
429
|
it "should group within individual column boxes" do
|
@@ -433,14 +458,14 @@ describe "The render() feature" do
|
|
433
458
|
|
434
459
|
it "should trigger before_render callbacks just before rendering" do
|
435
460
|
pdf = Prawn::Document.new
|
436
|
-
|
461
|
+
|
437
462
|
seq = sequence("callback_order")
|
438
463
|
|
439
464
|
# Verify the order: finalize -> fire callbacks -> render body
|
440
465
|
pdf.expects(:finalize_all_page_contents).in_sequence(seq)
|
441
466
|
trigger = mock()
|
442
467
|
trigger.expects(:fire).in_sequence(seq)
|
443
|
-
|
468
|
+
|
444
469
|
# Store away the render_body method to be called below
|
445
470
|
render_body = pdf.method(:render_body)
|
446
471
|
pdf.expects(:render_body).in_sequence(seq)
|
@@ -464,10 +489,10 @@ end
|
|
464
489
|
describe "The :optimize_objects option" do
|
465
490
|
before(:all) do
|
466
491
|
@wasteful_doc = lambda do |pdf|
|
467
|
-
pdf.transaction do
|
492
|
+
pdf.transaction do
|
468
493
|
pdf.start_new_page
|
469
494
|
pdf.text "Hidden text"
|
470
|
-
pdf.rollback
|
495
|
+
pdf.rollback
|
471
496
|
end
|
472
497
|
|
473
498
|
pdf.text "Hello world"
|
@@ -478,12 +503,12 @@ describe "The :optimize_objects option" do
|
|
478
503
|
wasteful_pdf = Prawn::Document.new(&@wasteful_doc)
|
479
504
|
frugal_pdf = Prawn::Document.new(:optimize_objects => true,
|
480
505
|
&@wasteful_doc)
|
481
|
-
frugal_pdf.render.size.should
|
506
|
+
frugal_pdf.render.size.should be < wasteful_pdf.render.size
|
482
507
|
end
|
483
508
|
|
484
509
|
it "should default to :false" do
|
485
510
|
default_pdf = Prawn::Document.new(&@wasteful_doc)
|
486
|
-
wasteful_pdf = Prawn::Document.new(:optimize_objects => false,
|
511
|
+
wasteful_pdf = Prawn::Document.new(:optimize_objects => false,
|
487
512
|
&@wasteful_doc)
|
488
513
|
default_pdf.render.size.should == wasteful_pdf.render.size
|
489
514
|
end
|
@@ -565,25 +590,25 @@ describe "The number_pages method" do
|
|
565
590
|
before do
|
566
591
|
@pdf = Prawn::Document.new(:skip_page_creation => true)
|
567
592
|
end
|
568
|
-
|
593
|
+
|
569
594
|
it "replaces the '<page>' string with the proper page number" do
|
570
595
|
@pdf.start_new_page
|
571
596
|
@pdf.expects(:text_box).with("1, test", { :height => 50 })
|
572
597
|
@pdf.number_pages "<page>, test", {:page_filter => :all}
|
573
598
|
end
|
574
|
-
|
599
|
+
|
575
600
|
it "replaces the '<total>' string with the total page count" do
|
576
601
|
@pdf.start_new_page
|
577
602
|
@pdf.expects(:text_box).with("test, 1", { :height => 50 })
|
578
603
|
@pdf.number_pages "test, <total>", {:page_filter => :all}
|
579
604
|
end
|
580
|
-
|
605
|
+
|
581
606
|
it "must print each page if given the :all page_filter" do
|
582
607
|
10.times { @pdf.start_new_page }
|
583
608
|
@pdf.expects(:text_box).times(10)
|
584
609
|
@pdf.number_pages "test", {:page_filter => :all}
|
585
610
|
end
|
586
|
-
|
611
|
+
|
587
612
|
it "must print each page if no :page_filter is specified" do
|
588
613
|
10.times { @pdf.start_new_page }
|
589
614
|
@pdf.expects(:text_box).times(10)
|
@@ -595,8 +620,8 @@ describe "The number_pages method" do
|
|
595
620
|
@pdf.expects(:text_box).never
|
596
621
|
@pdf.number_pages "test", {:page_filter => nil}
|
597
622
|
end
|
598
|
-
|
599
|
-
context "start_count_at option" do
|
623
|
+
|
624
|
+
context "start_count_at option" do
|
600
625
|
[1, 2].each do |startat|
|
601
626
|
context "equal to #{startat}" do
|
602
627
|
it "increments the pages" do
|
@@ -605,10 +630,10 @@ describe "The number_pages method" do
|
|
605
630
|
@pdf.expects(:text_box).with("#{startat} 2", { :height => 50 })
|
606
631
|
@pdf.expects(:text_box).with("#{startat+1} 2", { :height => 50 })
|
607
632
|
@pdf.number_pages "<page> <total>", options
|
608
|
-
end
|
633
|
+
end
|
609
634
|
end
|
610
635
|
end
|
611
|
-
|
636
|
+
|
612
637
|
[0, nil].each do |val|
|
613
638
|
context "equal to #{val}" do
|
614
639
|
it "defaults to start at page 1" do
|
@@ -622,7 +647,7 @@ describe "The number_pages method" do
|
|
622
647
|
end
|
623
648
|
end
|
624
649
|
end
|
625
|
-
|
650
|
+
|
626
651
|
context "total_pages option" do
|
627
652
|
it "allows the total pages count to be overridden" do
|
628
653
|
2.times { @pdf.start_new_page }
|
@@ -631,7 +656,7 @@ describe "The number_pages method" do
|
|
631
656
|
@pdf.number_pages "<page> <total>", :page_filter => :all, :total_pages => 10
|
632
657
|
end
|
633
658
|
end
|
634
|
-
|
659
|
+
|
635
660
|
context "special page filter" do
|
636
661
|
context "such as :odd" do
|
637
662
|
it "increments the pages" do
|
@@ -676,6 +701,27 @@ describe "The number_pages method" do
|
|
676
701
|
end
|
677
702
|
end
|
678
703
|
end
|
704
|
+
|
705
|
+
context "height option" do
|
706
|
+
before do
|
707
|
+
@pdf.start_new_page
|
708
|
+
end
|
709
|
+
|
710
|
+
it "with 10 height" do
|
711
|
+
@pdf.expects(:text_box).with("1 1", { :height => 10 })
|
712
|
+
@pdf.number_pages "<page> <total>", :height => 10
|
713
|
+
end
|
714
|
+
|
715
|
+
it "with nil height" do
|
716
|
+
@pdf.expects(:text_box).with("1 1", { :height => nil })
|
717
|
+
@pdf.number_pages "<page> <total>", :height => nil
|
718
|
+
end
|
719
|
+
|
720
|
+
it "with no height" do
|
721
|
+
@pdf.expects(:text_box).with("1 1", { :height => 50 })
|
722
|
+
@pdf.number_pages "<page> <total>"
|
723
|
+
end
|
724
|
+
end
|
679
725
|
end
|
680
726
|
|
681
727
|
describe "The page_match? method" do
|
@@ -683,33 +729,33 @@ describe "The page_match? method" do
|
|
683
729
|
@pdf = Prawn::Document.new(:skip_page_creation => true)
|
684
730
|
10.times {@pdf.start_new_page}
|
685
731
|
end
|
686
|
-
|
732
|
+
|
687
733
|
it "returns nil given no filter" do
|
688
|
-
|
734
|
+
@pdf.page_match?(:nil, 1).should be_false
|
689
735
|
end
|
690
|
-
|
736
|
+
|
691
737
|
it "must provide an :all filter" do
|
692
|
-
|
738
|
+
(1..@pdf.page_count).all? { |i| @pdf.page_match?(:all, i) }.should be_true
|
693
739
|
end
|
694
740
|
|
695
741
|
it "must provide an :odd filter" do
|
696
742
|
odd, even = (1..@pdf.page_count).partition { |e| e % 2 == 1 }
|
697
|
-
|
698
|
-
|
743
|
+
odd.all? { |i| @pdf.page_match?(:odd, i) }.should be_true
|
744
|
+
even.any? { |i| @pdf.page_match?(:odd, i) }.should be_false
|
699
745
|
end
|
700
746
|
|
701
747
|
it "must be able to filter by an array of page numbers" do
|
702
748
|
fltr = [1,2,7]
|
703
|
-
|
749
|
+
(1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [1,2,7]
|
704
750
|
end
|
705
751
|
|
706
752
|
it "must be able to filter by a range of page numbers" do
|
707
753
|
fltr = 2..4
|
708
|
-
|
754
|
+
(1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [2,3,4]
|
709
755
|
end
|
710
756
|
|
711
757
|
it "must be able to filter by an arbitrary proc" do
|
712
758
|
fltr = lambda { |x| x == 1 or x % 3 == 0 }
|
713
|
-
|
714
|
-
end
|
759
|
+
(1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [1,3,6,9]
|
760
|
+
end
|
715
761
|
end
|