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
data/spec/graphics_spec.rb
CHANGED
@@ -200,22 +200,22 @@ describe "When filling" do
|
|
200
200
|
before(:each) { create_pdf }
|
201
201
|
|
202
202
|
it "should default to the f operator (nonzero winding number rule)" do
|
203
|
-
@pdf.renderer.
|
203
|
+
expect(@pdf.renderer).to receive(:add_content).with("f")
|
204
204
|
@pdf.fill
|
205
205
|
end
|
206
206
|
|
207
207
|
it "should use f* for :fill_rule => :even_odd" do
|
208
|
-
@pdf.renderer.
|
208
|
+
expect(@pdf.renderer).to receive(:add_content).with("f*")
|
209
209
|
@pdf.fill(:fill_rule => :even_odd)
|
210
210
|
end
|
211
211
|
|
212
212
|
it "should use b by default for fill_and_stroke (nonzero winding number)" do
|
213
|
-
@pdf.renderer.
|
213
|
+
expect(@pdf.renderer).to receive(:add_content).with("b")
|
214
214
|
@pdf.fill_and_stroke
|
215
215
|
end
|
216
216
|
|
217
217
|
it "should use b* for fill_and_stroke(:fill_rule => :even_odd)" do
|
218
|
-
@pdf.renderer.
|
218
|
+
expect(@pdf.renderer).to receive(:add_content).with("b*")
|
219
219
|
@pdf.fill_and_stroke(:fill_rule => :even_odd)
|
220
220
|
end
|
221
221
|
end
|
@@ -280,10 +280,10 @@ describe "Patterns" do
|
|
280
280
|
expect(pattern[:Shading][:Coords]).to eq([0, 0, @pdf.bounds.width, 0])
|
281
281
|
expect(pattern[:Shading][:Function][:C0].zip([1, 0, 0]).all?{ |x1, x2|
|
282
282
|
(x1 - x2).abs < 0.01
|
283
|
-
}).to
|
283
|
+
}).to eq true
|
284
284
|
expect(pattern[:Shading][:Function][:C1].zip([0, 0, 1]).all?{ |x1, x2|
|
285
285
|
(x1 - x2).abs < 0.01
|
286
|
-
}).to
|
286
|
+
}).to eq true
|
287
287
|
end
|
288
288
|
|
289
289
|
it "fill_gradient should set fill color to the pattern" do
|
@@ -319,10 +319,10 @@ describe "Patterns" do
|
|
319
319
|
expect(pattern[:Shading][:Coords]).to eq([0, 0, 10, @pdf.bounds.width, 0, 20])
|
320
320
|
expect(pattern[:Shading][:Function][:C0].zip([1, 0, 0]).all?{ |x1, x2|
|
321
321
|
(x1 - x2).abs < 0.01
|
322
|
-
}).to
|
322
|
+
}).to eq true
|
323
323
|
expect(pattern[:Shading][:Function][:C1].zip([0, 0, 1]).all?{ |x1, x2|
|
324
324
|
(x1 - x2).abs < 0.01
|
325
|
-
}).to
|
325
|
+
}).to eq true
|
326
326
|
end
|
327
327
|
|
328
328
|
it "fill_gradient should set fill color to the pattern" do
|
@@ -343,21 +343,60 @@ describe "Patterns" do
|
|
343
343
|
expect(str).to match(%r{/Pattern\s+CS\s*/SP-?\d+\s+SCN})
|
344
344
|
end
|
345
345
|
end
|
346
|
+
|
347
|
+
describe "gradient transformations" do
|
348
|
+
subject do
|
349
|
+
@pdf.scale 2 do
|
350
|
+
@pdf.translate 40, 40 do
|
351
|
+
@pdf.fill_gradient [0, 10], [15, 15], 'FF0000', '0000FF', opts
|
352
|
+
@pdf.fill_gradient [0, 10], 15, [15, 15], 25, 'FF0000', '0000FF', opts
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
|
357
|
+
grad.patterns.values.map { |pattern| pattern[:Matrix] }.uniq
|
358
|
+
end
|
359
|
+
|
360
|
+
context "when :apply_transformations is true" do
|
361
|
+
let(:opts) { { apply_transformations: true } }
|
362
|
+
|
363
|
+
it "uses the transformation stack to translate user co-ordinates to document co-ordinates required by /Pattern" do
|
364
|
+
expect(subject).to eq([[2, 0, 0, 2, 80, 100]])
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
context "when :apply_transformations is false" do
|
369
|
+
let(:opts) { { apply_transformations: false } }
|
370
|
+
|
371
|
+
it "doesn't transform the gradient" do
|
372
|
+
expect(subject).to eq([[1, 0, 0, 1, 0, 10]])
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
context "when :apply_transformations is unset" do
|
377
|
+
let(:opts) { {} }
|
378
|
+
|
379
|
+
it "doesn't transform the gradient and displays a warning" do
|
380
|
+
expect(@pdf).to receive(:warn).twice
|
381
|
+
expect(subject).to eq([[1, 0, 0, 1, 0, 10]])
|
382
|
+
end
|
383
|
+
end
|
384
|
+
end
|
346
385
|
end
|
347
386
|
|
348
387
|
describe "When using painting shortcuts" do
|
349
388
|
before(:each) { create_pdf }
|
350
389
|
|
351
390
|
it "should convert stroke_some_method(args) into some_method(args); stroke" do
|
352
|
-
@pdf.
|
353
|
-
@pdf.
|
391
|
+
expect(@pdf).to receive(:line_to).with([100, 100])
|
392
|
+
expect(@pdf).to receive(:stroke)
|
354
393
|
|
355
394
|
@pdf.stroke_line_to [100, 100]
|
356
395
|
end
|
357
396
|
|
358
397
|
it "should convert fill_some_method(args) into some_method(args); fill" do
|
359
|
-
@pdf.
|
360
|
-
@pdf.
|
398
|
+
expect(@pdf).to receive(:line_to).with([100, 100])
|
399
|
+
expect(@pdf).to receive(:fill)
|
361
400
|
|
362
401
|
@pdf.fill_line_to [100, 100]
|
363
402
|
end
|
@@ -372,22 +411,21 @@ describe "When using graphics states" do
|
|
372
411
|
before(:each) { create_pdf }
|
373
412
|
|
374
413
|
it "should add the right content on save_graphics_state" do
|
375
|
-
@pdf.renderer.
|
414
|
+
expect(@pdf.renderer).to receive(:add_content).with('q')
|
376
415
|
|
377
416
|
@pdf.save_graphics_state
|
378
417
|
end
|
379
418
|
|
380
419
|
it "should add the right content on restore_graphics_state" do
|
381
|
-
@pdf.renderer.
|
420
|
+
expect(@pdf.renderer).to receive(:add_content).with('Q')
|
382
421
|
|
383
422
|
@pdf.restore_graphics_state
|
384
423
|
end
|
385
424
|
|
386
425
|
it "should save and restore when save_graphics_state is used with a block" do
|
387
|
-
|
388
|
-
@pdf.
|
389
|
-
@pdf.
|
390
|
-
@pdf.renderer.expects(:add_content).with('Q').in_sequence(state)
|
426
|
+
expect(@pdf.renderer).to receive(:add_content).with('q').ordered
|
427
|
+
allow(@pdf).to receive(:foo).ordered
|
428
|
+
expect(@pdf.renderer).to receive(:add_content).with('Q').ordered
|
391
429
|
|
392
430
|
@pdf.save_graphics_state do
|
393
431
|
@pdf.foo
|
@@ -503,14 +541,14 @@ describe "When using transformation matrix" do
|
|
503
541
|
# part is 5 (PDF Reference, Third Edition, p. 706)
|
504
542
|
|
505
543
|
it "should send the right content on transformation_matrix" do
|
506
|
-
@pdf.renderer.
|
544
|
+
expect(@pdf.renderer).to receive(:add_content).with('1.00000 0.00000 0.12346 -1.00000 5.50000 20.00000 cm')
|
507
545
|
@pdf.transformation_matrix 1, 0, 0.123456789, -1.0, 5.5, 20
|
508
546
|
end
|
509
547
|
|
510
548
|
it "should use fixed digits with very small number" do
|
511
549
|
values = Array.new(6, 0.000000000001)
|
512
550
|
string = Array.new(6, "0.00000").join " "
|
513
|
-
@pdf.renderer.
|
551
|
+
expect(@pdf.renderer).to receive(:add_content).with("#{string} cm")
|
514
552
|
@pdf.transformation_matrix(*values)
|
515
553
|
end
|
516
554
|
|
@@ -523,12 +561,13 @@ describe "When using transformation matrix" do
|
|
523
561
|
it "should save the graphics state inside the given block" do
|
524
562
|
values = Array.new(6, 0.000000000001)
|
525
563
|
string = Array.new(6, "0.00000").join " "
|
526
|
-
process = sequence "process"
|
527
564
|
|
528
|
-
@pdf.
|
529
|
-
@pdf.renderer.
|
530
|
-
@pdf.
|
531
|
-
@pdf.
|
565
|
+
expect(@pdf).to receive(:save_graphics_state).with(no_args).ordered
|
566
|
+
allow(@pdf.renderer).to receive(:add_content).with(any_args).twice
|
567
|
+
expect(@pdf.renderer).to receive(:add_content).with("#{string} cm").ordered
|
568
|
+
allow(@pdf).to receive(:do_something).ordered
|
569
|
+
expect(@pdf).to receive(:restore_graphics_state).with(no_args).ordered
|
570
|
+
|
532
571
|
@pdf.transformation_matrix(*values) do
|
533
572
|
@pdf.do_something
|
534
573
|
end
|
@@ -547,7 +586,7 @@ describe "When using transformations shortcuts" do
|
|
547
586
|
|
548
587
|
describe "#rotate" do
|
549
588
|
it "should rotate" do
|
550
|
-
@pdf.
|
589
|
+
expect(@pdf).to receive(:transformation_matrix).with(@cos, @sin, -@sin, @cos, 0, 0)
|
551
590
|
@pdf.rotate(@angle)
|
552
591
|
end
|
553
592
|
end
|
@@ -603,14 +642,14 @@ describe "When using transformations shortcuts" do
|
|
603
642
|
describe "#translate" do
|
604
643
|
it "should translate" do
|
605
644
|
x, y = 12, 54.32
|
606
|
-
@pdf.
|
645
|
+
expect(@pdf).to receive(:transformation_matrix).with(1, 0, 0, 1, x, y)
|
607
646
|
@pdf.translate(x, y)
|
608
647
|
end
|
609
648
|
end
|
610
649
|
|
611
650
|
describe "#scale" do
|
612
651
|
it "should scale" do
|
613
|
-
@pdf.
|
652
|
+
expect(@pdf).to receive(:transformation_matrix).with(@factor, 0, 0, @factor, 0, 0)
|
614
653
|
@pdf.scale(@factor)
|
615
654
|
end
|
616
655
|
end
|
data/spec/image_handler_spec.rb
CHANGED
@@ -5,11 +5,11 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
|
5
5
|
describe "ImageHandler" do
|
6
6
|
let(:image_handler) { Prawn::ImageHandler.new }
|
7
7
|
|
8
|
-
let(:handler_a) {
|
9
|
-
let(:handler_b) {
|
8
|
+
let(:handler_a) { double("Handler A") }
|
9
|
+
let(:handler_b) { double("Handler B") }
|
10
10
|
|
11
11
|
it "finds the image handler for an image" do
|
12
|
-
handler_a.
|
12
|
+
allow(handler_a).to receive(:can_render?).and_return(true)
|
13
13
|
|
14
14
|
image_handler.register(handler_a)
|
15
15
|
image_handler.register(handler_b)
|
@@ -19,7 +19,7 @@ describe "ImageHandler" do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "can prepend handlers" do
|
22
|
-
handler_b.
|
22
|
+
allow(handler_b).to receive(:can_render?).and_return(true)
|
23
23
|
|
24
24
|
image_handler.register(handler_a)
|
25
25
|
image_handler.register!(handler_b)
|
@@ -29,7 +29,7 @@ describe "ImageHandler" do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "can unregister a handler" do
|
32
|
-
handler_b.
|
32
|
+
allow(handler_b).to receive(:can_render?).and_return(true)
|
33
33
|
|
34
34
|
image_handler.register(handler_a)
|
35
35
|
image_handler.register(handler_b)
|
@@ -41,8 +41,8 @@ describe "ImageHandler" do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it "raises an error when no matching handler is found" do
|
44
|
-
handler_a.
|
45
|
-
handler_b.
|
44
|
+
allow(handler_a).to receive(:can_render?).and_return(false)
|
45
|
+
allow(handler_b).to receive(:can_render?).and_return(false)
|
46
46
|
|
47
47
|
image_handler.register(handler_a)
|
48
48
|
image_handler.register(handler_b)
|
data/spec/images_spec.rb
CHANGED
@@ -114,7 +114,7 @@ describe "the image() function" do
|
|
114
114
|
end
|
115
115
|
|
116
116
|
it "should not start a new page just for a stretchy bounding box" do
|
117
|
-
@pdf.
|
117
|
+
expect(@pdf).to_not receive(:start_new_page)
|
118
118
|
@pdf.bounding_box([0, @pdf.cursor], :width => @pdf.bounds.width) do
|
119
119
|
@pdf.image @filename
|
120
120
|
end
|
data/spec/png_spec.rb
CHANGED
@@ -95,10 +95,32 @@ describe "When reading an RGB PNG file with transparency (color type 2)" do
|
|
95
95
|
end
|
96
96
|
|
97
97
|
describe "When reading an indexed color PNG file with transparency (color type 3)" do
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
98
|
+
let(:filename) { "#{Prawn::DATADIR}/images/indexed_transparency.png" }
|
99
|
+
let(:color_filename) { "#{Prawn::DATADIR}/images/indexed_transparency_color.dat" }
|
100
|
+
let(:transparency_filename) { "#{Prawn::DATADIR}/images/indexed_transparency_alpha.dat" }
|
101
|
+
let(:img_data) { File.binread(filename) }
|
102
|
+
let(:png) { Prawn::Images::PNG.new(img_data) }
|
103
|
+
|
104
|
+
it "reads the attributes from the header chunk correctly" do
|
105
|
+
expect(png.width).to eq(200)
|
106
|
+
expect(png.height).to eq(200)
|
107
|
+
expect(png.bits).to eq(8)
|
108
|
+
expect(png.color_type).to eq(3)
|
109
|
+
expect(png.compression_method).to eq(0)
|
110
|
+
expect(png.filter_method).to eq(0)
|
111
|
+
expect(png.interlace_method).to eq(0)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "reads the image data correctly" do
|
115
|
+
data = Zlib::Inflate.inflate(File.binread(color_filename))
|
116
|
+
expect(png.img_data).to eq(data)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "reads the image transparency correctly" do
|
120
|
+
png.split_alpha_channel!
|
121
|
+
|
122
|
+
data = Zlib::Inflate.inflate(File.binread(transparency_filename))
|
123
|
+
expect(png.alpha_channel).to eq(data)
|
102
124
|
end
|
103
125
|
end
|
104
126
|
|
data/spec/repeater_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe "Repeaters" do
|
|
7
7
|
orig_count = Prawn::Repeater.count
|
8
8
|
|
9
9
|
doc = sample_document
|
10
|
-
doc.
|
10
|
+
expect(doc).to receive(:create_stamp).with("prawn_repeater(#{orig_count})")
|
11
11
|
|
12
12
|
r = repeater(doc, :all) { :do_nothing }
|
13
13
|
|
@@ -18,7 +18,7 @@ describe "Repeaters" do
|
|
18
18
|
doc = sample_document
|
19
19
|
r = repeater(doc, :all) { :do_nothing }
|
20
20
|
|
21
|
-
expect((1..doc.page_count).all? { |i| r.match?(i) }).to
|
21
|
+
expect((1..doc.page_count).all? { |i| r.match?(i) }).to eq true
|
22
22
|
end
|
23
23
|
|
24
24
|
it "must provide an :odd filter" do
|
@@ -27,8 +27,8 @@ describe "Repeaters" do
|
|
27
27
|
|
28
28
|
odd, even = (1..doc.page_count).partition(&:odd?)
|
29
29
|
|
30
|
-
expect(odd.all? { |i| r.match?(i) }).to
|
31
|
-
expect(even.any? { |i| r.match?(i) }).to
|
30
|
+
expect(odd.all? { |i| r.match?(i) }).to eq true
|
31
|
+
expect(even.any? { |i| r.match?(i) }).to eq false
|
32
32
|
end
|
33
33
|
|
34
34
|
it "must be able to filter by an array of page numbers" do
|
@@ -54,7 +54,7 @@ describe "Repeaters" do
|
|
54
54
|
|
55
55
|
it "must try to run a stamp if the page number matches" do
|
56
56
|
doc = sample_document
|
57
|
-
doc.
|
57
|
+
expect(doc).to receive(:stamp)
|
58
58
|
|
59
59
|
repeater(doc, :odd).run(3)
|
60
60
|
end
|
@@ -62,28 +62,28 @@ describe "Repeaters" do
|
|
62
62
|
it "must not try to run a stamp unless the page number matches" do
|
63
63
|
doc = sample_document
|
64
64
|
|
65
|
-
doc.
|
65
|
+
expect(doc).to_not receive(:stamp)
|
66
66
|
repeater(doc, :odd).run(2)
|
67
67
|
end
|
68
68
|
|
69
69
|
it "must not try to run a stamp if dynamic is selected" do
|
70
70
|
doc = sample_document
|
71
71
|
|
72
|
-
doc.
|
72
|
+
expect(doc).to_not receive(:stamp)
|
73
73
|
(1..10).each { |p| repeater(doc, :all, true){ :do_nothing }.run(p) }
|
74
74
|
end
|
75
75
|
|
76
76
|
it "must try to run a block if the page number matches" do
|
77
77
|
doc = sample_document
|
78
78
|
|
79
|
-
doc.
|
79
|
+
expect(doc).to receive(:draw_text).twice
|
80
80
|
(1..10).each { |p| repeater(doc, [1, 2], true){ doc.draw_text "foo" }.run(p) }
|
81
81
|
end
|
82
82
|
|
83
83
|
it "must not try to run a block unless the page number matches" do
|
84
84
|
doc = sample_document
|
85
85
|
|
86
|
-
doc.
|
86
|
+
expect(doc).to_not receive(:draw_text)
|
87
87
|
repeater(doc, :odd, true){ doc.draw_text "foo" }.run(2)
|
88
88
|
end
|
89
89
|
|
data/spec/spec_helper.rb
CHANGED
@@ -18,7 +18,6 @@ Prawn.debug = true
|
|
18
18
|
Prawn::Font::AFM.hide_m17n_warning = true
|
19
19
|
|
20
20
|
require "rspec"
|
21
|
-
require "mocha/api"
|
22
21
|
require "pdf/reader"
|
23
22
|
require "pdf/inspector"
|
24
23
|
|
@@ -27,9 +26,7 @@ require "pdf/inspector"
|
|
27
26
|
Dir[File.dirname(__FILE__) + "/extensions/**/*.rb"].each { |f| require f }
|
28
27
|
|
29
28
|
RSpec.configure do |config|
|
30
|
-
config.mock_framework = :mocha
|
31
29
|
config.include EncodingHelpers
|
32
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
33
30
|
end
|
34
31
|
|
35
32
|
def create_pdf(klass = Prawn::Document)
|
@@ -41,7 +38,7 @@ RSpec::Matchers.define :have_parseable_xobjects do
|
|
41
38
|
expect { PDF::Inspector::XObject.analyze(actual.render) }.not_to raise_error
|
42
39
|
true
|
43
40
|
end
|
44
|
-
|
41
|
+
failure_message do |actual|
|
45
42
|
"expected that #{actual}'s XObjects could be successfully parsed"
|
46
43
|
end
|
47
44
|
end
|
data/spec/text_at_spec.rb
CHANGED
@@ -58,7 +58,7 @@ describe "#draw_text" do
|
|
58
58
|
|
59
59
|
text = rotated_text_inspector.analyze(@pdf.render)
|
60
60
|
|
61
|
-
expect(text.tm_operator_used).to
|
61
|
+
expect(text.tm_operator_used).to eq true
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should not use rotation matrix by default" do
|
@@ -66,7 +66,7 @@ describe "#draw_text" do
|
|
66
66
|
|
67
67
|
text = rotated_text_inspector.analyze(@pdf.render)
|
68
68
|
|
69
|
-
expect(text.tm_operator_used).to
|
69
|
+
expect(text.tm_operator_used).to eq false
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should allow overriding default font for a single instance" do
|
data/spec/text_box_spec.rb
CHANGED
@@ -3,43 +3,45 @@
|
|
3
3
|
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
4
|
|
5
5
|
describe "Text::Box#nothing_printed?" do
|
6
|
-
it "
|
6
|
+
it "returns true when nothing printed" do
|
7
7
|
create_pdf
|
8
8
|
string = "Hello world, how are you?\nI'm fine, thank you."
|
9
9
|
text_box = Prawn::Text::Box.new(string,
|
10
10
|
:height => 2,
|
11
11
|
:document => @pdf)
|
12
12
|
text_box.render
|
13
|
-
expect(text_box.nothing_printed?).to
|
13
|
+
expect(text_box.nothing_printed?).to eq true
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
|
+
it "returns false when something printed" do
|
16
17
|
create_pdf
|
17
18
|
string = "Hello world, how are you?\nI'm fine, thank you."
|
18
19
|
text_box = Prawn::Text::Box.new(string,
|
19
20
|
:height => 14,
|
20
21
|
:document => @pdf)
|
21
22
|
text_box.render
|
22
|
-
expect(text_box.nothing_printed?).to
|
23
|
+
expect(text_box.nothing_printed?).to eq false
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
27
|
describe "Text::Box#everything_printed?" do
|
27
|
-
it "
|
28
|
+
it "returns false when not everything printed" do
|
28
29
|
create_pdf
|
29
30
|
string = "Hello world, how are you?\nI'm fine, thank you."
|
30
31
|
text_box = Prawn::Text::Box.new(string,
|
31
32
|
:height => 14,
|
32
33
|
:document => @pdf)
|
33
34
|
text_box.render
|
34
|
-
expect(text_box.everything_printed?).to
|
35
|
+
expect(text_box.everything_printed?).to eq false
|
35
36
|
end
|
36
|
-
|
37
|
+
|
38
|
+
it "returns true when everything printed" do
|
37
39
|
create_pdf
|
38
40
|
string = "Hello world, how are you?\nI'm fine, thank you."
|
39
41
|
text_box = Prawn::Text::Box.new(string,
|
40
42
|
:document => @pdf)
|
41
43
|
text_box.render
|
42
|
-
expect(text_box.everything_printed?).to
|
44
|
+
expect(text_box.everything_printed?).to eq true
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
@@ -186,28 +188,30 @@ describe "Text::Box with :draw_text_callback" do
|
|
186
188
|
before(:each) { create_pdf }
|
187
189
|
|
188
190
|
it "hits the callback whenever text is drawn" do
|
189
|
-
draw_block =
|
190
|
-
draw_block.expects(:kick).with("this text is long enough to")
|
191
|
-
draw_block.expects(:kick).with("span two lines")
|
191
|
+
draw_block = spy("Draw block")
|
192
192
|
|
193
193
|
@pdf.text_box "this text is long enough to span two lines",
|
194
194
|
:width => 150,
|
195
195
|
:draw_text_callback => lambda { |text, _| draw_block.kick(text) }
|
196
|
+
|
197
|
+
expect(draw_block).to have_received(:kick).with("this text is long enough to")
|
198
|
+
expect(draw_block).to have_received(:kick).with("span two lines")
|
196
199
|
end
|
197
200
|
|
198
201
|
it "hits the callback once per fragment for :inline_format" do
|
199
|
-
draw_block =
|
200
|
-
draw_block.expects(:kick).with("this text has ")
|
201
|
-
draw_block.expects(:kick).with("fancy")
|
202
|
-
draw_block.expects(:kick).with(" formatting")
|
202
|
+
draw_block = spy("Draw block")
|
203
203
|
|
204
204
|
@pdf.text_box "this text has <b>fancy</b> formatting",
|
205
205
|
:inline_format => true, :width => 500,
|
206
206
|
:draw_text_callback => lambda { |text, _| draw_block.kick(text) }
|
207
|
+
|
208
|
+
expect(draw_block).to have_received(:kick).with("this text has ")
|
209
|
+
expect(draw_block).to have_received(:kick).with("fancy")
|
210
|
+
expect(draw_block).to have_received(:kick).with(" formatting")
|
207
211
|
end
|
208
212
|
|
209
213
|
it "does not call #draw_text!" do
|
210
|
-
@pdf.
|
214
|
+
expect(@pdf).to_not receive(:draw_text!)
|
211
215
|
@pdf.text_box "some text", :width => 500,
|
212
216
|
:draw_text_callback => lambda { |_, _| }
|
213
217
|
end
|