prawn 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYING +2 -2
- data/Gemfile +18 -0
- data/LICENSE +1 -1
- data/README.md +17 -4
- data/Rakefile +18 -22
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/pdfs/nested_pages.pdf +13 -13
- data/lib/pdf/core.rb +35 -0
- data/lib/{prawn → pdf}/core/annotations.rb +6 -7
- data/lib/{prawn → pdf}/core/byte_string.rb +1 -1
- data/lib/{prawn → pdf}/core/destinations.rb +23 -23
- data/lib/{prawn → pdf}/core/document_state.rb +8 -8
- data/lib/pdf/core/filter_list.rb +51 -0
- data/lib/pdf/core/filters.rb +36 -0
- data/lib/pdf/core/graphics_state.rb +68 -0
- data/lib/{prawn → pdf}/core/literal_string.rb +1 -1
- data/lib/{prawn → pdf}/core/name_tree.rb +14 -2
- data/lib/{prawn → pdf}/core/object_store.rb +80 -24
- data/lib/pdf/core/outline.rb +315 -0
- data/lib/{prawn → pdf}/core/page.rb +23 -26
- data/lib/{prawn/document → pdf/core}/page_geometry.rb +11 -21
- data/lib/{prawn → pdf}/core/pdf_object.rb +48 -32
- data/lib/{prawn → pdf}/core/reference.rb +35 -44
- data/lib/pdf/core/stream.rb +98 -0
- data/lib/{prawn → pdf}/core/text.rb +24 -17
- data/lib/prawn.rb +95 -17
- data/lib/prawn/compatibility.rb +66 -26
- data/lib/prawn/document.rb +48 -30
- data/lib/prawn/document/bounding_box.rb +3 -3
- data/lib/prawn/document/column_box.rb +46 -8
- data/lib/prawn/document/graphics_state.rb +10 -73
- data/lib/prawn/document/internals.rb +24 -23
- data/lib/prawn/document/snapshot.rb +6 -7
- data/lib/prawn/document/span.rb +10 -10
- data/lib/prawn/encoding.rb +7 -7
- data/lib/prawn/errors.rb +18 -29
- data/lib/prawn/font.rb +64 -28
- data/lib/prawn/font/afm.rb +32 -74
- data/lib/prawn/font/dfont.rb +2 -2
- data/lib/prawn/font/ttf.rb +28 -57
- data/lib/prawn/font_metric_cache.rb +45 -0
- data/lib/prawn/graphics.rb +307 -41
- data/lib/prawn/graphics/cap_style.rb +3 -3
- data/lib/prawn/graphics/color.rb +12 -5
- data/lib/prawn/graphics/dash.rb +52 -31
- data/lib/prawn/graphics/join_style.rb +7 -7
- data/lib/prawn/graphics/patterns.rb +137 -0
- data/lib/prawn/graphics/transformation.rb +9 -9
- data/lib/prawn/graphics/transparency.rb +1 -1
- data/lib/prawn/image_handler.rb +30 -0
- data/lib/prawn/images.rb +86 -105
- data/lib/prawn/images/image.rb +48 -0
- data/lib/prawn/images/jpg.rb +14 -10
- data/lib/prawn/images/png.rb +50 -37
- data/lib/prawn/layout.rb +2 -2
- data/lib/prawn/layout/grid.rb +51 -51
- data/lib/prawn/measurement_extensions.rb +5 -5
- data/lib/prawn/measurements.rb +25 -21
- data/lib/prawn/outline.rb +4 -308
- data/lib/prawn/repeater.rb +8 -8
- data/lib/prawn/security.rb +50 -36
- data/lib/prawn/soft_mask.rb +94 -0
- data/lib/prawn/stamp.rb +3 -3
- data/lib/prawn/table.rb +292 -118
- data/lib/prawn/table/cell.rb +272 -45
- data/lib/prawn/table/cell/image.rb +70 -0
- data/lib/prawn/table/cell/in_table.rb +2 -2
- data/lib/prawn/table/cell/span_dummy.rb +92 -0
- data/lib/prawn/table/cell/subtable.rb +2 -2
- data/lib/prawn/table/cell/text.rb +42 -24
- data/lib/prawn/table/cells.rb +137 -48
- data/lib/prawn/text.rb +35 -23
- data/lib/prawn/text/box.rb +18 -5
- data/lib/prawn/text/formatted.rb +5 -4
- data/lib/prawn/text/formatted/arranger.rb +292 -0
- data/lib/prawn/text/formatted/box.rb +52 -13
- data/lib/prawn/text/formatted/fragment.rb +37 -22
- data/lib/prawn/text/formatted/line_wrap.rb +286 -0
- data/lib/prawn/text/formatted/parser.rb +14 -6
- data/lib/prawn/text/formatted/wrap.rb +151 -0
- 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 +411 -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 +24 -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 +48 -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 +35 -0
- data/manual/manual/foreword.rb +85 -0
- data/manual/manual/how_to_read_this_manual.rb +41 -0
- data/manual/manual/manual.rb +35 -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 +25 -0
- data/manual/templates/page_template.rb +48 -0
- data/manual/templates/templates.rb +27 -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 +54 -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/{examples/m17n → manual/text}/win_ansi_charset.rb +14 -10
- data/prawn.gemspec +18 -12
- data/spec/acceptance/png.rb +23 -0
- data/spec/annotations_spec.rb +16 -32
- data/spec/bounding_box_spec.rb +128 -15
- data/spec/cell_spec.rb +169 -38
- data/spec/column_box_spec.rb +33 -0
- data/spec/destinations_spec.rb +5 -5
- data/spec/document_spec.rb +150 -104
- data/spec/extensions/encoding_helpers.rb +10 -0
- data/spec/extensions/mocha.rb +1 -0
- data/spec/filters_spec.rb +34 -0
- data/spec/font_metric_cache_spec.rb +52 -0
- data/spec/font_spec.rb +183 -97
- data/spec/formatted_text_arranger_spec.rb +43 -43
- data/spec/formatted_text_box_spec.rb +30 -20
- data/spec/formatted_text_fragment_spec.rb +8 -8
- data/spec/graphics_spec.rb +158 -69
- data/spec/grid_spec.rb +15 -15
- data/spec/image_handler_spec.rb +42 -0
- data/spec/images_spec.rb +49 -24
- data/spec/inline_formatted_text_parser_spec.rb +73 -19
- data/spec/jpg_spec.rb +4 -4
- data/spec/line_wrap_spec.rb +26 -26
- data/spec/measurement_units_spec.rb +6 -6
- data/spec/name_tree_spec.rb +21 -21
- data/spec/object_store_spec.rb +39 -39
- data/spec/outline_spec.rb +93 -53
- data/spec/pdf_object_spec.rb +88 -86
- data/spec/png_spec.rb +31 -28
- data/spec/reference_spec.rb +32 -32
- data/spec/repeater_spec.rb +25 -11
- data/spec/security_spec.rb +44 -12
- data/spec/snapshot_spec.rb +8 -9
- data/spec/soft_mask_spec.rb +117 -0
- data/spec/span_spec.rb +10 -15
- data/spec/spec_helper.rb +25 -8
- data/spec/stamp_spec.rb +29 -30
- data/spec/stream_spec.rb +58 -0
- data/spec/stroke_styles_spec.rb +36 -18
- data/spec/table/span_dummy_spec.rb +17 -0
- data/spec/table_spec.rb +697 -105
- data/spec/template_spec.rb +108 -54
- data/spec/text_at_spec.rb +18 -17
- data/spec/text_box_spec.rb +111 -62
- data/spec/text_rendering_mode_spec.rb +5 -5
- data/spec/text_spacing_spec.rb +4 -4
- data/spec/text_spec.rb +57 -49
- data/spec/transparency_spec.rb +5 -5
- metadata +421 -213
- data/data/fonts/Action Man.dfont +0 -0
- data/data/fonts/Activa.ttf +0 -0
- data/data/fonts/Chalkboard.ttf +0 -0
- data/data/fonts/DejaVuSans.ttf +0 -0
- data/data/fonts/Dustismo_Roman.ttf +0 -0
- data/data/fonts/comicsans.ttf +0 -0
- data/data/fonts/gkai00mp.ttf +0 -0
- data/data/images/rails.dat +0 -0
- data/data/images/rails.png +0 -0
- data/examples/bounding_box/russian_boxes.rb +0 -37
- data/examples/example_helper.rb +0 -11
- data/examples/general/context_sensitive_headers.rb +0 -38
- data/examples/graphics/cmyk.rb +0 -13
- data/examples/graphics/gradient.rb +0 -23
- data/examples/graphics/png_types.rb +0 -23
- data/examples/graphics/remote_images.rb +0 -13
- data/examples/m17n/full_win_ansi_character_list.rb +0 -20
- data/examples/m17n/sjis.rb +0 -29
- data/examples/table/bill.rb +0 -54
- data/examples/table/header.rb +0 -15
- data/examples/text/font_calculations.rb +0 -92
- data/examples/text/hyphenation.rb +0 -45
- data/examples/text/indent_paragraphs.rb +0 -24
- data/lib/prawn/core.rb +0 -85
- data/lib/prawn/core/text/formatted/arranger.rb +0 -294
- data/lib/prawn/core/text/formatted/line_wrap.rb +0 -273
- data/lib/prawn/core/text/formatted/wrap.rb +0 -153
- data/lib/prawn/graphics/gradient.rb +0 -84
- data/lib/prawn/security/arcfour.rb +0 -51
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
|
|
@@ -31,7 +31,7 @@ describe "When reading a greyscale PNG file (color type 0)" do
|
|
31
31
|
|
32
32
|
it "should read the image data chunk correctly" do
|
33
33
|
png = Prawn::Images::PNG.new(@img_data)
|
34
|
-
data = File.binread(@data_filename)
|
34
|
+
data = Zlib::Inflate.inflate(File.binread(@data_filename))
|
35
35
|
png.img_data.should == data
|
36
36
|
end
|
37
37
|
end
|
@@ -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
|
|
@@ -75,7 +75,7 @@ describe "When reading an RGB PNG file (color type 2)" do
|
|
75
75
|
|
76
76
|
it "should read the image data chunk correctly" do
|
77
77
|
png = Prawn::Images::PNG.new(@img_data)
|
78
|
-
data = File.binread(@data_filename)
|
78
|
+
data = Zlib::Inflate.inflate(File.binread(@data_filename))
|
79
79
|
png.img_data.should == data
|
80
80
|
end
|
81
81
|
end
|
@@ -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,16 +103,16 @@ 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/indexed_color.png"
|
107
|
+
@data_filename = "#{Prawn::DATADIR}/images/indexed_color.dat"
|
108
108
|
@img_data = File.binread(@filename)
|
109
109
|
end
|
110
110
|
|
111
111
|
it "should read the attributes from the header chunk correctly" do
|
112
112
|
png = Prawn::Images::PNG.new(@img_data)
|
113
113
|
|
114
|
-
png.width.should ==
|
115
|
-
png.height.should ==
|
114
|
+
png.width.should == 150
|
115
|
+
png.height.should == 200
|
116
116
|
png.bits.should == 8
|
117
117
|
png.color_type.should == 3
|
118
118
|
png.compression_method.should == 0
|
@@ -122,7 +122,7 @@ describe "When reading an indexed color PNG file (color type 3)" do
|
|
122
122
|
|
123
123
|
it "should read the image data chunk correctly" do
|
124
124
|
png = Prawn::Images::PNG.new(@img_data)
|
125
|
-
data = File.binread(@data_filename)
|
125
|
+
data = Zlib::Inflate.inflate(File.binread(@data_filename))
|
126
126
|
png.img_data.should == data
|
127
127
|
end
|
128
128
|
end
|
@@ -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
|
|
@@ -151,14 +151,14 @@ describe "When reading a greyscale+alpha PNG file (color type 4)" do
|
|
151
151
|
it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
|
152
152
|
png = Prawn::Images::PNG.new(@img_data)
|
153
153
|
png.split_alpha_channel!
|
154
|
-
data = File.binread(@data_filename)
|
154
|
+
data = Zlib::Inflate.inflate(File.binread(@data_filename))
|
155
155
|
png.img_data.should == data
|
156
156
|
end
|
157
157
|
|
158
158
|
it "should correctly extract the alpha channel data from the image data chunk" do
|
159
159
|
png = Prawn::Images::PNG.new(@img_data)
|
160
160
|
png.split_alpha_channel!
|
161
|
-
data = File.binread(@alpha_data_filename)
|
161
|
+
data = Zlib::Inflate.inflate(File.binread(@alpha_data_filename))
|
162
162
|
png.alpha_channel.should == data
|
163
163
|
end
|
164
164
|
end
|
@@ -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
|
|
@@ -187,14 +187,17 @@ describe "When reading an RGB+alpha PNG file (color type 6)" do
|
|
187
187
|
it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
|
188
188
|
png = Prawn::Images::PNG.new(@img_data)
|
189
189
|
png.split_alpha_channel!
|
190
|
-
data = File.binread(@data_filename)
|
190
|
+
data = Zlib::Inflate.inflate(File.binread(@data_filename))
|
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
|
191
194
|
png.img_data.should == 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
|
-
data = File.binread(@alpha_data_filename)
|
200
|
+
data = Zlib::Inflate.inflate(File.binread(@alpha_data_filename))
|
198
201
|
png.alpha_channel.should == data
|
199
202
|
end
|
200
203
|
end
|
@@ -202,10 +205,10 @@ end
|
|
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
|
|
@@ -224,14 +227,14 @@ describe "When reading a 16bit RGB+alpha PNG file (color type 6)" do
|
|
224
227
|
it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
|
225
228
|
png = Prawn::Images::PNG.new(@img_data)
|
226
229
|
png.split_alpha_channel!
|
227
|
-
data = File.binread(@data_filename)
|
230
|
+
data = Zlib::Inflate.inflate(File.binread(@data_filename))
|
228
231
|
png.img_data.should == data
|
229
232
|
end
|
230
233
|
|
231
234
|
it "should correctly extract the alpha channel data from the image data chunk" do
|
232
235
|
png = Prawn::Images::PNG.new(@img_data)
|
233
236
|
png.split_alpha_channel!
|
234
|
-
data = File.binread(@alpha_data_filename)
|
237
|
+
data = Zlib::Inflate.inflate(File.binread(@alpha_data_filename))
|
235
238
|
png.alpha_channel.should == data
|
236
239
|
end
|
237
240
|
end
|
data/spec/reference_spec.rb
CHANGED
@@ -4,47 +4,40 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
|
4
4
|
|
5
5
|
describe "A Reference object" do
|
6
6
|
it "should produce a PDF reference on #to_s call" do
|
7
|
-
ref =
|
7
|
+
ref = PDF::Core::Reference(1,true)
|
8
8
|
ref.to_s.should == "1 0 R"
|
9
|
-
end
|
10
|
-
|
9
|
+
end
|
10
|
+
|
11
11
|
it "should allow changing generation number" do
|
12
|
-
ref =
|
12
|
+
ref = PDF::Core::Reference(1,true)
|
13
13
|
ref.gen = 1
|
14
14
|
ref.to_s.should == "1 1 R"
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "should generate a valid PDF object for the referenced data" do
|
18
|
-
ref =
|
19
|
-
ref.object.should == "2 0 obj\n#{
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should automatically open a stream when #<< is used" do
|
23
|
-
ref = Prawn::Core::Reference(1, :Length => 41)
|
24
|
-
ref << "BT\n/F1 12 Tf\n72 712 Td\n( A stream ) Tj\nET"
|
25
|
-
ref.object.should == "1 0 obj\n<< /Length 41\n>>\nstream"+
|
26
|
-
"\nBT\n/F1 12 Tf\n72 712 Td\n( A stream ) Tj\nET" +
|
27
|
-
"\nendstream\nendobj\n"
|
18
|
+
ref = PDF::Core::Reference(2,[1,"foo"])
|
19
|
+
ref.object.should == "2 0 obj\n#{PDF::Core::PdfObject([1,"foo"])}\nendobj\n"
|
28
20
|
end
|
29
21
|
|
30
|
-
it "should
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
cref << "Hi There " * 20
|
36
|
-
cref.compress_stream
|
22
|
+
it "should include stream fileds in dictionary when serializing" do
|
23
|
+
ref = PDF::Core::Reference(1, {})
|
24
|
+
ref.stream << 'Hello'
|
25
|
+
ref.object.should == "1 0 obj\n<< /Length 5\n>>\nstream\nHello\nendstream\nendobj\n"
|
26
|
+
end
|
37
27
|
|
38
|
-
|
39
|
-
|
40
|
-
|
28
|
+
it "should append data to stream when #<< is used" do
|
29
|
+
ref = PDF::Core::Reference(1, {})
|
30
|
+
ref << "BT\n/F1 12 Tf\n72 712 Td\n( A stream ) Tj\nET"
|
31
|
+
ref.object.should == "1 0 obj\n<< /Length 41\n>>\nstream"+
|
32
|
+
"\nBT\n/F1 12 Tf\n72 712 Td\n( A stream ) Tj\nET" +
|
33
|
+
"\nendstream\nendobj\n"
|
41
34
|
end
|
42
35
|
|
43
36
|
it "should copy the data and stream from another ref on #replace" do
|
44
|
-
from =
|
37
|
+
from = PDF::Core::Reference(3, {:foo => 'bar'})
|
45
38
|
from << "has a stream too"
|
46
39
|
|
47
|
-
to =
|
40
|
+
to = PDF::Core::Reference(4, {:foo => 'baz'})
|
48
41
|
to.replace from
|
49
42
|
|
50
43
|
# should preserve identifier but copy data and stream
|
@@ -54,23 +47,23 @@ describe "A Reference object" do
|
|
54
47
|
end
|
55
48
|
|
56
49
|
it "should copy a compressed stream from a compressed ref on #replace" do
|
57
|
-
from =
|
50
|
+
from = PDF::Core::Reference(5, {:foo => 'bar'})
|
58
51
|
from << "has a stream too " * 20
|
59
|
-
from.
|
52
|
+
from.stream.compress!
|
60
53
|
|
61
|
-
to =
|
54
|
+
to = PDF::Core::Reference(6, {:foo => 'baz'})
|
62
55
|
to.replace from
|
63
56
|
|
64
57
|
to.identifier.should == 6
|
65
58
|
to.data.should == from.data
|
66
59
|
to.stream.should == from.stream
|
67
|
-
to.compressed?.should == true
|
60
|
+
to.stream.compressed?.should == true
|
68
61
|
end
|
69
62
|
|
70
63
|
describe "generated via Prawn::Document" do
|
71
64
|
it "should return a proper reference on ref!" do
|
72
65
|
pdf = Prawn::Document.new
|
73
|
-
pdf.ref!({}).is_a?(
|
66
|
+
pdf.ref!({}).is_a?(PDF::Core::Reference).should == true
|
74
67
|
end
|
75
68
|
|
76
69
|
it "should return an identifier on ref" do
|
@@ -78,5 +71,12 @@ describe "A Reference object" do
|
|
78
71
|
r = pdf.ref({})
|
79
72
|
r.is_a?(Integer).should == true
|
80
73
|
end
|
74
|
+
|
75
|
+
it "should have :Length of stream if it has one when compression disabled" do
|
76
|
+
pdf = Prawn::Document.new :compress => false
|
77
|
+
ref = pdf.ref!({})
|
78
|
+
ref << 'Hello'
|
79
|
+
ref.stream.data[:Length].should == 5
|
80
|
+
end
|
81
81
|
end
|
82
82
|
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
|
@@ -58,7 +58,7 @@ describe "Repeaters" do
|
|
58
58
|
repeater(doc, :odd).run(3)
|
59
59
|
end
|
60
60
|
|
61
|
-
it "must not try to run a stamp
|
61
|
+
it "must not try to run a stamp unless the page number matches" do
|
62
62
|
doc = sample_document
|
63
63
|
|
64
64
|
doc.expects(:stamp).never
|
@@ -72,6 +72,20 @@ describe "Repeaters" do
|
|
72
72
|
(1..10).each { |p| repeater(doc, :all, true){:do_nothing}.run(p) }
|
73
73
|
end
|
74
74
|
|
75
|
+
it "must try to run a block if the page number matches" do
|
76
|
+
doc = sample_document
|
77
|
+
|
78
|
+
doc.expects(:draw_text).twice
|
79
|
+
(1..10).each { |p| repeater(doc, [1,2], true){doc.draw_text "foo"}.run(p) }
|
80
|
+
end
|
81
|
+
|
82
|
+
it "must not try to run a block unless the page number matches" do
|
83
|
+
doc = sample_document
|
84
|
+
|
85
|
+
doc.expects(:draw_text).never
|
86
|
+
repeater(doc, :odd, true){doc.draw_text "foo"}.run(2)
|
87
|
+
end
|
88
|
+
|
75
89
|
it "must treat any block as a closure" do
|
76
90
|
doc = sample_document
|
77
91
|
|
@@ -81,7 +95,7 @@ describe "Repeaters" do
|
|
81
95
|
end
|
82
96
|
|
83
97
|
text = PDF::Inspector::Text.analyze(doc.render)
|
84
|
-
|
98
|
+
text.strings.should == (1..10).to_a.map{|p| "Page #{p}"}
|
85
99
|
end
|
86
100
|
|
87
101
|
it "must treat any block as a closure (Document.new instance_eval form)" do
|
@@ -96,7 +110,7 @@ describe "Repeaters" do
|
|
96
110
|
end
|
97
111
|
|
98
112
|
text = PDF::Inspector::Text.analyze(doc.render)
|
99
|
-
|
113
|
+
text.strings.should == (1..10).to_a.map{|p| "Page #{p}"}
|
100
114
|
end
|
101
115
|
|
102
116
|
def sample_document
|
@@ -136,7 +150,7 @@ describe "Repeaters" do
|
|
136
150
|
text.strings.include?("cap_style: round").should == false
|
137
151
|
text.strings.include?("cap_style: butt").should == true
|
138
152
|
end
|
139
|
-
|
153
|
+
|
140
154
|
end
|
141
155
|
|
142
156
|
end
|
data/spec/security_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "tempfile"
|
3
3
|
|
4
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
5
5
|
|
6
6
|
describe "Document encryption" do
|
7
7
|
|
@@ -31,9 +31,9 @@ describe "Document encryption" do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
describe "Setting permissions" do
|
36
|
-
|
36
|
+
|
37
37
|
def doc_with_permissions(permissions)
|
38
38
|
pdf = Prawn::Document.new
|
39
39
|
|
@@ -66,10 +66,10 @@ describe "Document encryption" do
|
|
66
66
|
should == 0b1111_1111_1111_1111_1111_1111_1101_1111
|
67
67
|
end
|
68
68
|
|
69
|
-
it "should
|
69
|
+
it "should raise_error ArgumentError if invalid option is provided" do
|
70
70
|
lambda {
|
71
71
|
doc_with_permissions(:modify_document => false)
|
72
|
-
}.should
|
72
|
+
}.should raise_error(ArgumentError)
|
73
73
|
end
|
74
74
|
|
75
75
|
end
|
@@ -89,7 +89,7 @@ describe "Document encryption" do
|
|
89
89
|
end
|
90
90
|
|
91
91
|
it "should calculate the correct owner hash" do
|
92
|
-
@pdf.owner_password_hash.unpack("H*").first.should
|
92
|
+
@pdf.owner_password_hash.unpack("H*").first.should match(/^61CA855012/i)
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should calculate the correct user hash" do
|
@@ -106,21 +106,53 @@ describe "Document encryption" do
|
|
106
106
|
describe "EncryptedPdfObject" do
|
107
107
|
|
108
108
|
it "should delegate to PdfObject for simple types" do
|
109
|
-
|
110
|
-
|
109
|
+
PDF::Core::EncryptedPdfObject(true, nil, nil, nil).should == "true"
|
110
|
+
PDF::Core::EncryptedPdfObject(42, nil, nil, nil).should == "42"
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should encrypt strings properly" do
|
114
|
-
|
114
|
+
PDF::Core::EncryptedPdfObject("foo", "12345", 123, 0).should == "<4ad6e3>"
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should encrypt literal strings properly" do
|
118
|
+
PDF::Core::EncryptedPdfObject(PDF::Core::LiteralString.new("foo"), "12345", 123, 0).should == bin_string("(J\xD6\xE3)")
|
119
|
+
PDF::Core::EncryptedPdfObject(PDF::Core::LiteralString.new("lhfbqg3do5u0satu3fjf"), nil, 123, 0).should == bin_string("(\xF1\x8B\\(\b\xBB\xE18S\x130~4*#\\(%\x87\xE7\x8E\\\n)")
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should encrypt time properly" do
|
123
|
+
PDF::Core::EncryptedPdfObject(Time.utc(2050, 04, 26, 10, 17, 10), "12345", 123, 0).should == bin_string("(h\x83\xBE\xDC\xEC\x99\x0F\xD7\\)%\x13\xD4$\xB8\xF0\x16\xB8\x80\xC5\xE91+\xCF)")
|
115
124
|
end
|
116
125
|
|
117
126
|
it "should properly handle compound types" do
|
118
|
-
|
127
|
+
PDF::Core::EncryptedPdfObject({:Bar => "foo"}, "12345", 123, 0).should ==
|
119
128
|
"<< /Bar <4ad6e3>\n>>"
|
120
|
-
|
129
|
+
PDF::Core::EncryptedPdfObject(["foo", "bar"], "12345", 123, 0).should ==
|
121
130
|
"[<4ad6e3> <4ed8fe>]"
|
122
131
|
end
|
123
|
-
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "Reference#encrypted_object" do
|
136
|
+
it "should encrypt references properly" do
|
137
|
+
ref = PDF::Core::Reference(1,["foo"])
|
138
|
+
ref.encrypted_object(nil).should == "1 0 obj\n[<4fca3f>]\nendobj\n"
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should encrypt references with streams properly" do
|
142
|
+
ref = PDF::Core::Reference(1, {})
|
143
|
+
ref << 'foo'
|
144
|
+
result = bin_string("1 0 obj\n<< /Length 3\n>>\nstream\nO\xCA?\nendstream\nendobj\n")
|
145
|
+
ref.encrypted_object(nil).should == result
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "String#encrypted_object" do
|
150
|
+
it "should encrypt stream properly" do
|
151
|
+
stream = PDF::Core::Stream.new
|
152
|
+
stream << "foo"
|
153
|
+
result = bin_string("stream\nO\xCA?\nendstream\n")
|
154
|
+
stream.encrypted_object(nil, 1, 0).should == result
|
155
|
+
end
|
124
156
|
end
|
125
157
|
|
126
158
|
end
|