pdf-wrapper 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +12 -4
- data/Rakefile +1 -1
- data/lib/pdf/wrapper.rb +33 -15
- data/specs/wrapper_spec.rb +258 -20
- metadata +3 -3
data/CHANGELOG
CHANGED
@@ -1,9 +1,17 @@
|
|
1
|
-
v0.0.
|
1
|
+
v0.0.4 (12th March 2008)
|
2
|
+
- added support for custom line widths on primitive drawing shapes (circles,
|
3
|
+
lines, etc). Thanks Paweł Kondzior
|
4
|
+
- fixed a bug where the first line of text in a multi-line cell appeared at the
|
5
|
+
current cursor location instead of inside the cell. Thanks Paweł Kondzior
|
6
|
+
- bumped dependency on PDF::Reader for running specs to 0.6.1
|
7
|
+
|
8
|
+
v0.0.3 (17th January 2008)
|
2
9
|
- added support for repeating elements (like page numbers) via repeating_element
|
3
10
|
- Ensured consistent behaviour WRT functions moving the internal cursor
|
4
|
-
- functions that require positioning info (cell, shapes, etc) will not move
|
5
|
-
|
6
|
-
|
11
|
+
- functions that require positioning info (cell, shapes, etc) will not move
|
12
|
+
the cursor at all
|
13
|
+
- functions where positioning info in optional (text, image, etc), the cursor
|
14
|
+
will be moved to the bottom left corner of the object
|
7
15
|
- Ensure no unrecognised options are provided to various functions
|
8
16
|
- Add support for padding between a cell border and its text
|
9
17
|
- added support for scaling images proportionally
|
data/Rakefile
CHANGED
data/lib/pdf/wrapper.rb
CHANGED
@@ -123,6 +123,7 @@ module PDF
|
|
123
123
|
|
124
124
|
# set a default drawing colour and font style
|
125
125
|
default_color(:black)
|
126
|
+
default_line_width(2.0)
|
126
127
|
default_font("Sans Serif")
|
127
128
|
default_font_size(16)
|
128
129
|
|
@@ -246,6 +247,15 @@ module PDF
|
|
246
247
|
alias default_color= default_color
|
247
248
|
alias stroke_color default_color # PDF::Writer compatibility
|
248
249
|
|
250
|
+
# change the default line width used to draw stroke on the canvas
|
251
|
+
#
|
252
|
+
# Parameters:
|
253
|
+
# <tt>f</tt>:: float value of stroke width from 0.01 to 255
|
254
|
+
def default_line_width(f)
|
255
|
+
@default_line_width = f
|
256
|
+
end
|
257
|
+
alias default_line_width= default_line_width
|
258
|
+
|
249
259
|
# add text to the page, bounded by a box with dimensions HxW, with it's top left corner
|
250
260
|
# at x,y. Any text that doesn't fit it the box will be silently dropped.
|
251
261
|
#
|
@@ -256,7 +266,7 @@ module PDF
|
|
256
266
|
# <tt>:border_width</tt>:: How wide should the border be?
|
257
267
|
# <tt>:border_color</tt>:: What color should the border be?
|
258
268
|
# <tt>:bgcolor</tt>:: A background color for the cell. Defaults to none.
|
259
|
-
# <tt>:padding</tt>:: The number of points to leave between the inside of the border and text. Defaults to 3.
|
269
|
+
# <tt>:padding</tt>:: The number of points to leave between the inside of the border and text. Defaults to 3.
|
260
270
|
def cell(str, x, y, w, h, opts={})
|
261
271
|
# TODO: add support for pango markup (see http://ruby-gnome2.sourceforge.jp/hiki.cgi?pango-markup)
|
262
272
|
# TODO: add a wrap option so wrapping can be disabled
|
@@ -302,9 +312,10 @@ module PDF
|
|
302
312
|
end
|
303
313
|
|
304
314
|
# draws a basic table onto the page
|
305
|
-
# data - a 2d array with the data for the columns. The first row will be treated as the headings
|
306
315
|
#
|
307
|
-
#
|
316
|
+
# <tt>data</tt>:: a 2d array with the data for the columns. The first row will be treated as the headings
|
317
|
+
#
|
318
|
+
# In addition to the standard text style options (see the documentation for text), table supports
|
308
319
|
# the following options:
|
309
320
|
#
|
310
321
|
# <tt>:left</tt>:: The x co-ordinate of the left-hand side of the table. Defaults to the left margin
|
@@ -422,13 +433,15 @@ module PDF
|
|
422
433
|
#
|
423
434
|
# Options:
|
424
435
|
# <tt>:color</tt>:: The colour of the circle outline
|
436
|
+
# <tt>:line_width</tt>:: The width of outline. Defaults to 2.0
|
425
437
|
# <tt>:fill_color</tt>:: The colour to fill the circle with. Defaults to nil (no fill)
|
426
438
|
def circle(x, y, r, opts = {})
|
427
439
|
options = {:color => @default_color,
|
440
|
+
:line_width => @default_line_width,
|
428
441
|
:fill_color => nil
|
429
442
|
}
|
430
443
|
options.merge!(opts)
|
431
|
-
options.assert_valid_keys(:color, :fill_color)
|
444
|
+
options.assert_valid_keys(:color, :line_width, :fill_color)
|
432
445
|
|
433
446
|
# save the cursor position so we can restore it at the end
|
434
447
|
origx, origy = current_point
|
@@ -442,6 +455,7 @@ module PDF
|
|
442
455
|
end
|
443
456
|
|
444
457
|
set_color(options[:color])
|
458
|
+
@context.set_line_width(options[:line_width])
|
445
459
|
@context.circle(x, y, r).stroke
|
446
460
|
|
447
461
|
# restore the cursor position
|
@@ -452,16 +466,17 @@ module PDF
|
|
452
466
|
#
|
453
467
|
# Options:
|
454
468
|
# <tt>:color</tt>:: The colour of the line
|
469
|
+
# <tt>:line_width</tt>:: The width of line. Defaults its 2.0
|
455
470
|
def line(x0, y0, x1, y1, opts = {})
|
456
|
-
options = {:color => @default_color }
|
471
|
+
options = {:color => @default_color, :line_width => @default_line_width }
|
457
472
|
options.merge!(opts)
|
458
|
-
options.assert_valid_keys(:color)
|
473
|
+
options.assert_valid_keys(:color, :line_width)
|
459
474
|
|
460
475
|
# save the cursor position so we can restore it at the end
|
461
476
|
origx, origy = current_point
|
462
477
|
|
463
478
|
set_color(options[:color])
|
464
|
-
|
479
|
+
@context.set_line_width(options[:line_width])
|
465
480
|
move_to(x0,y0)
|
466
481
|
@context.line_to(x1,y1).stroke
|
467
482
|
|
@@ -478,13 +493,15 @@ module PDF
|
|
478
493
|
#
|
479
494
|
# Options:
|
480
495
|
# <tt>:color</tt>:: The colour of the rectangle outline
|
496
|
+
# <tt>:line_width</tt>:: The width of outline. Defaults to 2.0
|
481
497
|
# <tt>:fill_color</tt>:: The colour to fill the rectangle with. Defaults to nil (no fill)
|
482
498
|
def rectangle(x, y, w, h, opts = {})
|
483
499
|
options = {:color => @default_color,
|
500
|
+
:line_width => @default_line_width,
|
484
501
|
:fill_color => nil
|
485
502
|
}
|
486
503
|
options.merge!(opts)
|
487
|
-
options.assert_valid_keys(:color, :fill_color)
|
504
|
+
options.assert_valid_keys(:color, :line_width, :fill_color)
|
488
505
|
|
489
506
|
# save the cursor position so we can restore it at the end
|
490
507
|
origx, origy = current_point
|
@@ -496,6 +513,7 @@ module PDF
|
|
496
513
|
end
|
497
514
|
|
498
515
|
set_color(options[:color])
|
516
|
+
@context.set_line_width(options[:line_width])
|
499
517
|
@context.rectangle(x, y, w, h).stroke
|
500
518
|
|
501
519
|
# restore the cursor position
|
@@ -512,13 +530,15 @@ module PDF
|
|
512
530
|
#
|
513
531
|
# Options:
|
514
532
|
# <tt>:color</tt>:: The colour of the rectangle outline
|
533
|
+
# <tt>:line_width</tt>:: The width of outline. Defaults to 2.0
|
515
534
|
# <tt>:fill_color</tt>:: The colour to fill the rectangle with. Defaults to nil (no fill)
|
516
535
|
def rounded_rectangle(x, y, w, h, r, opts = {})
|
517
536
|
options = {:color => @default_color,
|
537
|
+
:line_width => @default_line_width,
|
518
538
|
:fill_color => nil
|
519
539
|
}
|
520
540
|
options.merge!(opts)
|
521
|
-
options.assert_valid_keys(:color, :fill_color)
|
541
|
+
options.assert_valid_keys(:color, :fill_color, :line_width)
|
522
542
|
|
523
543
|
raise ArgumentError, "Argument r must be less than both w and h arguments" if r >= w || r >= h
|
524
544
|
|
@@ -532,6 +552,7 @@ module PDF
|
|
532
552
|
end
|
533
553
|
|
534
554
|
set_color(options[:color])
|
555
|
+
@context.set_line_width(options[:line_width])
|
535
556
|
@context.rounded_rectangle(x, y, w, h, r).stroke
|
536
557
|
|
537
558
|
# restore the cursor position
|
@@ -958,7 +979,7 @@ module PDF
|
|
958
979
|
# distributed with rcairo - it's still black magic to me and has a few edge
|
959
980
|
# cases where it doesn't work too well. Needs to be improved.
|
960
981
|
def render_layout(layout, x, y, h, opts = {})
|
961
|
-
# we can't use
|
982
|
+
# we can't use context.show_pango_layout, as that won't start
|
962
983
|
# a new page if the layout hits the bottom margin. Instead,
|
963
984
|
# we iterate over each line of text in the layout and add it to
|
964
985
|
# the canvas, page breaking as necessary
|
@@ -972,14 +993,9 @@ module PDF
|
|
972
993
|
|
973
994
|
# for each line in the layout
|
974
995
|
layout.lines.each do |line|
|
975
|
-
|
976
|
-
# draw the line on the canvas
|
977
|
-
@context.show_pango_layout_line(line)
|
978
|
-
|
979
996
|
#calculate where the next line starts
|
980
997
|
ink_rect, logical_rect = line.extents
|
981
998
|
y = y + (logical_rect.height / Pango::SCALE * (3.0/4.0)) + 1
|
982
|
-
|
983
999
|
if y >= (orig_y + h)
|
984
1000
|
# our text is using the maximum amount of vertical space we want it to
|
985
1001
|
if options[:auto_new_page]
|
@@ -996,6 +1012,8 @@ module PDF
|
|
996
1012
|
|
997
1013
|
# move to the start of the next line
|
998
1014
|
move_to(x, y)
|
1015
|
+
# draw the line on the canvas
|
1016
|
+
@context.show_pango_layout_line(line)
|
999
1017
|
end
|
1000
1018
|
|
1001
1019
|
# return the y co-ord we finished on
|
data/specs/wrapper_spec.rb
CHANGED
@@ -5,6 +5,9 @@ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
|
5
5
|
require 'pdf/wrapper'
|
6
6
|
require 'tempfile'
|
7
7
|
require 'rubygems'
|
8
|
+
|
9
|
+
gem "pdf-reader", ">=0.6.1"
|
10
|
+
|
8
11
|
require 'pdf/reader'
|
9
12
|
|
10
13
|
# make some private methods of PDF::Wrapper public for testing
|
@@ -140,6 +143,31 @@ context "The PDF::Wrapper class" do
|
|
140
143
|
pdf.instance_variable_get("@default_color").should eql([0.0,0.0,0.0,1.0])
|
141
144
|
pdf.instance_variable_get("@default_font").should eql("Sans Serif")
|
142
145
|
pdf.instance_variable_get("@default_font_size").should eql(16)
|
146
|
+
pdf.instance_variable_get("@default_line_width").should eql(2.0)
|
147
|
+
end
|
148
|
+
|
149
|
+
specify "should be able to change the default color" do
|
150
|
+
pdf = PDF::Wrapper.new
|
151
|
+
pdf.default_color(:red)
|
152
|
+
pdf.instance_variable_get("@default_color").should eql([1.0,0.0,0.0,1.0])
|
153
|
+
end
|
154
|
+
|
155
|
+
specify "should be able to change the default font" do
|
156
|
+
pdf = PDF::Wrapper.new
|
157
|
+
pdf.default_font("Arial")
|
158
|
+
pdf.instance_variable_get("@default_font").should eql("Arial")
|
159
|
+
end
|
160
|
+
|
161
|
+
specify "should be able to change the default font size" do
|
162
|
+
pdf = PDF::Wrapper.new
|
163
|
+
pdf.default_font_size(24)
|
164
|
+
pdf.instance_variable_get("@default_font_size").should eql(24)
|
165
|
+
end
|
166
|
+
|
167
|
+
specify "should be able to change the default line width" do
|
168
|
+
pdf = PDF::Wrapper.new
|
169
|
+
pdf.default_line_width(10)
|
170
|
+
pdf.instance_variable_get("@default_line_width").should eql(10)
|
143
171
|
end
|
144
172
|
|
145
173
|
specify "should initialize with the cursor at the top left of the body of the page" do
|
@@ -213,6 +241,25 @@ context "The PDF::Wrapper class" do
|
|
213
241
|
receiver.first_occurance_of(:append_line)[:args].should eql([x1.to_f, y1.to_f])
|
214
242
|
end
|
215
243
|
|
244
|
+
specify "should be able to draw a single line onto the canvas with a width of 5" do
|
245
|
+
x0 = y0 = 100
|
246
|
+
x1 = y1 = 200
|
247
|
+
width = 5
|
248
|
+
pdf = PDF::Wrapper.new
|
249
|
+
pdf.line(x0,y0,x1,y1, :line_width => width)
|
250
|
+
|
251
|
+
receiver = PDF::Reader::RegisterReceiver.new
|
252
|
+
reader = PDF::Reader.string(pdf.render, receiver)
|
253
|
+
|
254
|
+
# the begin_new_subpath command specifies the start of the line, append line specifies the end
|
255
|
+
receiver.count(:set_line_width).should eql(1)
|
256
|
+
receiver.count(:begin_new_subpath).should eql(1)
|
257
|
+
receiver.count(:append_line).should eql(1)
|
258
|
+
receiver.first_occurance_of(:set_line_width)[:args].should eql([width.to_f])
|
259
|
+
receiver.first_occurance_of(:begin_new_subpath)[:args].should eql([x0.to_f, y0.to_f])
|
260
|
+
receiver.first_occurance_of(:append_line)[:args].should eql([x1.to_f, y1.to_f])
|
261
|
+
end
|
262
|
+
|
216
263
|
specify "should be able to draw an empty rectangle onto the canvas" do
|
217
264
|
x = y = 100
|
218
265
|
w = h = 200
|
@@ -230,6 +277,28 @@ context "The PDF::Wrapper class" do
|
|
230
277
|
callbacks.shift[:args].should eql([x.to_f, (y+h).to_f])
|
231
278
|
end
|
232
279
|
|
280
|
+
specify "should be able to draw an empty rectangle onto the canvas with a line width of 5" do
|
281
|
+
x = y = 100
|
282
|
+
w = h = 200
|
283
|
+
width = 5
|
284
|
+
pdf = PDF::Wrapper.new
|
285
|
+
pdf.rectangle(x,y,w,h, :line_width => width)
|
286
|
+
|
287
|
+
receiver = PDF::Reader::RegisterReceiver.new
|
288
|
+
reader = PDF::Reader.string(pdf.render, receiver)
|
289
|
+
|
290
|
+
# ensure the line width was set correctly
|
291
|
+
receiver.count(:set_line_width).should eql(1)
|
292
|
+
receiver.first_occurance_of(:set_line_width)[:args].should eql([width.to_f])
|
293
|
+
|
294
|
+
# the begin_new_subpath command specifies the start of the line, append line specifies the end
|
295
|
+
callbacks = receiver.series(:begin_new_subpath, :append_line,:append_line,:append_line, :close_subpath)
|
296
|
+
callbacks.shift[:args].should eql([x.to_f, y.to_f])
|
297
|
+
callbacks.shift[:args].should eql([(x+w).to_f, y.to_f])
|
298
|
+
callbacks.shift[:args].should eql([(x+w).to_f, (y+h).to_f])
|
299
|
+
callbacks.shift[:args].should eql([x.to_f, (y+h).to_f])
|
300
|
+
end
|
301
|
+
|
233
302
|
specify "should leave the cursor in the bottom left of a layout when new text is added" do
|
234
303
|
pdf = PDF::Wrapper.new
|
235
304
|
x, y = pdf.current_point
|
@@ -275,6 +344,23 @@ context "The PDF::Wrapper class" do
|
|
275
344
|
end
|
276
345
|
=end
|
277
346
|
|
347
|
+
specify "should be able to draw an empty rounded rectangle onto the canvas with a line width of 5"
|
348
|
+
=begin
|
349
|
+
do
|
350
|
+
x = y = 100
|
351
|
+
w = h = 200
|
352
|
+
r = 5
|
353
|
+
w = 5
|
354
|
+
pdf = PDF::Wrapper.new
|
355
|
+
pdf.rounded_rectangle(x,y,w,h,r, :line_width => w)
|
356
|
+
|
357
|
+
receiver = PDF::Reader::RegisterReceiver.new
|
358
|
+
reader = PDF::Reader.string(pdf.render, receiver)
|
359
|
+
|
360
|
+
# TODO: test for the appropriate pattern of callbacks
|
361
|
+
end
|
362
|
+
=end
|
363
|
+
|
278
364
|
specify "should be able to draw a filled rounded rectangle onto the canvas"
|
279
365
|
=begin
|
280
366
|
do
|
@@ -307,14 +393,15 @@ context "The PDF::Wrapper class" do
|
|
307
393
|
end
|
308
394
|
=end
|
309
395
|
|
310
|
-
specify "should be able to draw
|
396
|
+
specify "should be able to draw an empty circle onto the canvas with a line width of 5"
|
311
397
|
=begin
|
312
398
|
do
|
313
399
|
x = 100
|
314
400
|
y = 200
|
315
401
|
r = 5
|
402
|
+
w = 5
|
316
403
|
pdf = PDF::Wrapper.new
|
317
|
-
pdf.circle(x,y,r, :
|
404
|
+
pdf.circle(x,y,r, :line_width => w)
|
318
405
|
|
319
406
|
receiver = PDF::Reader::RegisterReceiver.new
|
320
407
|
reader = PDF::Reader.string(pdf.render, receiver)
|
@@ -323,9 +410,23 @@ context "The PDF::Wrapper class" do
|
|
323
410
|
end
|
324
411
|
=end
|
325
412
|
|
326
|
-
specify "should be able to
|
413
|
+
specify "should be able to draw a filled circle onto the canvas"
|
327
414
|
=begin
|
328
415
|
do
|
416
|
+
x = 100
|
417
|
+
y = 200
|
418
|
+
r = 5
|
419
|
+
pdf = PDF::Wrapper.new
|
420
|
+
pdf.circle(x,y,r, :fill_color => :red)
|
421
|
+
|
422
|
+
receiver = PDF::Reader::RegisterReceiver.new
|
423
|
+
reader = PDF::Reader.string(pdf.render, receiver)
|
424
|
+
|
425
|
+
# TODO: test for the appropriate pattern of callbacks
|
426
|
+
end
|
427
|
+
=end
|
428
|
+
|
429
|
+
specify "should be able to add ascii text to the canvas" do
|
329
430
|
msg = "Chunky Bacon"
|
330
431
|
pdf = PDF::Wrapper.new
|
331
432
|
pdf.text msg
|
@@ -333,14 +434,11 @@ context "The PDF::Wrapper class" do
|
|
333
434
|
receiver = PageTextReceiver.new
|
334
435
|
reader = PDF::Reader.string(pdf.render, receiver)
|
335
436
|
|
336
|
-
# TODO: test for the
|
337
|
-
|
437
|
+
# TODO: test for the text is in the appropriate location on the page
|
438
|
+
receiver.content.first.should eql(msg)
|
338
439
|
end
|
339
|
-
=end
|
340
440
|
|
341
|
-
specify "should be able to add unicode text to the canvas"
|
342
|
-
=begin
|
343
|
-
do
|
441
|
+
specify "should be able to add unicode text to the canvas" do
|
344
442
|
msg = "メインページ"
|
345
443
|
pdf = PDF::Wrapper.new
|
346
444
|
pdf.text msg
|
@@ -348,25 +446,47 @@ context "The PDF::Wrapper class" do
|
|
348
446
|
receiver = PageTextReceiver.new
|
349
447
|
reader = PDF::Reader.string(pdf.render, receiver)
|
350
448
|
|
351
|
-
# TODO: test for the
|
352
|
-
|
449
|
+
# TODO: test for the text is in the appropriate location on the page
|
450
|
+
receiver.content.first.should eql(msg)
|
353
451
|
end
|
354
|
-
=end
|
355
452
|
|
356
|
-
specify "should be able to add text to the canvas in a bounding box using the cell method"
|
357
|
-
=begin
|
358
|
-
do
|
453
|
+
specify "should be able to add text to the canvas in a bounding box using the cell method" do
|
359
454
|
msg = "メインページ"
|
360
455
|
pdf = PDF::Wrapper.new
|
361
|
-
pdf.
|
456
|
+
pdf.cell msg, 100, 100, 200, 200
|
362
457
|
|
363
458
|
receiver = PageTextReceiver.new
|
364
459
|
reader = PDF::Reader.string(pdf.render, receiver)
|
365
460
|
|
366
|
-
# TODO: test for the
|
367
|
-
|
461
|
+
# TODO: test for the text is in the appropriate location on the page
|
462
|
+
receiver.content.first.should eql(msg)
|
463
|
+
end
|
464
|
+
|
465
|
+
specify "should keep all text for a cell inside the cell boundaries" do
|
466
|
+
msg = "This is a text cell, added by James"
|
467
|
+
pdf = PDF::Wrapper.new
|
468
|
+
x = y = 100
|
469
|
+
w = h = 200
|
470
|
+
pdf.cell msg, x, y, w, h
|
471
|
+
|
472
|
+
receiver = PDF::Reader::RegisterReceiver.new
|
473
|
+
reader = PDF::Reader.string(pdf.render, receiver)
|
474
|
+
|
475
|
+
receiver.all(:set_text_matrix_and_text_line_matrix).each do |cb|
|
476
|
+
# horizontal location
|
477
|
+
# TODO: we're only testing the it doesn't start past the right boundary of the cell
|
478
|
+
# should also test that it doesn't start in the cell but overrun it
|
479
|
+
(cb[:args][4] >= x).should be_true
|
480
|
+
(cb[:args][4] <= x + w).should be_true
|
481
|
+
|
482
|
+
# vertical location
|
483
|
+
# TODO: we're only testing the it doesn't start past the bottom boundary of the cell
|
484
|
+
# should also test that it doesn't start in the cell but overrun it
|
485
|
+
cell_top_bound = pdf.page_height - y
|
486
|
+
(cb[:args][5] <= cell_top_bound).should be_true
|
487
|
+
(cb[:args][5] >= cell_top_bound - h).should be_true
|
488
|
+
end
|
368
489
|
end
|
369
|
-
=end
|
370
490
|
|
371
491
|
specify "should be able to render to a file" do
|
372
492
|
# generate a PDF
|
@@ -456,7 +576,125 @@ context "The PDF::Wrapper class" do
|
|
456
576
|
lambda { pdf.validate_color([1000, 255, 0])}.should raise_error(ArgumentError)
|
457
577
|
end
|
458
578
|
|
459
|
-
specify "should be able to add repeating elements to
|
579
|
+
specify "should be able to add repeating elements to :all pages" do
|
580
|
+
test_str = "repeating"
|
581
|
+
|
582
|
+
pdf = PDF::Wrapper.new
|
583
|
+
pdf.repeating_element(:all) { pdf.text test_str }
|
584
|
+
|
585
|
+
pdf.start_new_page
|
586
|
+
pdf.start_new_page
|
587
|
+
pdf.start_new_page
|
588
|
+
|
589
|
+
receiver = PageTextReceiver.new
|
590
|
+
reader = PDF::Reader.string(pdf.render, receiver)
|
591
|
+
|
592
|
+
receiver.content.size.should eql(4)
|
593
|
+
receiver.content[0].should eql(test_str)
|
594
|
+
receiver.content[1].should eql(test_str)
|
595
|
+
receiver.content[2].should eql(test_str)
|
596
|
+
receiver.content[3].should eql(test_str)
|
597
|
+
end
|
598
|
+
|
599
|
+
specify "should be able to add repeating elements to :odd pages" do
|
600
|
+
test_str = "repeating"
|
601
|
+
|
602
|
+
pdf = PDF::Wrapper.new
|
603
|
+
pdf.repeating_element(:odd) { pdf.text test_str }
|
604
|
+
|
605
|
+
pdf.start_new_page
|
606
|
+
pdf.start_new_page
|
607
|
+
pdf.start_new_page
|
608
|
+
|
609
|
+
receiver = PageTextReceiver.new
|
610
|
+
reader = PDF::Reader.string(pdf.render, receiver)
|
611
|
+
|
612
|
+
receiver.content.size.should eql(4)
|
613
|
+
receiver.content[0].should eql(test_str)
|
614
|
+
receiver.content[1].should eql("")
|
615
|
+
receiver.content[2].should eql(test_str)
|
616
|
+
receiver.content[3].should eql("")
|
617
|
+
end
|
618
|
+
|
619
|
+
specify "should be able to add repeating elements to :even pages" do
|
620
|
+
test_str = "repeating"
|
621
|
+
|
622
|
+
pdf = PDF::Wrapper.new
|
623
|
+
pdf.repeating_element(:even) { pdf.text test_str }
|
624
|
+
|
625
|
+
pdf.start_new_page
|
626
|
+
pdf.start_new_page
|
627
|
+
pdf.start_new_page
|
628
|
+
|
629
|
+
receiver = PageTextReceiver.new
|
630
|
+
reader = PDF::Reader.string(pdf.render, receiver)
|
631
|
+
|
632
|
+
receiver.content.size.should eql(4)
|
633
|
+
receiver.content[0].should eql("")
|
634
|
+
receiver.content[1].should eql(test_str)
|
635
|
+
receiver.content[2].should eql("")
|
636
|
+
receiver.content[3].should eql(test_str)
|
637
|
+
end
|
638
|
+
|
639
|
+
specify "should be able to add repeating elements to a range of pages" do
|
640
|
+
test_str = "repeating"
|
641
|
+
|
642
|
+
pdf = PDF::Wrapper.new
|
643
|
+
pdf.repeating_element((2..3)) { pdf.text test_str }
|
644
|
+
|
645
|
+
pdf.start_new_page
|
646
|
+
pdf.start_new_page
|
647
|
+
pdf.start_new_page
|
648
|
+
|
649
|
+
receiver = PageTextReceiver.new
|
650
|
+
reader = PDF::Reader.string(pdf.render, receiver)
|
651
|
+
|
652
|
+
receiver.content.size.should eql(4)
|
653
|
+
receiver.content[0].should eql("")
|
654
|
+
receiver.content[1].should eql(test_str)
|
655
|
+
receiver.content[2].should eql(test_str)
|
656
|
+
receiver.content[3].should eql("")
|
657
|
+
end
|
658
|
+
|
659
|
+
specify "should be able to add repeating elements to a single page" do
|
660
|
+
test_str = "repeating"
|
661
|
+
|
662
|
+
pdf = PDF::Wrapper.new
|
663
|
+
pdf.repeating_element(2) { pdf.text test_str }
|
664
|
+
|
665
|
+
pdf.start_new_page
|
666
|
+
pdf.start_new_page
|
667
|
+
pdf.start_new_page
|
668
|
+
|
669
|
+
receiver = PageTextReceiver.new
|
670
|
+
reader = PDF::Reader.string(pdf.render, receiver)
|
671
|
+
|
672
|
+
receiver.content.size.should eql(4)
|
673
|
+
receiver.content[0].should eql("")
|
674
|
+
receiver.content[1].should eql(test_str)
|
675
|
+
receiver.content[2].should eql("")
|
676
|
+
receiver.content[3].should eql("")
|
677
|
+
end
|
678
|
+
|
679
|
+
specify "should be able to add repeating elements to an array of pages" do
|
680
|
+
test_str = "repeating"
|
681
|
+
|
682
|
+
pdf = PDF::Wrapper.new
|
683
|
+
pdf.repeating_element([1,3,4]) { pdf.text test_str }
|
684
|
+
|
685
|
+
pdf.start_new_page
|
686
|
+
pdf.start_new_page
|
687
|
+
pdf.start_new_page
|
688
|
+
|
689
|
+
receiver = PageTextReceiver.new
|
690
|
+
reader = PDF::Reader.string(pdf.render, receiver)
|
691
|
+
|
692
|
+
receiver.content.size.should eql(4)
|
693
|
+
receiver.content[0].should eql(test_str)
|
694
|
+
receiver.content[1].should eql("")
|
695
|
+
receiver.content[2].should eql(test_str)
|
696
|
+
receiver.content[3].should eql(test_str)
|
697
|
+
end
|
460
698
|
|
461
699
|
specify "should not change the state of the cairo canvas or PDF::Writer defaults (fonts, colors, etc) when adding repeating elements"
|
462
700
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdf-wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Healy
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-03-12 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -35,8 +35,8 @@ files:
|
|
35
35
|
- lib/pdf/wrapper.rb
|
36
36
|
- lib/pdf/core.rb
|
37
37
|
- specs/data
|
38
|
-
- specs/data/google.png
|
39
38
|
- specs/data/shift_jis.txt
|
39
|
+
- specs/data/google.png
|
40
40
|
- specs/data/utf8-long.txt
|
41
41
|
- specs/data/iso-2022-jp.txt
|
42
42
|
- specs/data/utf8.txt
|