prawn 0.15.0 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +2 -2
- data/LICENSE +1 -1
- data/README.md +96 -0
- data/Rakefile +27 -30
- 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.alpha +0 -0
- data/data/images/16bit.dat +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/page_white_text.alpha +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/data/pdfs/nested_pages.pdf +13 -13
- data/lib/prawn.rb +21 -85
- data/lib/prawn/compatibility.rb +51 -0
- data/lib/prawn/core.rb +85 -0
- data/lib/prawn/core/annotations.rb +61 -0
- data/lib/prawn/core/byte_string.rb +9 -0
- data/lib/prawn/core/destinations.rb +90 -0
- data/lib/prawn/core/document_state.rb +78 -0
- data/lib/prawn/core/literal_string.rb +16 -0
- data/lib/prawn/core/name_tree.rb +177 -0
- data/lib/prawn/core/object_store.rb +264 -0
- data/lib/prawn/core/page.rb +215 -0
- data/lib/prawn/core/pdf_object.rb +108 -0
- data/lib/prawn/core/reference.rb +115 -0
- data/lib/prawn/core/text.rb +268 -0
- data/lib/prawn/core/text/formatted/arranger.rb +294 -0
- data/lib/prawn/core/text/formatted/line_wrap.rb +273 -0
- data/lib/prawn/core/text/formatted/wrap.rb +153 -0
- data/lib/prawn/document.rb +122 -155
- data/lib/prawn/document/bounding_box.rb +7 -36
- data/lib/prawn/document/column_box.rb +10 -38
- data/lib/prawn/document/graphics_state.rb +74 -11
- data/lib/prawn/document/internals.rb +23 -24
- data/lib/prawn/document/page_geometry.rb +136 -0
- data/lib/prawn/document/snapshot.rb +6 -7
- data/lib/prawn/document/span.rb +10 -12
- data/lib/prawn/encoding.rb +10 -9
- data/lib/prawn/errors.rb +30 -15
- data/lib/prawn/font.rb +104 -136
- data/lib/prawn/font/afm.rb +44 -46
- data/lib/prawn/font/dfont.rb +3 -4
- data/lib/prawn/font/ttf.rb +50 -31
- data/lib/prawn/graphics.rb +57 -302
- data/lib/prawn/graphics/cap_style.rb +3 -4
- data/lib/prawn/graphics/color.rb +5 -13
- data/lib/prawn/graphics/dash.rb +31 -53
- data/lib/prawn/graphics/gradient.rb +84 -0
- data/lib/prawn/graphics/join_style.rb +7 -9
- data/lib/prawn/graphics/transformation.rb +9 -10
- data/lib/prawn/graphics/transparency.rb +1 -3
- data/lib/prawn/images.rb +59 -69
- data/lib/prawn/images/image.rb +22 -6
- data/lib/prawn/images/jpg.rb +14 -20
- data/lib/prawn/images/png.rb +118 -61
- data/lib/prawn/layout.rb +15 -10
- data/lib/prawn/layout/grid.rb +54 -66
- data/lib/prawn/measurement_extensions.rb +6 -10
- data/lib/prawn/measurements.rb +21 -27
- data/lib/prawn/outline.rb +308 -6
- data/lib/prawn/repeater.rb +8 -10
- data/lib/prawn/security.rb +33 -55
- data/lib/prawn/security/arcfour.rb +0 -1
- data/lib/prawn/stamp.rb +3 -5
- data/lib/prawn/table.rb +60 -188
- data/lib/prawn/table/cell.rb +44 -272
- data/lib/prawn/table/cell/image.rb +3 -2
- data/lib/prawn/table/cell/in_table.rb +2 -4
- data/lib/prawn/table/cell/subtable.rb +2 -2
- data/lib/prawn/table/cell/text.rb +18 -41
- data/lib/prawn/table/cells.rb +48 -142
- data/lib/prawn/text.rb +25 -32
- data/lib/prawn/text/box.rb +6 -12
- data/lib/prawn/text/formatted.rb +4 -5
- data/lib/prawn/text/formatted/box.rb +59 -96
- data/lib/prawn/text/formatted/fragment.rb +23 -34
- data/lib/prawn/text/formatted/parser.rb +5 -15
- data/prawn.gemspec +13 -24
- data/spec/annotations_spec.rb +32 -16
- data/spec/bounding_box_spec.rb +17 -119
- data/spec/cell_spec.rb +42 -112
- data/spec/destinations_spec.rb +5 -5
- data/spec/document_spec.rb +111 -155
- data/spec/extensions/mocha.rb +0 -1
- data/spec/font_spec.rb +99 -149
- data/spec/formatted_text_arranger_spec.rb +43 -43
- data/spec/formatted_text_box_spec.rb +44 -43
- data/spec/formatted_text_fragment_spec.rb +8 -8
- data/spec/graphics_spec.rb +68 -151
- data/spec/grid_spec.rb +15 -26
- data/spec/images_spec.rb +30 -51
- data/spec/inline_formatted_text_parser_spec.rb +20 -69
- 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/name_tree_spec.rb +112 -0
- data/spec/object_store_spec.rb +106 -17
- data/spec/outline_spec.rb +63 -103
- data/spec/pdf_object_spec.rb +170 -0
- data/spec/png_spec.rb +25 -25
- data/spec/reference_spec.rb +65 -8
- data/spec/repeater_spec.rb +10 -10
- data/spec/security_spec.rb +12 -44
- data/spec/snapshot_spec.rb +7 -7
- data/spec/span_spec.rb +15 -10
- data/spec/spec_helper.rb +8 -32
- data/spec/stamp_spec.rb +30 -29
- data/spec/stroke_styles_spec.rb +18 -36
- data/spec/table_spec.rb +111 -706
- data/spec/template_spec.rb +297 -0
- data/spec/text_at_spec.rb +33 -19
- data/spec/text_box_spec.rb +64 -100
- data/spec/text_rendering_mode_spec.rb +5 -5
- data/spec/text_spacing_spec.rb +4 -4
- data/spec/text_spec.rb +64 -84
- data/spec/transparency_spec.rb +5 -5
- metadata +290 -463
- checksums.yaml +0 -7
- data/.yardopts +0 -10
- data/Gemfile +0 -11
- data/data/images/16bit.color +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.color +0 -0
- data/lib/prawn/font_metric_cache.rb +0 -47
- data/lib/prawn/graphics/patterns.rb +0 -138
- data/lib/prawn/image_handler.rb +0 -36
- data/lib/prawn/soft_mask.rb +0 -96
- data/lib/prawn/table/cell/span_dummy.rb +0 -93
- data/lib/prawn/table/column_width_calculator.rb +0 -61
- data/lib/prawn/text/formatted/arranger.rb +0 -290
- data/lib/prawn/text/formatted/line_wrap.rb +0 -266
- data/lib/prawn/text/formatted/wrap.rb +0 -150
- data/lib/prawn/utilities.rb +0 -46
- data/manual/basic_concepts/adding_pages.rb +0 -27
- data/manual/basic_concepts/basic_concepts.rb +0 -34
- data/manual/basic_concepts/creation.rb +0 -39
- data/manual/basic_concepts/cursor.rb +0 -33
- data/manual/basic_concepts/measurement.rb +0 -25
- data/manual/basic_concepts/origin.rb +0 -38
- data/manual/basic_concepts/other_cursor_helpers.rb +0 -40
- data/manual/bounding_box/bounding_box.rb +0 -39
- data/manual/bounding_box/bounds.rb +0 -49
- data/manual/bounding_box/canvas.rb +0 -24
- data/manual/bounding_box/creation.rb +0 -23
- data/manual/bounding_box/indentation.rb +0 -46
- data/manual/bounding_box/nesting.rb +0 -45
- data/manual/bounding_box/russian_boxes.rb +0 -40
- data/manual/bounding_box/stretchy.rb +0 -31
- data/manual/document_and_page_options/background.rb +0 -27
- data/manual/document_and_page_options/document_and_page_options.rb +0 -32
- data/manual/document_and_page_options/metadata.rb +0 -23
- data/manual/document_and_page_options/page_margins.rb +0 -38
- data/manual/document_and_page_options/page_size.rb +0 -34
- data/manual/document_and_page_options/print_scaling.rb +0 -20
- data/manual/example_file.rb +0 -111
- data/manual/example_helper.rb +0 -411
- data/manual/example_package.rb +0 -53
- data/manual/example_section.rb +0 -46
- data/manual/graphics/circle_and_ellipse.rb +0 -22
- data/manual/graphics/color.rb +0 -24
- data/manual/graphics/common_lines.rb +0 -30
- data/manual/graphics/fill_and_stroke.rb +0 -42
- data/manual/graphics/fill_rules.rb +0 -37
- data/manual/graphics/gradients.rb +0 -37
- data/manual/graphics/graphics.rb +0 -58
- data/manual/graphics/helper.rb +0 -24
- data/manual/graphics/line_width.rb +0 -35
- data/manual/graphics/lines_and_curves.rb +0 -41
- data/manual/graphics/polygon.rb +0 -29
- data/manual/graphics/rectangle.rb +0 -21
- data/manual/graphics/rotate.rb +0 -28
- data/manual/graphics/scale.rb +0 -41
- data/manual/graphics/soft_masks.rb +0 -46
- data/manual/graphics/stroke_cap.rb +0 -31
- data/manual/graphics/stroke_dash.rb +0 -48
- data/manual/graphics/stroke_join.rb +0 -30
- data/manual/graphics/translate.rb +0 -29
- data/manual/graphics/transparency.rb +0 -35
- data/manual/images/absolute_position.rb +0 -23
- data/manual/images/fit.rb +0 -21
- data/manual/images/horizontal.rb +0 -25
- data/manual/images/images.rb +0 -40
- data/manual/images/plain_image.rb +0 -18
- data/manual/images/scale.rb +0 -22
- data/manual/images/vertical.rb +0 -28
- data/manual/images/width_and_height.rb +0 -25
- data/manual/layout/boxes.rb +0 -27
- data/manual/layout/content.rb +0 -25
- data/manual/layout/layout.rb +0 -28
- data/manual/layout/simple_grid.rb +0 -23
- data/manual/manual/cover.rb +0 -36
- data/manual/manual/foreword.rb +0 -85
- data/manual/manual/how_to_read_this_manual.rb +0 -41
- data/manual/manual/manual.rb +0 -34
- data/manual/outline/add_subsection_to.rb +0 -61
- data/manual/outline/insert_section_after.rb +0 -47
- data/manual/outline/outline.rb +0 -32
- data/manual/outline/sections_and_pages.rb +0 -67
- data/manual/repeatable_content/page_numbering.rb +0 -54
- data/manual/repeatable_content/repeatable_content.rb +0 -31
- data/manual/repeatable_content/repeater.rb +0 -55
- data/manual/repeatable_content/stamp.rb +0 -41
- data/manual/security/encryption.rb +0 -31
- data/manual/security/permissions.rb +0 -38
- data/manual/security/security.rb +0 -28
- data/manual/syntax_highlight.rb +0 -52
- data/manual/table/basic_block.rb +0 -53
- data/manual/table/before_rendering_page.rb +0 -26
- data/manual/table/cell_border_lines.rb +0 -24
- data/manual/table/cell_borders_and_bg.rb +0 -31
- data/manual/table/cell_dimensions.rb +0 -30
- data/manual/table/cell_text.rb +0 -38
- data/manual/table/column_widths.rb +0 -30
- data/manual/table/content_and_subtables.rb +0 -39
- data/manual/table/creation.rb +0 -27
- data/manual/table/filtering.rb +0 -36
- data/manual/table/flow_and_header.rb +0 -17
- data/manual/table/image_cells.rb +0 -33
- data/manual/table/position.rb +0 -29
- data/manual/table/row_colors.rb +0 -20
- data/manual/table/span.rb +0 -30
- data/manual/table/style.rb +0 -22
- data/manual/table/table.rb +0 -52
- data/manual/table/width.rb +0 -27
- data/manual/text/alignment.rb +0 -44
- data/manual/text/color.rb +0 -24
- data/manual/text/column_box.rb +0 -32
- data/manual/text/fallback_fonts.rb +0 -37
- data/manual/text/font.rb +0 -41
- data/manual/text/font_size.rb +0 -45
- data/manual/text/font_style.rb +0 -23
- data/manual/text/formatted_callbacks.rb +0 -60
- data/manual/text/formatted_text.rb +0 -54
- data/manual/text/free_flowing_text.rb +0 -51
- data/manual/text/group.rb +0 -31
- data/manual/text/inline.rb +0 -43
- data/manual/text/kerning_and_character_spacing.rb +0 -39
- data/manual/text/leading.rb +0 -25
- data/manual/text/line_wrapping.rb +0 -41
- data/manual/text/paragraph_indentation.rb +0 -26
- data/manual/text/positioned_text.rb +0 -38
- data/manual/text/registering_families.rb +0 -48
- data/manual/text/rendering_and_color.rb +0 -37
- data/manual/text/right_to_left_text.rb +0 -43
- data/manual/text/rotation.rb +0 -43
- data/manual/text/single_usage.rb +0 -37
- data/manual/text/text.rb +0 -75
- data/manual/text/text_box_excess.rb +0 -32
- data/manual/text/text_box_extensions.rb +0 -45
- data/manual/text/text_box_overflow.rb +0 -44
- data/manual/text/utf8.rb +0 -28
- data/manual/text/win_ansi_charset.rb +0 -59
- data/spec/acceptance/png.rb +0 -23
- data/spec/column_box_spec.rb +0 -65
- data/spec/extensions/encoding_helpers.rb +0 -9
- data/spec/font_metric_cache_spec.rb +0 -52
- data/spec/image_handler_spec.rb +0 -54
- data/spec/soft_mask_spec.rb +0 -117
- data/spec/table/span_dummy_spec.rb +0 -17
data/spec/cell_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
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
4
|
|
5
5
|
module CellHelpers
|
6
6
|
|
@@ -10,6 +10,10 @@ module CellHelpers
|
|
10
10
|
Prawn::Table::Cell::Text.new(@pdf, at, options)
|
11
11
|
end
|
12
12
|
|
13
|
+
def close?(actual, expected, epsilon=0.01)
|
14
|
+
(actual - expected).abs < epsilon
|
15
|
+
end
|
16
|
+
|
13
17
|
end
|
14
18
|
|
15
19
|
describe "Prawn::Table::Cell" do
|
@@ -26,18 +30,13 @@ describe "Prawn::Table::Cell" do
|
|
26
30
|
end
|
27
31
|
|
28
32
|
it "should return a Cell" do
|
29
|
-
@pdf.cell(:content => "text").should
|
30
|
-
end
|
31
|
-
|
32
|
-
it "accepts :content => nil in a hash" do
|
33
|
-
@pdf.cell(:content => nil).should be_a_kind_of(Prawn::Table::Cell::Text)
|
34
|
-
@pdf.make_cell(:content => nil).should be_a_kind_of(Prawn::Table::Cell::Text)
|
33
|
+
@pdf.cell(:content => "text").should.be.a.kind_of Prawn::Table::Cell
|
35
34
|
end
|
36
35
|
|
37
36
|
it "should convert nil, Numeric, and Date values to strings" do
|
38
37
|
[nil, 123, 123.45, Date.today].each do |value|
|
39
38
|
c = @pdf.cell(:content => value)
|
40
|
-
c.should
|
39
|
+
c.should.be.a.kind_of Prawn::Table::Cell::Text
|
41
40
|
c.content.should == value.to_s
|
42
41
|
end
|
43
42
|
end
|
@@ -46,7 +45,7 @@ describe "Prawn::Table::Cell" do
|
|
46
45
|
# used for table([[{:text => "...", :font_style => :bold, ...}, ...]])
|
47
46
|
c = Prawn::Table::Cell.make(@pdf,
|
48
47
|
{:content => 'hello', :font_style => :bold})
|
49
|
-
c.should
|
48
|
+
c.should.be.a.kind_of Prawn::Table::Cell::Text
|
50
49
|
c.content.should == "hello"
|
51
50
|
c.font.name.should == 'Helvetica-Bold'
|
52
51
|
end
|
@@ -57,22 +56,22 @@ describe "Prawn::Table::Cell" do
|
|
57
56
|
@pdf.expects(:move_down)
|
58
57
|
@pdf.expects(:draw_text!).with { |text, options| text == "hello world" }
|
59
58
|
|
60
|
-
@pdf.cell(:content => "hello world",
|
59
|
+
@pdf.cell(:content => "hello world",
|
61
60
|
:at => [10, 20],
|
62
61
|
:padding => [30, 40],
|
63
|
-
:size => 7,
|
62
|
+
:size => 7,
|
64
63
|
:font_style => :bold)
|
65
64
|
end
|
66
65
|
end
|
67
|
-
|
66
|
+
|
68
67
|
describe "Prawn::Document#make_cell" do
|
69
68
|
it "should not draw the cell" do
|
70
69
|
Prawn::Table::Cell::Text.any_instance.expects(:draw).never
|
71
70
|
@pdf.make_cell("text")
|
72
71
|
end
|
73
|
-
|
72
|
+
|
74
73
|
it "should return a Cell" do
|
75
|
-
@pdf.make_cell("text", :size => 7).should
|
74
|
+
@pdf.make_cell("text", :size => 7).should.be.a.kind_of Prawn::Table::Cell
|
76
75
|
end
|
77
76
|
end
|
78
77
|
|
@@ -87,12 +86,6 @@ describe "Prawn::Table::Cell" do
|
|
87
86
|
|
88
87
|
c.style(:padding => 50, :size => 7)
|
89
88
|
end
|
90
|
-
|
91
|
-
it "ignores unknown properties" do
|
92
|
-
c = cell(:content => 'text')
|
93
|
-
|
94
|
-
c.style(:foobarbaz => 'frobnitz')
|
95
|
-
end
|
96
89
|
end
|
97
90
|
|
98
91
|
describe "cell width" do
|
@@ -110,7 +103,7 @@ describe "Prawn::Table::Cell" do
|
|
110
103
|
|
111
104
|
it "should incorporate padding when specified" do
|
112
105
|
c = cell(:content => "text", :padding => [1, 2, 3, 4])
|
113
|
-
c.width.should
|
106
|
+
c.width.should.be.close(@pdf.width_of("text") + 6, 0.01)
|
114
107
|
end
|
115
108
|
|
116
109
|
it "should allow width to be reset after it has been calculated" do
|
@@ -124,7 +117,7 @@ describe "Prawn::Table::Cell" do
|
|
124
117
|
it "should return proper width with size set" do
|
125
118
|
text = "text " * 4
|
126
119
|
c = cell(:content => text, :size => 7)
|
127
|
-
c.width.should ==
|
120
|
+
c.width.should ==
|
128
121
|
@pdf.width_of(text, :size => 7) + c.padding[1] + c.padding[3]
|
129
122
|
end
|
130
123
|
|
@@ -135,14 +128,17 @@ describe "Prawn::Table::Cell" do
|
|
135
128
|
|
136
129
|
it "content_width should exclude padding even with manual :width" do
|
137
130
|
c = cell(:content => "text", :padding => 10, :width => 400)
|
138
|
-
c.content_width.should
|
131
|
+
c.content_width.should.be.close(380, 0.01)
|
139
132
|
end
|
140
133
|
|
141
134
|
it "should have a reasonable minimum width that can fit @content" do
|
142
135
|
c = cell(:content => "text", :padding => 10)
|
143
136
|
min_content_width = c.min_width - c.padding[1] - c.padding[3]
|
144
137
|
|
145
|
-
@pdf.height_of("text", :width => min_content_width).
|
138
|
+
lambda { @pdf.height_of("text", :width => min_content_width) }.
|
139
|
+
should.not.raise(Prawn::Errors::CannotFit)
|
140
|
+
|
141
|
+
@pdf.height_of("text", :width => min_content_width).should.be <
|
146
142
|
(5 * @pdf.height_of("text"))
|
147
143
|
end
|
148
144
|
|
@@ -151,14 +147,14 @@ describe "Prawn::Table::Cell" do
|
|
151
147
|
c.padding = 0
|
152
148
|
|
153
149
|
# Make sure we use the new value of padding in calculating min_width
|
154
|
-
c.min_width.should
|
150
|
+
c.min_width.should.be < 100
|
155
151
|
end
|
156
152
|
|
157
153
|
it "should defer min_width's evaluation of size" do
|
158
154
|
c = cell(:content => "text", :size => 50)
|
159
155
|
c.size = 8
|
160
156
|
c.padding = 0
|
161
|
-
c.min_width.should
|
157
|
+
c.min_width.should.be < 10
|
162
158
|
end
|
163
159
|
|
164
160
|
end
|
@@ -168,7 +164,7 @@ describe "Prawn::Table::Cell" do
|
|
168
164
|
|
169
165
|
it "should be calculated for text" do
|
170
166
|
c = cell(:content => "text")
|
171
|
-
c.height.should ==
|
167
|
+
c.height.should ==
|
172
168
|
@pdf.height_of("text", :width => @pdf.width_of("text")) +
|
173
169
|
c.padding[0] + c.padding[3]
|
174
170
|
end
|
@@ -180,8 +176,8 @@ describe "Prawn::Table::Cell" do
|
|
180
176
|
|
181
177
|
it "should incorporate :padding when specified" do
|
182
178
|
c = cell(:content => "text", :padding => [1, 2, 3, 4])
|
183
|
-
c.height.should
|
184
|
-
@pdf.height_of("text", :width => @pdf.width_of("text")))
|
179
|
+
c.height.should.be.close(1 + 3 +
|
180
|
+
@pdf.height_of("text", :width => @pdf.width_of("text")), 0.01)
|
185
181
|
end
|
186
182
|
|
187
183
|
it "should allow height to be reset after it has been calculated" do
|
@@ -215,10 +211,10 @@ describe "Prawn::Table::Cell" do
|
|
215
211
|
c = cell(:content => "text", :padding => 10)
|
216
212
|
c.content_height.should == @pdf.height_of("text")
|
217
213
|
end
|
218
|
-
|
214
|
+
|
219
215
|
it "content_height should exclude padding even with manual :height" do
|
220
216
|
c = cell(:content => "text", :padding => 10, :height => 400)
|
221
|
-
c.content_height.should
|
217
|
+
c.content_height.should.be.close(380, 0.01)
|
222
218
|
end
|
223
219
|
end
|
224
220
|
|
@@ -239,7 +235,7 @@ describe "Prawn::Table::Cell" do
|
|
239
235
|
c = cell(:content => "text", :padding => [20, 30])
|
240
236
|
c.padding.should == [20, 30, 20, 30]
|
241
237
|
end
|
242
|
-
|
238
|
+
|
243
239
|
it "should accept [t,h,b]" do
|
244
240
|
c = cell(:content => "text", :padding => [10, 20, 30])
|
245
241
|
c.padding.should == [10, 20, 30, 20]
|
@@ -253,7 +249,7 @@ describe "Prawn::Table::Cell" do
|
|
253
249
|
it "should reject other formats" do
|
254
250
|
lambda{
|
255
251
|
cell(:content => "text", :padding => [10])
|
256
|
-
}.should
|
252
|
+
}.should.raise(ArgumentError)
|
257
253
|
end
|
258
254
|
end
|
259
255
|
|
@@ -267,10 +263,10 @@ describe "Prawn::Table::Cell" do
|
|
267
263
|
@pdf.stubs(:fill_color)
|
268
264
|
@pdf.expects(:fill_color).with('123456')
|
269
265
|
@pdf.expects(:fill_rectangle).checking do |(x, y), w, h|
|
270
|
-
x.should
|
271
|
-
y.should
|
272
|
-
w.should
|
273
|
-
h.should
|
266
|
+
x.should.be.close(0, 0.01)
|
267
|
+
y.should.be.close(@pdf.cursor, 0.01)
|
268
|
+
w.should.be.close(29.344, 0.01)
|
269
|
+
h.should.be.close(23.872, 0.01)
|
274
270
|
end
|
275
271
|
@pdf.cell(:content => "text", :background_color => '123456')
|
276
272
|
end
|
@@ -283,10 +279,10 @@ describe "Prawn::Table::Cell" do
|
|
283
279
|
@pdf.stubs(:fill_color)
|
284
280
|
@pdf.expects(:fill_color).with('123456')
|
285
281
|
@pdf.expects(:fill_rectangle).checking do |(x, y), w, h|
|
286
|
-
x.should
|
287
|
-
y.should
|
288
|
-
w.should
|
289
|
-
h.should
|
282
|
+
x.should.be.close(12.0, 0.01)
|
283
|
+
y.should.be.close(34.0, 0.01)
|
284
|
+
w.should.be.close(29.344, 0.01)
|
285
|
+
h.should.be.close(23.872, 0.01)
|
290
286
|
end
|
291
287
|
c = @pdf.make_cell(:content => "text", :background_color => '123456')
|
292
288
|
c.draw([12.0, 34.0])
|
@@ -412,34 +408,8 @@ describe "Prawn::Table::Cell" do
|
|
412
408
|
:border_width => [2, 3, 4, 5])
|
413
409
|
c.border_widths.should == [2, 3, 4, 5]
|
414
410
|
end
|
415
|
-
|
416
|
-
it "should set default border lines to :solid" do
|
417
|
-
c = @pdf.cell(:content => "text")
|
418
|
-
c.border_top_line.should == :solid
|
419
|
-
c.border_right_line.should == :solid
|
420
|
-
c.border_bottom_line.should == :solid
|
421
|
-
c.border_left_line.should == :solid
|
422
|
-
c.border_lines.should == [:solid] * 4
|
423
|
-
end
|
424
|
-
|
425
|
-
it "should set border line with :border_..._line" do
|
426
|
-
c = @pdf.cell(:content => "text", :border_bottom_line => :dotted)
|
427
|
-
c.border_bottom_line.should == :dotted
|
428
|
-
c.border_lines[2].should == :dotted
|
429
|
-
end
|
430
|
-
|
431
|
-
it "should set border lines with :border_lines" do
|
432
|
-
c = @pdf.cell(:content => "text",
|
433
|
-
:border_lines => [:solid, :dotted, :dashed, :solid])
|
434
|
-
c.border_lines.should == [:solid, :dotted, :dashed, :solid]
|
435
|
-
end
|
436
411
|
end
|
437
412
|
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
413
|
describe "Text cell attributes" do
|
444
414
|
include CellHelpers
|
445
415
|
|
@@ -469,47 +439,6 @@ describe "Prawn::Table::Cell" do
|
|
469
439
|
c.draw
|
470
440
|
end
|
471
441
|
|
472
|
-
it "supports variant styles of the current font" do
|
473
|
-
font_path = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
|
474
|
-
@pdf.font_families.merge!("Action Man" => {
|
475
|
-
:normal => { :file => font_path, :font => "ActionMan" },
|
476
|
-
:bold => { :file => font_path, :font => "ActionMan-Bold" },
|
477
|
-
})
|
478
|
-
@pdf.font "Action Man"
|
479
|
-
|
480
|
-
c = cell(:content => "text", :font_style => :bold)
|
481
|
-
|
482
|
-
box = Prawn::Text::Box.new("text", :document => @pdf)
|
483
|
-
Prawn::Text::Box.expects(:new).checking do |text, options|
|
484
|
-
text.should == "text"
|
485
|
-
options[:style].should == :bold
|
486
|
-
@pdf.font.family.should == 'Action Man'
|
487
|
-
end.at_least_once.returns(box)
|
488
|
-
|
489
|
-
c.draw
|
490
|
-
end
|
491
|
-
|
492
|
-
|
493
|
-
it "uses the style of the current font if none given" do
|
494
|
-
font_path = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
|
495
|
-
@pdf.font_families.merge!("Action Man" => {
|
496
|
-
:normal => { :file => font_path, :font => "ActionMan" },
|
497
|
-
:bold => { :file => font_path, :font => "ActionMan-Bold" },
|
498
|
-
})
|
499
|
-
@pdf.font "Action Man", :style => :bold
|
500
|
-
|
501
|
-
c = cell(:content => "text")
|
502
|
-
|
503
|
-
box = Prawn::Text::Box.new("text", :document => @pdf)
|
504
|
-
Prawn::Text::Box.expects(:new).checking do |text, options|
|
505
|
-
text.should == "text"
|
506
|
-
@pdf.font.family.should == 'Action Man'
|
507
|
-
@pdf.font.options[:style].should == :bold
|
508
|
-
end.at_least_once.returns(box)
|
509
|
-
|
510
|
-
c.draw
|
511
|
-
end
|
512
|
-
|
513
442
|
it "should allow inline formatting in cells" do
|
514
443
|
c = cell(:content => "foo <b>bar</b> baz", :inline_format => true)
|
515
444
|
|
@@ -569,6 +498,7 @@ describe "Prawn::Table::Cell" do
|
|
569
498
|
c.content_width.should == font.compute_width_of("text")
|
570
499
|
end
|
571
500
|
end
|
501
|
+
|
572
502
|
end
|
573
503
|
|
574
504
|
describe "Image cells" do
|
@@ -579,11 +509,11 @@ describe "Image cells" do
|
|
579
509
|
describe "with default options" do
|
580
510
|
before(:each) do
|
581
511
|
@cell = Prawn::Table::Cell.make(@pdf,
|
582
|
-
:image => "#{Prawn::
|
512
|
+
:image => "#{Prawn::BASEDIR}/data/images/prawn.png")
|
583
513
|
end
|
584
514
|
|
585
515
|
it "should create a Cell::Image" do
|
586
|
-
@cell.should
|
516
|
+
@cell.should.be.a.kind_of(Prawn::Table::Cell::Image)
|
587
517
|
end
|
588
518
|
|
589
519
|
it "should pull the natural width and height from the image" do
|
@@ -595,7 +525,7 @@ describe "Image cells" do
|
|
595
525
|
describe "hash syntax" do
|
596
526
|
before(:each) do
|
597
527
|
@table = @pdf.make_table([[{
|
598
|
-
:image => "#{Prawn::
|
528
|
+
:image => "#{Prawn::BASEDIR}/data/images/prawn.png",
|
599
529
|
:scale => 2,
|
600
530
|
:fit => [100, 200],
|
601
531
|
:image_width => 123,
|
@@ -608,7 +538,7 @@ describe "Image cells" do
|
|
608
538
|
|
609
539
|
|
610
540
|
it "should create a Cell::Image" do
|
611
|
-
@cell.should
|
541
|
+
@cell.should.be.a.kind_of(Prawn::Table::Cell::Image)
|
612
542
|
end
|
613
543
|
|
614
544
|
it "should pass through image options" do
|
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")
|
4
|
-
|
5
|
-
describe "When creating destinations" do
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
6
4
|
|
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 equal 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,40 +27,14 @@ 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
|
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
|
30
|
+
end
|
57
31
|
|
58
32
|
describe "when generating a document from a subclass" do
|
59
33
|
it "should be an instance of the subclass" do
|
60
34
|
custom_document = Class.new(Prawn::Document)
|
61
|
-
custom_document.generate(Tempfile.new("generate_test").path) do |e|
|
35
|
+
custom_document.generate(Tempfile.new("generate_test").path) do |e|
|
62
36
|
e.class.should == custom_document
|
63
|
-
e.should
|
37
|
+
e.should.be.kind_of(Prawn::Document)
|
64
38
|
end
|
65
39
|
end
|
66
40
|
|
@@ -71,51 +45,51 @@ describe "when generating a document from a subclass" do
|
|
71
45
|
Prawn::Document.extensions << mod1 << mod2
|
72
46
|
|
73
47
|
custom_document = Class.new(Prawn::Document)
|
74
|
-
|
48
|
+
assert_equal [mod1, mod2], custom_document.extensions
|
75
49
|
|
76
50
|
# remove the extensions we added to prawn document
|
77
51
|
Prawn::Document.extensions.delete(mod1)
|
78
52
|
Prawn::Document.extensions.delete(mod2)
|
79
53
|
|
80
|
-
Prawn::Document.new.respond_to?(:test_extensions1)
|
81
|
-
Prawn::Document.new.respond_to?(:test_extensions2)
|
54
|
+
assert ! Prawn::Document.new.respond_to?(:test_extensions1)
|
55
|
+
assert ! Prawn::Document.new.respond_to?(:test_extensions2)
|
82
56
|
|
83
57
|
# verify these still exist on custom class
|
84
|
-
|
58
|
+
assert_equal [mod1, mod2], custom_document.extensions
|
85
59
|
|
86
|
-
custom_document.new.respond_to?(:test_extensions1)
|
87
|
-
custom_document.new.respond_to?(:test_extensions2)
|
60
|
+
assert custom_document.new.respond_to?(:test_extensions1)
|
61
|
+
assert custom_document.new.respond_to?(:test_extensions2)
|
88
62
|
end
|
89
63
|
|
90
64
|
end
|
91
65
|
|
92
|
-
|
93
|
-
describe "When creating multi-page documents" do
|
94
|
-
|
66
|
+
|
67
|
+
describe "When creating multi-page documents" do
|
68
|
+
|
95
69
|
before(:each) { create_pdf }
|
96
|
-
|
97
|
-
it "should initialize with a single page" do
|
70
|
+
|
71
|
+
it "should initialize with a single page" do
|
98
72
|
page_counter = PDF::Inspector::Page.analyze(@pdf.render)
|
99
|
-
|
100
|
-
page_counter.pages.size.should == 1
|
101
|
-
@pdf.page_count.should == 1
|
73
|
+
|
74
|
+
page_counter.pages.size.should == 1
|
75
|
+
@pdf.page_count.should == 1
|
102
76
|
end
|
103
|
-
|
77
|
+
|
104
78
|
it "should provide an accurate page_count" do
|
105
|
-
3.times { @pdf.start_new_page }
|
79
|
+
3.times { @pdf.start_new_page }
|
106
80
|
page_counter = PDF::Inspector::Page.analyze(@pdf.render)
|
107
|
-
|
81
|
+
|
108
82
|
page_counter.pages.size.should == 4
|
109
83
|
@pdf.page_count.should == 4
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
113
87
|
|
114
88
|
describe "When beginning each new page" do
|
115
89
|
|
116
90
|
describe "Background template feature" do
|
117
91
|
before(:each) do
|
118
|
-
@filename = "#{Prawn::
|
92
|
+
@filename = "#{Prawn::BASEDIR}/data/images/pigs.jpg"
|
119
93
|
@pdf = Prawn::Document.new(:background => @filename)
|
120
94
|
end
|
121
95
|
it "should place a background image if it is in options block" do
|
@@ -128,11 +102,11 @@ describe "When beginning each new page" do
|
|
128
102
|
@pdf.instance_variable_defined?(:@background).should == true
|
129
103
|
@pdf.instance_variable_get(:@background).should == @filename
|
130
104
|
end
|
131
|
-
|
132
|
-
|
105
|
+
|
106
|
+
|
133
107
|
end
|
134
|
-
|
135
|
-
|
108
|
+
|
109
|
+
|
136
110
|
end
|
137
111
|
|
138
112
|
describe "Prawn::Document#float" do
|
@@ -145,7 +119,7 @@ describe "Prawn::Document#float" do
|
|
145
119
|
|
146
120
|
it "should teleport across pages if necessary" do
|
147
121
|
create_pdf
|
148
|
-
|
122
|
+
|
149
123
|
@pdf.float do
|
150
124
|
@pdf.text "Foo"
|
151
125
|
@pdf.start_new_page
|
@@ -182,7 +156,7 @@ end
|
|
182
156
|
|
183
157
|
describe "on_page_create callback" do
|
184
158
|
before do
|
185
|
-
create_pdf
|
159
|
+
create_pdf
|
186
160
|
end
|
187
161
|
|
188
162
|
it "should be invoked with document" do
|
@@ -203,34 +177,34 @@ describe "on_page_create callback" do
|
|
203
177
|
|
204
178
|
5.times { @pdf.start_new_page }
|
205
179
|
end
|
206
|
-
|
180
|
+
|
207
181
|
it "should be replaceable" do
|
208
182
|
trigger1 = mock()
|
209
183
|
trigger1.expects(:fire).times(1)
|
210
|
-
|
184
|
+
|
211
185
|
trigger2 = mock()
|
212
186
|
trigger2.expects(:fire).times(1)
|
213
187
|
|
214
188
|
@pdf.on_page_create { trigger1.fire }
|
215
|
-
|
189
|
+
|
216
190
|
@pdf.start_new_page
|
217
|
-
|
191
|
+
|
218
192
|
@pdf.on_page_create { trigger2.fire }
|
219
|
-
|
193
|
+
|
220
194
|
@pdf.start_new_page
|
221
195
|
end
|
222
|
-
|
196
|
+
|
223
197
|
it "should be clearable by calling on_page_create without a block" do
|
224
198
|
trigger = mock()
|
225
199
|
trigger.expects(:fire).times(1)
|
226
200
|
|
227
201
|
@pdf.on_page_create { trigger.fire }
|
228
202
|
|
229
|
-
@pdf.start_new_page
|
230
|
-
|
203
|
+
@pdf.start_new_page
|
204
|
+
|
231
205
|
@pdf.on_page_create
|
232
|
-
|
233
|
-
@pdf.start_new_page
|
206
|
+
|
207
|
+
@pdf.start_new_page
|
234
208
|
end
|
235
209
|
|
236
210
|
end
|
@@ -240,8 +214,8 @@ describe "Document compression" do
|
|
240
214
|
it "should not compress the page content stream if compression is disabled" do
|
241
215
|
|
242
216
|
pdf = Prawn::Document.new(:compress => false)
|
243
|
-
pdf.page.content.
|
244
|
-
pdf.page.content.
|
217
|
+
pdf.page.content.stubs(:compress_stream).returns(true)
|
218
|
+
pdf.page.content.expects(:compress_stream).never
|
245
219
|
|
246
220
|
pdf.text "Hi There" * 20
|
247
221
|
pdf.render
|
@@ -250,8 +224,8 @@ describe "Document compression" do
|
|
250
224
|
it "should compress the page content stream if compression is enabled" do
|
251
225
|
|
252
226
|
pdf = Prawn::Document.new(:compress => true)
|
253
|
-
pdf.page.content.
|
254
|
-
pdf.page.content.
|
227
|
+
pdf.page.content.stubs(:compress_stream).returns(true)
|
228
|
+
pdf.page.content.expects(:compress_stream).once
|
255
229
|
|
256
230
|
pdf.text "Hi There" * 20
|
257
231
|
pdf.render
|
@@ -261,14 +235,14 @@ describe "Document compression" do
|
|
261
235
|
doc_uncompressed = Prawn::Document.new
|
262
236
|
doc_compressed = Prawn::Document.new(:compress => true)
|
263
237
|
[doc_compressed, doc_uncompressed].each do |pdf|
|
264
|
-
pdf.font "#{Prawn::
|
238
|
+
pdf.font "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
|
265
239
|
pdf.text "更可怕的是,同质化竞争对手可以按照URL中后面这个ID来遍历" * 10
|
266
240
|
end
|
267
241
|
|
268
|
-
doc_compressed.render.length.should
|
269
|
-
end
|
242
|
+
doc_compressed.render.length.should.be < doc_uncompressed.render.length
|
243
|
+
end
|
270
244
|
|
271
|
-
end
|
245
|
+
end
|
272
246
|
|
273
247
|
describe "Document metadata" do
|
274
248
|
it "should output strings as UTF-16 with a byte order mark" do
|
@@ -288,10 +262,11 @@ describe "When reopening pages" do
|
|
288
262
|
pdf.go_to_page 1
|
289
263
|
pdf.text "More for page 1"
|
290
264
|
end
|
291
|
-
|
292
|
-
#
|
293
|
-
#
|
294
|
-
PDF::Inspector::Page.analyze(@pdf.render)
|
265
|
+
|
266
|
+
# MalformedPDFError raised if content stream actual length does not match
|
267
|
+
# dictionary length
|
268
|
+
lambda{ PDF::Inspector::Page.analyze(@pdf.render) }.
|
269
|
+
should.not.raise(PDF::Reader::MalformedPDFError)
|
295
270
|
end
|
296
271
|
|
297
272
|
it "should insert pages after the current page when calling start_new_page" do
|
@@ -323,21 +298,21 @@ describe "When setting page size" do
|
|
323
298
|
it "should default to LETTER" do
|
324
299
|
@pdf = Prawn::Document.new
|
325
300
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
326
|
-
pages.first[:size].should ==
|
327
|
-
end
|
328
|
-
|
329
|
-
(
|
301
|
+
pages.first[:size].should == Prawn::Document::PageGeometry::SIZES["LETTER"]
|
302
|
+
end
|
303
|
+
|
304
|
+
(Prawn::Document::PageGeometry::SIZES.keys - ["LETTER"]).each do |k|
|
330
305
|
it "should provide #{k} geometry" do
|
331
306
|
@pdf = Prawn::Document.new(:page_size => k)
|
332
|
-
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
333
|
-
pages.first[:size].should ==
|
307
|
+
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
308
|
+
pages.first[:size].should == Prawn::Document::PageGeometry::SIZES[k]
|
334
309
|
end
|
335
310
|
end
|
336
|
-
|
337
|
-
it "should allow custom page size" do
|
311
|
+
|
312
|
+
it "should allow custom page size" do
|
338
313
|
@pdf = Prawn::Document.new(:page_size => [1920, 1080] )
|
339
|
-
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
340
|
-
pages.first[:size].should == [1920, 1080]
|
314
|
+
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
315
|
+
pages.first[:size].should == [1920, 1080]
|
341
316
|
end
|
342
317
|
|
343
318
|
|
@@ -346,25 +321,25 @@ describe "When setting page size" do
|
|
346
321
|
@pdf.start_new_page
|
347
322
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
348
323
|
pages.each do |page|
|
349
|
-
page[:size].should ==
|
324
|
+
page[:size].should == Prawn::Document::PageGeometry::SIZES["LEGAL"]
|
350
325
|
end
|
351
326
|
end
|
352
327
|
|
353
|
-
end
|
328
|
+
end
|
354
329
|
|
355
330
|
describe "When setting page layout" do
|
356
331
|
it "should reverse coordinates for landscape" do
|
357
332
|
@pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
|
358
|
-
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
359
|
-
pages.first[:size].should ==
|
360
|
-
end
|
333
|
+
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
334
|
+
pages.first[:size].should == Prawn::Document::PageGeometry::SIZES["A4"].reverse
|
335
|
+
end
|
361
336
|
|
362
337
|
it "should retain page layout by default when starting a new page" do
|
363
338
|
@pdf = Prawn::Document.new(:page_layout => :landscape)
|
364
339
|
@pdf.start_new_page(:trace => true)
|
365
340
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
366
341
|
pages.each do |page|
|
367
|
-
page[:size].should ==
|
342
|
+
page[:size].should == Prawn::Document::PageGeometry::SIZES["LETTER"].reverse
|
368
343
|
end
|
369
344
|
end
|
370
345
|
|
@@ -383,11 +358,11 @@ describe "The mask() feature" do
|
|
383
358
|
@pdf.mask(:y, :line_width) do
|
384
359
|
@pdf.y = y + 1
|
385
360
|
@pdf.line_width = line_width + 1
|
386
|
-
@pdf.y.
|
387
|
-
@pdf.line_width.
|
361
|
+
@pdf.y.should.not == y
|
362
|
+
@pdf.line_width.should.not == line_width
|
388
363
|
end
|
389
364
|
@pdf.y.should == y
|
390
|
-
@pdf.line_width.should == line_width
|
365
|
+
@pdf.line_width.should == line_width
|
391
366
|
end
|
392
367
|
end
|
393
368
|
|
@@ -416,14 +391,14 @@ describe "The group() feature" do
|
|
416
391
|
pages[1][:strings].should == ["Hello", "World"]
|
417
392
|
end
|
418
393
|
|
419
|
-
it "should
|
394
|
+
it "should raise CannotGroup if the content is too tall" do
|
420
395
|
lambda {
|
421
396
|
Prawn::Document.new do
|
422
397
|
group do
|
423
398
|
100.times { text "Too long" }
|
424
399
|
end
|
425
400
|
end.render
|
426
|
-
}.should
|
401
|
+
}.should.raise(Prawn::Errors::CannotGroup)
|
427
402
|
end
|
428
403
|
|
429
404
|
it "should group within individual column boxes" do
|
@@ -447,23 +422,25 @@ describe "The group() feature" do
|
|
447
422
|
end
|
448
423
|
|
449
424
|
describe "The render() feature" do
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
425
|
+
if "spec".respond_to?(:encode!)
|
426
|
+
it "should return a 8 bit encoded string on a m17n aware VM" do
|
427
|
+
@pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
|
428
|
+
@pdf.line [100,100], [200,200]
|
429
|
+
str = @pdf.render
|
430
|
+
str.encoding.to_s.should == "ASCII-8BIT"
|
431
|
+
end
|
455
432
|
end
|
456
433
|
|
457
434
|
it "should trigger before_render callbacks just before rendering" do
|
458
435
|
pdf = Prawn::Document.new
|
459
|
-
|
436
|
+
|
460
437
|
seq = sequence("callback_order")
|
461
438
|
|
462
439
|
# Verify the order: finalize -> fire callbacks -> render body
|
463
440
|
pdf.expects(:finalize_all_page_contents).in_sequence(seq)
|
464
441
|
trigger = mock()
|
465
442
|
trigger.expects(:fire).in_sequence(seq)
|
466
|
-
|
443
|
+
|
467
444
|
# Store away the render_body method to be called below
|
468
445
|
render_body = pdf.method(:render_body)
|
469
446
|
pdf.expects(:render_body).in_sequence(seq)
|
@@ -487,10 +464,10 @@ end
|
|
487
464
|
describe "The :optimize_objects option" do
|
488
465
|
before(:all) do
|
489
466
|
@wasteful_doc = lambda do |pdf|
|
490
|
-
pdf.transaction do
|
467
|
+
pdf.transaction do
|
491
468
|
pdf.start_new_page
|
492
469
|
pdf.text "Hidden text"
|
493
|
-
pdf.rollback
|
470
|
+
pdf.rollback
|
494
471
|
end
|
495
472
|
|
496
473
|
pdf.text "Hello world"
|
@@ -501,12 +478,12 @@ describe "The :optimize_objects option" do
|
|
501
478
|
wasteful_pdf = Prawn::Document.new(&@wasteful_doc)
|
502
479
|
frugal_pdf = Prawn::Document.new(:optimize_objects => true,
|
503
480
|
&@wasteful_doc)
|
504
|
-
frugal_pdf.render.size.should
|
481
|
+
frugal_pdf.render.size.should.be < wasteful_pdf.render.size
|
505
482
|
end
|
506
483
|
|
507
484
|
it "should default to :false" do
|
508
485
|
default_pdf = Prawn::Document.new(&@wasteful_doc)
|
509
|
-
wasteful_pdf = Prawn::Document.new(:optimize_objects => false,
|
486
|
+
wasteful_pdf = Prawn::Document.new(:optimize_objects => false,
|
510
487
|
&@wasteful_doc)
|
511
488
|
default_pdf.render.size.should == wasteful_pdf.render.size
|
512
489
|
end
|
@@ -588,25 +565,25 @@ describe "The number_pages method" do
|
|
588
565
|
before do
|
589
566
|
@pdf = Prawn::Document.new(:skip_page_creation => true)
|
590
567
|
end
|
591
|
-
|
568
|
+
|
592
569
|
it "replaces the '<page>' string with the proper page number" do
|
593
570
|
@pdf.start_new_page
|
594
571
|
@pdf.expects(:text_box).with("1, test", { :height => 50 })
|
595
572
|
@pdf.number_pages "<page>, test", {:page_filter => :all}
|
596
573
|
end
|
597
|
-
|
574
|
+
|
598
575
|
it "replaces the '<total>' string with the total page count" do
|
599
576
|
@pdf.start_new_page
|
600
577
|
@pdf.expects(:text_box).with("test, 1", { :height => 50 })
|
601
578
|
@pdf.number_pages "test, <total>", {:page_filter => :all}
|
602
579
|
end
|
603
|
-
|
580
|
+
|
604
581
|
it "must print each page if given the :all page_filter" do
|
605
582
|
10.times { @pdf.start_new_page }
|
606
583
|
@pdf.expects(:text_box).times(10)
|
607
584
|
@pdf.number_pages "test", {:page_filter => :all}
|
608
585
|
end
|
609
|
-
|
586
|
+
|
610
587
|
it "must print each page if no :page_filter is specified" do
|
611
588
|
10.times { @pdf.start_new_page }
|
612
589
|
@pdf.expects(:text_box).times(10)
|
@@ -618,8 +595,8 @@ describe "The number_pages method" do
|
|
618
595
|
@pdf.expects(:text_box).never
|
619
596
|
@pdf.number_pages "test", {:page_filter => nil}
|
620
597
|
end
|
621
|
-
|
622
|
-
context "start_count_at option" do
|
598
|
+
|
599
|
+
context "start_count_at option" do
|
623
600
|
[1, 2].each do |startat|
|
624
601
|
context "equal to #{startat}" do
|
625
602
|
it "increments the pages" do
|
@@ -628,10 +605,10 @@ describe "The number_pages method" do
|
|
628
605
|
@pdf.expects(:text_box).with("#{startat} 2", { :height => 50 })
|
629
606
|
@pdf.expects(:text_box).with("#{startat+1} 2", { :height => 50 })
|
630
607
|
@pdf.number_pages "<page> <total>", options
|
631
|
-
end
|
608
|
+
end
|
632
609
|
end
|
633
610
|
end
|
634
|
-
|
611
|
+
|
635
612
|
[0, nil].each do |val|
|
636
613
|
context "equal to #{val}" do
|
637
614
|
it "defaults to start at page 1" do
|
@@ -645,7 +622,7 @@ describe "The number_pages method" do
|
|
645
622
|
end
|
646
623
|
end
|
647
624
|
end
|
648
|
-
|
625
|
+
|
649
626
|
context "total_pages option" do
|
650
627
|
it "allows the total pages count to be overridden" do
|
651
628
|
2.times { @pdf.start_new_page }
|
@@ -654,7 +631,7 @@ describe "The number_pages method" do
|
|
654
631
|
@pdf.number_pages "<page> <total>", :page_filter => :all, :total_pages => 10
|
655
632
|
end
|
656
633
|
end
|
657
|
-
|
634
|
+
|
658
635
|
context "special page filter" do
|
659
636
|
context "such as :odd" do
|
660
637
|
it "increments the pages" do
|
@@ -699,27 +676,6 @@ describe "The number_pages method" do
|
|
699
676
|
end
|
700
677
|
end
|
701
678
|
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
|
723
679
|
end
|
724
680
|
|
725
681
|
describe "The page_match? method" do
|
@@ -727,33 +683,33 @@ describe "The page_match? method" do
|
|
727
683
|
@pdf = Prawn::Document.new(:skip_page_creation => true)
|
728
684
|
10.times {@pdf.start_new_page}
|
729
685
|
end
|
730
|
-
|
686
|
+
|
731
687
|
it "returns nil given no filter" do
|
732
|
-
@pdf.page_match?(:nil, 1)
|
688
|
+
assert ! @pdf.page_match?(:nil, 1)
|
733
689
|
end
|
734
|
-
|
690
|
+
|
735
691
|
it "must provide an :all filter" do
|
736
|
-
(1..@pdf.page_count).all? { |i| @pdf.page_match?(:all, i) }
|
692
|
+
assert (1..@pdf.page_count).all? { |i| @pdf.page_match?(:all, i) }
|
737
693
|
end
|
738
694
|
|
739
695
|
it "must provide an :odd filter" do
|
740
696
|
odd, even = (1..@pdf.page_count).partition { |e| e % 2 == 1 }
|
741
|
-
odd.all? { |i| @pdf.page_match?(:odd, i) }
|
742
|
-
even.any? { |i| @pdf.page_match?(:odd, i) }
|
697
|
+
assert odd.all? { |i| @pdf.page_match?(:odd, i) }
|
698
|
+
assert ! even.any? { |i| @pdf.page_match?(:odd, i) }
|
743
699
|
end
|
744
700
|
|
745
701
|
it "must be able to filter by an array of page numbers" do
|
746
702
|
fltr = [1,2,7]
|
747
|
-
(1..10).select { |i| @pdf.page_match?(fltr, i) }
|
703
|
+
assert_equal [1,2,7], (1..10).select { |i| @pdf.page_match?(fltr, i) }
|
748
704
|
end
|
749
705
|
|
750
706
|
it "must be able to filter by a range of page numbers" do
|
751
707
|
fltr = 2..4
|
752
|
-
(1..10).select { |i| @pdf.page_match?(fltr, i) }
|
708
|
+
assert_equal [2,3,4], (1..10).select { |i| @pdf.page_match?(fltr, i) }
|
753
709
|
end
|
754
710
|
|
755
711
|
it "must be able to filter by an arbitrary proc" do
|
756
712
|
fltr = lambda { |x| x == 1 or x % 3 == 0 }
|
757
|
-
(1..10).select { |i| @pdf.page_match?(fltr, i) }
|
758
|
-
end
|
713
|
+
assert_equal [1,3,6,9], (1..10).select { |i| @pdf.page_match?(fltr, i) }
|
714
|
+
end
|
759
715
|
end
|