prawn 1.0.0.rc1 → 1.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +18 -0
- data/README.md +5 -3
- data/Rakefile +8 -14
- data/data/pdfs/nested_pages.pdf +13 -13
- data/lib/prawn.rb +3 -1
- data/lib/prawn/compatibility.rb +46 -10
- data/lib/prawn/core.rb +3 -1
- data/lib/prawn/core/document_state.rb +2 -1
- data/lib/prawn/core/object_store.rb +61 -5
- data/lib/prawn/core/page.rb +3 -6
- data/lib/prawn/core/pdf_object.rb +21 -4
- data/lib/prawn/core/reference.rb +6 -2
- data/lib/prawn/core/text.rb +4 -4
- data/lib/prawn/core/text/formatted/line_wrap.rb +23 -8
- data/lib/prawn/document.rb +21 -15
- data/lib/prawn/document/bounding_box.rb +3 -3
- data/lib/prawn/document/column_box.rb +22 -4
- data/lib/prawn/document/snapshot.rb +1 -1
- data/lib/prawn/encoding.rb +1 -1
- data/lib/prawn/errors.rb +4 -0
- data/lib/prawn/font.rb +1 -1
- data/lib/prawn/font/afm.rb +30 -72
- data/lib/prawn/font/ttf.rb +6 -33
- data/lib/prawn/graphics.rb +148 -23
- data/lib/prawn/graphics/color.rb +8 -1
- data/lib/prawn/graphics/patterns.rb +137 -0
- data/lib/prawn/images.rb +25 -19
- data/lib/prawn/images/jpg.rb +4 -4
- data/lib/prawn/images/png.rb +18 -12
- data/lib/prawn/security.rb +6 -4
- data/lib/prawn/soft_mask.rb +94 -0
- data/lib/prawn/table.rb +136 -31
- data/lib/prawn/table/cell.rb +260 -29
- data/lib/prawn/table/cell/span_dummy.rb +88 -0
- data/lib/prawn/table/cell/text.rb +36 -14
- data/lib/prawn/table/cells.rb +91 -41
- data/lib/prawn/text.rb +3 -2
- data/lib/prawn/text/formatted/box.rb +14 -5
- data/lib/prawn/text/formatted/fragment.rb +33 -22
- data/lib/prawn/text/formatted/parser.rb +5 -2
- data/lib/prawn/utilities.rb +44 -0
- data/manual/basic_concepts/adding_pages.rb +27 -0
- data/manual/basic_concepts/basic_concepts.rb +34 -0
- data/manual/basic_concepts/creation.rb +39 -0
- data/manual/basic_concepts/cursor.rb +33 -0
- data/manual/basic_concepts/measurement.rb +25 -0
- data/manual/basic_concepts/origin.rb +38 -0
- data/manual/basic_concepts/other_cursor_helpers.rb +40 -0
- data/manual/bounding_box/bounding_box.rb +39 -0
- data/manual/bounding_box/bounds.rb +49 -0
- data/manual/bounding_box/canvas.rb +24 -0
- data/manual/bounding_box/creation.rb +23 -0
- data/manual/bounding_box/indentation.rb +46 -0
- data/manual/bounding_box/nesting.rb +45 -0
- data/manual/bounding_box/russian_boxes.rb +40 -0
- data/manual/bounding_box/stretchy.rb +31 -0
- data/manual/document_and_page_options/background.rb +27 -0
- data/manual/document_and_page_options/document_and_page_options.rb +31 -0
- data/manual/document_and_page_options/metadata.rb +23 -0
- data/manual/document_and_page_options/page_margins.rb +38 -0
- data/manual/document_and_page_options/page_size.rb +34 -0
- data/manual/example_file.rb +116 -0
- data/manual/example_helper.rb +430 -0
- data/manual/example_package.rb +53 -0
- data/manual/example_section.rb +46 -0
- data/manual/graphics/circle_and_ellipse.rb +22 -0
- data/manual/graphics/color.rb +24 -0
- data/manual/graphics/common_lines.rb +28 -0
- data/manual/graphics/fill_and_stroke.rb +42 -0
- data/manual/graphics/fill_rules.rb +37 -0
- data/manual/graphics/gradients.rb +37 -0
- data/manual/graphics/graphics.rb +58 -0
- data/manual/graphics/helper.rb +17 -0
- data/manual/graphics/line_width.rb +35 -0
- data/manual/graphics/lines_and_curves.rb +41 -0
- data/manual/graphics/polygon.rb +29 -0
- data/manual/graphics/rectangle.rb +21 -0
- data/manual/graphics/rotate.rb +28 -0
- data/manual/graphics/scale.rb +41 -0
- data/manual/graphics/soft_masks.rb +46 -0
- data/manual/graphics/stroke_cap.rb +31 -0
- data/manual/graphics/stroke_dash.rb +43 -0
- data/manual/graphics/stroke_join.rb +30 -0
- data/manual/graphics/translate.rb +29 -0
- data/manual/graphics/transparency.rb +35 -0
- data/manual/images/absolute_position.rb +23 -0
- data/manual/images/fit.rb +21 -0
- data/manual/images/horizontal.rb +25 -0
- data/manual/images/images.rb +40 -0
- data/manual/images/plain_image.rb +18 -0
- data/manual/images/scale.rb +22 -0
- data/manual/images/vertical.rb +28 -0
- data/manual/images/width_and_height.rb +25 -0
- data/manual/layout/boxes.rb +27 -0
- data/manual/layout/content.rb +25 -0
- data/manual/layout/layout.rb +28 -0
- data/manual/layout/simple_grid.rb +23 -0
- data/manual/manual/cover.rb +26 -0
- data/manual/manual/foreword.rb +13 -0
- data/manual/manual/how_to_read_this_manual.rb +41 -0
- data/manual/manual/manual.rb +36 -0
- data/manual/outline/add_subsection_to.rb +61 -0
- data/manual/outline/insert_section_after.rb +47 -0
- data/manual/outline/outline.rb +32 -0
- data/manual/outline/sections_and_pages.rb +67 -0
- data/manual/repeatable_content/page_numbering.rb +54 -0
- data/manual/repeatable_content/repeatable_content.rb +31 -0
- data/manual/repeatable_content/repeater.rb +55 -0
- data/manual/repeatable_content/stamp.rb +41 -0
- data/manual/security/encryption.rb +31 -0
- data/manual/security/permissions.rb +38 -0
- data/manual/security/security.rb +28 -0
- data/manual/syntax_highlight.rb +52 -0
- data/manual/table/basic_block.rb +53 -0
- data/manual/table/before_rendering_page.rb +26 -0
- data/manual/table/cell_border_lines.rb +24 -0
- data/manual/table/cell_borders_and_bg.rb +31 -0
- data/manual/table/cell_dimensions.rb +30 -0
- data/manual/table/cell_text.rb +38 -0
- data/manual/table/column_widths.rb +30 -0
- data/manual/table/content_and_subtables.rb +39 -0
- data/manual/table/creation.rb +27 -0
- data/manual/table/filtering.rb +36 -0
- data/manual/table/flow_and_header.rb +17 -0
- data/manual/table/image_cells.rb +33 -0
- data/manual/table/position.rb +29 -0
- data/manual/table/row_colors.rb +20 -0
- data/manual/table/span.rb +30 -0
- data/manual/table/style.rb +22 -0
- data/manual/table/table.rb +52 -0
- data/manual/table/width.rb +27 -0
- data/manual/templates/full_template.rb +23 -0
- data/manual/templates/page_template.rb +47 -0
- data/manual/templates/templates.rb +26 -0
- data/manual/text/alignment.rb +44 -0
- data/manual/text/color.rb +24 -0
- data/manual/text/column_box.rb +32 -0
- data/manual/text/fallback_fonts.rb +37 -0
- data/manual/text/font.rb +41 -0
- data/manual/text/font_size.rb +45 -0
- data/manual/text/font_style.rb +23 -0
- data/manual/text/formatted_callbacks.rb +60 -0
- data/manual/text/formatted_text.rb +50 -0
- data/manual/text/free_flowing_text.rb +51 -0
- data/manual/text/group.rb +29 -0
- data/manual/text/inline.rb +43 -0
- data/manual/text/kerning_and_character_spacing.rb +39 -0
- data/manual/text/leading.rb +25 -0
- data/manual/text/line_wrapping.rb +41 -0
- data/manual/text/paragraph_indentation.rb +26 -0
- data/manual/text/positioned_text.rb +38 -0
- data/manual/text/registering_families.rb +48 -0
- data/manual/text/rendering_and_color.rb +37 -0
- data/manual/text/right_to_left_text.rb +43 -0
- data/manual/text/rotation.rb +43 -0
- data/manual/text/single_usage.rb +37 -0
- data/manual/text/text.rb +75 -0
- data/manual/text/text_box_excess.rb +32 -0
- data/manual/text/text_box_extensions.rb +45 -0
- data/manual/text/text_box_overflow.rb +44 -0
- data/manual/text/utf8.rb +28 -0
- data/manual/text/win_ansi_charset.rb +59 -0
- data/prawn.gemspec +10 -7
- data/spec/bounding_box_spec.rb +107 -17
- data/spec/cell_spec.rb +66 -40
- data/spec/column_box_spec.rb +33 -0
- data/spec/document_spec.rb +45 -24
- data/spec/extensions/encoding_helpers.rb +6 -0
- data/spec/extensions/mocha.rb +1 -0
- data/spec/font_spec.rb +71 -53
- data/spec/formatted_text_arranger_spec.rb +19 -19
- data/spec/formatted_text_box_spec.rb +16 -16
- data/spec/formatted_text_fragment_spec.rb +6 -6
- data/spec/graphics_spec.rb +96 -31
- data/spec/grid_spec.rb +2 -2
- data/spec/images_spec.rb +18 -10
- data/spec/jpg_spec.rb +1 -1
- data/spec/line_wrap_spec.rb +14 -14
- data/spec/measurement_units_spec.rb +2 -2
- data/spec/name_tree_spec.rb +6 -6
- data/spec/object_store_spec.rb +17 -17
- data/spec/outline_spec.rb +35 -17
- data/spec/pdf_object_spec.rb +3 -1
- data/spec/png_spec.rb +22 -19
- data/spec/reference_spec.rb +24 -1
- data/spec/repeater_spec.rb +9 -9
- data/spec/security_spec.rb +3 -3
- data/spec/snapshot_spec.rb +3 -3
- data/spec/soft_mask_spec.rb +117 -0
- data/spec/span_spec.rb +4 -4
- data/spec/spec_helper.rb +12 -6
- data/spec/stamp_spec.rb +12 -12
- data/spec/stroke_styles_spec.rb +5 -5
- data/spec/table_spec.rb +458 -88
- data/spec/template_spec.rb +108 -54
- data/spec/text_at_spec.rb +17 -17
- data/spec/text_box_spec.rb +76 -45
- data/spec/text_rendering_mode_spec.rb +5 -5
- data/spec/text_spacing_spec.rb +4 -4
- data/spec/text_spec.rb +44 -40
- metadata +419 -250
- data/lib/prawn/graphics/gradient.rb +0 -84
- data/lib/prawn/security/arcfour.rb +0 -51
@@ -224,13 +224,13 @@ describe "Text::Formatted::Fragment that is a subscript" do
|
|
224
224
|
@fragment.ascender = 17
|
225
225
|
end
|
226
226
|
describe "#subscript?" do
|
227
|
-
it "should
|
228
|
-
@fragment.should
|
227
|
+
it "should be_true" do
|
228
|
+
@fragment.should be_subscript
|
229
229
|
end
|
230
230
|
end
|
231
231
|
describe "#y_offset" do
|
232
232
|
it "should return a negative value" do
|
233
|
-
@fragment.y_offset.should
|
233
|
+
@fragment.y_offset.should be < 0
|
234
234
|
end
|
235
235
|
end
|
236
236
|
end
|
@@ -252,13 +252,13 @@ describe "Text::Formatted::Fragment that is a superscript" do
|
|
252
252
|
@fragment.ascender = 17
|
253
253
|
end
|
254
254
|
describe "#superscript?" do
|
255
|
-
it "should
|
256
|
-
@fragment.should
|
255
|
+
it "should be_true" do
|
256
|
+
@fragment.should be_superscript
|
257
257
|
end
|
258
258
|
end
|
259
259
|
describe "#y_offset" do
|
260
260
|
it "should return a positive value" do
|
261
|
-
@fragment.y_offset.should
|
261
|
+
@fragment.y_offset.should be > 0
|
262
262
|
end
|
263
263
|
end
|
264
264
|
end
|
data/spec/graphics_spec.rb
CHANGED
@@ -68,7 +68,7 @@ describe "When drawing a line" do
|
|
68
68
|
end
|
69
69
|
it "should require a y coordinate" do
|
70
70
|
lambda { @pdf.vertical_line(400,500) }.
|
71
|
-
should
|
71
|
+
should raise_error(ArgumentError)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -162,6 +162,29 @@ describe "When drawing an ellipse" do
|
|
162
162
|
@pdf.ellipse [100,100], 25, 50
|
163
163
|
@curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
164
164
|
end
|
165
|
+
|
166
|
+
it "should use a Bézier approximation" do
|
167
|
+
@curve.coords.should ==
|
168
|
+
[125.0, 100.0,
|
169
|
+
|
170
|
+
125.0, 127.614,
|
171
|
+
113.807, 150,
|
172
|
+
100.0, 150.0,
|
173
|
+
|
174
|
+
86.193, 150.0,
|
175
|
+
75.0, 127.614,
|
176
|
+
75.0, 100.0,
|
177
|
+
|
178
|
+
75.0, 72.386,
|
179
|
+
86.193, 50.0,
|
180
|
+
100.0, 50.0,
|
181
|
+
|
182
|
+
113.807, 50.0,
|
183
|
+
125.0, 72.386,
|
184
|
+
125.0, 100.0,
|
185
|
+
|
186
|
+
100.0, 100.0]
|
187
|
+
end
|
165
188
|
|
166
189
|
it "should move the pointer to the center of the ellipse after drawing" do
|
167
190
|
@curve.coords[-2..-1].should == [100,100]
|
@@ -257,37 +280,79 @@ describe "When setting colors" do
|
|
257
280
|
end
|
258
281
|
end
|
259
282
|
|
260
|
-
describe "
|
283
|
+
describe "Patterns" do
|
261
284
|
before(:each) { create_pdf }
|
262
285
|
|
263
|
-
|
264
|
-
|
265
|
-
@pdf.
|
286
|
+
describe 'linear gradients' do
|
287
|
+
it "should create a /Pattern resource" do
|
288
|
+
@pdf.fill_gradient [0, @pdf.bounds.height],
|
289
|
+
[@pdf.bounds.width, @pdf.bounds.height], 'FF0000', '0000FF'
|
290
|
+
|
291
|
+
grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
|
292
|
+
pattern = grad.patterns.values.first
|
293
|
+
|
294
|
+
pattern.should_not be_nil
|
295
|
+
pattern[:Shading][:ShadingType].should == 2
|
296
|
+
pattern[:Shading][:Coords].should == [0, 0, @pdf.bounds.width, 0]
|
297
|
+
pattern[:Shading][:Function][:C0].zip([1, 0, 0]).all?{ |x1, x2|
|
298
|
+
(x1-x2).abs < 0.01
|
299
|
+
}.should be_true
|
300
|
+
pattern[:Shading][:Function][:C1].zip([0, 0, 1]).all?{ |x1, x2|
|
301
|
+
(x1-x2).abs < 0.01
|
302
|
+
}.should be_true
|
303
|
+
end
|
266
304
|
|
267
|
-
|
268
|
-
|
305
|
+
it "fill_gradient should set fill color to the pattern" do
|
306
|
+
@pdf.fill_gradient [0, @pdf.bounds.height],
|
307
|
+
[@pdf.bounds.width, @pdf.bounds.height], 'FF0000', '0000FF'
|
269
308
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
assert pattern[:Shading][:Function][:C1].zip([0, 0, 1]).
|
274
|
-
all?{ |x1, x2| (x1-x2).abs < 0.01 }
|
275
|
-
end
|
309
|
+
str = @pdf.render
|
310
|
+
str.should =~ %r{/Pattern\s+cs\s*/SP-?\d+\s+scn}
|
311
|
+
end
|
276
312
|
|
277
|
-
|
278
|
-
|
279
|
-
|
313
|
+
it "stroke_gradient should set stroke color to the pattern" do
|
314
|
+
@pdf.stroke_gradient [0, @pdf.bounds.height],
|
315
|
+
[@pdf.bounds.width, @pdf.bounds.height], 'FF0000', '0000FF'
|
280
316
|
|
281
|
-
|
282
|
-
|
317
|
+
str = @pdf.render
|
318
|
+
str.should =~ %r{/Pattern\s+CS\s*/SP-?\d+\s+SCN}
|
319
|
+
end
|
283
320
|
end
|
284
321
|
|
285
|
-
|
286
|
-
|
287
|
-
@pdf.
|
322
|
+
describe 'radial gradients' do
|
323
|
+
it "should create a /Pattern resource" do
|
324
|
+
@pdf.fill_gradient [0, @pdf.bounds.height], 10,
|
325
|
+
[@pdf.bounds.width, @pdf.bounds.height], 20, 'FF0000', '0000FF'
|
288
326
|
|
289
|
-
|
290
|
-
|
327
|
+
grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
|
328
|
+
pattern = grad.patterns.values.first
|
329
|
+
|
330
|
+
pattern.should_not be_nil
|
331
|
+
pattern[:Shading][:ShadingType].should == 3
|
332
|
+
pattern[:Shading][:Coords].should == [0, 0, 10, @pdf.bounds.width, 0, 20]
|
333
|
+
pattern[:Shading][:Function][:C0].zip([1, 0, 0]).all?{ |x1, x2|
|
334
|
+
(x1-x2).abs < 0.01
|
335
|
+
}.should be_true
|
336
|
+
pattern[:Shading][:Function][:C1].zip([0, 0, 1]).all?{ |x1, x2|
|
337
|
+
(x1-x2).abs < 0.01
|
338
|
+
}.should be_true
|
339
|
+
end
|
340
|
+
|
341
|
+
it "fill_gradient should set fill color to the pattern" do
|
342
|
+
@pdf.fill_gradient [0, @pdf.bounds.height], 10,
|
343
|
+
[@pdf.bounds.width, @pdf.bounds.height], 20, 'FF0000', '0000FF'
|
344
|
+
|
345
|
+
str = @pdf.render
|
346
|
+
str.should =~ %r{/Pattern\s+cs\s*/SP-?\d+\s+scn}
|
347
|
+
end
|
348
|
+
|
349
|
+
it "stroke_gradient should set stroke color to the pattern" do
|
350
|
+
@pdf.stroke_gradient [0, @pdf.bounds.height], 10,
|
351
|
+
[@pdf.bounds.width, @pdf.bounds.height], 20, 'FF0000', '0000FF'
|
352
|
+
|
353
|
+
str = @pdf.render
|
354
|
+
str.should =~ %r{/Pattern\s+CS\s*/SP-?\d+\s+SCN}
|
355
|
+
end
|
291
356
|
end
|
292
357
|
end
|
293
358
|
|
@@ -310,7 +375,7 @@ describe "When using painting shortcuts" do
|
|
310
375
|
|
311
376
|
it "should not break method_missing" do
|
312
377
|
lambda { @pdf.i_have_a_pretty_girlfriend_named_jia }.
|
313
|
-
should
|
378
|
+
should raise_error(NoMethodError)
|
314
379
|
end
|
315
380
|
end
|
316
381
|
|
@@ -407,11 +472,11 @@ describe "When using graphics states" do
|
|
407
472
|
end
|
408
473
|
|
409
474
|
|
410
|
-
it "should
|
411
|
-
|
475
|
+
it "should raise_error error if closing an empty graphic stack" do
|
476
|
+
lambda {
|
412
477
|
@pdf.render
|
413
478
|
@pdf.restore_graphics_state
|
414
|
-
|
479
|
+
}.should raise_error(Prawn::Errors::EmptyGraphicStateStack)
|
415
480
|
end
|
416
481
|
end
|
417
482
|
|
@@ -509,10 +574,10 @@ describe "When using transformations shortcuts" do
|
|
509
574
|
reduce_precision(@cos), 0, 0]
|
510
575
|
end
|
511
576
|
|
512
|
-
it "should
|
577
|
+
it "should raise_error BlockRequired if no block is given" do
|
513
578
|
lambda {
|
514
579
|
@pdf.rotate(@angle, :origin => [@x, @y])
|
515
|
-
}.should
|
580
|
+
}.should raise_error(Prawn::Errors::BlockRequired)
|
516
581
|
end
|
517
582
|
|
518
583
|
def reduce_precision(float)
|
@@ -565,10 +630,10 @@ describe "When using transformations shortcuts" do
|
|
565
630
|
matrices.matrices[1].should == [@factor, 0, 0, @factor, 0, 0]
|
566
631
|
end
|
567
632
|
|
568
|
-
it "should
|
633
|
+
it "should raise_error BlockRequired if no block is given" do
|
569
634
|
lambda {
|
570
635
|
@pdf.scale(@factor, :origin => [@x, @y])
|
571
|
-
}.should
|
636
|
+
}.should raise_error(Prawn::Errors::BlockRequired)
|
572
637
|
end
|
573
638
|
|
574
639
|
def reduce_precision(float)
|
data/spec/grid_spec.rb
CHANGED
@@ -62,8 +62,8 @@ describe "A document's grid" do
|
|
62
62
|
@pdf.grid.show_all('cccccc')
|
63
63
|
|
64
64
|
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
65
|
-
colors.fill_color.
|
66
|
-
colors.stroke_color.
|
65
|
+
colors.fill_color.should_not == [0.8,0.8,0.8]
|
66
|
+
colors.stroke_color.should_not == [0.8,0.8,0.8]
|
67
67
|
|
68
68
|
# Hardcoded default color as I haven't been able to come up with a stable converter
|
69
69
|
# between fill_color without lots code.
|
data/spec/images_spec.rb
CHANGED
@@ -7,7 +7,7 @@ require 'pathname'
|
|
7
7
|
describe "the image() function" do
|
8
8
|
|
9
9
|
before(:each) do
|
10
|
-
@filename = "#{Prawn::
|
10
|
+
@filename = "#{Prawn::DATADIR}/images/pigs.jpg"
|
11
11
|
create_pdf
|
12
12
|
end
|
13
13
|
|
@@ -26,7 +26,7 @@ describe "the image() function" do
|
|
26
26
|
it "should return the image info object" do
|
27
27
|
info = @pdf.image(@filename)
|
28
28
|
|
29
|
-
info.should
|
29
|
+
info.should be_a_kind_of(Prawn::Images::JPG)
|
30
30
|
|
31
31
|
info.height.should == 453
|
32
32
|
end
|
@@ -38,23 +38,31 @@ describe "the image() function" do
|
|
38
38
|
info.height.should == 453
|
39
39
|
end
|
40
40
|
|
41
|
+
it "rewinds IO objects to be able to embed them multiply" do
|
42
|
+
file = File.open(@filename, "rb")
|
43
|
+
|
44
|
+
@pdf.image(file)
|
45
|
+
info = @pdf.image(file)
|
46
|
+
info.height.should == 453
|
47
|
+
end
|
48
|
+
|
41
49
|
it "should accept Pathname objects" do
|
42
50
|
info = @pdf.image(Pathname.new(@filename))
|
43
51
|
info.height.should == 453
|
44
52
|
end
|
45
53
|
|
46
|
-
it "should
|
47
|
-
filename = "#{Prawn::
|
48
|
-
lambda { @pdf.image filename, :at => [100,100] }.should
|
54
|
+
it "should raise_error an UnsupportedImageType if passed a BMP" do
|
55
|
+
filename = "#{Prawn::DATADIR}/images/tru256.bmp"
|
56
|
+
lambda { @pdf.image filename, :at => [100,100] }.should raise_error(Prawn::Errors::UnsupportedImageType)
|
49
57
|
end
|
50
58
|
|
51
|
-
it "should
|
52
|
-
filename = "#{Prawn::
|
53
|
-
lambda { @pdf.image filename, :at => [100,100] }.should
|
59
|
+
it "should raise_error an UnsupportedImageType if passed an interlaced PNG" do
|
60
|
+
filename = "#{Prawn::DATADIR}/images/dice_interlaced.png"
|
61
|
+
lambda { @pdf.image filename, :at => [100,100] }.should raise_error(Prawn::Errors::UnsupportedImageType)
|
54
62
|
end
|
55
63
|
|
56
64
|
it "should bump PDF version to 1.5 or greater on embedding 16-bit PNGs" do
|
57
|
-
@pdf.image "#{Prawn::
|
65
|
+
@pdf.image "#{Prawn::DATADIR}/images/16bit.png"
|
58
66
|
@pdf.state.version.should >= 1.5
|
59
67
|
end
|
60
68
|
|
@@ -63,7 +71,7 @@ describe "the image() function" do
|
|
63
71
|
# or anything. OS X Preview handles those files just fine.
|
64
72
|
#
|
65
73
|
it "should embed 8-bit alpha channels for 16-bit PNGs" do
|
66
|
-
@pdf.image "#{Prawn::
|
74
|
+
@pdf.image "#{Prawn::DATADIR}/images/16bit.png"
|
67
75
|
|
68
76
|
output = @pdf.render
|
69
77
|
output.should =~ /\/BitsPerComponent 16/
|
data/spec/jpg_spec.rb
CHANGED
@@ -9,7 +9,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
|
9
9
|
describe "When reading a JPEG file" do
|
10
10
|
|
11
11
|
before(:each) do
|
12
|
-
@filename = "#{Prawn::
|
12
|
+
@filename = "#{Prawn::DATADIR}/images/pigs.jpg"
|
13
13
|
@img_data = File.open(@filename, "rb") { |f| f.read }
|
14
14
|
end
|
15
15
|
|
data/spec/line_wrap_spec.rb
CHANGED
@@ -30,7 +30,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
|
|
30
30
|
:document => @pdf)
|
31
31
|
string.should == "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
32
32
|
end
|
33
|
-
it "should
|
33
|
+
it "should raise_error CannotFit if a too-small width is given" do
|
34
34
|
array = [{ :text => " hello world, " },
|
35
35
|
{ :text => "goodbye ", :style => [:bold] }]
|
36
36
|
@arranger.format_array = array
|
@@ -38,7 +38,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
|
|
38
38
|
@line_wrap.wrap_line(:arranger => @arranger,
|
39
39
|
:width => 1,
|
40
40
|
:document => @pdf)
|
41
|
-
end.should
|
41
|
+
end.should raise_error(Prawn::Errors::CannotFit)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should break on space" do
|
@@ -51,7 +51,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should break on zero-width space" do
|
54
|
-
@pdf.font("#{Prawn::
|
54
|
+
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
55
55
|
array = [{ :text => "hello#{Prawn::Text::ZWSP}world" }]
|
56
56
|
@arranger.format_array = array
|
57
57
|
string = @line_wrap.wrap_line(:arranger => @arranger,
|
@@ -61,7 +61,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should not display zero-width space" do
|
64
|
-
@pdf.font("#{Prawn::
|
64
|
+
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
65
65
|
array = [{ :text => "hello#{Prawn::Text::ZWSP}world" }]
|
66
66
|
@arranger.format_array = array
|
67
67
|
string = @line_wrap.wrap_line(:arranger => @arranger,
|
@@ -116,7 +116,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
|
|
116
116
|
expected.force_encoding("utf-8") if "".respond_to?(:force_encoding)
|
117
117
|
string.should == expected
|
118
118
|
|
119
|
-
@pdf.font("#{Prawn::
|
119
|
+
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
120
120
|
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
121
121
|
|
122
122
|
string = "hello#{Prawn::Text::SHY}world"
|
@@ -137,7 +137,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
|
|
137
137
|
:document => @pdf)
|
138
138
|
string.should == "helloworld"
|
139
139
|
|
140
|
-
@pdf.font("#{Prawn::
|
140
|
+
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
141
141
|
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
142
142
|
|
143
143
|
string = "hello#{Prawn::Text::SHY}world"
|
@@ -166,7 +166,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
|
|
166
166
|
:document => @pdf)
|
167
167
|
string.should == "hello"
|
168
168
|
|
169
|
-
@pdf.font("#{Prawn::
|
169
|
+
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
170
170
|
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
171
171
|
enough_width_for_hello_world = 68
|
172
172
|
|
@@ -205,7 +205,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
|
|
205
205
|
expected.force_encoding("utf-8") if "".respond_to?(:force_encoding)
|
206
206
|
string.should == expected
|
207
207
|
|
208
|
-
@pdf.font("#{Prawn::
|
208
|
+
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
209
209
|
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
210
210
|
|
211
211
|
string = "hello#{Prawn::Text::SHY}-"
|
@@ -273,12 +273,12 @@ describe "Core::Text::Formatted::LineWrap" do
|
|
273
273
|
line = @line_wrap.wrap_line(:arranger => @arranger,
|
274
274
|
:width => 200,
|
275
275
|
:document => @pdf)
|
276
|
-
line.
|
276
|
+
line.should_not be_empty
|
277
277
|
end
|
278
278
|
line = @line_wrap.wrap_line(:arranger => @arranger,
|
279
279
|
:width => 200,
|
280
280
|
:document => @pdf)
|
281
|
-
line.should
|
281
|
+
line.should be_empty
|
282
282
|
end
|
283
283
|
end
|
284
284
|
|
@@ -289,7 +289,7 @@ describe "Core::Text::Formatted::LineWrap#paragraph_finished?" do
|
|
289
289
|
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
290
290
|
@one_word_width = 50
|
291
291
|
end
|
292
|
-
it "should
|
292
|
+
it "should be_false when the last printed line is not the end of the paragraph" do
|
293
293
|
array = [{ :text => "hello world" }]
|
294
294
|
@arranger.format_array = array
|
295
295
|
string = @line_wrap.wrap_line(:arranger => @arranger,
|
@@ -298,7 +298,7 @@ describe "Core::Text::Formatted::LineWrap#paragraph_finished?" do
|
|
298
298
|
|
299
299
|
@line_wrap.paragraph_finished?.should == false
|
300
300
|
end
|
301
|
-
it "should
|
301
|
+
it "should be_true when the last printed line is the last fragment to print" do
|
302
302
|
array = [{ :text => "hello world" }]
|
303
303
|
@arranger.format_array = array
|
304
304
|
string = @line_wrap.wrap_line(:arranger => @arranger,
|
@@ -310,7 +310,7 @@ describe "Core::Text::Formatted::LineWrap#paragraph_finished?" do
|
|
310
310
|
|
311
311
|
@line_wrap.paragraph_finished?.should == true
|
312
312
|
end
|
313
|
-
it "should
|
313
|
+
it "should be_true when a newline exists on the current line" do
|
314
314
|
array = [{ :text => "hello\n world" }]
|
315
315
|
@arranger.format_array = array
|
316
316
|
string = @line_wrap.wrap_line(:arranger => @arranger,
|
@@ -319,7 +319,7 @@ describe "Core::Text::Formatted::LineWrap#paragraph_finished?" do
|
|
319
319
|
|
320
320
|
@line_wrap.paragraph_finished?.should == true
|
321
321
|
end
|
322
|
-
it "should
|
322
|
+
it "should be_true when a newline exists in the next fragment" do
|
323
323
|
array = [{ :text => "hello " },
|
324
324
|
{ :text => " \n" },
|
325
325
|
{ :text => "world" }]
|
@@ -4,7 +4,7 @@ require "prawn/measurement_extensions"
|
|
4
4
|
describe "Measurement units" do
|
5
5
|
|
6
6
|
it "should convert units to PostScriptPoints" do
|
7
|
-
1.mm.should.
|
7
|
+
1.mm.should be_within(0.000000001).of(2.834645669)
|
8
8
|
1.mm.should == (72 / 25.4)
|
9
9
|
2.mm.should == (2 * 72 / 25.4)
|
10
10
|
3.mm.should == 3 * 72 / 25.4
|
@@ -20,4 +20,4 @@ describe "Measurement units" do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
23
|
-
|
23
|
+
|
data/spec/name_tree_spec.rb
CHANGED
@@ -48,7 +48,7 @@ describe "Name Tree" do
|
|
48
48
|
ref_count = @pdf.object_store.length
|
49
49
|
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
50
50
|
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
51
|
-
@pdf.object_store.length.should
|
51
|
+
@pdf.object_store.length.should == ref_count+2
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should create a one new reference when subtree is split" do
|
@@ -58,7 +58,7 @@ describe "Name Tree" do
|
|
58
58
|
ref_count = @pdf.object_store.length # save when root is split
|
59
59
|
tree_add(node, ["five", 5], ["six", 6], ["seven", 7])
|
60
60
|
tree_dump(node).should == "[[five=5,four=4,one=1],[seven=7,six=6],[three=3,two=2]]"
|
61
|
-
@pdf.object_store.length.should
|
61
|
+
@pdf.object_store.length.should == ref_count+1
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should keep tree balanced when subtree split cascades to root" do
|
@@ -78,7 +78,7 @@ describe "Name Tree" do
|
|
78
78
|
it "should emit only :Names key with to_hash if root is only node" do
|
79
79
|
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
80
80
|
tree_add(node, ["one", 1], ["two", 2], ["three", 3])
|
81
|
-
node.to_hash.should
|
81
|
+
node.to_hash.should ==(
|
82
82
|
{ :Names => [tree_value("one", 1), tree_value("three", 3), tree_value("two", 2)] }
|
83
83
|
)
|
84
84
|
end
|
@@ -86,13 +86,13 @@ describe "Name Tree" do
|
|
86
86
|
it "should emit only :Kids key with to_hash if root has children" do
|
87
87
|
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
88
88
|
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
89
|
-
node.to_hash.should
|
89
|
+
node.to_hash.should ==({ :Kids => node.children.map { |child| child.ref } })
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should emit :Limits and :Names keys with to_hash for leaf node" do
|
93
93
|
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
94
94
|
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
95
|
-
node.children.first.to_hash.should
|
95
|
+
node.children.first.to_hash.should ==(
|
96
96
|
{ :Limits => %w(four one),
|
97
97
|
:Names => [tree_value("four", 4), tree_value("one", 1)] }
|
98
98
|
)
|
@@ -104,7 +104,7 @@ describe "Name Tree" do
|
|
104
104
|
tree_add(node, ["five", 5], ["six", 6], ["seven", 7], ["eight", 8])
|
105
105
|
tree_add(node, ["nine", 9], ["ten", 10], ["eleven", 11], ["twelve", 12])
|
106
106
|
tree_add(node, ["thirteen", 13], ["fourteen", 14], ["fifteen", 15], ["sixteen", 16])
|
107
|
-
node.children.first.to_hash.should
|
107
|
+
node.children.first.to_hash.should ==(
|
108
108
|
{ :Limits => %w(eight one),
|
109
109
|
:Kids => node.children.first.children.map { |child| child.ref } }
|
110
110
|
)
|