prawn 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +7 -5
- data/lib/prawn.rb +4 -4
- data/lib/prawn/document.rb +47 -46
- data/lib/prawn/document/bounding_box.rb +13 -19
- data/lib/prawn/document/column_box.rb +3 -5
- data/lib/prawn/document/internals.rb +0 -1
- data/lib/prawn/document/span.rb +12 -12
- data/lib/prawn/errors.rb +32 -33
- data/lib/prawn/font.rb +29 -36
- data/lib/prawn/font/afm.rb +20 -20
- data/lib/prawn/font/dfont.rb +0 -1
- data/lib/prawn/font/ttf.rb +30 -27
- data/lib/prawn/font_metric_cache.rb +4 -8
- data/lib/prawn/graphics.rb +37 -42
- data/lib/prawn/graphics/cap_style.rb +1 -1
- data/lib/prawn/graphics/color.rb +21 -23
- data/lib/prawn/graphics/dash.rb +5 -6
- data/lib/prawn/graphics/join_style.rb +1 -2
- data/lib/prawn/graphics/patterns.rb +25 -21
- data/lib/prawn/graphics/transformation.rb +4 -5
- data/lib/prawn/graphics/transparency.rb +6 -8
- data/lib/prawn/grid.rb +21 -14
- data/lib/prawn/image_handler.rb +2 -2
- data/lib/prawn/images.rb +29 -31
- data/lib/prawn/images/image.rb +1 -1
- data/lib/prawn/images/jpg.rb +10 -12
- data/lib/prawn/images/png.rb +13 -13
- data/lib/prawn/measurements.rb +7 -14
- data/lib/prawn/outline.rb +6 -6
- data/lib/prawn/repeater.rb +1 -5
- data/lib/prawn/security.rb +17 -25
- data/lib/prawn/security/arcfour.rb +1 -1
- data/lib/prawn/soft_mask.rb +11 -12
- data/lib/prawn/stamp.rb +16 -8
- data/lib/prawn/text.rb +23 -20
- data/lib/prawn/text/box.rb +3 -6
- data/lib/prawn/text/formatted/arranger.rb +9 -12
- data/lib/prawn/text/formatted/box.rb +23 -22
- data/lib/prawn/text/formatted/fragment.rb +0 -4
- data/lib/prawn/text/formatted/line_wrap.rb +13 -24
- data/lib/prawn/text/formatted/parser.rb +16 -20
- data/lib/prawn/text/formatted/wrap.rb +2 -7
- data/lib/prawn/utilities.rb +6 -3
- data/lib/prawn/version.rb +1 -1
- data/manual/basic_concepts/basic_concepts.rb +0 -2
- data/manual/basic_concepts/view.rb +1 -1
- data/manual/bounding_box/bounding_box.rb +0 -3
- data/manual/bounding_box/russian_boxes.rb +7 -8
- data/manual/bounding_box/stretchy.rb +0 -1
- data/manual/contents.rb +2 -2
- data/manual/cover.rb +11 -12
- data/manual/document_and_page_options/document_and_page_options.rb +2 -5
- data/manual/document_and_page_options/metadata.rb +10 -10
- data/manual/document_and_page_options/page_size.rb +0 -1
- data/manual/graphics/fill_rules.rb +5 -4
- data/manual/graphics/graphics.rb +0 -3
- data/manual/graphics/lines_and_curves.rb +1 -1
- data/manual/graphics/rotate.rb +0 -2
- data/manual/graphics/scale.rb +4 -2
- data/manual/graphics/soft_masks.rb +0 -1
- data/manual/graphics/stroke_cap.rb +1 -1
- data/manual/graphics/stroke_join.rb +1 -1
- data/manual/graphics/translate.rb +3 -3
- data/manual/graphics/transparency.rb +0 -1
- data/manual/how_to_read_this_manual.rb +0 -1
- data/manual/images/images.rb +0 -3
- data/manual/layout/boxes.rb +5 -5
- data/manual/layout/content.rb +2 -2
- data/manual/layout/layout.rb +0 -3
- data/manual/outline/outline.rb +0 -3
- data/manual/repeatable_content/page_numbering.rb +1 -1
- data/manual/repeatable_content/repeatable_content.rb +0 -3
- data/manual/repeatable_content/repeater.rb +6 -6
- data/manual/security/encryption.rb +0 -2
- data/manual/security/permissions.rb +0 -2
- data/manual/security/security.rb +0 -3
- data/manual/text/alignment.rb +3 -3
- data/manual/text/color.rb +0 -1
- data/manual/text/column_box.rb +0 -1
- data/manual/text/fallback_fonts.rb +2 -2
- data/manual/text/formatted_callbacks.rb +3 -2
- data/manual/text/paragraph_indentation.rb +2 -3
- data/manual/text/registering_families.rb +13 -9
- data/manual/text/rotation.rb +0 -1
- data/manual/text/text.rb +0 -3
- data/manual/text/text_box_overflow.rb +7 -5
- data/manual/text/utf8.rb +1 -1
- data/manual/text/win_ansi_charset.rb +2 -2
- data/prawn.gemspec +4 -4
- data/spec/acceptance/png.rb +6 -7
- data/spec/annotations_spec.rb +21 -28
- data/spec/bounding_box_spec.rb +100 -109
- data/spec/column_box_spec.rb +26 -32
- data/spec/destinations_spec.rb +2 -4
- data/spec/document_spec.rb +145 -151
- data/spec/extensions/mocha.rb +0 -1
- data/spec/font_metric_cache_spec.rb +7 -7
- data/spec/font_spec.rb +103 -102
- data/spec/formatted_text_arranger_spec.rb +76 -74
- data/spec/formatted_text_box_spec.rb +170 -159
- data/spec/formatted_text_fragment_spec.rb +57 -56
- data/spec/graphics_spec.rb +158 -175
- data/spec/grid_spec.rb +28 -29
- data/spec/image_handler_spec.rb +4 -5
- data/spec/images_spec.rb +50 -36
- data/spec/inline_formatted_text_parser_spec.rb +397 -393
- data/spec/jpg_spec.rb +4 -6
- data/spec/line_wrap_spec.rb +54 -55
- data/spec/measurement_units_spec.rb +12 -15
- data/spec/outline_spec.rb +77 -98
- data/spec/png_spec.rb +55 -65
- data/spec/reference_spec.rb +3 -3
- data/spec/repeater_spec.rb +20 -26
- data/spec/security_spec.rb +42 -49
- data/spec/soft_mask_spec.rb +4 -5
- data/spec/span_spec.rb +5 -6
- data/spec/spec_helper.rb +2 -4
- data/spec/stamp_spec.rb +41 -22
- data/spec/stroke_styles_spec.rb +36 -39
- data/spec/text_at_spec.rb +28 -29
- data/spec/text_box_spec.rb +160 -165
- data/spec/text_rendering_mode_spec.rb +9 -9
- data/spec/text_spacing_spec.rb +13 -13
- data/spec/text_spec.rb +116 -124
- data/spec/text_with_inline_formatting_spec.rb +5 -5
- data/spec/transparency_spec.rb +20 -20
- data/spec/view_spec.rb +0 -1
- metadata +7 -7
data/spec/column_box_spec.rb
CHANGED
@@ -5,30 +5,28 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
|
5
5
|
describe "A column box" do
|
6
6
|
it "has sensible left and right values" do
|
7
7
|
create_pdf
|
8
|
-
@pdf.column_box [0, @pdf.cursor], :width => @pdf.bounds.width,
|
9
|
-
|
10
|
-
|
11
|
-
right = @pdf.bounds.right
|
8
|
+
@pdf.column_box [0, @pdf.cursor], :width => @pdf.bounds.width, :height => 200, :columns => 3, :spacer => 25 do
|
9
|
+
left = @pdf.bounds.left
|
10
|
+
right = @pdf.bounds.right
|
12
11
|
|
13
|
-
|
12
|
+
@pdf.bounds.move_past_bottom # next column
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
expect(@pdf.bounds.left).to be > left
|
15
|
+
expect(@pdf.bounds.left).to be > right
|
16
|
+
expect(@pdf.bounds.right).to be > @pdf.bounds.left
|
17
|
+
end
|
19
18
|
end
|
20
19
|
|
21
20
|
it "includes spacers between columns but not at the end" do
|
22
21
|
create_pdf
|
23
|
-
@pdf.column_box [0, @pdf.cursor], :width => 500,
|
24
|
-
|
25
|
-
@pdf.bounds.width.should == 150 # (500 - (25 * 2)) / 3
|
22
|
+
@pdf.column_box [0, @pdf.cursor], :width => 500, :height => 200, :columns => 3, :spacer => 25 do
|
23
|
+
expect(@pdf.bounds.width).to eq(150) # (500 - (25 * 2)) / 3
|
26
24
|
|
27
|
-
|
28
|
-
|
25
|
+
@pdf.bounds.move_past_bottom
|
26
|
+
@pdf.bounds.move_past_bottom
|
29
27
|
|
30
|
-
|
31
|
-
|
28
|
+
expect(@pdf.bounds.right).to eq(500)
|
29
|
+
end
|
32
30
|
end
|
33
31
|
|
34
32
|
it "does not reset the top margin on a new page by default" do
|
@@ -36,15 +34,13 @@ describe "A column box" do
|
|
36
34
|
page_top = @pdf.cursor
|
37
35
|
@pdf.move_down 50
|
38
36
|
init_column_top = @pdf.cursor
|
39
|
-
@pdf.column_box [0, @pdf.cursor], :width => 500,
|
40
|
-
|
37
|
+
@pdf.column_box [0, @pdf.cursor], :width => 500, :height => 200, :columns => 2 do
|
38
|
+
@pdf.bounds.move_past_bottom
|
39
|
+
@pdf.bounds.move_past_bottom
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
@pdf.bounds.absolute_top.should == init_column_top
|
46
|
-
@pdf.bounds.absolute_top.should_not == page_top
|
47
|
-
end
|
41
|
+
expect(@pdf.bounds.absolute_top).to eq(init_column_top)
|
42
|
+
expect(@pdf.bounds.absolute_top).not_to eq(page_top)
|
43
|
+
end
|
48
44
|
end
|
49
45
|
|
50
46
|
it "does reset the top margin when reflow_margins is set" do
|
@@ -52,14 +48,12 @@ describe "A column box" do
|
|
52
48
|
page_top = @pdf.cursor
|
53
49
|
@pdf.move_down 50
|
54
50
|
init_column_top = @pdf.cursor
|
55
|
-
@pdf.column_box [0, @pdf.cursor], :width => 500, :reflow_margins => true,
|
56
|
-
|
57
|
-
|
58
|
-
@pdf.bounds.move_past_bottom
|
59
|
-
@pdf.bounds.move_past_bottom
|
51
|
+
@pdf.column_box [0, @pdf.cursor], :width => 500, :reflow_margins => true, :height => 200, :columns => 2 do
|
52
|
+
@pdf.bounds.move_past_bottom
|
53
|
+
@pdf.bounds.move_past_bottom
|
60
54
|
|
61
|
-
|
62
|
-
|
63
|
-
|
55
|
+
expect(@pdf.bounds.absolute_top).to eq(page_top)
|
56
|
+
expect(@pdf.bounds.absolute_top).not_to eq(init_column_top)
|
57
|
+
end
|
64
58
|
end
|
65
59
|
end
|
data/spec/destinations_spec.rb
CHANGED
@@ -3,13 +3,11 @@
|
|
3
3
|
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
4
|
|
5
5
|
describe "When creating destinations" do
|
6
|
-
|
7
6
|
before(:each) { create_pdf }
|
8
7
|
|
9
8
|
it "should add entry to Dests name tree" do
|
10
|
-
@pdf.dests.data.empty
|
9
|
+
expect(@pdf.dests.data.empty?).to eq(true)
|
11
10
|
@pdf.add_dest "candy", "chocolate"
|
12
|
-
@pdf.dests.data.size.
|
11
|
+
expect(@pdf.dests.data.size).to eq(1)
|
13
12
|
end
|
14
|
-
|
15
13
|
end
|
data/spec/document_spec.rb
CHANGED
@@ -5,27 +5,27 @@ 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
|
8
|
-
options = {:page_layout => :landscape}
|
8
|
+
options = { :page_layout => :landscape }
|
9
9
|
Prawn::Document.new(options)
|
10
|
-
options.
|
10
|
+
expect(options).to eq(:page_layout => :landscape)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "The cursor" do
|
15
15
|
it "should == pdf.y - bounds.absolute_bottom" do
|
16
16
|
pdf = Prawn::Document.new
|
17
|
-
pdf.cursor.
|
17
|
+
expect(pdf.cursor).to eq(pdf.bounds.top)
|
18
18
|
|
19
19
|
pdf.y = 300
|
20
|
-
pdf.cursor.
|
20
|
+
expect(pdf.cursor).to eq(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
|
24
24
|
pdf = Prawn::Document.new
|
25
25
|
pdf.move_cursor_to(10)
|
26
26
|
|
27
|
-
pdf.cursor.
|
28
|
-
pdf.y.
|
27
|
+
expect(pdf.cursor).to eq(10)
|
28
|
+
expect(pdf.y).to eq(pdf.cursor + pdf.bounds.absolute_bottom)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -51,7 +51,7 @@ describe "when generating a document with a custom text formatter" do
|
|
51
51
|
pdf = Prawn::Document.new text_formatter: TestTextFormatter
|
52
52
|
pdf.text "Dr. Who?", inline_format: true
|
53
53
|
text = PDF::Inspector::Text.analyze(pdf.render)
|
54
|
-
text.strings.first.
|
54
|
+
expect(text.strings.first).to eq("Just 'The Doctor'.")
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -59,8 +59,8 @@ describe "when generating a document from a subclass" do
|
|
59
59
|
it "should be an instance of the subclass" do
|
60
60
|
custom_document = Class.new(Prawn::Document)
|
61
61
|
custom_document.generate(Tempfile.new("generate_test").path) do |e|
|
62
|
-
e.class.
|
63
|
-
e.
|
62
|
+
expect(e.class).to eq(custom_document)
|
63
|
+
expect(e).to be_a_kind_of(Prawn::Document)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -71,44 +71,40 @@ describe "when generating a document from a subclass" do
|
|
71
71
|
Prawn::Document.extensions << mod1 << mod2
|
72
72
|
|
73
73
|
custom_document = Class.new(Prawn::Document)
|
74
|
-
custom_document.extensions.
|
74
|
+
expect(custom_document.extensions).to eq([mod1, mod2])
|
75
75
|
|
76
76
|
# remove the extensions we added to prawn document
|
77
77
|
Prawn::Document.extensions.delete(mod1)
|
78
78
|
Prawn::Document.extensions.delete(mod2)
|
79
79
|
|
80
|
-
Prawn::Document.new.respond_to?(:test_extensions1).
|
81
|
-
Prawn::Document.new.respond_to?(:test_extensions2).
|
80
|
+
expect(Prawn::Document.new.respond_to?(:test_extensions1)).to be_false
|
81
|
+
expect(Prawn::Document.new.respond_to?(:test_extensions2)).to be_false
|
82
82
|
|
83
83
|
# verify these still exist on custom class
|
84
|
-
custom_document.extensions.
|
84
|
+
expect(custom_document.extensions).to eq([mod1, mod2])
|
85
85
|
|
86
|
-
custom_document.new.respond_to?(:test_extensions1).
|
87
|
-
custom_document.new.respond_to?(:test_extensions2).
|
86
|
+
expect(custom_document.new.respond_to?(:test_extensions1)).to be_true
|
87
|
+
expect(custom_document.new.respond_to?(:test_extensions2)).to be_true
|
88
88
|
end
|
89
|
-
|
90
89
|
end
|
91
90
|
|
92
|
-
|
93
91
|
describe "When creating multi-page documents" do
|
94
|
-
|
95
92
|
before(:each) { create_pdf }
|
96
93
|
|
97
94
|
it "should initialize with a single page" do
|
98
95
|
page_counter = PDF::Inspector::Page.analyze(@pdf.render)
|
99
96
|
|
100
|
-
page_counter.pages.size.
|
101
|
-
@pdf.page_count.
|
97
|
+
expect(page_counter.pages.size).to eq(1)
|
98
|
+
expect(@pdf.page_count).to eq(1)
|
102
99
|
end
|
103
100
|
|
104
101
|
it "should provide an accurate page_count" do
|
105
102
|
3.times { @pdf.start_new_page }
|
106
103
|
page_counter = PDF::Inspector::Page.analyze(@pdf.render)
|
107
104
|
|
108
|
-
page_counter.pages.size.
|
109
|
-
@pdf.page_count.
|
105
|
+
expect(page_counter.pages.size).to eq(4)
|
106
|
+
expect(@pdf.page_count).to eq(4)
|
110
107
|
end
|
111
|
-
|
112
108
|
end
|
113
109
|
|
114
110
|
describe "When beginning each new page" do
|
@@ -121,11 +117,11 @@ describe "When beginning each new page" do
|
|
121
117
|
output = @pdf.render
|
122
118
|
images = PDF::Inspector::XObject.analyze(output)
|
123
119
|
# there should be 2 images in the page resources
|
124
|
-
images.page_xobjects.first.size.
|
120
|
+
expect(images.page_xobjects.first.size).to eq(1)
|
125
121
|
end
|
126
122
|
it "should place a background image if it is in options block" do
|
127
|
-
@pdf.instance_variable_defined?(:@background).
|
128
|
-
@pdf.instance_variable_get(:@background).
|
123
|
+
expect(@pdf.instance_variable_defined?(:@background)).to eq(true)
|
124
|
+
expect(@pdf.instance_variable_get(:@background)).to eq(@filename)
|
129
125
|
end
|
130
126
|
end
|
131
127
|
end
|
@@ -135,7 +131,7 @@ describe "Prawn::Document#float" do
|
|
135
131
|
create_pdf
|
136
132
|
orig_y = @pdf.y
|
137
133
|
@pdf.float { @pdf.text "Foo" }
|
138
|
-
@pdf.y.
|
134
|
+
expect(@pdf.y).to eq(orig_y)
|
139
135
|
end
|
140
136
|
|
141
137
|
it "should teleport across pages if necessary" do
|
@@ -149,30 +145,29 @@ describe "Prawn::Document#float" do
|
|
149
145
|
@pdf.text "Baz"
|
150
146
|
|
151
147
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
152
|
-
pages.size.
|
153
|
-
pages[0][:strings].
|
154
|
-
pages[1][:strings].
|
148
|
+
expect(pages.size).to eq(2)
|
149
|
+
expect(pages[0][:strings]).to eq(["Foo", "Baz"])
|
150
|
+
expect(pages[1][:strings]).to eq(["Bar"])
|
155
151
|
end
|
156
152
|
end
|
157
153
|
|
158
154
|
describe "The page_number method" do
|
159
155
|
it "should be 1 for a new document" do
|
160
156
|
pdf = Prawn::Document.new
|
161
|
-
pdf.page_number.
|
157
|
+
expect(pdf.page_number).to eq(1)
|
162
158
|
end
|
163
159
|
|
164
160
|
it "should be 0 for documents with no pages" do
|
165
161
|
pdf = Prawn::Document.new(:skip_page_creation => true)
|
166
|
-
pdf.page_number.
|
162
|
+
expect(pdf.page_number).to eq(0)
|
167
163
|
end
|
168
164
|
|
169
165
|
it "should be changed by go_to_page" do
|
170
166
|
pdf = Prawn::Document.new
|
171
167
|
10.times { pdf.start_new_page }
|
172
168
|
pdf.go_to_page 3
|
173
|
-
pdf.page_number.
|
169
|
+
expect(pdf.page_number).to eq(3)
|
174
170
|
end
|
175
|
-
|
176
171
|
end
|
177
172
|
|
178
173
|
describe "on_page_create callback" do
|
@@ -191,11 +186,11 @@ describe "on_page_create callback" do
|
|
191
186
|
|
192
187
|
@pdf.start_new_page
|
193
188
|
|
194
|
-
called_with.
|
189
|
+
expect(called_with).to eq([@pdf])
|
195
190
|
end
|
196
191
|
|
197
192
|
it "should be invoked for each new page" do
|
198
|
-
trigger = mock
|
193
|
+
trigger = mock
|
199
194
|
trigger.expects(:fire).times(5)
|
200
195
|
|
201
196
|
@pdf.renderer.on_page_create { trigger.fire }
|
@@ -204,40 +199,37 @@ describe "on_page_create callback" do
|
|
204
199
|
end
|
205
200
|
|
206
201
|
it "should be replaceable" do
|
207
|
-
|
208
|
-
|
202
|
+
trigger1 = mock
|
203
|
+
trigger1.expects(:fire).times(1)
|
209
204
|
|
210
|
-
|
211
|
-
|
205
|
+
trigger2 = mock
|
206
|
+
trigger2.expects(:fire).times(1)
|
212
207
|
|
213
|
-
|
208
|
+
@pdf.renderer.on_page_create { trigger1.fire }
|
214
209
|
|
215
|
-
|
210
|
+
@pdf.start_new_page
|
216
211
|
|
217
|
-
|
212
|
+
@pdf.renderer.on_page_create { trigger2.fire }
|
218
213
|
|
219
|
-
|
214
|
+
@pdf.start_new_page
|
220
215
|
end
|
221
216
|
|
222
217
|
it "should be clearable by calling on_page_create without a block" do
|
223
|
-
|
224
|
-
|
218
|
+
trigger = mock
|
219
|
+
trigger.expects(:fire).times(1)
|
225
220
|
|
226
|
-
|
221
|
+
@pdf.renderer.on_page_create { trigger.fire }
|
227
222
|
|
228
|
-
|
223
|
+
@pdf.start_new_page
|
229
224
|
|
230
|
-
|
225
|
+
@pdf.renderer.on_page_create
|
231
226
|
|
232
|
-
|
227
|
+
@pdf.start_new_page
|
233
228
|
end
|
234
|
-
|
235
229
|
end
|
236
230
|
|
237
231
|
describe "Document compression" do
|
238
|
-
|
239
232
|
it "should not compress the page content stream if compression is disabled" do
|
240
|
-
|
241
233
|
pdf = Prawn::Document.new(:compress => false)
|
242
234
|
pdf.page.content.stream.stubs(:compress!).returns(true)
|
243
235
|
pdf.page.content.stream.expects(:compress!).never
|
@@ -247,7 +239,6 @@ describe "Document compression" do
|
|
247
239
|
end
|
248
240
|
|
249
241
|
it "should compress the page content stream if compression is enabled" do
|
250
|
-
|
251
242
|
pdf = Prawn::Document.new(:compress => true)
|
252
243
|
pdf.page.content.stream.stubs(:compress!).returns(true)
|
253
244
|
pdf.page.content.stream.expects(:compress!).once
|
@@ -260,21 +251,21 @@ describe "Document compression" do
|
|
260
251
|
doc_uncompressed = Prawn::Document.new
|
261
252
|
doc_compressed = Prawn::Document.new(:compress => true)
|
262
253
|
[doc_compressed, doc_uncompressed].each do |pdf|
|
263
|
-
|
264
|
-
|
254
|
+
pdf.font "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
|
255
|
+
pdf.text "更可怕的是,同质化竞争对手可以按照URL中后面这个ID来遍历" * 10
|
265
256
|
end
|
266
257
|
|
267
|
-
doc_compressed.render.length.
|
258
|
+
expect(doc_compressed.render.length).to be < doc_uncompressed.render.length
|
268
259
|
end
|
269
|
-
|
270
260
|
end
|
271
261
|
|
272
262
|
describe "Document metadata" do
|
273
263
|
it "should output strings as UTF-16 with a byte order mark" do
|
274
|
-
pdf = Prawn::Document.new(:info => {:Author => "Lóránt"})
|
275
|
-
pdf.state.store.info.object.
|
264
|
+
pdf = Prawn::Document.new(:info => { :Author => "Lóránt" })
|
265
|
+
expect(pdf.state.store.info.object).to match(
|
276
266
|
# UTF-16: BOM L ó r á n t
|
277
267
|
%r{/Author\s*<feff004c00f3007200e1006e0074>}i
|
268
|
+
)
|
278
269
|
end
|
279
270
|
end
|
280
271
|
|
@@ -295,17 +286,21 @@ describe "When reopening pages" do
|
|
295
286
|
|
296
287
|
it "should insert pages after the current page when calling start_new_page" do
|
297
288
|
pdf = Prawn::Document.new
|
298
|
-
3.times
|
289
|
+
3.times do |i|
|
290
|
+
pdf.text "Old page #{i + 1}"
|
291
|
+
pdf.start_new_page
|
292
|
+
end
|
293
|
+
|
299
294
|
pdf.go_to_page 1
|
300
295
|
pdf.start_new_page
|
301
296
|
pdf.text "New page 2"
|
302
297
|
|
303
|
-
pdf.page_number.
|
298
|
+
expect(pdf.page_number).to eq(2)
|
304
299
|
|
305
300
|
pages = PDF::Inspector::Page.analyze(pdf.render).pages
|
306
|
-
pages.size.
|
307
|
-
pages[1][:strings].
|
308
|
-
pages[2][:strings].
|
301
|
+
expect(pages.size).to eq(5)
|
302
|
+
expect(pages[1][:strings]).to eq(["New page 2"])
|
303
|
+
expect(pages[2][:strings]).to eq(["Old page 2"])
|
309
304
|
end
|
310
305
|
|
311
306
|
it "should restore the layout of the page" do
|
@@ -325,7 +320,7 @@ describe "When reopening pages" do
|
|
325
320
|
|
326
321
|
start_new_page(:margin => [200, 200])
|
327
322
|
|
328
|
-
[bounds.width, bounds.height].should == [page1_bounds.width
|
323
|
+
[bounds.width, bounds.height].should == [page1_bounds.width - 200,
|
329
324
|
page1_bounds.height - 200]
|
330
325
|
|
331
326
|
go_to_page(1)
|
@@ -333,7 +328,6 @@ describe "When reopening pages" do
|
|
333
328
|
bounds.width.should == page1_bounds.width
|
334
329
|
bounds.height.should == page1_bounds.height
|
335
330
|
end
|
336
|
-
|
337
331
|
end
|
338
332
|
end
|
339
333
|
|
@@ -341,40 +335,38 @@ describe "When setting page size" do
|
|
341
335
|
it "should default to LETTER" do
|
342
336
|
@pdf = Prawn::Document.new
|
343
337
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
344
|
-
pages.first[:size].
|
338
|
+
expect(pages.first[:size]).to eq(PDF::Core::PageGeometry::SIZES["LETTER"])
|
345
339
|
end
|
346
340
|
|
347
341
|
(PDF::Core::PageGeometry::SIZES.keys - ["LETTER"]).each do |k|
|
348
342
|
it "should provide #{k} geometry" do
|
349
343
|
@pdf = Prawn::Document.new(:page_size => k)
|
350
344
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
351
|
-
pages.first[:size].
|
345
|
+
expect(pages.first[:size]).to eq(PDF::Core::PageGeometry::SIZES[k])
|
352
346
|
end
|
353
347
|
end
|
354
348
|
|
355
349
|
it "should allow custom page size" do
|
356
|
-
@pdf = Prawn::Document.new(:page_size => [1920, 1080]
|
350
|
+
@pdf = Prawn::Document.new(:page_size => [1920, 1080])
|
357
351
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
358
|
-
pages.first[:size].
|
352
|
+
expect(pages.first[:size]).to eq([1920, 1080])
|
359
353
|
end
|
360
354
|
|
361
|
-
|
362
355
|
it "should retain page size by default when starting a new page" do
|
363
356
|
@pdf = Prawn::Document.new(:page_size => "LEGAL")
|
364
357
|
@pdf.start_new_page
|
365
358
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
366
359
|
pages.each do |page|
|
367
|
-
page[:size].
|
360
|
+
expect(page[:size]).to eq(PDF::Core::PageGeometry::SIZES["LEGAL"])
|
368
361
|
end
|
369
362
|
end
|
370
|
-
|
371
363
|
end
|
372
364
|
|
373
365
|
describe "When setting page layout" do
|
374
366
|
it "should reverse coordinates for landscape" do
|
375
367
|
@pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
|
376
368
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
377
|
-
pages.first[:size].
|
369
|
+
expect(pages.first[:size]).to eq(PDF::Core::PageGeometry::SIZES["A4"].reverse)
|
378
370
|
end
|
379
371
|
|
380
372
|
it "should retain page layout by default when starting a new page" do
|
@@ -382,7 +374,7 @@ describe "When setting page layout" do
|
|
382
374
|
@pdf.start_new_page(:trace => true)
|
383
375
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
384
376
|
pages.each do |page|
|
385
|
-
page[:size].
|
377
|
+
expect(page[:size]).to eq(PDF::Core::PageGeometry::SIZES["LETTER"].reverse)
|
386
378
|
end
|
387
379
|
end
|
388
380
|
|
@@ -390,7 +382,7 @@ describe "When setting page layout" do
|
|
390
382
|
@pdf = Prawn::Document.new
|
391
383
|
size = [@pdf.bounds.width, @pdf.bounds.height]
|
392
384
|
@pdf.start_new_page(:layout => :landscape)
|
393
|
-
[@pdf.bounds.width, @pdf.bounds.height].
|
385
|
+
expect([@pdf.bounds.width, @pdf.bounds.height]).to eq(size.reverse)
|
394
386
|
end
|
395
387
|
end
|
396
388
|
|
@@ -401,19 +393,22 @@ describe "The mask() feature" do
|
|
401
393
|
@pdf.mask(:y, :line_width) do
|
402
394
|
@pdf.y = y + 1
|
403
395
|
@pdf.line_width = line_width + 1
|
404
|
-
@pdf.y.
|
405
|
-
@pdf.line_width.
|
396
|
+
expect(@pdf.y).not_to eq(y)
|
397
|
+
expect(@pdf.line_width).not_to eq(line_width)
|
406
398
|
end
|
407
|
-
@pdf.y.
|
408
|
-
@pdf.line_width.
|
399
|
+
expect(@pdf.y).to eq(y)
|
400
|
+
expect(@pdf.line_width).to eq(line_width)
|
409
401
|
end
|
410
402
|
end
|
411
403
|
|
412
404
|
describe "The group() feature" do
|
413
405
|
xit "should return a true value if the content fits on one page" do
|
414
406
|
pdf = Prawn::Document.new do
|
415
|
-
val = group {
|
416
|
-
|
407
|
+
val = group {
|
408
|
+
text "Hello"
|
409
|
+
text "World"
|
410
|
+
}
|
411
|
+
expect(!!val).to eq(true)
|
417
412
|
end
|
418
413
|
end
|
419
414
|
|
@@ -426,25 +421,25 @@ describe "The group() feature" do
|
|
426
421
|
end
|
427
422
|
|
428
423
|
# group should return a false value since a new page was started
|
429
|
-
(!!val).
|
424
|
+
expect(!!val).to eq(false)
|
430
425
|
end
|
431
426
|
pages = PDF::Inspector::Page.analyze(pdf.render).pages
|
432
|
-
pages.size.
|
433
|
-
pages[0][:strings].
|
434
|
-
pages[1][:strings].
|
427
|
+
expect(pages.size).to eq(2)
|
428
|
+
expect(pages[0][:strings]).to eq([])
|
429
|
+
expect(pages[1][:strings]).to eq(["Hello", "World"])
|
435
430
|
end
|
436
431
|
|
437
432
|
xit "should raise_error CannotGroup if the content is too tall" do
|
438
|
-
|
433
|
+
expect {
|
439
434
|
Prawn::Document.new do
|
440
435
|
group do
|
441
436
|
100.times { text "Too long" }
|
442
437
|
end
|
443
438
|
end.render
|
444
|
-
}.
|
439
|
+
}.to raise_error(Prawn::Errors::CannotGroup)
|
445
440
|
end
|
446
441
|
|
447
|
-
|
442
|
+
xit "should group within individual column boxes" do
|
448
443
|
pdf = Prawn::Document.new do
|
449
444
|
# Set up columns with grouped blocks of 0..49. 0 to 49 is slightly short
|
450
445
|
# of the height of one page / column, so each column should get its own
|
@@ -458,18 +453,17 @@ describe "The group() feature" do
|
|
458
453
|
|
459
454
|
# Second page should start with a 0 because it's a new group.
|
460
455
|
pages = PDF::Inspector::Page.analyze(pdf.render).pages
|
461
|
-
pages.size.
|
462
|
-
pages[1][:strings].first.
|
456
|
+
expect(pages.size).to eq(2)
|
457
|
+
expect(pages[1][:strings].first).to eq('0')
|
463
458
|
end
|
464
|
-
|
465
459
|
end
|
466
460
|
|
467
461
|
describe "The render() feature" do
|
468
462
|
it "should return a 8 bit encoded string on a m17n aware VM" do
|
469
463
|
@pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
|
470
|
-
@pdf.line [100,100], [200,200]
|
464
|
+
@pdf.line [100, 100], [200, 200]
|
471
465
|
str = @pdf.render
|
472
|
-
str.encoding.to_s.
|
466
|
+
expect(str.encoding.to_s).to eq("ASCII-8BIT")
|
473
467
|
end
|
474
468
|
|
475
469
|
it "should trigger before_render callbacks just before rendering" do
|
@@ -479,7 +473,7 @@ describe "The render() feature" do
|
|
479
473
|
|
480
474
|
# Verify the order: finalize -> fire callbacks -> render body
|
481
475
|
pdf.renderer.expects(:finalize_all_page_contents).in_sequence(seq)
|
482
|
-
trigger = mock
|
476
|
+
trigger = mock
|
483
477
|
trigger.expects(:fire).in_sequence(seq)
|
484
478
|
|
485
479
|
# Store away the render_body method to be called below
|
@@ -498,7 +492,7 @@ describe "The render() feature" do
|
|
498
492
|
|
499
493
|
contents = pdf.render
|
500
494
|
contents2 = pdf.render
|
501
|
-
contents2.
|
495
|
+
expect(contents2).to eq(contents)
|
502
496
|
end
|
503
497
|
end
|
504
498
|
|
@@ -506,19 +500,19 @@ describe "PDF file versions" do
|
|
506
500
|
it "should default to 1.3" do
|
507
501
|
@pdf = Prawn::Document.new
|
508
502
|
str = @pdf.render
|
509
|
-
str[0,8].
|
503
|
+
expect(str[0, 8]).to eq("%PDF-1.3")
|
510
504
|
end
|
511
505
|
|
512
506
|
it "should allow the default to be changed" do
|
513
507
|
@pdf = Prawn::Document.new
|
514
508
|
@pdf.renderer.min_version(1.4)
|
515
509
|
str = @pdf.render
|
516
|
-
str[0,8].
|
510
|
+
expect(str[0, 8]).to eq("%PDF-1.4")
|
517
511
|
end
|
518
512
|
end
|
519
513
|
|
520
514
|
describe "Documents that use go_to_page" do
|
521
|
-
|
515
|
+
it "should have 2 pages after calling start_new_page and go_to_page" do
|
522
516
|
@pdf = Prawn::Document.new
|
523
517
|
@pdf.text "James"
|
524
518
|
@pdf.start_new_page
|
@@ -527,7 +521,7 @@ describe "Documents that use go_to_page" do
|
|
527
521
|
@pdf.text "Healy"
|
528
522
|
|
529
523
|
page_counter = PDF::Inspector::Page.analyze(@pdf.render)
|
530
|
-
page_counter.pages.size.
|
524
|
+
expect(page_counter.pages.size).to eq(2)
|
531
525
|
end
|
532
526
|
|
533
527
|
it "should correctly add text to pages" do
|
@@ -540,15 +534,15 @@ describe "Documents that use go_to_page" do
|
|
540
534
|
|
541
535
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
542
536
|
|
543
|
-
text.strings.size.
|
544
|
-
text.strings.include?("James").
|
545
|
-
text.strings.include?("Anthony").
|
546
|
-
text.strings.include?("Healy").
|
537
|
+
expect(text.strings.size).to eq(3)
|
538
|
+
expect(text.strings.include?("James")).to eq(true)
|
539
|
+
expect(text.strings.include?("Anthony")).to eq(true)
|
540
|
+
expect(text.strings.include?("Healy")).to eq(true)
|
547
541
|
end
|
548
542
|
end
|
549
543
|
|
550
544
|
describe "content stream characteristics" do
|
551
|
-
|
545
|
+
it "should have 1 single content stream for a single page PDF" do
|
552
546
|
@pdf = Prawn::Document.new
|
553
547
|
@pdf.text "James"
|
554
548
|
output = StringIO.new(@pdf.render)
|
@@ -556,10 +550,10 @@ describe "content stream characteristics" do
|
|
556
550
|
|
557
551
|
streams = hash.values.select { |obj| obj.kind_of?(PDF::Reader::Stream) }
|
558
552
|
|
559
|
-
streams.size.
|
553
|
+
expect(streams.size).to eq(1)
|
560
554
|
end
|
561
555
|
|
562
|
-
|
556
|
+
it "should have 1 single content stream for a single page PDF, even if go_to_page is used" do
|
563
557
|
@pdf = Prawn::Document.new
|
564
558
|
@pdf.text "James"
|
565
559
|
@pdf.go_to_page(1)
|
@@ -569,7 +563,7 @@ describe "content stream characteristics" do
|
|
569
563
|
|
570
564
|
streams = hash.values.select { |obj| obj.kind_of?(PDF::Reader::Stream) }
|
571
565
|
|
572
|
-
streams.size.
|
566
|
+
expect(streams.size).to eq(1)
|
573
567
|
end
|
574
568
|
end
|
575
569
|
|
@@ -580,20 +574,20 @@ describe "The number_pages method" do
|
|
580
574
|
|
581
575
|
it "replaces the '<page>' string with the proper page number" do
|
582
576
|
@pdf.start_new_page
|
583
|
-
@pdf.expects(:text_box).with("1, test",
|
584
|
-
@pdf.number_pages "<page>, test",
|
577
|
+
@pdf.expects(:text_box).with("1, test", :height => 50)
|
578
|
+
@pdf.number_pages "<page>, test", :page_filter => :all
|
585
579
|
end
|
586
580
|
|
587
581
|
it "replaces the '<total>' string with the total page count" do
|
588
582
|
@pdf.start_new_page
|
589
|
-
@pdf.expects(:text_box).with("test, 1",
|
590
|
-
@pdf.number_pages "test, <total>",
|
583
|
+
@pdf.expects(:text_box).with("test, 1", :height => 50)
|
584
|
+
@pdf.number_pages "test, <total>", :page_filter => :all
|
591
585
|
end
|
592
586
|
|
593
587
|
it "must print each page if given the :all page_filter" do
|
594
588
|
10.times { @pdf.start_new_page }
|
595
589
|
@pdf.expects(:text_box).times(10)
|
596
|
-
@pdf.number_pages "test",
|
590
|
+
@pdf.number_pages "test", :page_filter => :all
|
597
591
|
end
|
598
592
|
|
599
593
|
it "must print each page if no :page_filter is specified" do
|
@@ -605,7 +599,7 @@ describe "The number_pages method" do
|
|
605
599
|
it "must not print the page number if given a nil filter" do
|
606
600
|
10.times { @pdf.start_new_page }
|
607
601
|
@pdf.expects(:text_box).never
|
608
|
-
@pdf.number_pages "test",
|
602
|
+
@pdf.number_pages "test", :page_filter => nil
|
609
603
|
end
|
610
604
|
|
611
605
|
context "start_count_at option" do
|
@@ -613,9 +607,9 @@ describe "The number_pages method" do
|
|
613
607
|
context "equal to #{startat}" do
|
614
608
|
it "increments the pages" do
|
615
609
|
2.times { @pdf.start_new_page }
|
616
|
-
options = {:page_filter => :all, :start_count_at => startat}
|
617
|
-
@pdf.expects(:text_box).with("#{startat} 2",
|
618
|
-
@pdf.expects(:text_box).with("#{startat+1} 2",
|
610
|
+
options = { :page_filter => :all, :start_count_at => startat }
|
611
|
+
@pdf.expects(:text_box).with("#{startat} 2", :height => 50)
|
612
|
+
@pdf.expects(:text_box).with("#{startat + 1} 2", :height => 50)
|
619
613
|
@pdf.number_pages "<page> <total>", options
|
620
614
|
end
|
621
615
|
end
|
@@ -625,10 +619,10 @@ describe "The number_pages method" do
|
|
625
619
|
context "equal to #{val}" do
|
626
620
|
it "defaults to start at page 1" do
|
627
621
|
3.times { @pdf.start_new_page }
|
628
|
-
options = {:page_filter => :all, :start_count_at => val}
|
629
|
-
@pdf.expects(:text_box).with("1 3",
|
630
|
-
@pdf.expects(:text_box).with("2 3",
|
631
|
-
@pdf.expects(:text_box).with("3 3",
|
622
|
+
options = { :page_filter => :all, :start_count_at => val }
|
623
|
+
@pdf.expects(:text_box).with("1 3", :height => 50)
|
624
|
+
@pdf.expects(:text_box).with("2 3", :height => 50)
|
625
|
+
@pdf.expects(:text_box).with("3 3", :height => 50)
|
632
626
|
@pdf.number_pages "<page> <total>", options
|
633
627
|
end
|
634
628
|
end
|
@@ -638,8 +632,8 @@ describe "The number_pages method" do
|
|
638
632
|
context "total_pages option" do
|
639
633
|
it "allows the total pages count to be overridden" do
|
640
634
|
2.times { @pdf.start_new_page }
|
641
|
-
@pdf.expects(:text_box).with("1 10",
|
642
|
-
@pdf.expects(:text_box).with("2 10",
|
635
|
+
@pdf.expects(:text_box).with("1 10", :height => 50)
|
636
|
+
@pdf.expects(:text_box).with("2 10", :height => 50)
|
643
637
|
@pdf.number_pages "<page> <total>", :page_filter => :all, :total_pages => 10
|
644
638
|
end
|
645
639
|
end
|
@@ -648,9 +642,9 @@ describe "The number_pages method" do
|
|
648
642
|
context "such as :odd" do
|
649
643
|
it "increments the pages" do
|
650
644
|
3.times { @pdf.start_new_page }
|
651
|
-
@pdf.expects(:text_box).with("1 3",
|
652
|
-
@pdf.expects(:text_box).with("3 3",
|
653
|
-
@pdf.expects(:text_box).with("2 3",
|
645
|
+
@pdf.expects(:text_box).with("1 3", :height => 50)
|
646
|
+
@pdf.expects(:text_box).with("3 3", :height => 50)
|
647
|
+
@pdf.expects(:text_box).with("2 3", :height => 50).never
|
654
648
|
@pdf.number_pages "<page> <total>", :page_filter => :odd
|
655
649
|
end
|
656
650
|
end
|
@@ -667,23 +661,23 @@ describe "The number_pages method" do
|
|
667
661
|
context "such as :odd and 7" do
|
668
662
|
it "increments the pages" do
|
669
663
|
3.times { @pdf.start_new_page }
|
670
|
-
@pdf.expects(:text_box).with("1 3",
|
671
|
-
@pdf.expects(:text_box).with("5 3",
|
672
|
-
@pdf.expects(:text_box).with("6 3",
|
673
|
-
@pdf.expects(:text_box).with("7 3",
|
664
|
+
@pdf.expects(:text_box).with("1 3", :height => 50).never
|
665
|
+
@pdf.expects(:text_box).with("5 3", :height => 50) # page 1
|
666
|
+
@pdf.expects(:text_box).with("6 3", :height => 50).never # page 2
|
667
|
+
@pdf.expects(:text_box).with("7 3", :height => 50) # page 3
|
674
668
|
@pdf.number_pages "<page> <total>", :page_filter => :odd, :start_count_at => 5
|
675
669
|
end
|
676
670
|
end
|
677
671
|
context "some crazy proc and 2" do
|
678
672
|
it "increments the pages" do
|
679
673
|
6.times { @pdf.start_new_page }
|
680
|
-
options = {:page_filter => lambda {|p| p != 2 && p != 5}, :start_count_at => 4}
|
681
|
-
@pdf.expects(:text_box).with("4 6",
|
682
|
-
@pdf.expects(:text_box).with("5 6",
|
683
|
-
@pdf.expects(:text_box).with("6 6",
|
684
|
-
@pdf.expects(:text_box).with("7 6",
|
685
|
-
@pdf.expects(:text_box).with("8 6",
|
686
|
-
@pdf.expects(:text_box).with("9 6",
|
674
|
+
options = { :page_filter => lambda { |p| p != 2 && p != 5 }, :start_count_at => 4 }
|
675
|
+
@pdf.expects(:text_box).with("4 6", :height => 50) # page 1
|
676
|
+
@pdf.expects(:text_box).with("5 6", :height => 50).never # page 2
|
677
|
+
@pdf.expects(:text_box).with("6 6", :height => 50) # page 3
|
678
|
+
@pdf.expects(:text_box).with("7 6", :height => 50) # page 4
|
679
|
+
@pdf.expects(:text_box).with("8 6", :height => 50).never # page 5
|
680
|
+
@pdf.expects(:text_box).with("9 6", :height => 50) # page 6
|
687
681
|
@pdf.number_pages "<page> <total>", options
|
688
682
|
end
|
689
683
|
end
|
@@ -695,17 +689,17 @@ describe "The number_pages method" do
|
|
695
689
|
end
|
696
690
|
|
697
691
|
it "with 10 height" do
|
698
|
-
@pdf.expects(:text_box).with("1 1",
|
692
|
+
@pdf.expects(:text_box).with("1 1", :height => 10)
|
699
693
|
@pdf.number_pages "<page> <total>", :height => 10
|
700
694
|
end
|
701
695
|
|
702
696
|
it "with nil height" do
|
703
|
-
@pdf.expects(:text_box).with("1 1",
|
697
|
+
@pdf.expects(:text_box).with("1 1", :height => nil)
|
704
698
|
@pdf.number_pages "<page> <total>", :height => nil
|
705
699
|
end
|
706
700
|
|
707
701
|
it "with no height" do
|
708
|
-
@pdf.expects(:text_box).with("1 1",
|
702
|
+
@pdf.expects(:text_box).with("1 1", :height => 50)
|
709
703
|
@pdf.number_pages "<page> <total>"
|
710
704
|
end
|
711
705
|
end
|
@@ -714,35 +708,35 @@ end
|
|
714
708
|
describe "The page_match? method" do
|
715
709
|
before do
|
716
710
|
@pdf = Prawn::Document.new(:skip_page_creation => true)
|
717
|
-
10.times {@pdf.start_new_page}
|
711
|
+
10.times { @pdf.start_new_page }
|
718
712
|
end
|
719
713
|
|
720
714
|
it "returns nil given no filter" do
|
721
|
-
@pdf.page_match?(:nil, 1).
|
715
|
+
expect(@pdf.page_match?(:nil, 1)).to be_false
|
722
716
|
end
|
723
717
|
|
724
718
|
it "must provide an :all filter" do
|
725
|
-
(1..@pdf.page_count).all? { |i| @pdf.page_match?(:all, i) }.
|
719
|
+
expect((1..@pdf.page_count).all? { |i| @pdf.page_match?(:all, i) }).to be_true
|
726
720
|
end
|
727
721
|
|
728
722
|
it "must provide an :odd filter" do
|
729
|
-
odd, even = (1..@pdf.page_count).partition
|
730
|
-
odd.all? { |i| @pdf.page_match?(:odd, i) }.
|
731
|
-
even.any? { |i| @pdf.page_match?(:odd, i) }.
|
723
|
+
odd, even = (1..@pdf.page_count).partition(&:odd?)
|
724
|
+
expect(odd.all? { |i| @pdf.page_match?(:odd, i) }).to be_true
|
725
|
+
expect(even.any? { |i| @pdf.page_match?(:odd, i) }).to be_false
|
732
726
|
end
|
733
727
|
|
734
728
|
it "must be able to filter by an array of page numbers" do
|
735
|
-
fltr = [1,2,7]
|
736
|
-
(1..10).select { |i| @pdf.page_match?(fltr, i) }.
|
729
|
+
fltr = [1, 2, 7]
|
730
|
+
expect((1..10).select { |i| @pdf.page_match?(fltr, i) }).to eq([1, 2, 7])
|
737
731
|
end
|
738
732
|
|
739
733
|
it "must be able to filter by a range of page numbers" do
|
740
734
|
fltr = 2..4
|
741
|
-
(1..10).select { |i| @pdf.page_match?(fltr, i) }.
|
735
|
+
expect((1..10).select { |i| @pdf.page_match?(fltr, i) }).to eq([2, 3, 4])
|
742
736
|
end
|
743
737
|
|
744
738
|
it "must be able to filter by an arbitrary proc" do
|
745
739
|
fltr = lambda { |x| x == 1 or x % 3 == 0 }
|
746
|
-
(1..10).select { |i| @pdf.page_match?(fltr, i) }.
|
740
|
+
expect((1..10).select { |i| @pdf.page_match?(fltr, i) }).to eq([1, 3, 6, 9])
|
747
741
|
end
|
748
742
|
end
|