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
data/spec/object_store_spec.rb
CHANGED
@@ -35,27 +35,27 @@ describe "Prawn::ObjectStore" do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should import all objects from a PDF that has an indirect reference in a stream dict" do
|
38
|
-
filename = "#{Prawn::
|
38
|
+
filename = "#{Prawn::DATADIR}/pdfs/indirect_reference.pdf"
|
39
39
|
store = Prawn::Core::ObjectStore.new(:template => filename)
|
40
40
|
store.size.should == 8
|
41
41
|
end
|
42
42
|
|
43
|
-
it "should
|
43
|
+
it "should raise_error ArgumentError when given a file that doesn exist as a template" do
|
44
44
|
filename = "not_really_there.pdf"
|
45
45
|
|
46
|
-
lambda { Prawn::Core::ObjectStore.new(:template => filename) }.should
|
46
|
+
lambda { Prawn::Core::ObjectStore.new(:template => filename) }.should raise_error(ArgumentError)
|
47
47
|
end
|
48
48
|
|
49
|
-
it "should
|
50
|
-
filename = "#{Prawn::
|
49
|
+
it "should raise_error Prawn::Errors::TemplateError when given a non PDF as a template" do
|
50
|
+
filename = "#{Prawn::DATADIR}/images/dice.png"
|
51
51
|
|
52
|
-
lambda { Prawn::Core::ObjectStore.new(:template => filename) }.should
|
52
|
+
lambda { Prawn::Core::ObjectStore.new(:template => filename) }.should raise_error(Prawn::Errors::TemplateError)
|
53
53
|
end
|
54
54
|
|
55
|
-
it "should
|
56
|
-
filename = "#{Prawn::
|
55
|
+
it "should raise_error Prawn::Errors::TemplateError when given an encrypted PDF as a template" do
|
56
|
+
filename = "#{Prawn::DATADIR}/pdfs/encrypted.pdf"
|
57
57
|
|
58
|
-
lambda { Prawn::Core::ObjectStore.new(:template => filename) }.should
|
58
|
+
lambda { Prawn::Core::ObjectStore.new(:template => filename) }.should raise_error(Prawn::Errors::TemplateError)
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should add to its objects when ref() is called" do
|
@@ -100,7 +100,7 @@ describe "Prawn::ObjectStore#compact" do
|
|
100
100
|
old_size = store.size
|
101
101
|
store.compact
|
102
102
|
|
103
|
-
store.size.should
|
103
|
+
store.size.should be < old_size
|
104
104
|
store.map{ |o| o.identifier }.should == (1..store.size).to_a
|
105
105
|
end
|
106
106
|
|
@@ -111,44 +111,44 @@ describe "Prawn::ObjectStore#compact" do
|
|
111
111
|
old_size = store.size
|
112
112
|
store.compact
|
113
113
|
|
114
|
-
store.size.should
|
114
|
+
store.size.should be < old_size
|
115
115
|
store.map{ |o| o.identifier }.should == (1..store.size).to_a
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
119
|
describe "Prawn::ObjectStorie#object_id_for_page" do
|
120
120
|
it "should return the object ID of an imported template page" do
|
121
|
-
filename = "#{Prawn::
|
121
|
+
filename = "#{Prawn::DATADIR}/pdfs/hexagon.pdf"
|
122
122
|
store = Prawn::Core::ObjectStore.new(:template => filename)
|
123
123
|
store.object_id_for_page(0).should == 4
|
124
124
|
end
|
125
125
|
|
126
126
|
it "should return the object ID of the first imported template page" do
|
127
|
-
filename = "#{Prawn::
|
127
|
+
filename = "#{Prawn::DATADIR}/pdfs/two_hexagons.pdf"
|
128
128
|
store = Prawn::Core::ObjectStore.new(:template => filename)
|
129
129
|
store.object_id_for_page(1).should == 4
|
130
130
|
end
|
131
131
|
|
132
132
|
it "should return the object ID of the last imported template page" do
|
133
|
-
filename = "#{Prawn::
|
133
|
+
filename = "#{Prawn::DATADIR}/pdfs/two_hexagons.pdf"
|
134
134
|
store = Prawn::Core::ObjectStore.new(:template => filename)
|
135
135
|
store.object_id_for_page(-1).should == 6
|
136
136
|
end
|
137
137
|
|
138
138
|
it "should return the object ID of the first page of a template that uses nested Pages" do
|
139
|
-
filename = "#{Prawn::
|
139
|
+
filename = "#{Prawn::DATADIR}/pdfs/nested_pages.pdf"
|
140
140
|
store = Prawn::Core::ObjectStore.new(:template => filename)
|
141
141
|
store.object_id_for_page(1).should == 5
|
142
142
|
end
|
143
143
|
|
144
144
|
it "should return the object ID of the last page of a template that uses nested Pages" do
|
145
|
-
filename = "#{Prawn::
|
145
|
+
filename = "#{Prawn::DATADIR}/pdfs/nested_pages.pdf"
|
146
146
|
store = Prawn::Core::ObjectStore.new(:template => filename)
|
147
147
|
store.object_id_for_page(-1).should == 8
|
148
148
|
end
|
149
149
|
|
150
150
|
it "should return nil if given an invalid page number" do
|
151
|
-
filename = "#{Prawn::
|
151
|
+
filename = "#{Prawn::DATADIR}/pdfs/hexagon.pdf"
|
152
152
|
store = Prawn::Core::ObjectStore.new(:template => filename)
|
153
153
|
store.object_id_for_page(10).should == nil
|
154
154
|
end
|
data/spec/outline_spec.rb
CHANGED
@@ -36,7 +36,7 @@ describe "Outline" do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should create a root outline dictionary item" do
|
39
|
-
|
39
|
+
@outline_root.should_not be_nil
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should set the first and last top items of the root outline dictionary item" do
|
@@ -46,7 +46,7 @@ describe "Outline" do
|
|
46
46
|
|
47
47
|
describe "#create_outline_item" do
|
48
48
|
it "should create outline items for each section and page" do
|
49
|
-
[@section_1, @page_1, @page_2].each {|item|
|
49
|
+
[@section_1, @page_1, @page_2].each {|item| item.should_not be_nil}
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -70,7 +70,7 @@ describe "Outline" do
|
|
70
70
|
|
71
71
|
it "should add the count of all descendant items" do
|
72
72
|
@outline_root[:Count].should == 3
|
73
|
-
@section_1[:Count].should
|
73
|
+
@section_1[:Count].abs.should == 2
|
74
74
|
@page_1[:Count].should == 0
|
75
75
|
@page_2[:Count].should == 0
|
76
76
|
end
|
@@ -100,7 +100,7 @@ describe "Outline" do
|
|
100
100
|
end
|
101
101
|
|
102
102
|
it "should add new outline items to document" do
|
103
|
-
[@section_2, @page_3].each { |item|
|
103
|
+
[@section_2, @page_3].each { |item| item.should_not be_nil}
|
104
104
|
end
|
105
105
|
|
106
106
|
it "should reset the last items for root outline dictionary" do
|
@@ -139,7 +139,7 @@ describe "Outline" do
|
|
139
139
|
end
|
140
140
|
|
141
141
|
it "should add new outline items to document" do
|
142
|
-
[@subsection, @added_page_3].each { |item|
|
142
|
+
[@subsection, @added_page_3].each { |item| item.should_not be_nil}
|
143
143
|
end
|
144
144
|
|
145
145
|
it "should reset the last item for parent item dictionary" do
|
@@ -186,7 +186,7 @@ describe "Outline" do
|
|
186
186
|
end
|
187
187
|
|
188
188
|
it "should add new outline items to document" do
|
189
|
-
[@subsection, @added_page_3].each { |item|
|
189
|
+
[@subsection, @added_page_3].each { |item| item.should_not be_nil}
|
190
190
|
end
|
191
191
|
|
192
192
|
it "should reset the first item for parent item dictionary" do
|
@@ -217,7 +217,7 @@ describe "Outline" do
|
|
217
217
|
end
|
218
218
|
|
219
219
|
it "should require an existing title" do
|
220
|
-
|
220
|
+
lambda do
|
221
221
|
@pdf.go_to_page 1
|
222
222
|
@pdf.start_new_page
|
223
223
|
@pdf.text "Inserted Page"
|
@@ -227,7 +227,7 @@ describe "Outline" do
|
|
227
227
|
end
|
228
228
|
end
|
229
229
|
render_and_find_objects
|
230
|
-
end
|
230
|
+
end.should raise_error(Prawn::Errors::UnknownOutlineTitle)
|
231
231
|
end
|
232
232
|
end
|
233
233
|
|
@@ -246,13 +246,13 @@ describe "Outline" do
|
|
246
246
|
|
247
247
|
it "should insert new outline items to document" do
|
248
248
|
render_and_find_objects
|
249
|
-
|
249
|
+
@inserted_page.should_not be_nil
|
250
250
|
end
|
251
251
|
|
252
252
|
it "should adjust the count of all ancestors" do
|
253
253
|
render_and_find_objects
|
254
254
|
@outline_root[:Count].should == 4
|
255
|
-
@section_1[:Count].should
|
255
|
+
@section_1[:Count].abs.should == 3
|
256
256
|
end
|
257
257
|
|
258
258
|
describe "#adjust_relations" do
|
@@ -317,7 +317,7 @@ describe "Outline" do
|
|
317
317
|
end
|
318
318
|
|
319
319
|
it "should set the sibling relation of added item to adjoining items" do
|
320
|
-
|
320
|
+
referenced_object(@inserted_page[:Next]).should be_nil
|
321
321
|
referenced_object(@inserted_page[:Prev]).should == @page_2
|
322
322
|
end
|
323
323
|
|
@@ -329,7 +329,7 @@ describe "Outline" do
|
|
329
329
|
end
|
330
330
|
|
331
331
|
it "should require an existing title" do
|
332
|
-
|
332
|
+
lambda do
|
333
333
|
@pdf.go_to_page 1
|
334
334
|
@pdf.start_new_page
|
335
335
|
@pdf.text "Inserted Page"
|
@@ -339,26 +339,26 @@ describe "Outline" do
|
|
339
339
|
end
|
340
340
|
end
|
341
341
|
render_and_find_objects
|
342
|
-
end
|
342
|
+
end.should raise_error(Prawn::Errors::UnknownOutlineTitle)
|
343
343
|
end
|
344
344
|
|
345
345
|
end
|
346
346
|
|
347
347
|
describe "#page" do
|
348
348
|
it "should require a title option to be set" do
|
349
|
-
|
349
|
+
lambda do
|
350
350
|
@pdf = Prawn::Document.new() do
|
351
351
|
text "Page 1. This is the first Chapter. "
|
352
352
|
outline.define do
|
353
353
|
page :destination => 1, :title => nil
|
354
354
|
end
|
355
355
|
end
|
356
|
-
end
|
356
|
+
end.should raise_error(Prawn::Errors::RequiredOption)
|
357
357
|
end
|
358
358
|
end
|
359
359
|
end
|
360
360
|
|
361
|
-
|
361
|
+
describe "foreign character encoding" do
|
362
362
|
before(:each) do
|
363
363
|
pdf = Prawn::Document.new() do
|
364
364
|
outline.define do
|
@@ -370,7 +370,25 @@ context "foreign character encoding" do
|
|
370
370
|
|
371
371
|
it "should handle other encodings for the title" do
|
372
372
|
object = find_by_title('La pomme croquée')
|
373
|
-
object.
|
373
|
+
object.should_not == nil
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
describe "with optimize_objects option" do
|
378
|
+
before(:each) do
|
379
|
+
@pdf = Prawn::Document.new(:optimize_objects => true) do
|
380
|
+
outline.define do
|
381
|
+
section 'Chapter 1', :destination => 1, :closed => true do
|
382
|
+
page :destination => 1, :title => 'Page 1'
|
383
|
+
end
|
384
|
+
end
|
385
|
+
end
|
386
|
+
render_and_find_objects
|
387
|
+
end
|
388
|
+
|
389
|
+
it "should generate an outline" do
|
390
|
+
@section_1.should_not be_nil
|
391
|
+
@page_1.should_not be_nil
|
374
392
|
end
|
375
393
|
end
|
376
394
|
|
data/spec/pdf_object_spec.rb
CHANGED
@@ -17,6 +17,8 @@ describe "PDF Object Serialization" do
|
|
17
17
|
it "should convert a Ruby number to PDF number" do
|
18
18
|
Prawn::Core::PdfObject(1).should == "1"
|
19
19
|
Prawn::Core::PdfObject(1.214112421).should == "1.214112421"
|
20
|
+
# scientific notation is not valid in PDF
|
21
|
+
Prawn::Core::PdfObject(0.000005).should == "0.000005"
|
20
22
|
end
|
21
23
|
|
22
24
|
it "should convert a Ruby time object to a PDF timestamp" do
|
@@ -151,7 +153,7 @@ describe "PDF Object Serialization" do
|
|
151
153
|
|
152
154
|
it "should not allow keys other than strings or symbols for PDF dicts" do
|
153
155
|
lambda { Prawn::Core::PdfObject(:foo => :bar, :baz => :bang, 1 => 4) }.
|
154
|
-
should
|
156
|
+
should raise_error(Prawn::Errors::FailedObjectConversion)
|
155
157
|
end
|
156
158
|
|
157
159
|
it "should convert a Prawn::Reference to a PDF indirect object reference" do
|
data/spec/png_spec.rb
CHANGED
@@ -12,8 +12,8 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
|
12
12
|
describe "When reading a greyscale PNG file (color type 0)" do
|
13
13
|
|
14
14
|
before(:each) do
|
15
|
-
@filename = "#{Prawn::
|
16
|
-
@data_filename = "#{Prawn::
|
15
|
+
@filename = "#{Prawn::DATADIR}/images/web-links.png"
|
16
|
+
@data_filename = "#{Prawn::DATADIR}/images/web-links.dat"
|
17
17
|
@img_data = File.binread(@filename)
|
18
18
|
end
|
19
19
|
|
@@ -39,7 +39,7 @@ end
|
|
39
39
|
describe "When reading a greyscale PNG file with transparency (color type 0)" do
|
40
40
|
|
41
41
|
before(:each) do
|
42
|
-
@filename = "#{Prawn::
|
42
|
+
@filename = "#{Prawn::DATADIR}/images/ruport_type0.png"
|
43
43
|
@img_data = File.binread(@filename)
|
44
44
|
end
|
45
45
|
|
@@ -56,8 +56,8 @@ end
|
|
56
56
|
describe "When reading an RGB PNG file (color type 2)" do
|
57
57
|
|
58
58
|
before(:each) do
|
59
|
-
@filename = "#{Prawn::
|
60
|
-
@data_filename = "#{Prawn::
|
59
|
+
@filename = "#{Prawn::DATADIR}/images/ruport.png"
|
60
|
+
@data_filename = "#{Prawn::DATADIR}/images/ruport_data.dat"
|
61
61
|
@img_data = File.binread(@filename)
|
62
62
|
end
|
63
63
|
|
@@ -83,7 +83,7 @@ end
|
|
83
83
|
describe "When reading an RGB PNG file with transparency (color type 2)" do
|
84
84
|
|
85
85
|
before(:each) do
|
86
|
-
@filename = "#{Prawn::
|
86
|
+
@filename = "#{Prawn::DATADIR}/images/arrow2.png"
|
87
87
|
@img_data = File.binread(@filename)
|
88
88
|
end
|
89
89
|
|
@@ -103,8 +103,8 @@ end
|
|
103
103
|
describe "When reading an indexed color PNG file (color type 3)" do
|
104
104
|
|
105
105
|
before(:each) do
|
106
|
-
@filename = "#{Prawn::
|
107
|
-
@data_filename = "#{Prawn::
|
106
|
+
@filename = "#{Prawn::DATADIR}/images/rails.png"
|
107
|
+
@data_filename = "#{Prawn::DATADIR}/images/rails.dat"
|
108
108
|
@img_data = File.binread(@filename)
|
109
109
|
end
|
110
110
|
|
@@ -130,9 +130,9 @@ end
|
|
130
130
|
describe "When reading a greyscale+alpha PNG file (color type 4)" do
|
131
131
|
|
132
132
|
before(:each) do
|
133
|
-
@filename = "#{Prawn::
|
134
|
-
@data_filename = "#{Prawn::
|
135
|
-
@alpha_data_filename = "#{Prawn::
|
133
|
+
@filename = "#{Prawn::DATADIR}/images/page_white_text.png"
|
134
|
+
@data_filename = "#{Prawn::DATADIR}/images/page_white_text.dat"
|
135
|
+
@alpha_data_filename = "#{Prawn::DATADIR}/images/page_white_text.alpha"
|
136
136
|
@img_data = File.binread(@filename)
|
137
137
|
end
|
138
138
|
|
@@ -166,9 +166,9 @@ end
|
|
166
166
|
describe "When reading an RGB+alpha PNG file (color type 6)" do
|
167
167
|
|
168
168
|
before(:each) do
|
169
|
-
@filename = "#{Prawn::
|
170
|
-
@data_filename = "#{Prawn::
|
171
|
-
@alpha_data_filename = "#{Prawn::
|
169
|
+
@filename = "#{Prawn::DATADIR}/images/dice.png"
|
170
|
+
@data_filename = "#{Prawn::DATADIR}/images/dice.dat"
|
171
|
+
@alpha_data_filename = "#{Prawn::DATADIR}/images/dice.alpha"
|
172
172
|
@img_data = File.binread(@filename)
|
173
173
|
end
|
174
174
|
|
@@ -188,24 +188,27 @@ describe "When reading an RGB+alpha PNG file (color type 6)" do
|
|
188
188
|
png = Prawn::Images::PNG.new(@img_data)
|
189
189
|
png.split_alpha_channel!
|
190
190
|
data = File.binread(@data_filename)
|
191
|
-
|
191
|
+
# compare decompressed rather than compressed image data
|
192
|
+
# because JRuby's implementation of Zlib is different from MRI --
|
193
|
+
# both generate valid gzipped data, but not bit-identical to each other
|
194
|
+
Zlib::Inflate.inflate(png.img_data).should == Zlib::Inflate.inflate(data)
|
192
195
|
end
|
193
196
|
|
194
197
|
it "should correctly extract the alpha channel data from the image data chunk" do
|
195
198
|
png = Prawn::Images::PNG.new(@img_data)
|
196
199
|
png.split_alpha_channel!
|
197
200
|
data = File.binread(@alpha_data_filename)
|
198
|
-
png.alpha_channel.should == data
|
201
|
+
Zlib::Inflate.inflate(png.alpha_channel).should == Zlib::Inflate.inflate(data)
|
199
202
|
end
|
200
203
|
end
|
201
204
|
|
202
205
|
describe "When reading a 16bit RGB+alpha PNG file (color type 6)" do
|
203
206
|
|
204
207
|
before(:each) do
|
205
|
-
@filename = "#{Prawn::
|
206
|
-
@data_filename = "#{Prawn::
|
208
|
+
@filename = "#{Prawn::DATADIR}/images/16bit.png"
|
209
|
+
@data_filename = "#{Prawn::DATADIR}/images/16bit.dat"
|
207
210
|
# alpha channel truncated to 8-bit
|
208
|
-
@alpha_data_filename = "#{Prawn::
|
211
|
+
@alpha_data_filename = "#{Prawn::DATADIR}/images/16bit.alpha"
|
209
212
|
@img_data = File.binread(@filename)
|
210
213
|
end
|
211
214
|
|
data/spec/reference_spec.rb
CHANGED
@@ -35,7 +35,7 @@ describe "A Reference object" do
|
|
35
35
|
cref << "Hi There " * 20
|
36
36
|
cref.compress_stream
|
37
37
|
|
38
|
-
|
38
|
+
cref.stream.size.should be < ref.stream.size,
|
39
39
|
"compressed stream expected to be smaller than source but wasn't"
|
40
40
|
cref.data[:Filter].should == :FlateDecode
|
41
41
|
end
|
@@ -67,6 +67,22 @@ describe "A Reference object" do
|
|
67
67
|
to.compressed?.should == true
|
68
68
|
end
|
69
69
|
|
70
|
+
it "should have Length if stream present" do
|
71
|
+
ref = Prawn::Core::Reference(7, {})
|
72
|
+
ref << "Hello"
|
73
|
+
|
74
|
+
ref.data[:Length].should == 5
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should update Length when stream is updated" do
|
78
|
+
ref = Prawn::Core::Reference(7, {})
|
79
|
+
ref << "Hello"
|
80
|
+
ref.data[:Length].should == 5
|
81
|
+
|
82
|
+
ref << " world"
|
83
|
+
ref.data[:Length].should == 11
|
84
|
+
end
|
85
|
+
|
70
86
|
describe "generated via Prawn::Document" do
|
71
87
|
it "should return a proper reference on ref!" do
|
72
88
|
pdf = Prawn::Document.new
|
@@ -78,5 +94,12 @@ describe "A Reference object" do
|
|
78
94
|
r = pdf.ref({})
|
79
95
|
r.is_a?(Integer).should == true
|
80
96
|
end
|
97
|
+
|
98
|
+
it "should have :Length of stream if it has one when compression disabled" do
|
99
|
+
pdf = Prawn::Document.new :compress => false
|
100
|
+
ref = pdf.ref!({})
|
101
|
+
ref << 'Hello'
|
102
|
+
ref.data[:Length].should == 5
|
103
|
+
end
|
81
104
|
end
|
82
105
|
end
|
data/spec/repeater_spec.rb
CHANGED
@@ -10,14 +10,14 @@ describe "Repeaters" do
|
|
10
10
|
|
11
11
|
r = repeater(doc, :all) { :do_nothing }
|
12
12
|
|
13
|
-
|
13
|
+
Prawn::Repeater.count.should == orig_count + 1
|
14
14
|
end
|
15
15
|
|
16
16
|
it "must provide an :all filter" do
|
17
17
|
doc = sample_document
|
18
18
|
r = repeater(doc, :all) { :do_nothing }
|
19
19
|
|
20
|
-
|
20
|
+
(1..doc.page_count).all? { |i| r.match?(i) }.should be_true
|
21
21
|
end
|
22
22
|
|
23
23
|
it "must provide an :odd filter" do
|
@@ -26,29 +26,29 @@ describe "Repeaters" do
|
|
26
26
|
|
27
27
|
odd, even = (1..doc.page_count).partition { |e| e % 2 == 1 }
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
odd.all? { |i| r.match?(i) }.should be_true
|
30
|
+
even.any? { |i| r.match?(i) }.should be_false
|
31
31
|
end
|
32
32
|
|
33
33
|
it "must be able to filter by an array of page numbers" do
|
34
34
|
doc = sample_document
|
35
35
|
r = repeater(doc, [1,2,7]) { :do_nothing }
|
36
36
|
|
37
|
-
|
37
|
+
(1..10).select { |i| r.match?(i) }.should == [1,2,7]
|
38
38
|
end
|
39
39
|
|
40
40
|
it "must be able to filter by a range of page numbers" do
|
41
41
|
doc = sample_document
|
42
42
|
r = repeater(doc, 2..4) { :do_nothing }
|
43
43
|
|
44
|
-
|
44
|
+
(1..10).select { |i| r.match?(i) }.should == [2,3,4]
|
45
45
|
end
|
46
46
|
|
47
47
|
it "must be able to filter by an arbitrary proc" do
|
48
48
|
doc = sample_document
|
49
49
|
r = repeater(doc, lambda { |x| x == 1 or x % 3 == 0 })
|
50
50
|
|
51
|
-
|
51
|
+
(1..10).select { |i| r.match?(i) }.should == [1,3,6,9]
|
52
52
|
end
|
53
53
|
|
54
54
|
it "must try to run a stamp if the page number matches" do
|
@@ -95,7 +95,7 @@ describe "Repeaters" do
|
|
95
95
|
end
|
96
96
|
|
97
97
|
text = PDF::Inspector::Text.analyze(doc.render)
|
98
|
-
|
98
|
+
text.strings.should == (1..10).to_a.map{|p| "Page #{p}"}
|
99
99
|
end
|
100
100
|
|
101
101
|
it "must treat any block as a closure (Document.new instance_eval form)" do
|
@@ -110,7 +110,7 @@ describe "Repeaters" do
|
|
110
110
|
end
|
111
111
|
|
112
112
|
text = PDF::Inspector::Text.analyze(doc.render)
|
113
|
-
|
113
|
+
text.strings.should == (1..10).to_a.map{|p| "Page #{p}"}
|
114
114
|
end
|
115
115
|
|
116
116
|
def sample_document
|