prawn 0.15.0 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +2 -2
- data/LICENSE +1 -1
- data/README.md +96 -0
- data/Rakefile +27 -30
- 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/16bit.alpha +0 -0
- data/data/images/16bit.dat +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.dat +0 -0
- data/data/images/rails.dat +0 -0
- data/data/images/rails.png +0 -0
- data/data/pdfs/nested_pages.pdf +13 -13
- data/lib/prawn.rb +21 -85
- data/lib/prawn/compatibility.rb +51 -0
- data/lib/prawn/core.rb +85 -0
- data/lib/prawn/core/annotations.rb +61 -0
- data/lib/prawn/core/byte_string.rb +9 -0
- data/lib/prawn/core/destinations.rb +90 -0
- data/lib/prawn/core/document_state.rb +78 -0
- data/lib/prawn/core/literal_string.rb +16 -0
- data/lib/prawn/core/name_tree.rb +177 -0
- data/lib/prawn/core/object_store.rb +264 -0
- data/lib/prawn/core/page.rb +215 -0
- data/lib/prawn/core/pdf_object.rb +108 -0
- data/lib/prawn/core/reference.rb +115 -0
- data/lib/prawn/core/text.rb +268 -0
- data/lib/prawn/core/text/formatted/arranger.rb +294 -0
- data/lib/prawn/core/text/formatted/line_wrap.rb +273 -0
- data/lib/prawn/core/text/formatted/wrap.rb +153 -0
- data/lib/prawn/document.rb +122 -155
- data/lib/prawn/document/bounding_box.rb +7 -36
- data/lib/prawn/document/column_box.rb +10 -38
- data/lib/prawn/document/graphics_state.rb +74 -11
- data/lib/prawn/document/internals.rb +23 -24
- data/lib/prawn/document/page_geometry.rb +136 -0
- data/lib/prawn/document/snapshot.rb +6 -7
- data/lib/prawn/document/span.rb +10 -12
- data/lib/prawn/encoding.rb +10 -9
- data/lib/prawn/errors.rb +30 -15
- data/lib/prawn/font.rb +104 -136
- data/lib/prawn/font/afm.rb +44 -46
- data/lib/prawn/font/dfont.rb +3 -4
- data/lib/prawn/font/ttf.rb +50 -31
- data/lib/prawn/graphics.rb +57 -302
- data/lib/prawn/graphics/cap_style.rb +3 -4
- data/lib/prawn/graphics/color.rb +5 -13
- data/lib/prawn/graphics/dash.rb +31 -53
- data/lib/prawn/graphics/gradient.rb +84 -0
- data/lib/prawn/graphics/join_style.rb +7 -9
- data/lib/prawn/graphics/transformation.rb +9 -10
- data/lib/prawn/graphics/transparency.rb +1 -3
- data/lib/prawn/images.rb +59 -69
- data/lib/prawn/images/image.rb +22 -6
- data/lib/prawn/images/jpg.rb +14 -20
- data/lib/prawn/images/png.rb +118 -61
- data/lib/prawn/layout.rb +15 -10
- data/lib/prawn/layout/grid.rb +54 -66
- data/lib/prawn/measurement_extensions.rb +6 -10
- data/lib/prawn/measurements.rb +21 -27
- data/lib/prawn/outline.rb +308 -6
- data/lib/prawn/repeater.rb +8 -10
- data/lib/prawn/security.rb +33 -55
- data/lib/prawn/security/arcfour.rb +0 -1
- data/lib/prawn/stamp.rb +3 -5
- data/lib/prawn/table.rb +60 -188
- data/lib/prawn/table/cell.rb +44 -272
- data/lib/prawn/table/cell/image.rb +3 -2
- data/lib/prawn/table/cell/in_table.rb +2 -4
- data/lib/prawn/table/cell/subtable.rb +2 -2
- data/lib/prawn/table/cell/text.rb +18 -41
- data/lib/prawn/table/cells.rb +48 -142
- data/lib/prawn/text.rb +25 -32
- data/lib/prawn/text/box.rb +6 -12
- data/lib/prawn/text/formatted.rb +4 -5
- data/lib/prawn/text/formatted/box.rb +59 -96
- data/lib/prawn/text/formatted/fragment.rb +23 -34
- data/lib/prawn/text/formatted/parser.rb +5 -15
- data/prawn.gemspec +13 -24
- data/spec/annotations_spec.rb +32 -16
- data/spec/bounding_box_spec.rb +17 -119
- data/spec/cell_spec.rb +42 -112
- data/spec/destinations_spec.rb +5 -5
- data/spec/document_spec.rb +111 -155
- data/spec/extensions/mocha.rb +0 -1
- data/spec/font_spec.rb +99 -149
- data/spec/formatted_text_arranger_spec.rb +43 -43
- data/spec/formatted_text_box_spec.rb +44 -43
- data/spec/formatted_text_fragment_spec.rb +8 -8
- data/spec/graphics_spec.rb +68 -151
- data/spec/grid_spec.rb +15 -26
- data/spec/images_spec.rb +30 -51
- data/spec/inline_formatted_text_parser_spec.rb +20 -69
- data/spec/jpg_spec.rb +4 -4
- data/spec/line_wrap_spec.rb +28 -28
- data/spec/measurement_units_spec.rb +6 -6
- data/spec/name_tree_spec.rb +112 -0
- data/spec/object_store_spec.rb +106 -17
- data/spec/outline_spec.rb +63 -103
- data/spec/pdf_object_spec.rb +170 -0
- data/spec/png_spec.rb +25 -25
- data/spec/reference_spec.rb +65 -8
- data/spec/repeater_spec.rb +10 -10
- data/spec/security_spec.rb +12 -44
- data/spec/snapshot_spec.rb +7 -7
- data/spec/span_spec.rb +15 -10
- data/spec/spec_helper.rb +8 -32
- data/spec/stamp_spec.rb +30 -29
- data/spec/stroke_styles_spec.rb +18 -36
- data/spec/table_spec.rb +111 -706
- data/spec/template_spec.rb +297 -0
- data/spec/text_at_spec.rb +33 -19
- data/spec/text_box_spec.rb +64 -100
- data/spec/text_rendering_mode_spec.rb +5 -5
- data/spec/text_spacing_spec.rb +4 -4
- data/spec/text_spec.rb +64 -84
- data/spec/transparency_spec.rb +5 -5
- metadata +290 -463
- checksums.yaml +0 -7
- data/.yardopts +0 -10
- data/Gemfile +0 -11
- data/data/images/16bit.color +0 -0
- data/data/images/dice.color +0 -0
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/images/page_white_text.color +0 -0
- data/lib/prawn/font_metric_cache.rb +0 -47
- data/lib/prawn/graphics/patterns.rb +0 -138
- data/lib/prawn/image_handler.rb +0 -36
- data/lib/prawn/soft_mask.rb +0 -96
- data/lib/prawn/table/cell/span_dummy.rb +0 -93
- data/lib/prawn/table/column_width_calculator.rb +0 -61
- data/lib/prawn/text/formatted/arranger.rb +0 -290
- data/lib/prawn/text/formatted/line_wrap.rb +0 -266
- data/lib/prawn/text/formatted/wrap.rb +0 -150
- data/lib/prawn/utilities.rb +0 -46
- data/manual/basic_concepts/adding_pages.rb +0 -27
- data/manual/basic_concepts/basic_concepts.rb +0 -34
- data/manual/basic_concepts/creation.rb +0 -39
- data/manual/basic_concepts/cursor.rb +0 -33
- data/manual/basic_concepts/measurement.rb +0 -25
- data/manual/basic_concepts/origin.rb +0 -38
- data/manual/basic_concepts/other_cursor_helpers.rb +0 -40
- data/manual/bounding_box/bounding_box.rb +0 -39
- data/manual/bounding_box/bounds.rb +0 -49
- data/manual/bounding_box/canvas.rb +0 -24
- data/manual/bounding_box/creation.rb +0 -23
- data/manual/bounding_box/indentation.rb +0 -46
- data/manual/bounding_box/nesting.rb +0 -45
- data/manual/bounding_box/russian_boxes.rb +0 -40
- data/manual/bounding_box/stretchy.rb +0 -31
- data/manual/document_and_page_options/background.rb +0 -27
- data/manual/document_and_page_options/document_and_page_options.rb +0 -32
- data/manual/document_and_page_options/metadata.rb +0 -23
- data/manual/document_and_page_options/page_margins.rb +0 -38
- data/manual/document_and_page_options/page_size.rb +0 -34
- data/manual/document_and_page_options/print_scaling.rb +0 -20
- data/manual/example_file.rb +0 -111
- data/manual/example_helper.rb +0 -411
- data/manual/example_package.rb +0 -53
- data/manual/example_section.rb +0 -46
- data/manual/graphics/circle_and_ellipse.rb +0 -22
- data/manual/graphics/color.rb +0 -24
- data/manual/graphics/common_lines.rb +0 -30
- data/manual/graphics/fill_and_stroke.rb +0 -42
- data/manual/graphics/fill_rules.rb +0 -37
- data/manual/graphics/gradients.rb +0 -37
- data/manual/graphics/graphics.rb +0 -58
- data/manual/graphics/helper.rb +0 -24
- data/manual/graphics/line_width.rb +0 -35
- data/manual/graphics/lines_and_curves.rb +0 -41
- data/manual/graphics/polygon.rb +0 -29
- data/manual/graphics/rectangle.rb +0 -21
- data/manual/graphics/rotate.rb +0 -28
- data/manual/graphics/scale.rb +0 -41
- data/manual/graphics/soft_masks.rb +0 -46
- data/manual/graphics/stroke_cap.rb +0 -31
- data/manual/graphics/stroke_dash.rb +0 -48
- data/manual/graphics/stroke_join.rb +0 -30
- data/manual/graphics/translate.rb +0 -29
- data/manual/graphics/transparency.rb +0 -35
- data/manual/images/absolute_position.rb +0 -23
- data/manual/images/fit.rb +0 -21
- data/manual/images/horizontal.rb +0 -25
- data/manual/images/images.rb +0 -40
- data/manual/images/plain_image.rb +0 -18
- data/manual/images/scale.rb +0 -22
- data/manual/images/vertical.rb +0 -28
- data/manual/images/width_and_height.rb +0 -25
- data/manual/layout/boxes.rb +0 -27
- data/manual/layout/content.rb +0 -25
- data/manual/layout/layout.rb +0 -28
- data/manual/layout/simple_grid.rb +0 -23
- data/manual/manual/cover.rb +0 -36
- data/manual/manual/foreword.rb +0 -85
- data/manual/manual/how_to_read_this_manual.rb +0 -41
- data/manual/manual/manual.rb +0 -34
- data/manual/outline/add_subsection_to.rb +0 -61
- data/manual/outline/insert_section_after.rb +0 -47
- data/manual/outline/outline.rb +0 -32
- data/manual/outline/sections_and_pages.rb +0 -67
- data/manual/repeatable_content/page_numbering.rb +0 -54
- data/manual/repeatable_content/repeatable_content.rb +0 -31
- data/manual/repeatable_content/repeater.rb +0 -55
- data/manual/repeatable_content/stamp.rb +0 -41
- data/manual/security/encryption.rb +0 -31
- data/manual/security/permissions.rb +0 -38
- data/manual/security/security.rb +0 -28
- data/manual/syntax_highlight.rb +0 -52
- data/manual/table/basic_block.rb +0 -53
- data/manual/table/before_rendering_page.rb +0 -26
- data/manual/table/cell_border_lines.rb +0 -24
- data/manual/table/cell_borders_and_bg.rb +0 -31
- data/manual/table/cell_dimensions.rb +0 -30
- data/manual/table/cell_text.rb +0 -38
- data/manual/table/column_widths.rb +0 -30
- data/manual/table/content_and_subtables.rb +0 -39
- data/manual/table/creation.rb +0 -27
- data/manual/table/filtering.rb +0 -36
- data/manual/table/flow_and_header.rb +0 -17
- data/manual/table/image_cells.rb +0 -33
- data/manual/table/position.rb +0 -29
- data/manual/table/row_colors.rb +0 -20
- data/manual/table/span.rb +0 -30
- data/manual/table/style.rb +0 -22
- data/manual/table/table.rb +0 -52
- data/manual/table/width.rb +0 -27
- data/manual/text/alignment.rb +0 -44
- data/manual/text/color.rb +0 -24
- data/manual/text/column_box.rb +0 -32
- data/manual/text/fallback_fonts.rb +0 -37
- data/manual/text/font.rb +0 -41
- data/manual/text/font_size.rb +0 -45
- data/manual/text/font_style.rb +0 -23
- data/manual/text/formatted_callbacks.rb +0 -60
- data/manual/text/formatted_text.rb +0 -54
- data/manual/text/free_flowing_text.rb +0 -51
- data/manual/text/group.rb +0 -31
- data/manual/text/inline.rb +0 -43
- data/manual/text/kerning_and_character_spacing.rb +0 -39
- data/manual/text/leading.rb +0 -25
- data/manual/text/line_wrapping.rb +0 -41
- data/manual/text/paragraph_indentation.rb +0 -26
- data/manual/text/positioned_text.rb +0 -38
- data/manual/text/registering_families.rb +0 -48
- data/manual/text/rendering_and_color.rb +0 -37
- data/manual/text/right_to_left_text.rb +0 -43
- data/manual/text/rotation.rb +0 -43
- data/manual/text/single_usage.rb +0 -37
- data/manual/text/text.rb +0 -75
- data/manual/text/text_box_excess.rb +0 -32
- data/manual/text/text_box_extensions.rb +0 -45
- data/manual/text/text_box_overflow.rb +0 -44
- data/manual/text/utf8.rb +0 -28
- data/manual/text/win_ansi_charset.rb +0 -59
- data/spec/acceptance/png.rb +0 -23
- data/spec/column_box_spec.rb +0 -65
- data/spec/extensions/encoding_helpers.rb +0 -9
- data/spec/font_metric_cache_spec.rb +0 -52
- data/spec/image_handler_spec.rb +0 -54
- data/spec/soft_mask_spec.rb +0 -117
- data/spec/table/span_dummy_spec.rb +0 -17
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::BASEDIR}/data/images/web-links.png"
|
16
|
+
@data_filename = "#{Prawn::BASEDIR}/data/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 =
|
34
|
+
data = 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::BASEDIR}/data/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::BASEDIR}/data/images/ruport.png"
|
60
|
+
@data_filename = "#{Prawn::BASEDIR}/data/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 =
|
78
|
+
data = 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::BASEDIR}/data/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::BASEDIR}/data/images/rails.png"
|
107
|
+
@data_filename = "#{Prawn::BASEDIR}/data/images/rails.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 == 50
|
115
|
+
png.height.should == 64
|
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 =
|
125
|
+
data = 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
|
-
@
|
135
|
-
@alpha_data_filename = "#{Prawn::
|
133
|
+
@filename = "#{Prawn::BASEDIR}/data/images/page_white_text.png"
|
134
|
+
@data_filename = "#{Prawn::BASEDIR}/data/images/page_white_text.dat"
|
135
|
+
@alpha_data_filename = "#{Prawn::BASEDIR}/data/images/page_white_text.alpha"
|
136
136
|
@img_data = File.binread(@filename)
|
137
137
|
end
|
138
138
|
|
@@ -151,7 +151,7 @@ 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(@
|
154
|
+
data = File.binread(@data_filename)
|
155
155
|
png.img_data.should == data
|
156
156
|
end
|
157
157
|
|
@@ -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
|
-
@
|
171
|
-
@alpha_data_filename = "#{Prawn::
|
169
|
+
@filename = "#{Prawn::BASEDIR}/data/images/dice.png"
|
170
|
+
@data_filename = "#{Prawn::BASEDIR}/data/images/dice.dat"
|
171
|
+
@alpha_data_filename = "#{Prawn::BASEDIR}/data/images/dice.alpha"
|
172
172
|
@img_data = File.binread(@filename)
|
173
173
|
end
|
174
174
|
|
@@ -187,7 +187,7 @@ 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(@
|
190
|
+
data = File.binread(@data_filename)
|
191
191
|
png.img_data.should == data
|
192
192
|
end
|
193
193
|
|
@@ -202,10 +202,10 @@ end
|
|
202
202
|
describe "When reading a 16bit RGB+alpha PNG file (color type 6)" do
|
203
203
|
|
204
204
|
before(:each) do
|
205
|
-
@filename = "#{Prawn::
|
206
|
-
@
|
205
|
+
@filename = "#{Prawn::BASEDIR}/data/images/16bit.png"
|
206
|
+
@data_filename = "#{Prawn::BASEDIR}/data/images/16bit.dat"
|
207
207
|
# alpha channel truncated to 8-bit
|
208
|
-
@alpha_data_filename = "#{Prawn::
|
208
|
+
@alpha_data_filename = "#{Prawn::BASEDIR}/data/images/16bit.alpha"
|
209
209
|
@img_data = File.binread(@filename)
|
210
210
|
end
|
211
211
|
|
@@ -224,7 +224,7 @@ describe "When reading a 16bit RGB+alpha PNG file (color type 6)" do
|
|
224
224
|
it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
|
225
225
|
png = Prawn::Images::PNG.new(@img_data)
|
226
226
|
png.split_alpha_channel!
|
227
|
-
data = File.binread(@
|
227
|
+
data = File.binread(@data_filename)
|
228
228
|
png.img_data.should == data
|
229
229
|
end
|
230
230
|
|
data/spec/reference_spec.rb
CHANGED
@@ -3,10 +3,74 @@
|
|
3
3
|
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
4
|
|
5
5
|
describe "A Reference object" do
|
6
|
+
it "should produce a PDF reference on #to_s call" do
|
7
|
+
ref = Prawn::Core::Reference(1,true)
|
8
|
+
ref.to_s.should == "1 0 R"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should allow changing generation number" do
|
12
|
+
ref = Prawn::Core::Reference(1,true)
|
13
|
+
ref.gen = 1
|
14
|
+
ref.to_s.should == "1 1 R"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should generate a valid PDF object for the referenced data" do
|
18
|
+
ref = Prawn::Core::Reference(2,[1,"foo"])
|
19
|
+
ref.object.should == "2 0 obj\n#{Prawn::Core::PdfObject([1,"foo"])}\nendobj\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"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should compress a stream upon request" do
|
31
|
+
ref = Prawn::Core::Reference(2,{})
|
32
|
+
ref << "Hi There " * 20
|
33
|
+
|
34
|
+
cref = Prawn::Core::Reference(2,{})
|
35
|
+
cref << "Hi There " * 20
|
36
|
+
cref.compress_stream
|
37
|
+
|
38
|
+
assert cref.stream.size < ref.stream.size,
|
39
|
+
"compressed stream expected to be smaller than source but wasn't"
|
40
|
+
cref.data[:Filter].should == :FlateDecode
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should copy the data and stream from another ref on #replace" do
|
44
|
+
from = Prawn::Core::Reference(3, {:foo => 'bar'})
|
45
|
+
from << "has a stream too"
|
46
|
+
|
47
|
+
to = Prawn::Core::Reference(4, {:foo => 'baz'})
|
48
|
+
to.replace from
|
49
|
+
|
50
|
+
# should preserve identifier but copy data and stream
|
51
|
+
to.identifier.should == 4
|
52
|
+
to.data.should == from.data
|
53
|
+
to.stream.should == from.stream
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should copy a compressed stream from a compressed ref on #replace" do
|
57
|
+
from = Prawn::Core::Reference(5, {:foo => 'bar'})
|
58
|
+
from << "has a stream too " * 20
|
59
|
+
from.compress_stream
|
60
|
+
|
61
|
+
to = Prawn::Core::Reference(6, {:foo => 'baz'})
|
62
|
+
to.replace from
|
63
|
+
|
64
|
+
to.identifier.should == 6
|
65
|
+
to.data.should == from.data
|
66
|
+
to.stream.should == from.stream
|
67
|
+
to.compressed?.should == true
|
68
|
+
end
|
69
|
+
|
6
70
|
describe "generated via Prawn::Document" do
|
7
71
|
it "should return a proper reference on ref!" do
|
8
72
|
pdf = Prawn::Document.new
|
9
|
-
pdf.ref!({}).is_a?(
|
73
|
+
pdf.ref!({}).is_a?(Prawn::Core::Reference).should == true
|
10
74
|
end
|
11
75
|
|
12
76
|
it "should return an identifier on ref" do
|
@@ -14,12 +78,5 @@ describe "A Reference object" do
|
|
14
78
|
r = pdf.ref({})
|
15
79
|
r.is_a?(Integer).should == true
|
16
80
|
end
|
17
|
-
|
18
|
-
it "should have :Length of stream if it has one when compression disabled" do
|
19
|
-
pdf = Prawn::Document.new :compress => false
|
20
|
-
ref = pdf.ref!({})
|
21
|
-
ref << 'Hello'
|
22
|
-
ref.stream.data[:Length].should == 5
|
23
|
-
end
|
24
81
|
end
|
25
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
|
+
assert_equal orig_count + 1, Prawn::Repeater.count
|
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
|
-
(1..doc.page_count).all? { |i| r.match?(i) }
|
20
|
+
assert (1..doc.page_count).all? { |i| r.match?(i) }
|
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
|
-
odd.all? { |i| r.match?(i) }
|
30
|
-
even.any? { |i| r.match?(i) }
|
29
|
+
assert odd.all? { |i| r.match?(i) }
|
30
|
+
assert ! even.any? { |i| r.match?(i) }
|
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
|
-
(1..10).select { |i| r.match?(i) }
|
37
|
+
assert_equal [1,2,7], (1..10).select { |i| r.match?(i) }
|
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
|
-
(1..10).select { |i| r.match?(i) }
|
44
|
+
assert_equal [2,3,4], (1..10).select { |i| r.match?(i) }
|
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
|
-
(1..10).select { |i| r.match?(i) }
|
51
|
+
assert_equal [1,3,6,9], (1..10).select { |i| r.match?(i) }
|
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
|
+
assert_equal (1..10).to_a.map{|p| "Page #{p}"}, text.strings
|
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
|
+
assert_equal (1..10).to_a.map{|p| "Page #{p}"}, text.strings
|
114
114
|
end
|
115
115
|
|
116
116
|
def sample_document
|
@@ -150,7 +150,7 @@ describe "Repeaters" do
|
|
150
150
|
text.strings.include?("cap_style: round").should == false
|
151
151
|
text.strings.include?("cap_style: butt").should == true
|
152
152
|
end
|
153
|
-
|
153
|
+
|
154
154
|
end
|
155
155
|
|
156
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 ArgumentError if invalid option is provided" do
|
70
70
|
lambda {
|
71
71
|
doc_with_permissions(:modify_document => false)
|
72
|
-
}.should
|
72
|
+
}.should.raise(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,53 +106,21 @@ 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
|
+
Prawn::Core::EncryptedPdfObject(true, nil, nil, nil).should == "true"
|
110
|
+
Prawn::Core::EncryptedPdfObject(42, nil, nil, nil).should == "42"
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should encrypt strings properly" do
|
114
|
-
|
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)")
|
114
|
+
Prawn::Core::EncryptedPdfObject("foo", "12345", 123, 0).should == "<4ad6e3>"
|
124
115
|
end
|
125
116
|
|
126
117
|
it "should properly handle compound types" do
|
127
|
-
|
118
|
+
Prawn::Core::EncryptedPdfObject({:Bar => "foo"}, "12345", 123, 0).should ==
|
128
119
|
"<< /Bar <4ad6e3>\n>>"
|
129
|
-
|
120
|
+
Prawn::Core::EncryptedPdfObject(["foo", "bar"], "12345", 123, 0).should ==
|
130
121
|
"[<4ad6e3> <4ed8fe>]"
|
131
122
|
end
|
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
|
123
|
+
|
156
124
|
end
|
157
125
|
|
158
126
|
end
|
data/spec/snapshot_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe "Prawn::Document#transaction" do
|
|
23
23
|
end
|
24
24
|
text = PDF::Inspector::Text.analyze(pdf.render)
|
25
25
|
text.strings.should == []
|
26
|
-
end
|
26
|
+
end
|
27
27
|
|
28
28
|
it "should return true/false value indicating success of the transaction" do
|
29
29
|
Prawn::Document.new do
|
@@ -34,7 +34,7 @@ describe "Prawn::Document#transaction" do
|
|
34
34
|
success.should == false
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
it "should support nested transactions" do
|
39
39
|
pdf = Prawn::Document.new do
|
40
40
|
transaction do
|
@@ -76,7 +76,7 @@ describe "Prawn::Document#transaction" do
|
|
76
76
|
rescue Prawn::Errors::CannotGroup
|
77
77
|
add_lines(pdf)
|
78
78
|
end
|
79
|
-
end.
|
79
|
+
end.should.not.raise#(Prawn::Document::Snapshot::RollbackTransaction)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -141,10 +141,10 @@ describe "Prawn::Document#transaction" do
|
|
141
141
|
Prawn::Document.new do |pdf|
|
142
142
|
pdf.add_dest("dest", pdf.dest_fit_horizontally(pdf.cursor, pdf.page))
|
143
143
|
pdf.text("Hello world")
|
144
|
-
lambda { pdf.transaction{} }.
|
144
|
+
lambda { pdf.transaction{} }.should.not.raise
|
145
145
|
end
|
146
146
|
end
|
147
|
-
|
147
|
+
|
148
148
|
describe "with a stamp dictionary present" do
|
149
149
|
|
150
150
|
it "should properly commit if no error is raised" do
|
@@ -166,8 +166,8 @@ describe "Prawn::Document#transaction" do
|
|
166
166
|
rollback
|
167
167
|
end
|
168
168
|
end
|
169
|
-
pdf.render.
|
170
|
-
end
|
169
|
+
pdf.render.should.not =~ /\/Stamp1 Do/
|
170
|
+
end
|
171
171
|
|
172
172
|
end
|
173
173
|
|