prawn 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/data/images/blend_modes_bottom_layer.jpg +0 -0
- data/data/images/blend_modes_top_layer.jpg +0 -0
- data/data/images/indexed_transparency.png +0 -0
- data/data/images/indexed_transparency_alpha.dat +0 -0
- data/data/images/indexed_transparency_color.dat +0 -0
- data/lib/prawn.rb +2 -1
- data/lib/prawn/document.rb +1 -0
- data/lib/prawn/document/internals.rb +10 -2
- data/lib/prawn/font.rb +14 -1
- data/lib/prawn/graphics.rb +2 -0
- data/lib/prawn/graphics/blend_mode.rb +64 -0
- data/lib/prawn/graphics/patterns.rb +52 -16
- data/lib/prawn/graphics/transformation.rb +3 -0
- data/lib/prawn/images/png.rb +43 -5
- data/lib/prawn/text/formatted/arranger.rb +25 -17
- data/lib/prawn/text/formatted/line_wrap.rb +2 -3
- data/lib/prawn/transformation_stack.rb +42 -0
- data/lib/prawn/version.rb +1 -1
- data/manual/graphics/blend_mode.rb +49 -0
- data/manual/graphics/graphics.rb +1 -0
- data/manual/graphics/soft_masks.rb +1 -1
- data/prawn.gemspec +4 -5
- data/spec/acceptance/png_spec.rb +35 -0
- data/spec/blend_mode_spec.rb +71 -0
- data/spec/document_spec.rb +72 -76
- data/spec/font_spec.rb +11 -11
- data/spec/formatted_text_arranger_spec.rb +178 -149
- data/spec/formatted_text_box_spec.rb +23 -23
- data/spec/graphics_spec.rb +67 -28
- data/spec/image_handler_spec.rb +7 -7
- data/spec/images_spec.rb +1 -1
- data/spec/png_spec.rb +26 -4
- data/spec/repeater_spec.rb +9 -9
- data/spec/spec_helper.rb +1 -4
- data/spec/text_at_spec.rb +2 -2
- data/spec/text_box_spec.rb +20 -16
- data/spec/text_spec.rb +8 -14
- data/spec/transformation_stack_spec.rb +63 -0
- data/spec/view_spec.rb +10 -10
- metadata +27 -31
- data/data/images/pal_bk.png +0 -0
- data/spec/acceptance/png.rb +0 -24
- data/spec/extensions/mocha.rb +0 -45
@@ -21,6 +21,8 @@ module Prawn
|
|
21
21
|
|
22
22
|
# The number of spaces in the last wrapped line
|
23
23
|
attr_reader :space_count
|
24
|
+
attr_reader :soft_hyphen
|
25
|
+
attr_reader :zero_width_space
|
24
26
|
|
25
27
|
# Whether this line is the last line in the paragraph
|
26
28
|
def paragraph_finished?
|
@@ -150,9 +152,6 @@ module Prawn
|
|
150
152
|
"-"
|
151
153
|
end
|
152
154
|
|
153
|
-
attr_reader :soft_hyphen
|
154
|
-
attr_reader :zero_width_space
|
155
|
-
|
156
155
|
def line_empty?
|
157
156
|
@line_empty && @accumulated_width == 0
|
158
157
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# transformation_stack.rb : Stores the transformations that have been applied to the document
|
4
|
+
#
|
5
|
+
# Copyright 2015, Roger Nesbitt. All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'matrix'
|
11
|
+
|
12
|
+
module Prawn
|
13
|
+
module TransformationStack
|
14
|
+
def add_to_transformation_stack(a, b, c, d, e, f)
|
15
|
+
@transformation_stack ||= [[]]
|
16
|
+
@transformation_stack.last.push([a, b, c, d, e, f].map(&:to_f))
|
17
|
+
end
|
18
|
+
|
19
|
+
def save_transformation_stack
|
20
|
+
@transformation_stack ||= [[]]
|
21
|
+
@transformation_stack.push(@transformation_stack.last.dup)
|
22
|
+
end
|
23
|
+
|
24
|
+
def restore_transformation_stack
|
25
|
+
@transformation_stack.pop if @transformation_stack
|
26
|
+
end
|
27
|
+
|
28
|
+
def current_transformation_matrix_with_translation(x = 0, y = 0)
|
29
|
+
transformations = (@transformation_stack || [[]]).last
|
30
|
+
|
31
|
+
matrix = Matrix.identity(3)
|
32
|
+
|
33
|
+
transformations.each do |a, b, c, d, e, f|
|
34
|
+
matrix *= Matrix[[a, c, e], [b, d, f], [0, 0, 1]]
|
35
|
+
end
|
36
|
+
|
37
|
+
matrix *= Matrix[[1, 0, x], [0, 1, y], [0, 0, 1]]
|
38
|
+
|
39
|
+
matrix.to_a[0..1].transpose.flatten
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/prawn/version.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Blend modes can be used to change the way two layers (images, graphics,
|
4
|
+
# text, etc.) are blended together. The <code>blend_mode</code> method
|
5
|
+
# accepts a single blend mode or an array of blend modes. PDF viewers should
|
6
|
+
# blend the layers based on the first recognized blend mode.
|
7
|
+
#
|
8
|
+
# Valid blend modes in v1.4 of the PDF spec include :Normal, :Multiply, :Screen,
|
9
|
+
# :Overlay, :Darken, :Lighten, :ColorDodge, :ColorBurn, :HardLight, :SoftLight,
|
10
|
+
# :Difference, :Exclusion, :Hue, :Saturation, :Color, and :Luminosity.
|
11
|
+
#
|
12
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
13
|
+
%w[.. example_helper]))
|
14
|
+
|
15
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
16
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
17
|
+
start_new_page
|
18
|
+
|
19
|
+
# https://commons.wikimedia.org/wiki/File:Blend_modes_2.-bottom-layer.jpg#/media/File:Blend_modes_2.-bottom-layer.jpg
|
20
|
+
bottom_layer = "#{Prawn::DATADIR}/images/blend_modes_bottom_layer.jpg"
|
21
|
+
|
22
|
+
# https://commons.wikimedia.org/wiki/File:Blend_modes_1.-top-layer.jpg#/media/File:Blend_modes_1.-top-layer.jpg
|
23
|
+
top_layer = "#{Prawn::DATADIR}/images/blend_modes_top_layer.jpg"
|
24
|
+
|
25
|
+
blend_modes = [:Normal, :Multiply, :Screen, :Overlay, :Darken, :Lighten, :ColorDodge, :ColorBurn, :HardLight, :SoftLight, :Difference, :Exclusion, :Hue, :Saturation, :Color, :Luminosity]
|
26
|
+
blend_modes.each_with_index do |blend_mode, index|
|
27
|
+
x = index % 4 * 135
|
28
|
+
y = cursor - (index / 4 * 200)
|
29
|
+
|
30
|
+
image bottom_layer, :at => [x, y], :fit => [125, 125]
|
31
|
+
blend_mode(blend_mode) do
|
32
|
+
image top_layer, :at => [x, y], :fit => [125, 125]
|
33
|
+
end
|
34
|
+
|
35
|
+
y -= 130
|
36
|
+
|
37
|
+
fill_color '009ddc'
|
38
|
+
fill_rectangle [x, y], 75, 25
|
39
|
+
blend_mode(blend_mode) do
|
40
|
+
fill_color 'fdb827'
|
41
|
+
fill_rectangle [x + 50, y], 75, 25
|
42
|
+
end
|
43
|
+
|
44
|
+
y -= 30
|
45
|
+
|
46
|
+
fill_color '000000'
|
47
|
+
text_box blend_mode.to_s, :at => [x, y]
|
48
|
+
end
|
49
|
+
end
|
data/manual/graphics/graphics.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#
|
3
|
-
# Soft masks are
|
3
|
+
# Soft masks are used for more complex alpha channel manipulations. You can use
|
4
4
|
# arbitrary drawing functions for creation of soft masks. The resulting alpha
|
5
5
|
# channel is made of greyscale version of the drawing (luminosity channel to be
|
6
6
|
# precise). So while you can use any combination of colors for soft masks it's
|
data/prawn.gemspec
CHANGED
@@ -22,15 +22,14 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.authors = ["Gregory Brown", "Brad Ediger", "Daniel Nelson", "Jonathan Greenberg", "James Healy"]
|
23
23
|
spec.email = ["gregory.t.brown@gmail.com", "brad@bradediger.com", "dnelson@bluejade.com", "greenberg@entryway.net", "jimmy@deefa.com"]
|
24
24
|
spec.rubyforge_project = "prawn"
|
25
|
-
spec.licenses =
|
25
|
+
spec.licenses = %w(PRAWN GPL-2.0 GPL-3.0)
|
26
26
|
|
27
27
|
spec.add_dependency('ttfunk', '~> 1.4.0')
|
28
|
-
spec.add_dependency('pdf-core', "~> 0.6.
|
28
|
+
spec.add_dependency('pdf-core', "~> 0.6.1")
|
29
29
|
|
30
|
-
spec.add_development_dependency('pdf-inspector', '~> 1.2.
|
30
|
+
spec.add_development_dependency('pdf-inspector', '~> 1.2.1')
|
31
31
|
spec.add_development_dependency('yard')
|
32
|
-
spec.add_development_dependency('rspec', '
|
33
|
-
spec.add_development_dependency('mocha')
|
32
|
+
spec.add_development_dependency('rspec', '~> 3.0')
|
34
33
|
spec.add_development_dependency('rake')
|
35
34
|
spec.add_development_dependency('simplecov')
|
36
35
|
spec.add_development_dependency('prawn-manual_builder', ">= 0.2.0")
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative "../../spec/spec_helper"
|
4
|
+
|
5
|
+
describe "When making a pdf file with png images" do
|
6
|
+
image_dir = "#{Prawn::BASEDIR}/data/images"
|
7
|
+
images = [
|
8
|
+
["Type 0", "#{image_dir}/web-links.png"],
|
9
|
+
["Type 0 with transparency", "#{image_dir}/ruport_type0.png"],
|
10
|
+
["Type 2", "#{image_dir}/ruport.png"],
|
11
|
+
["Type 2 with transparency", "#{image_dir}/arrow2.png"],
|
12
|
+
["Type 3", "#{image_dir}/indexed_color.png"],
|
13
|
+
["Type 3 with transparency", "#{image_dir}/indexed_transparency.png"],
|
14
|
+
["Type 4", "#{image_dir}/page_white_text.png"],
|
15
|
+
["Type 6", "#{image_dir}/dice.png"],
|
16
|
+
["Type 6 in 16bit", "#{image_dir}/16bit.png"]
|
17
|
+
]
|
18
|
+
|
19
|
+
images.each do |header, file|
|
20
|
+
describe "and the image is #{header}" do
|
21
|
+
it "does not error" do
|
22
|
+
expect do
|
23
|
+
Prawn::Document.generate("#{header}.pdf", :page_size => "A5") do
|
24
|
+
fill_color "00FF00"
|
25
|
+
|
26
|
+
fill_rectangle bounds.top_left, bounds.width, bounds.height
|
27
|
+
text header
|
28
|
+
|
29
|
+
image file, :at => [50, 450]
|
30
|
+
end
|
31
|
+
end.to_not raise_error
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
module BlendModeHelper
|
6
|
+
def make_blend_mode(blend_mode)
|
7
|
+
@pdf.blend_mode(blend_mode) do
|
8
|
+
yield if block_given?
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "Document with with blend_mode" do
|
14
|
+
include BlendModeHelper
|
15
|
+
|
16
|
+
it "the PDF version should be at least 1.4" do
|
17
|
+
create_pdf
|
18
|
+
make_blend_mode(:Multiply)
|
19
|
+
str = @pdf.render
|
20
|
+
expect(str[0, 8]).to eq("%PDF-1.4")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "a new extended graphics state should be created for " \
|
24
|
+
"each unique blend mode setting" do
|
25
|
+
create_pdf
|
26
|
+
make_blend_mode(:Multiply) do
|
27
|
+
make_blend_mode(:Screen)
|
28
|
+
end
|
29
|
+
extgstates = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates
|
30
|
+
expect(extgstates.length).to eq(2)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "a new extended graphics state should not be created for " \
|
34
|
+
"each duplicate blend mode setting" do
|
35
|
+
create_pdf
|
36
|
+
make_blend_mode(:Multiply) do
|
37
|
+
make_blend_mode(:Multiply)
|
38
|
+
end
|
39
|
+
extgstates = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates
|
40
|
+
expect(extgstates.length).to eq(1)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "setting the blend mode with only one parameter sets a single blend mode value" do
|
44
|
+
create_pdf
|
45
|
+
make_blend_mode(:Multiply)
|
46
|
+
extgstate = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates.first
|
47
|
+
expect(extgstate[:blend_mode]).to eq(:Multiply)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "setting the blend mode with multiple parameters sets an array of blend modes" do
|
51
|
+
create_pdf
|
52
|
+
make_blend_mode([:Multiply, :Screen, :Overlay])
|
53
|
+
extgstate = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates.first
|
54
|
+
expect(extgstate[:blend_mode]).to eq([:Multiply, :Screen, :Overlay])
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "with more than one page" do
|
58
|
+
include BlendModeHelper
|
59
|
+
|
60
|
+
it "the extended graphic state resource should be added to both pages" do
|
61
|
+
create_pdf
|
62
|
+
make_blend_mode(:Multiply)
|
63
|
+
@pdf.start_new_page
|
64
|
+
make_blend_mode(:Multiply)
|
65
|
+
extgstates = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates
|
66
|
+
extgstate = extgstates[0]
|
67
|
+
expect(extgstates.length).to eq(2)
|
68
|
+
expect(extgstate[:blend_mode]).to eq(:Multiply)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/spec/document_spec.rb
CHANGED
@@ -77,14 +77,14 @@ describe "when generating a document from a subclass" do
|
|
77
77
|
Prawn::Document.extensions.delete(mod1)
|
78
78
|
Prawn::Document.extensions.delete(mod2)
|
79
79
|
|
80
|
-
expect(Prawn::Document.new.respond_to?(:test_extensions1)).to
|
81
|
-
expect(Prawn::Document.new.respond_to?(:test_extensions2)).to
|
80
|
+
expect(Prawn::Document.new.respond_to?(:test_extensions1)).to eq false
|
81
|
+
expect(Prawn::Document.new.respond_to?(:test_extensions2)).to eq false
|
82
82
|
|
83
83
|
# verify these still exist on custom class
|
84
84
|
expect(custom_document.extensions).to eq([mod1, mod2])
|
85
85
|
|
86
|
-
expect(custom_document.new.respond_to?(:test_extensions1)).to
|
87
|
-
expect(custom_document.new.respond_to?(:test_extensions2)).to
|
86
|
+
expect(custom_document.new.respond_to?(:test_extensions1)).to eq true
|
87
|
+
expect(custom_document.new.respond_to?(:test_extensions2)).to eq true
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -176,7 +176,7 @@ describe "on_page_create callback" do
|
|
176
176
|
end
|
177
177
|
|
178
178
|
it "should be delegated from Document to renderer" do
|
179
|
-
expect(@pdf.respond_to?(:on_page_create)).to
|
179
|
+
expect(@pdf.respond_to?(:on_page_create)).to eq true
|
180
180
|
end
|
181
181
|
|
182
182
|
it "should be invoked with document" do
|
@@ -190,8 +190,8 @@ describe "on_page_create callback" do
|
|
190
190
|
end
|
191
191
|
|
192
192
|
it "should be invoked for each new page" do
|
193
|
-
trigger =
|
194
|
-
trigger.
|
193
|
+
trigger = double("trigger")
|
194
|
+
expect(trigger).to receive(:fire).exactly(5).times
|
195
195
|
|
196
196
|
@pdf.renderer.on_page_create { trigger.fire }
|
197
197
|
|
@@ -199,11 +199,11 @@ describe "on_page_create callback" do
|
|
199
199
|
end
|
200
200
|
|
201
201
|
it "should be replaceable" do
|
202
|
-
trigger1 =
|
203
|
-
trigger1.
|
202
|
+
trigger1 = double("trigger 1")
|
203
|
+
expect(trigger1).to receive(:fire).once
|
204
204
|
|
205
|
-
trigger2 =
|
206
|
-
trigger2.
|
205
|
+
trigger2 = double("trigger 2")
|
206
|
+
expect(trigger2).to receive(:fire).once
|
207
207
|
|
208
208
|
@pdf.renderer.on_page_create { trigger1.fire }
|
209
209
|
|
@@ -215,8 +215,8 @@ describe "on_page_create callback" do
|
|
215
215
|
end
|
216
216
|
|
217
217
|
it "should be clearable by calling on_page_create without a block" do
|
218
|
-
trigger =
|
219
|
-
trigger.
|
218
|
+
trigger = double("trigger")
|
219
|
+
expect(trigger).to receive(:fire).once
|
220
220
|
|
221
221
|
@pdf.renderer.on_page_create { trigger.fire }
|
222
222
|
|
@@ -231,8 +231,8 @@ end
|
|
231
231
|
describe "Document compression" do
|
232
232
|
it "should not compress the page content stream if compression is disabled" do
|
233
233
|
pdf = Prawn::Document.new(:compress => false)
|
234
|
-
pdf.page.content.stream.
|
235
|
-
pdf.page.content.stream.
|
234
|
+
allow(pdf.page.content.stream).to receive(:compress!).and_return(true)
|
235
|
+
expect(pdf.page.content.stream).to_not receive(:compress!)
|
236
236
|
|
237
237
|
pdf.text "Hi There" * 20
|
238
238
|
pdf.render
|
@@ -240,8 +240,8 @@ describe "Document compression" do
|
|
240
240
|
|
241
241
|
it "should compress the page content stream if compression is enabled" do
|
242
242
|
pdf = Prawn::Document.new(:compress => true)
|
243
|
-
pdf.page.content.stream.
|
244
|
-
pdf.page.content.stream.
|
243
|
+
allow(pdf.page.content.stream).to receive(:compress!).and_return(true)
|
244
|
+
expect(pdf.page.content.stream).to receive(:compress!).once
|
245
245
|
|
246
246
|
pdf.text "Hi There" * 20
|
247
247
|
pdf.render
|
@@ -304,30 +304,31 @@ describe "When reopening pages" do
|
|
304
304
|
end
|
305
305
|
|
306
306
|
it "should restore the layout of the page" do
|
307
|
-
Prawn::Document.new do
|
307
|
+
doc = Prawn::Document.new do
|
308
308
|
start_new_page :layout => :landscape
|
309
|
-
lsize = [bounds.width, bounds.height]
|
310
|
-
|
311
|
-
[bounds.width, bounds.height].should == lsize
|
312
|
-
go_to_page 1
|
313
|
-
[bounds.width, bounds.height].should == lsize.reverse
|
314
309
|
end
|
310
|
+
|
311
|
+
lsize = [doc.bounds.width, doc.bounds.height]
|
312
|
+
|
313
|
+
expect([doc.bounds.width, doc.bounds.height]).to eq lsize
|
314
|
+
doc.go_to_page 1
|
315
|
+
expect([doc.bounds.width, doc.bounds.height]).to eq lsize.reverse
|
315
316
|
end
|
316
317
|
|
317
318
|
it "should restore the margin box of the page" do
|
318
|
-
Prawn::Document.new(:margin => [100, 100])
|
319
|
-
|
319
|
+
doc = Prawn::Document.new(:margin => [100, 100])
|
320
|
+
page1_bounds = doc.bounds
|
320
321
|
|
321
|
-
|
322
|
+
doc.start_new_page(:margin => [200, 200])
|
322
323
|
|
323
|
-
|
324
|
-
|
324
|
+
expect([doc.bounds.width, doc.bounds.height]).to eq(
|
325
|
+
[page1_bounds.width - 200, page1_bounds.height - 200]
|
326
|
+
)
|
325
327
|
|
326
|
-
|
328
|
+
doc.go_to_page(1)
|
327
329
|
|
328
|
-
|
329
|
-
|
330
|
-
end
|
330
|
+
expect(doc.bounds.width).to eq page1_bounds.width
|
331
|
+
expect(doc.bounds.height).to eq page1_bounds.height
|
331
332
|
end
|
332
333
|
end
|
333
334
|
|
@@ -469,22 +470,17 @@ describe "The render() feature" do
|
|
469
470
|
it "should trigger before_render callbacks just before rendering" do
|
470
471
|
pdf = Prawn::Document.new
|
471
472
|
|
472
|
-
seq = sequence("callback_order")
|
473
|
-
|
474
473
|
# Verify the order: finalize -> fire callbacks -> render body
|
475
|
-
pdf.renderer.
|
476
|
-
trigger = mock
|
477
|
-
trigger.expects(:fire).in_sequence(seq)
|
474
|
+
expect(pdf.renderer).to receive(:finalize_all_page_contents).and_call_original.ordered
|
478
475
|
|
479
|
-
|
480
|
-
|
481
|
-
pdf.renderer.expects(:render_body).in_sequence(seq)
|
476
|
+
trigger = double("trigger")
|
477
|
+
expect(trigger).to receive(:fire).ordered
|
482
478
|
|
483
479
|
pdf.renderer.before_render{ trigger.fire }
|
484
480
|
|
485
|
-
|
486
|
-
|
487
|
-
pdf.render
|
481
|
+
expect(pdf.renderer).to receive(:render_body).and_call_original.ordered
|
482
|
+
|
483
|
+
pdf.render(StringIO.new)
|
488
484
|
end
|
489
485
|
|
490
486
|
it "should be idempotent" do
|
@@ -574,31 +570,31 @@ describe "The number_pages method" do
|
|
574
570
|
|
575
571
|
it "replaces the '<page>' string with the proper page number" do
|
576
572
|
@pdf.start_new_page
|
577
|
-
@pdf.
|
573
|
+
expect(@pdf).to receive(:text_box).with("1, test", :height => 50)
|
578
574
|
@pdf.number_pages "<page>, test", :page_filter => :all
|
579
575
|
end
|
580
576
|
|
581
577
|
it "replaces the '<total>' string with the total page count" do
|
582
578
|
@pdf.start_new_page
|
583
|
-
@pdf.
|
579
|
+
expect(@pdf).to receive(:text_box).with("test, 1", :height => 50)
|
584
580
|
@pdf.number_pages "test, <total>", :page_filter => :all
|
585
581
|
end
|
586
582
|
|
587
583
|
it "must print each page if given the :all page_filter" do
|
588
584
|
10.times { @pdf.start_new_page }
|
589
|
-
@pdf.
|
585
|
+
expect(@pdf).to receive(:text_box).exactly(10).times
|
590
586
|
@pdf.number_pages "test", :page_filter => :all
|
591
587
|
end
|
592
588
|
|
593
589
|
it "must print each page if no :page_filter is specified" do
|
594
590
|
10.times { @pdf.start_new_page }
|
595
|
-
@pdf.
|
591
|
+
expect(@pdf).to receive(:text_box).exactly(10).times
|
596
592
|
@pdf.number_pages "test"
|
597
593
|
end
|
598
594
|
|
599
595
|
it "must not print the page number if given a nil filter" do
|
600
596
|
10.times { @pdf.start_new_page }
|
601
|
-
@pdf.
|
597
|
+
expect(@pdf).to_not receive(:text_box)
|
602
598
|
@pdf.number_pages "test", :page_filter => nil
|
603
599
|
end
|
604
600
|
|
@@ -608,8 +604,8 @@ describe "The number_pages method" do
|
|
608
604
|
it "increments the pages" do
|
609
605
|
2.times { @pdf.start_new_page }
|
610
606
|
options = { :page_filter => :all, :start_count_at => startat }
|
611
|
-
@pdf.
|
612
|
-
@pdf.
|
607
|
+
expect(@pdf).to receive(:text_box).with("#{startat} 2", :height => 50)
|
608
|
+
expect(@pdf).to receive(:text_box).with("#{startat + 1} 2", :height => 50)
|
613
609
|
@pdf.number_pages "<page> <total>", options
|
614
610
|
end
|
615
611
|
end
|
@@ -620,9 +616,9 @@ describe "The number_pages method" do
|
|
620
616
|
it "defaults to start at page 1" do
|
621
617
|
3.times { @pdf.start_new_page }
|
622
618
|
options = { :page_filter => :all, :start_count_at => val }
|
623
|
-
@pdf.
|
624
|
-
@pdf.
|
625
|
-
@pdf.
|
619
|
+
expect(@pdf).to receive(:text_box).with("1 3", :height => 50)
|
620
|
+
expect(@pdf).to receive(:text_box).with("2 3", :height => 50)
|
621
|
+
expect(@pdf).to receive(:text_box).with("3 3", :height => 50)
|
626
622
|
@pdf.number_pages "<page> <total>", options
|
627
623
|
end
|
628
624
|
end
|
@@ -632,8 +628,8 @@ describe "The number_pages method" do
|
|
632
628
|
context "total_pages option" do
|
633
629
|
it "allows the total pages count to be overridden" do
|
634
630
|
2.times { @pdf.start_new_page }
|
635
|
-
@pdf.
|
636
|
-
@pdf.
|
631
|
+
expect(@pdf).to receive(:text_box).with("1 10", :height => 50)
|
632
|
+
expect(@pdf).to receive(:text_box).with("2 10", :height => 50)
|
637
633
|
@pdf.number_pages "<page> <total>", :page_filter => :all, :total_pages => 10
|
638
634
|
end
|
639
635
|
end
|
@@ -642,16 +638,16 @@ describe "The number_pages method" do
|
|
642
638
|
context "such as :odd" do
|
643
639
|
it "increments the pages" do
|
644
640
|
3.times { @pdf.start_new_page }
|
645
|
-
@pdf.
|
646
|
-
@pdf.
|
647
|
-
@pdf.
|
641
|
+
expect(@pdf).to receive(:text_box).with("1 3", :height => 50)
|
642
|
+
expect(@pdf).to receive(:text_box).with("3 3", :height => 50)
|
643
|
+
expect(@pdf).to_not receive(:text_box).with("2 3", :height => 50)
|
648
644
|
@pdf.number_pages "<page> <total>", :page_filter => :odd
|
649
645
|
end
|
650
646
|
end
|
651
647
|
context "missing" do
|
652
648
|
it "does not print any page numbers" do
|
653
649
|
3.times { @pdf.start_new_page }
|
654
|
-
@pdf.
|
650
|
+
expect(@pdf).to_not receive(:text_box)
|
655
651
|
@pdf.number_pages "<page> <total>", :page_filter => nil
|
656
652
|
end
|
657
653
|
end
|
@@ -661,10 +657,10 @@ describe "The number_pages method" do
|
|
661
657
|
context "such as :odd and 7" do
|
662
658
|
it "increments the pages" do
|
663
659
|
3.times { @pdf.start_new_page }
|
664
|
-
@pdf.
|
665
|
-
@pdf.
|
666
|
-
@pdf.
|
667
|
-
@pdf.
|
660
|
+
expect(@pdf).to_not receive(:text_box).with("1 3", :height => 50)
|
661
|
+
expect(@pdf).to receive(:text_box).with("5 3", :height => 50) # page 1
|
662
|
+
expect(@pdf).to_not receive(:text_box).with("6 3", :height => 50) # page 2
|
663
|
+
expect(@pdf).to receive(:text_box).with("7 3", :height => 50) # page 3
|
668
664
|
@pdf.number_pages "<page> <total>", :page_filter => :odd, :start_count_at => 5
|
669
665
|
end
|
670
666
|
end
|
@@ -672,12 +668,12 @@ describe "The number_pages method" do
|
|
672
668
|
it "increments the pages" do
|
673
669
|
6.times { @pdf.start_new_page }
|
674
670
|
options = { :page_filter => lambda { |p| p != 2 && p != 5 }, :start_count_at => 4 }
|
675
|
-
@pdf.
|
676
|
-
@pdf.
|
677
|
-
@pdf.
|
678
|
-
@pdf.
|
679
|
-
@pdf.
|
680
|
-
@pdf.
|
671
|
+
expect(@pdf).to receive(:text_box).with("4 6", :height => 50) # page 1
|
672
|
+
expect(@pdf).to_not receive(:text_box).with("5 6", :height => 50) # page 2
|
673
|
+
expect(@pdf).to receive(:text_box).with("6 6", :height => 50) # page 3
|
674
|
+
expect(@pdf).to receive(:text_box).with("7 6", :height => 50) # page 4
|
675
|
+
expect(@pdf).to_not receive(:text_box).with("8 6", :height => 50) # page 5
|
676
|
+
expect(@pdf).to receive(:text_box).with("9 6", :height => 50) # page 6
|
681
677
|
@pdf.number_pages "<page> <total>", options
|
682
678
|
end
|
683
679
|
end
|
@@ -689,17 +685,17 @@ describe "The number_pages method" do
|
|
689
685
|
end
|
690
686
|
|
691
687
|
it "with 10 height" do
|
692
|
-
@pdf.
|
688
|
+
expect(@pdf).to receive(:text_box).with("1 1", :height => 10)
|
693
689
|
@pdf.number_pages "<page> <total>", :height => 10
|
694
690
|
end
|
695
691
|
|
696
692
|
it "with nil height" do
|
697
|
-
@pdf.
|
693
|
+
expect(@pdf).to receive(:text_box).with("1 1", :height => nil)
|
698
694
|
@pdf.number_pages "<page> <total>", :height => nil
|
699
695
|
end
|
700
696
|
|
701
697
|
it "with no height" do
|
702
|
-
@pdf.
|
698
|
+
expect(@pdf).to receive(:text_box).with("1 1", height: 50)
|
703
699
|
@pdf.number_pages "<page> <total>"
|
704
700
|
end
|
705
701
|
end
|
@@ -712,17 +708,17 @@ describe "The page_match? method" do
|
|
712
708
|
end
|
713
709
|
|
714
710
|
it "returns nil given no filter" do
|
715
|
-
expect(@pdf.page_match?(:nil, 1)).to
|
711
|
+
expect(@pdf.page_match?(:nil, 1)).to be_falsey
|
716
712
|
end
|
717
713
|
|
718
714
|
it "must provide an :all filter" do
|
719
|
-
expect((1..@pdf.page_count).all? { |i| @pdf.page_match?(:all, i) }).to
|
715
|
+
expect((1..@pdf.page_count).all? { |i| @pdf.page_match?(:all, i) }).to eq true
|
720
716
|
end
|
721
717
|
|
722
718
|
it "must provide an :odd filter" do
|
723
719
|
odd, even = (1..@pdf.page_count).partition(&:odd?)
|
724
|
-
expect(odd.all? { |i| @pdf.page_match?(:odd, i) }).to
|
725
|
-
expect(even.any? { |i| @pdf.page_match?(:odd, i) }).to
|
720
|
+
expect(odd.all? { |i| @pdf.page_match?(:odd, i) }).to eq true
|
721
|
+
expect(even.any? { |i| @pdf.page_match?(:odd, i) }).to be_falsey
|
726
722
|
end
|
727
723
|
|
728
724
|
it "must be able to filter by an array of page numbers" do
|