prawn 0.11.1 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +10 -0
- data/COPYING +2 -2
- data/GPLv2 +340 -0
- data/GPLv3 +674 -0
- data/Gemfile +11 -0
- data/LICENSE +1 -1
- data/Rakefile +29 -38
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.color +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.color +0 -0
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.color +0 -0
- data/data/pdfs/nested_pages.pdf +13 -13
- data/lib/prawn/document/bounding_box.rb +87 -12
- data/lib/prawn/document/column_box.rb +57 -28
- data/lib/prawn/document/graphics_state.rb +11 -74
- data/lib/prawn/document/internals.rb +25 -23
- data/lib/prawn/document/snapshot.rb +11 -8
- data/lib/prawn/document/span.rb +12 -10
- data/lib/prawn/document.rb +250 -194
- data/lib/prawn/encoding.rb +9 -10
- data/lib/prawn/errors.rb +18 -29
- data/lib/prawn/font/afm.rb +52 -41
- data/lib/prawn/font/dfont.rb +4 -3
- data/lib/prawn/font/ttf.rb +44 -48
- data/lib/prawn/font.rb +138 -88
- data/lib/prawn/font_metric_cache.rb +47 -0
- data/lib/prawn/graphics/cap_style.rb +4 -3
- data/lib/prawn/graphics/color.rb +13 -5
- data/lib/prawn/graphics/dash.rb +53 -31
- data/lib/prawn/graphics/join_style.rb +9 -7
- data/lib/prawn/graphics/patterns.rb +138 -0
- data/lib/prawn/graphics/transformation.rb +10 -9
- data/lib/prawn/graphics/transparency.rb +3 -1
- data/lib/prawn/graphics.rb +316 -61
- data/lib/prawn/image_handler.rb +36 -0
- data/lib/prawn/images/image.rb +49 -0
- data/lib/prawn/images/jpg.rb +21 -15
- data/lib/prawn/images/png.rb +62 -119
- data/lib/prawn/images.rb +89 -108
- data/lib/prawn/layout/grid.rb +66 -54
- data/lib/prawn/layout.rb +10 -15
- data/lib/prawn/measurement_extensions.rb +10 -6
- data/lib/prawn/measurements.rb +27 -21
- data/lib/prawn/outline.rb +6 -308
- data/lib/prawn/repeater.rb +11 -9
- data/lib/prawn/security/arcfour.rb +1 -0
- data/lib/prawn/security.rb +55 -33
- data/lib/prawn/soft_mask.rb +96 -0
- data/lib/prawn/stamp.rb +5 -3
- data/lib/prawn/table/cell/image.rb +69 -0
- data/lib/prawn/table/cell/in_table.rb +4 -2
- data/lib/prawn/table/cell/span_dummy.rb +93 -0
- data/lib/prawn/table/cell/subtable.rb +2 -2
- data/lib/prawn/table/cell/text.rb +44 -26
- data/lib/prawn/table/cell.rb +302 -50
- data/lib/prawn/table/cells.rb +147 -49
- data/lib/prawn/table/column_width_calculator.rb +61 -0
- data/lib/prawn/table.rb +297 -118
- data/lib/prawn/text/box.rb +21 -5
- data/lib/prawn/text/formatted/arranger.rb +290 -0
- data/lib/prawn/text/formatted/box.rb +103 -59
- data/lib/prawn/text/formatted/fragment.rb +34 -23
- data/lib/prawn/text/formatted/line_wrap.rb +266 -0
- data/lib/prawn/text/formatted/parser.rb +15 -5
- data/lib/prawn/text/formatted/wrap.rb +150 -0
- data/lib/prawn/text/formatted.rb +5 -4
- data/lib/prawn/text.rb +38 -24
- data/lib/prawn/utilities.rb +46 -0
- data/lib/prawn.rb +85 -20
- 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 +32 -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/document_and_page_options/print_scaling.rb +20 -0
- data/manual/example_file.rb +111 -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 +30 -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 +36 -0
- data/manual/manual/foreword.rb +85 -0
- data/manual/manual/how_to_read_this_manual.rb +41 -0
- data/manual/manual/manual.rb +34 -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/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 +31 -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 +27 -17
- data/spec/acceptance/png.rb +23 -0
- data/spec/annotations_spec.rb +16 -32
- data/spec/bounding_box_spec.rb +284 -2
- data/spec/cell_spec.rb +169 -38
- data/spec/column_box_spec.rb +65 -0
- data/spec/data/curves.pdf +66 -0
- data/spec/destinations_spec.rb +5 -5
- data/spec/document_spec.rb +212 -113
- data/spec/extensions/encoding_helpers.rb +9 -0
- data/spec/extensions/mocha.rb +2 -3
- data/spec/font_metric_cache_spec.rb +52 -0
- data/spec/font_spec.rb +205 -95
- data/spec/formatted_text_arranger_spec.rb +43 -43
- data/spec/formatted_text_box_spec.rb +63 -24
- data/spec/formatted_text_fragment_spec.rb +8 -8
- data/spec/graphics_spec.rb +175 -68
- data/spec/grid_spec.rb +26 -15
- data/spec/image_handler_spec.rb +54 -0
- data/spec/images_spec.rb +58 -30
- data/spec/inline_formatted_text_parser_spec.rb +73 -19
- data/spec/jpg_spec.rb +4 -4
- data/spec/line_wrap_spec.rb +28 -28
- data/spec/measurement_units_spec.rb +6 -6
- data/spec/object_store_spec.rb +17 -106
- data/spec/outline_spec.rb +103 -63
- data/spec/png_spec.rb +25 -25
- data/spec/reference_spec.rb +8 -65
- data/spec/repeater_spec.rb +25 -11
- data/spec/security_spec.rb +44 -12
- data/spec/snapshot_spec.rb +38 -6
- data/spec/soft_mask_spec.rb +117 -0
- data/spec/span_spec.rb +10 -15
- data/spec/spec_helper.rb +32 -8
- data/spec/stamp_spec.rb +29 -30
- data/spec/stroke_styles_spec.rb +36 -18
- data/spec/table/span_dummy_spec.rb +17 -0
- data/spec/table_spec.rb +850 -104
- data/spec/text_at_spec.rb +19 -33
- data/spec/text_box_spec.rb +117 -64
- data/spec/text_rendering_mode_spec.rb +5 -5
- data/spec/text_spacing_spec.rb +20 -2
- data/spec/text_spec.rb +111 -59
- data/spec/transparency_spec.rb +5 -5
- metadata +477 -328
- data/HACKING +0 -50
- data/README +0 -141
- 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/16bit.dat +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/page_white_text.dat +0 -0
- data/data/images/rails.dat +0 -0
- data/data/images/rails.png +0 -0
- data/examples/bounding_box/bounding_boxes.rb +0 -44
- data/examples/bounding_box/indentation.rb +0 -35
- data/examples/bounding_box/russian_boxes.rb +0 -37
- data/examples/bounding_box/stretched_nesting.rb +0 -68
- data/examples/example_helper.rb +0 -8
- data/examples/general/background.rb +0 -24
- data/examples/general/canvas.rb +0 -16
- data/examples/general/context_sensitive_headers.rb +0 -38
- data/examples/general/float.rb +0 -12
- data/examples/general/margin.rb +0 -37
- data/examples/general/measurement_units.rb +0 -52
- data/examples/general/metadata-info.rb +0 -17
- data/examples/general/multi_page_layout.rb +0 -19
- data/examples/general/outlines.rb +0 -67
- data/examples/general/page_geometry.rb +0 -32
- data/examples/general/page_numbering.rb +0 -40
- data/examples/general/page_templates.rb +0 -20
- data/examples/general/repeaters.rb +0 -48
- data/examples/general/stamp.rb +0 -42
- data/examples/general/templates.rb +0 -14
- data/examples/graphics/basic_images.rb +0 -24
- data/examples/graphics/cmyk.rb +0 -13
- data/examples/graphics/curves.rb +0 -12
- data/examples/graphics/gradient.rb +0 -23
- data/examples/graphics/hexagon.rb +0 -14
- data/examples/graphics/image_fit.rb +0 -16
- data/examples/graphics/image_flow.rb +0 -38
- data/examples/graphics/image_position.rb +0 -18
- data/examples/graphics/line.rb +0 -33
- data/examples/graphics/png_types.rb +0 -23
- data/examples/graphics/polygons.rb +0 -17
- data/examples/graphics/remote_images.rb +0 -13
- data/examples/graphics/rounded_polygons.rb +0 -20
- data/examples/graphics/rounded_rectangle.rb +0 -21
- data/examples/graphics/ruport_style_helpers.rb +0 -20
- data/examples/graphics/stroke_bounds.rb +0 -21
- data/examples/graphics/stroke_cap_and_join.rb +0 -46
- data/examples/graphics/stroke_dash.rb +0 -43
- data/examples/graphics/transformations.rb +0 -53
- data/examples/graphics/transparency.rb +0 -27
- data/examples/grid/bounding_boxes.rb +0 -22
- data/examples/grid/column_gutter_grid.rb +0 -21
- data/examples/grid/multi_boxes.rb +0 -52
- data/examples/grid/show_grid.rb +0 -14
- data/examples/grid/simple_grid.rb +0 -21
- data/examples/m17n/chinese_text_wrapping.rb +0 -18
- data/examples/m17n/euro.rb +0 -16
- data/examples/m17n/full_win_ansi_character_list.rb +0 -20
- data/examples/m17n/sjis.rb +0 -29
- data/examples/m17n/utf8.rb +0 -14
- data/examples/security/hello_foo.rb +0 -9
- data/examples/table/bill.rb +0 -54
- data/examples/table/borders.rb +0 -25
- data/examples/table/cell.rb +0 -13
- data/examples/table/checkerboard.rb +0 -23
- data/examples/table/header.rb +0 -15
- data/examples/table/inline_format_table.rb +0 -13
- data/examples/table/multi_page_table.rb +0 -10
- data/examples/table/simple_table.rb +0 -25
- data/examples/table/subtable.rb +0 -13
- data/examples/table/widths.rb +0 -21
- data/examples/text/alignment.rb +0 -19
- data/examples/text/character_spacing.rb +0 -13
- data/examples/text/dfont.rb +0 -49
- data/examples/text/family_based_styling.rb +0 -25
- data/examples/text/font_calculations.rb +0 -92
- data/examples/text/font_size.rb +0 -34
- data/examples/text/hyphenation.rb +0 -45
- data/examples/text/indent_paragraphs.rb +0 -24
- data/examples/text/inline_format.rb +0 -104
- data/examples/text/kerning.rb +0 -31
- data/examples/text/rendering_mode.rb +0 -21
- data/examples/text/rotated.rb +0 -99
- data/examples/text/shaped_text_box.rb +0 -32
- data/examples/text/simple_text.rb +0 -18
- data/examples/text/simple_text_ttf.rb +0 -18
- data/examples/text/span.rb +0 -30
- data/examples/text/text_box.rb +0 -90
- data/examples/text/text_box_returning_excess.rb +0 -52
- data/examples/text/text_flow.rb +0 -68
- data/lib/prawn/compatibility.rb +0 -51
- data/lib/prawn/core/annotations.rb +0 -61
- data/lib/prawn/core/byte_string.rb +0 -9
- data/lib/prawn/core/destinations.rb +0 -90
- data/lib/prawn/core/document_state.rb +0 -78
- data/lib/prawn/core/literal_string.rb +0 -16
- data/lib/prawn/core/name_tree.rb +0 -165
- data/lib/prawn/core/object_store.rb +0 -264
- data/lib/prawn/core/page.rb +0 -213
- data/lib/prawn/core/pdf_object.rb +0 -108
- data/lib/prawn/core/reference.rb +0 -112
- data/lib/prawn/core/text/formatted/arranger.rb +0 -293
- data/lib/prawn/core/text/formatted/line_wrap.rb +0 -272
- data/lib/prawn/core/text/formatted/wrap.rb +0 -149
- data/lib/prawn/core/text.rb +0 -268
- data/lib/prawn/core.rb +0 -85
- data/lib/prawn/document/page_geometry.rb +0 -136
- data/lib/prawn/graphics/gradient.rb +0 -84
- data/spec/name_tree_spec.rb +0 -112
- data/spec/pdf_object_spec.rb +0 -170
- data/spec/template_spec.rb +0 -291
data/spec/document_spec.rb
CHANGED
@@ -1,15 +1,23 @@
|
|
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
|
+
|
6
|
+
describe "Prawn::Document.new" do
|
7
|
+
it "should not modify its argument" do
|
8
|
+
options = {:page_layout => :landscape}
|
9
|
+
Prawn::Document.new(options)
|
10
|
+
options.should == {:page_layout => :landscape}
|
11
|
+
end
|
12
|
+
end
|
5
13
|
|
6
14
|
describe "The cursor" do
|
7
|
-
it "should
|
15
|
+
it "should == pdf.y - bounds.absolute_bottom" do
|
8
16
|
pdf = Prawn::Document.new
|
9
17
|
pdf.cursor.should == pdf.bounds.top
|
10
|
-
|
18
|
+
|
11
19
|
pdf.y = 300
|
12
|
-
pdf.cursor.should == pdf.y - pdf.bounds.absolute_bottom
|
20
|
+
pdf.cursor.should == pdf.y - pdf.bounds.absolute_bottom
|
13
21
|
end
|
14
22
|
|
15
23
|
it "should be able to move relative to the bottom margin" do
|
@@ -19,14 +27,40 @@ describe "The cursor" do
|
|
19
27
|
pdf.cursor.should == 10
|
20
28
|
pdf.y.should == pdf.cursor + pdf.bounds.absolute_bottom
|
21
29
|
end
|
22
|
-
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
|
23
57
|
|
24
58
|
describe "when generating a document from a subclass" do
|
25
59
|
it "should be an instance of the subclass" do
|
26
60
|
custom_document = Class.new(Prawn::Document)
|
27
|
-
custom_document.generate(Tempfile.new("generate_test").path) do |e|
|
61
|
+
custom_document.generate(Tempfile.new("generate_test").path) do |e|
|
28
62
|
e.class.should == custom_document
|
29
|
-
e.should
|
63
|
+
e.should be_a_kind_of(Prawn::Document)
|
30
64
|
end
|
31
65
|
end
|
32
66
|
|
@@ -37,51 +71,51 @@ describe "when generating a document from a subclass" do
|
|
37
71
|
Prawn::Document.extensions << mod1 << mod2
|
38
72
|
|
39
73
|
custom_document = Class.new(Prawn::Document)
|
40
|
-
|
74
|
+
custom_document.extensions.should == [mod1, mod2]
|
41
75
|
|
42
76
|
# remove the extensions we added to prawn document
|
43
77
|
Prawn::Document.extensions.delete(mod1)
|
44
78
|
Prawn::Document.extensions.delete(mod2)
|
45
79
|
|
46
|
-
|
47
|
-
|
80
|
+
Prawn::Document.new.respond_to?(:test_extensions1).should be_false
|
81
|
+
Prawn::Document.new.respond_to?(:test_extensions2).should be_false
|
48
82
|
|
49
83
|
# verify these still exist on custom class
|
50
|
-
|
84
|
+
custom_document.extensions.should == [mod1, mod2]
|
51
85
|
|
52
|
-
|
53
|
-
|
86
|
+
custom_document.new.respond_to?(:test_extensions1).should be_true
|
87
|
+
custom_document.new.respond_to?(:test_extensions2).should be_true
|
54
88
|
end
|
55
89
|
|
56
90
|
end
|
57
91
|
|
58
|
-
|
59
|
-
describe "When creating multi-page documents" do
|
60
|
-
|
92
|
+
|
93
|
+
describe "When creating multi-page documents" do
|
94
|
+
|
61
95
|
before(:each) { create_pdf }
|
62
|
-
|
63
|
-
it "should initialize with a single page" do
|
96
|
+
|
97
|
+
it "should initialize with a single page" do
|
64
98
|
page_counter = PDF::Inspector::Page.analyze(@pdf.render)
|
65
|
-
|
66
|
-
page_counter.pages.size.should == 1
|
67
|
-
@pdf.page_count.should == 1
|
99
|
+
|
100
|
+
page_counter.pages.size.should == 1
|
101
|
+
@pdf.page_count.should == 1
|
68
102
|
end
|
69
|
-
|
103
|
+
|
70
104
|
it "should provide an accurate page_count" do
|
71
|
-
3.times { @pdf.start_new_page }
|
105
|
+
3.times { @pdf.start_new_page }
|
72
106
|
page_counter = PDF::Inspector::Page.analyze(@pdf.render)
|
73
|
-
|
107
|
+
|
74
108
|
page_counter.pages.size.should == 4
|
75
109
|
@pdf.page_count.should == 4
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
79
113
|
|
80
114
|
describe "When beginning each new page" do
|
81
115
|
|
82
116
|
describe "Background template feature" do
|
83
117
|
before(:each) do
|
84
|
-
@filename = "#{Prawn::
|
118
|
+
@filename = "#{Prawn::DATADIR}/images/pigs.jpg"
|
85
119
|
@pdf = Prawn::Document.new(:background => @filename)
|
86
120
|
end
|
87
121
|
it "should place a background image if it is in options block" do
|
@@ -94,11 +128,36 @@ describe "When beginning each new page" do
|
|
94
128
|
@pdf.instance_variable_defined?(:@background).should == true
|
95
129
|
@pdf.instance_variable_get(:@background).should == @filename
|
96
130
|
end
|
97
|
-
|
98
|
-
|
131
|
+
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "Prawn::Document#float" do
|
139
|
+
it "should restore the original y-position" do
|
140
|
+
create_pdf
|
141
|
+
orig_y = @pdf.y
|
142
|
+
@pdf.float { @pdf.text "Foo" }
|
143
|
+
@pdf.y.should == orig_y
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should teleport across pages if necessary" do
|
147
|
+
create_pdf
|
148
|
+
|
149
|
+
@pdf.float do
|
150
|
+
@pdf.text "Foo"
|
151
|
+
@pdf.start_new_page
|
152
|
+
@pdf.text "Bar"
|
153
|
+
end
|
154
|
+
@pdf.text "Baz"
|
155
|
+
|
156
|
+
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
157
|
+
pages.size.should == 2
|
158
|
+
pages[0][:strings].should == ["Foo", "Baz"]
|
159
|
+
pages[1][:strings].should == ["Bar"]
|
99
160
|
end
|
100
|
-
|
101
|
-
|
102
161
|
end
|
103
162
|
|
104
163
|
describe "The page_number method" do
|
@@ -123,7 +182,7 @@ end
|
|
123
182
|
|
124
183
|
describe "on_page_create callback" do
|
125
184
|
before do
|
126
|
-
create_pdf
|
185
|
+
create_pdf
|
127
186
|
end
|
128
187
|
|
129
188
|
it "should be invoked with document" do
|
@@ -144,34 +203,34 @@ describe "on_page_create callback" do
|
|
144
203
|
|
145
204
|
5.times { @pdf.start_new_page }
|
146
205
|
end
|
147
|
-
|
206
|
+
|
148
207
|
it "should be replaceable" do
|
149
208
|
trigger1 = mock()
|
150
209
|
trigger1.expects(:fire).times(1)
|
151
|
-
|
210
|
+
|
152
211
|
trigger2 = mock()
|
153
212
|
trigger2.expects(:fire).times(1)
|
154
213
|
|
155
214
|
@pdf.on_page_create { trigger1.fire }
|
156
|
-
|
215
|
+
|
157
216
|
@pdf.start_new_page
|
158
|
-
|
217
|
+
|
159
218
|
@pdf.on_page_create { trigger2.fire }
|
160
|
-
|
219
|
+
|
161
220
|
@pdf.start_new_page
|
162
221
|
end
|
163
|
-
|
222
|
+
|
164
223
|
it "should be clearable by calling on_page_create without a block" do
|
165
224
|
trigger = mock()
|
166
225
|
trigger.expects(:fire).times(1)
|
167
226
|
|
168
227
|
@pdf.on_page_create { trigger.fire }
|
169
228
|
|
170
|
-
@pdf.start_new_page
|
171
|
-
|
229
|
+
@pdf.start_new_page
|
230
|
+
|
172
231
|
@pdf.on_page_create
|
173
|
-
|
174
|
-
@pdf.start_new_page
|
232
|
+
|
233
|
+
@pdf.start_new_page
|
175
234
|
end
|
176
235
|
|
177
236
|
end
|
@@ -181,8 +240,8 @@ describe "Document compression" do
|
|
181
240
|
it "should not compress the page content stream if compression is disabled" do
|
182
241
|
|
183
242
|
pdf = Prawn::Document.new(:compress => false)
|
184
|
-
pdf.page.content.stubs(:
|
185
|
-
pdf.page.content.expects(:
|
243
|
+
pdf.page.content.stream.stubs(:compress!).returns(true)
|
244
|
+
pdf.page.content.stream.expects(:compress!).never
|
186
245
|
|
187
246
|
pdf.text "Hi There" * 20
|
188
247
|
pdf.render
|
@@ -191,8 +250,8 @@ describe "Document compression" do
|
|
191
250
|
it "should compress the page content stream if compression is enabled" do
|
192
251
|
|
193
252
|
pdf = Prawn::Document.new(:compress => true)
|
194
|
-
pdf.page.content.stubs(:
|
195
|
-
pdf.page.content.expects(:
|
253
|
+
pdf.page.content.stream.stubs(:compress!).returns(true)
|
254
|
+
pdf.page.content.stream.expects(:compress!).once
|
196
255
|
|
197
256
|
pdf.text "Hi There" * 20
|
198
257
|
pdf.render
|
@@ -202,14 +261,14 @@ describe "Document compression" do
|
|
202
261
|
doc_uncompressed = Prawn::Document.new
|
203
262
|
doc_compressed = Prawn::Document.new(:compress => true)
|
204
263
|
[doc_compressed, doc_uncompressed].each do |pdf|
|
205
|
-
pdf.font "#{Prawn::
|
264
|
+
pdf.font "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
|
206
265
|
pdf.text "更可怕的是,同质化竞争对手可以按照URL中后面这个ID来遍历" * 10
|
207
266
|
end
|
208
267
|
|
209
|
-
doc_compressed.render.length.should
|
210
|
-
end
|
268
|
+
doc_compressed.render.length.should be < doc_uncompressed.render.length
|
269
|
+
end
|
211
270
|
|
212
|
-
end
|
271
|
+
end
|
213
272
|
|
214
273
|
describe "Document metadata" do
|
215
274
|
it "should output strings as UTF-16 with a byte order mark" do
|
@@ -229,11 +288,10 @@ describe "When reopening pages" do
|
|
229
288
|
pdf.go_to_page 1
|
230
289
|
pdf.text "More for page 1"
|
231
290
|
end
|
232
|
-
|
233
|
-
#
|
234
|
-
#
|
235
|
-
|
236
|
-
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)
|
237
295
|
end
|
238
296
|
|
239
297
|
it "should insert pages after the current page when calling start_new_page" do
|
@@ -250,27 +308,36 @@ describe "When reopening pages" do
|
|
250
308
|
pages[1][:strings].should == ["New page 2"]
|
251
309
|
pages[2][:strings].should == ["Old page 2"]
|
252
310
|
end
|
311
|
+
|
312
|
+
it "should update the bounding box to the new page's margin box" do
|
313
|
+
Prawn::Document.new do
|
314
|
+
start_new_page :layout => :landscape
|
315
|
+
lsize = [bounds.width, bounds.height]
|
316
|
+
go_to_page 1
|
317
|
+
[bounds.width, bounds.height].should == lsize.reverse
|
318
|
+
end
|
319
|
+
end
|
253
320
|
end
|
254
321
|
|
255
322
|
describe "When setting page size" do
|
256
323
|
it "should default to LETTER" do
|
257
324
|
@pdf = Prawn::Document.new
|
258
325
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
259
|
-
pages.first[:size].should ==
|
260
|
-
end
|
261
|
-
|
262
|
-
(
|
326
|
+
pages.first[:size].should == PDF::Core::PageGeometry::SIZES["LETTER"]
|
327
|
+
end
|
328
|
+
|
329
|
+
(PDF::Core::PageGeometry::SIZES.keys - ["LETTER"]).each do |k|
|
263
330
|
it "should provide #{k} geometry" do
|
264
331
|
@pdf = Prawn::Document.new(:page_size => k)
|
265
|
-
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
266
|
-
pages.first[:size].should ==
|
332
|
+
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
333
|
+
pages.first[:size].should == PDF::Core::PageGeometry::SIZES[k]
|
267
334
|
end
|
268
335
|
end
|
269
|
-
|
270
|
-
it "should allow custom page size" do
|
336
|
+
|
337
|
+
it "should allow custom page size" do
|
271
338
|
@pdf = Prawn::Document.new(:page_size => [1920, 1080] )
|
272
|
-
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
273
|
-
pages.first[:size].should == [1920, 1080]
|
339
|
+
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
340
|
+
pages.first[:size].should == [1920, 1080]
|
274
341
|
end
|
275
342
|
|
276
343
|
|
@@ -279,27 +346,34 @@ describe "When setting page size" do
|
|
279
346
|
@pdf.start_new_page
|
280
347
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
281
348
|
pages.each do |page|
|
282
|
-
page[:size].should ==
|
349
|
+
page[:size].should == PDF::Core::PageGeometry::SIZES["LEGAL"]
|
283
350
|
end
|
284
351
|
end
|
285
352
|
|
286
|
-
end
|
353
|
+
end
|
287
354
|
|
288
355
|
describe "When setting page layout" do
|
289
356
|
it "should reverse coordinates for landscape" do
|
290
357
|
@pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
|
291
|
-
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
292
|
-
pages.first[:size].should ==
|
293
|
-
end
|
358
|
+
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
359
|
+
pages.first[:size].should == PDF::Core::PageGeometry::SIZES["A4"].reverse
|
360
|
+
end
|
294
361
|
|
295
|
-
it "should retain page layout
|
362
|
+
it "should retain page layout by default when starting a new page" do
|
296
363
|
@pdf = Prawn::Document.new(:page_layout => :landscape)
|
297
364
|
@pdf.start_new_page(:trace => true)
|
298
365
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
299
366
|
pages.each do |page|
|
300
|
-
page[:size].should ==
|
367
|
+
page[:size].should == PDF::Core::PageGeometry::SIZES["LETTER"].reverse
|
301
368
|
end
|
302
369
|
end
|
370
|
+
|
371
|
+
it "should swap the bounds when starting a new page with different layout" do
|
372
|
+
@pdf = Prawn::Document.new
|
373
|
+
size = [@pdf.bounds.width, @pdf.bounds.height]
|
374
|
+
@pdf.start_new_page(:layout => :landscape)
|
375
|
+
[@pdf.bounds.width, @pdf.bounds.height].should == size.reverse
|
376
|
+
end
|
303
377
|
end
|
304
378
|
|
305
379
|
describe "The mask() feature" do
|
@@ -309,11 +383,11 @@ describe "The mask() feature" do
|
|
309
383
|
@pdf.mask(:y, :line_width) do
|
310
384
|
@pdf.y = y + 1
|
311
385
|
@pdf.line_width = line_width + 1
|
312
|
-
@pdf.y.
|
313
|
-
@pdf.line_width.
|
386
|
+
@pdf.y.should_not == y
|
387
|
+
@pdf.line_width.should_not == line_width
|
314
388
|
end
|
315
389
|
@pdf.y.should == y
|
316
|
-
@pdf.line_width.should == line_width
|
390
|
+
@pdf.line_width.should == line_width
|
317
391
|
end
|
318
392
|
end
|
319
393
|
|
@@ -342,14 +416,14 @@ describe "The group() feature" do
|
|
342
416
|
pages[1][:strings].should == ["Hello", "World"]
|
343
417
|
end
|
344
418
|
|
345
|
-
it "should
|
419
|
+
it "should raise_error CannotGroup if the content is too tall" do
|
346
420
|
lambda {
|
347
421
|
Prawn::Document.new do
|
348
422
|
group do
|
349
423
|
100.times { text "Too long" }
|
350
424
|
end
|
351
425
|
end.render
|
352
|
-
}.should
|
426
|
+
}.should raise_error(Prawn::Errors::CannotGroup)
|
353
427
|
end
|
354
428
|
|
355
429
|
it "should group within individual column boxes" do
|
@@ -373,25 +447,23 @@ describe "The group() feature" do
|
|
373
447
|
end
|
374
448
|
|
375
449
|
describe "The render() feature" do
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
str.encoding.to_s.should == "ASCII-8BIT"
|
382
|
-
end
|
450
|
+
it "should return a 8 bit encoded string on a m17n aware VM" do
|
451
|
+
@pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
|
452
|
+
@pdf.line [100,100], [200,200]
|
453
|
+
str = @pdf.render
|
454
|
+
str.encoding.to_s.should == "ASCII-8BIT"
|
383
455
|
end
|
384
456
|
|
385
457
|
it "should trigger before_render callbacks just before rendering" do
|
386
458
|
pdf = Prawn::Document.new
|
387
|
-
|
459
|
+
|
388
460
|
seq = sequence("callback_order")
|
389
461
|
|
390
462
|
# Verify the order: finalize -> fire callbacks -> render body
|
391
463
|
pdf.expects(:finalize_all_page_contents).in_sequence(seq)
|
392
464
|
trigger = mock()
|
393
465
|
trigger.expects(:fire).in_sequence(seq)
|
394
|
-
|
466
|
+
|
395
467
|
# Store away the render_body method to be called below
|
396
468
|
render_body = pdf.method(:render_body)
|
397
469
|
pdf.expects(:render_body).in_sequence(seq)
|
@@ -415,10 +487,10 @@ end
|
|
415
487
|
describe "The :optimize_objects option" do
|
416
488
|
before(:all) do
|
417
489
|
@wasteful_doc = lambda do |pdf|
|
418
|
-
pdf.transaction do
|
490
|
+
pdf.transaction do
|
419
491
|
pdf.start_new_page
|
420
492
|
pdf.text "Hidden text"
|
421
|
-
pdf.rollback
|
493
|
+
pdf.rollback
|
422
494
|
end
|
423
495
|
|
424
496
|
pdf.text "Hello world"
|
@@ -429,12 +501,12 @@ describe "The :optimize_objects option" do
|
|
429
501
|
wasteful_pdf = Prawn::Document.new(&@wasteful_doc)
|
430
502
|
frugal_pdf = Prawn::Document.new(:optimize_objects => true,
|
431
503
|
&@wasteful_doc)
|
432
|
-
frugal_pdf.render.size.should
|
504
|
+
frugal_pdf.render.size.should be < wasteful_pdf.render.size
|
433
505
|
end
|
434
506
|
|
435
507
|
it "should default to :false" do
|
436
508
|
default_pdf = Prawn::Document.new(&@wasteful_doc)
|
437
|
-
wasteful_pdf = Prawn::Document.new(:optimize_objects => false,
|
509
|
+
wasteful_pdf = Prawn::Document.new(:optimize_objects => false,
|
438
510
|
&@wasteful_doc)
|
439
511
|
default_pdf.render.size.should == wasteful_pdf.render.size
|
440
512
|
end
|
@@ -516,32 +588,38 @@ describe "The number_pages method" do
|
|
516
588
|
before do
|
517
589
|
@pdf = Prawn::Document.new(:skip_page_creation => true)
|
518
590
|
end
|
519
|
-
|
591
|
+
|
520
592
|
it "replaces the '<page>' string with the proper page number" do
|
521
593
|
@pdf.start_new_page
|
522
594
|
@pdf.expects(:text_box).with("1, test", { :height => 50 })
|
523
595
|
@pdf.number_pages "<page>, test", {:page_filter => :all}
|
524
596
|
end
|
525
|
-
|
597
|
+
|
526
598
|
it "replaces the '<total>' string with the total page count" do
|
527
599
|
@pdf.start_new_page
|
528
600
|
@pdf.expects(:text_box).with("test, 1", { :height => 50 })
|
529
601
|
@pdf.number_pages "test, <total>", {:page_filter => :all}
|
530
602
|
end
|
531
|
-
|
532
|
-
it "must print
|
603
|
+
|
604
|
+
it "must print each page if given the :all page_filter" do
|
533
605
|
10.times { @pdf.start_new_page }
|
534
|
-
@pdf.expects(:text_box).
|
606
|
+
@pdf.expects(:text_box).times(10)
|
535
607
|
@pdf.number_pages "test", {:page_filter => :all}
|
536
608
|
end
|
537
609
|
|
538
|
-
it "must
|
610
|
+
it "must print each page if no :page_filter is specified" do
|
611
|
+
10.times { @pdf.start_new_page }
|
612
|
+
@pdf.expects(:text_box).times(10)
|
613
|
+
@pdf.number_pages "test"
|
614
|
+
end
|
615
|
+
|
616
|
+
it "must not print the page number if given a nil filter" do
|
539
617
|
10.times { @pdf.start_new_page }
|
540
618
|
@pdf.expects(:text_box).never
|
541
619
|
@pdf.number_pages "test", {:page_filter => nil}
|
542
620
|
end
|
543
|
-
|
544
|
-
context "start_count_at option" do
|
621
|
+
|
622
|
+
context "start_count_at option" do
|
545
623
|
[1, 2].each do |startat|
|
546
624
|
context "equal to #{startat}" do
|
547
625
|
it "increments the pages" do
|
@@ -550,10 +628,10 @@ describe "The number_pages method" do
|
|
550
628
|
@pdf.expects(:text_box).with("#{startat} 2", { :height => 50 })
|
551
629
|
@pdf.expects(:text_box).with("#{startat+1} 2", { :height => 50 })
|
552
630
|
@pdf.number_pages "<page> <total>", options
|
553
|
-
end
|
631
|
+
end
|
554
632
|
end
|
555
633
|
end
|
556
|
-
|
634
|
+
|
557
635
|
[0, nil].each do |val|
|
558
636
|
context "equal to #{val}" do
|
559
637
|
it "defaults to start at page 1" do
|
@@ -567,7 +645,7 @@ describe "The number_pages method" do
|
|
567
645
|
end
|
568
646
|
end
|
569
647
|
end
|
570
|
-
|
648
|
+
|
571
649
|
context "total_pages option" do
|
572
650
|
it "allows the total pages count to be overridden" do
|
573
651
|
2.times { @pdf.start_new_page }
|
@@ -576,7 +654,7 @@ describe "The number_pages method" do
|
|
576
654
|
@pdf.number_pages "<page> <total>", :page_filter => :all, :total_pages => 10
|
577
655
|
end
|
578
656
|
end
|
579
|
-
|
657
|
+
|
580
658
|
context "special page filter" do
|
581
659
|
context "such as :odd" do
|
582
660
|
it "increments the pages" do
|
@@ -621,6 +699,27 @@ describe "The number_pages method" do
|
|
621
699
|
end
|
622
700
|
end
|
623
701
|
end
|
702
|
+
|
703
|
+
context "height option" do
|
704
|
+
before do
|
705
|
+
@pdf.start_new_page
|
706
|
+
end
|
707
|
+
|
708
|
+
it "with 10 height" do
|
709
|
+
@pdf.expects(:text_box).with("1 1", { :height => 10 })
|
710
|
+
@pdf.number_pages "<page> <total>", :height => 10
|
711
|
+
end
|
712
|
+
|
713
|
+
it "with nil height" do
|
714
|
+
@pdf.expects(:text_box).with("1 1", { :height => nil })
|
715
|
+
@pdf.number_pages "<page> <total>", :height => nil
|
716
|
+
end
|
717
|
+
|
718
|
+
it "with no height" do
|
719
|
+
@pdf.expects(:text_box).with("1 1", { :height => 50 })
|
720
|
+
@pdf.number_pages "<page> <total>"
|
721
|
+
end
|
722
|
+
end
|
624
723
|
end
|
625
724
|
|
626
725
|
describe "The page_match? method" do
|
@@ -628,33 +727,33 @@ describe "The page_match? method" do
|
|
628
727
|
@pdf = Prawn::Document.new(:skip_page_creation => true)
|
629
728
|
10.times {@pdf.start_new_page}
|
630
729
|
end
|
631
|
-
|
730
|
+
|
632
731
|
it "returns nil given no filter" do
|
633
|
-
|
732
|
+
@pdf.page_match?(:nil, 1).should be_false
|
634
733
|
end
|
635
|
-
|
734
|
+
|
636
735
|
it "must provide an :all filter" do
|
637
|
-
|
736
|
+
(1..@pdf.page_count).all? { |i| @pdf.page_match?(:all, i) }.should be_true
|
638
737
|
end
|
639
738
|
|
640
739
|
it "must provide an :odd filter" do
|
641
740
|
odd, even = (1..@pdf.page_count).partition { |e| e % 2 == 1 }
|
642
|
-
|
643
|
-
|
741
|
+
odd.all? { |i| @pdf.page_match?(:odd, i) }.should be_true
|
742
|
+
even.any? { |i| @pdf.page_match?(:odd, i) }.should be_false
|
644
743
|
end
|
645
744
|
|
646
745
|
it "must be able to filter by an array of page numbers" do
|
647
746
|
fltr = [1,2,7]
|
648
|
-
|
747
|
+
(1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [1,2,7]
|
649
748
|
end
|
650
749
|
|
651
750
|
it "must be able to filter by a range of page numbers" do
|
652
751
|
fltr = 2..4
|
653
|
-
|
752
|
+
(1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [2,3,4]
|
654
753
|
end
|
655
754
|
|
656
755
|
it "must be able to filter by an arbitrary proc" do
|
657
756
|
fltr = lambda { |x| x == 1 or x % 3 == 0 }
|
658
|
-
|
659
|
-
end
|
757
|
+
(1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [1,3,6,9]
|
758
|
+
end
|
660
759
|
end
|
data/spec/extensions/mocha.rb
CHANGED
@@ -11,13 +11,12 @@
|
|
11
11
|
|
12
12
|
class ParameterChecker < Mocha::ParametersMatcher
|
13
13
|
def initialize(&matching_block)
|
14
|
+
@expected_parameters = [Mocha::ParameterMatchers::AnyParameters.new]
|
14
15
|
@matching_block = matching_block
|
15
|
-
@run_matching_block = false
|
16
16
|
end
|
17
17
|
|
18
18
|
def match?(actual_parameters = [])
|
19
|
-
@matching_block.call(*actual_parameters)
|
20
|
-
@run_matching_block = true
|
19
|
+
@matching_block.call(*actual_parameters)
|
21
20
|
|
22
21
|
true # always succeed
|
23
22
|
end
|