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/outline_spec.rb
CHANGED
@@ -16,27 +16,27 @@ describe "Outline" do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
if RUBY_VERSION >= "1.9"
|
20
|
+
describe "outline encoding" do
|
21
|
+
it "should store all outline titles as UTF-16" do
|
22
|
+
render_and_find_objects
|
23
|
+
@hash.values.each do |obj|
|
24
|
+
if obj.is_a?(Hash) && obj[:Title]
|
25
|
+
title = obj[:Title].dup
|
26
|
+
title.force_encoding("UTF-16LE")
|
27
|
+
title.valid_encoding?.should == true
|
28
|
+
end
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
32
|
-
|
33
33
|
describe "#generate_outline" do
|
34
34
|
before(:each) do
|
35
35
|
render_and_find_objects
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should create a root outline dictionary item" do
|
39
|
-
@outline_root
|
39
|
+
assert_not_nil @outline_root
|
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| item
|
49
|
+
[@section_1, @page_1, @page_2].each {|item| assert_not_nil item}
|
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].abs
|
73
|
+
@section_1[:Count].should.abs == 2
|
74
74
|
@page_1[:Count].should == 0
|
75
75
|
@page_2[:Count].should == 0
|
76
76
|
end
|
@@ -87,28 +87,6 @@ describe "Outline" do
|
|
87
87
|
|
88
88
|
end
|
89
89
|
|
90
|
-
describe "adding a custom destination" do
|
91
|
-
before(:each) do
|
92
|
-
@pdf.start_new_page
|
93
|
-
@pdf.text "Page 3 with a destination"
|
94
|
-
@pdf.add_dest('customdest', @pdf.dest_xyz(200, 200))
|
95
|
-
pdf = @pdf
|
96
|
-
@pdf.outline.update do
|
97
|
-
page :destination => pdf.dest_xyz(200, 200), :title => 'Custom Destination'
|
98
|
-
end
|
99
|
-
render_and_find_objects
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should create an outline item" do
|
103
|
-
@custom_dest.should_not be_nil
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should reference the custom destination" do
|
107
|
-
referenced_object(@custom_dest[:Dest].first).should == referenced_object(@pages.last)
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
90
|
describe "addding a section later with outline#section" do
|
113
91
|
before(:each) do
|
114
92
|
@pdf.start_new_page
|
@@ -122,7 +100,7 @@ describe "Outline" do
|
|
122
100
|
end
|
123
101
|
|
124
102
|
it "should add new outline items to document" do
|
125
|
-
[@section_2, @page_3].each { |item| item
|
103
|
+
[@section_2, @page_3].each { |item| assert_not_nil item}
|
126
104
|
end
|
127
105
|
|
128
106
|
it "should reset the last items for root outline dictionary" do
|
@@ -142,11 +120,11 @@ describe "Outline" do
|
|
142
120
|
@outline_root[:Count].should == 5
|
143
121
|
end
|
144
122
|
|
145
|
-
end
|
146
|
-
|
147
|
-
describe "#outline.add_subsection_to" do
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "#outline.add_subsection_to" do
|
148
126
|
context "positioned last" do
|
149
|
-
|
127
|
+
|
150
128
|
before(:each) do
|
151
129
|
@pdf.start_new_page
|
152
130
|
@pdf.text "Page 3. An added subsection "
|
@@ -155,45 +133,45 @@ describe "Outline" do
|
|
155
133
|
section 'Added SubSection', :destination => 3 do
|
156
134
|
page :destination => 3, :title => 'Added Page 3'
|
157
135
|
end
|
158
|
-
end
|
136
|
+
end
|
159
137
|
end
|
160
138
|
render_and_find_objects
|
161
139
|
end
|
162
|
-
|
140
|
+
|
163
141
|
it "should add new outline items to document" do
|
164
|
-
[@subsection, @added_page_3].each { |item| item
|
142
|
+
[@subsection, @added_page_3].each { |item| assert_not_nil item}
|
165
143
|
end
|
166
|
-
|
144
|
+
|
167
145
|
it "should reset the last item for parent item dictionary" do
|
168
146
|
referenced_object(@section_1[:First]).should == @page_1
|
169
147
|
referenced_object(@section_1[:Last]).should == @subsection
|
170
148
|
end
|
171
|
-
|
149
|
+
|
172
150
|
it "should set the prev relation for the new subsection to its parent's old last item" do
|
173
151
|
referenced_object(@subsection[:Prev]).should == @page_2
|
174
152
|
end
|
175
|
-
|
176
|
-
|
153
|
+
|
154
|
+
|
177
155
|
it "the subsection should become the next relation for its parent's old last item" do
|
178
156
|
referenced_object(@page_2[:Next]).should == @subsection
|
179
157
|
end
|
180
|
-
|
158
|
+
|
181
159
|
it "should set the first relation for the new subsection" do
|
182
160
|
referenced_object(@subsection[:First]).should == @added_page_3
|
183
161
|
end
|
184
|
-
|
162
|
+
|
185
163
|
it "should set the correct last relation of the added to section" do
|
186
164
|
referenced_object(@subsection[:Last]).should == @added_page_3
|
187
165
|
end
|
188
|
-
|
166
|
+
|
189
167
|
it "should increase the count of root outline dictionary" do
|
190
168
|
@outline_root[:Count].should == 5
|
191
169
|
end
|
192
|
-
|
193
|
-
end
|
194
|
-
|
170
|
+
|
171
|
+
end
|
172
|
+
|
195
173
|
context "positioned first" do
|
196
|
-
|
174
|
+
|
197
175
|
before(:each) do
|
198
176
|
@pdf.start_new_page
|
199
177
|
@pdf.text "Page 3. An added subsection "
|
@@ -208,14 +186,14 @@ describe "Outline" do
|
|
208
186
|
end
|
209
187
|
|
210
188
|
it "should add new outline items to document" do
|
211
|
-
[@subsection, @added_page_3].each { |item| item
|
189
|
+
[@subsection, @added_page_3].each { |item| assert_not_nil item}
|
212
190
|
end
|
213
191
|
|
214
192
|
it "should reset the first item for parent item dictionary" do
|
215
193
|
referenced_object(@section_1[:First]).should == @subsection
|
216
194
|
referenced_object(@section_1[:Last]).should == @page_2
|
217
195
|
end
|
218
|
-
|
196
|
+
|
219
197
|
it "should set the next relation for the new subsection to its parent's old first item" do
|
220
198
|
referenced_object(@subsection[:Next]).should == @page_1
|
221
199
|
end
|
@@ -237,9 +215,9 @@ describe "Outline" do
|
|
237
215
|
end
|
238
216
|
|
239
217
|
end
|
240
|
-
|
218
|
+
|
241
219
|
it "should require an existing title" do
|
242
|
-
|
220
|
+
assert_raise Prawn::Errors::UnknownOutlineTitle do
|
243
221
|
@pdf.go_to_page 1
|
244
222
|
@pdf.start_new_page
|
245
223
|
@pdf.text "Inserted Page"
|
@@ -249,9 +227,9 @@ describe "Outline" do
|
|
249
227
|
end
|
250
228
|
end
|
251
229
|
render_and_find_objects
|
252
|
-
end
|
230
|
+
end
|
253
231
|
end
|
254
|
-
end
|
232
|
+
end
|
255
233
|
|
256
234
|
describe "#outline.insert_section_after" do
|
257
235
|
describe "inserting in the middle of another section" do
|
@@ -268,47 +246,47 @@ describe "Outline" do
|
|
268
246
|
|
269
247
|
it "should insert new outline items to document" do
|
270
248
|
render_and_find_objects
|
271
|
-
@inserted_page
|
249
|
+
assert_not_nil @inserted_page
|
272
250
|
end
|
273
|
-
|
251
|
+
|
274
252
|
it "should adjust the count of all ancestors" do
|
275
253
|
render_and_find_objects
|
276
254
|
@outline_root[:Count].should == 4
|
277
|
-
@section_1[:Count].abs
|
255
|
+
@section_1[:Count].should.abs == 3
|
278
256
|
end
|
279
|
-
|
257
|
+
|
280
258
|
describe "#adjust_relations" do
|
281
|
-
|
259
|
+
|
282
260
|
it "should reset the sibling relations of adjoining items to inserted item" do
|
283
261
|
render_and_find_objects
|
284
262
|
referenced_object(@page_1[:Next]).should == @inserted_page
|
285
263
|
referenced_object(@page_2[:Prev]).should == @inserted_page
|
286
264
|
end
|
287
|
-
|
265
|
+
|
288
266
|
it "should set the sibling relation of added item to adjoining items" do
|
289
267
|
render_and_find_objects
|
290
268
|
referenced_object(@inserted_page[:Next]).should == @page_2
|
291
269
|
referenced_object(@inserted_page[:Prev]).should == @page_1
|
292
270
|
end
|
293
|
-
|
271
|
+
|
294
272
|
it "should not affect the first and last relations of parent item" do
|
295
273
|
render_and_find_objects
|
296
274
|
referenced_object(@section_1[:First]).should == @page_1
|
297
275
|
referenced_object(@section_1[:Last]).should == @page_2
|
298
276
|
end
|
299
|
-
|
300
|
-
end
|
301
|
-
|
302
|
-
|
303
|
-
context "when adding another section afterwards" do
|
277
|
+
|
278
|
+
end
|
279
|
+
|
280
|
+
|
281
|
+
context "when adding another section afterwards" do
|
304
282
|
it "should have reset the root position so that a new section is added at the end of root sections" do
|
305
283
|
@pdf.start_new_page
|
306
284
|
@pdf.text "Another Inserted Page"
|
307
285
|
@pdf.outline.update do
|
308
286
|
section 'Added Section' do
|
309
287
|
page :destination => page_number, :title => "Inserted Page"
|
310
|
-
end
|
311
|
-
end
|
288
|
+
end
|
289
|
+
end
|
312
290
|
render_and_find_objects
|
313
291
|
referenced_object(@outline_root[:Last]).should == @section_2
|
314
292
|
referenced_object(@section_1[:Next]).should == @section_2
|
@@ -327,7 +305,7 @@ describe "Outline" do
|
|
327
305
|
@pdf.outline.update do
|
328
306
|
insert_section_after 'Page 2' do
|
329
307
|
page :destination => page_number, :title => "Inserted Page"
|
330
|
-
end
|
308
|
+
end
|
331
309
|
end
|
332
310
|
render_and_find_objects
|
333
311
|
end
|
@@ -339,7 +317,7 @@ describe "Outline" do
|
|
339
317
|
end
|
340
318
|
|
341
319
|
it "should set the sibling relation of added item to adjoining items" do
|
342
|
-
referenced_object(@inserted_page[:Next])
|
320
|
+
assert_nil referenced_object(@inserted_page[:Next])
|
343
321
|
referenced_object(@inserted_page[:Prev]).should == @page_2
|
344
322
|
end
|
345
323
|
|
@@ -351,7 +329,7 @@ describe "Outline" do
|
|
351
329
|
end
|
352
330
|
|
353
331
|
it "should require an existing title" do
|
354
|
-
|
332
|
+
assert_raise Prawn::Errors::UnknownOutlineTitle do
|
355
333
|
@pdf.go_to_page 1
|
356
334
|
@pdf.start_new_page
|
357
335
|
@pdf.text "Inserted Page"
|
@@ -361,26 +339,26 @@ describe "Outline" do
|
|
361
339
|
end
|
362
340
|
end
|
363
341
|
render_and_find_objects
|
364
|
-
end
|
342
|
+
end
|
365
343
|
end
|
366
344
|
|
367
345
|
end
|
368
346
|
|
369
347
|
describe "#page" do
|
370
348
|
it "should require a title option to be set" do
|
371
|
-
|
349
|
+
assert_raise Prawn::Errors::RequiredOption do
|
372
350
|
@pdf = Prawn::Document.new() do
|
373
351
|
text "Page 1. This is the first Chapter. "
|
374
352
|
outline.define do
|
375
353
|
page :destination => 1, :title => nil
|
376
354
|
end
|
377
355
|
end
|
378
|
-
end
|
356
|
+
end
|
379
357
|
end
|
380
358
|
end
|
381
359
|
end
|
382
|
-
|
383
|
-
|
360
|
+
|
361
|
+
context "foreign character encoding" do
|
384
362
|
before(:each) do
|
385
363
|
pdf = Prawn::Document.new() do
|
386
364
|
outline.define do
|
@@ -392,25 +370,7 @@ describe "foreign character encoding" do
|
|
392
370
|
|
393
371
|
it "should handle other encodings for the title" do
|
394
372
|
object = find_by_title('La pomme croquée')
|
395
|
-
object.
|
396
|
-
end
|
397
|
-
end
|
398
|
-
|
399
|
-
describe "with optimize_objects option" do
|
400
|
-
before(:each) do
|
401
|
-
@pdf = Prawn::Document.new(:optimize_objects => true) do
|
402
|
-
outline.define do
|
403
|
-
section 'Chapter 1', :destination => 1, :closed => true do
|
404
|
-
page :destination => 1, :title => 'Page 1'
|
405
|
-
end
|
406
|
-
end
|
407
|
-
end
|
408
|
-
render_and_find_objects
|
409
|
-
end
|
410
|
-
|
411
|
-
it "should generate an outline" do
|
412
|
-
@section_1.should_not be_nil
|
413
|
-
@page_1.should_not be_nil
|
373
|
+
object.should.not == nil
|
414
374
|
end
|
415
375
|
end
|
416
376
|
|
@@ -424,10 +384,9 @@ def render_and_find_objects
|
|
424
384
|
@page_2 = find_by_title('Page 2')
|
425
385
|
@section_2 = find_by_title('Added Section')
|
426
386
|
@page_3 = find_by_title('Page 3')
|
427
|
-
@inserted_page = find_by_title('Inserted Page')
|
387
|
+
@inserted_page = find_by_title('Inserted Page')
|
428
388
|
@subsection = find_by_title('Added SubSection')
|
429
389
|
@added_page_3 = find_by_title('Added Page 3')
|
430
|
-
@custom_dest = find_by_title('Custom Destination')
|
431
390
|
end
|
432
391
|
|
433
392
|
# Outline titles are stored as UTF-16. This method accepts a UTF-8 outline title
|
@@ -446,3 +405,4 @@ end
|
|
446
405
|
def referenced_object(reference)
|
447
406
|
@hash[reference]
|
448
407
|
end
|
408
|
+
|
@@ -0,0 +1,170 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
# See PDF Reference, Sixth Edition (1.7) pp51-60 for details
|
6
|
+
describe "PDF Object Serialization" do
|
7
|
+
|
8
|
+
it "should convert Ruby's nil to PDF null" do
|
9
|
+
Prawn::Core::PdfObject(nil).should == "null"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should convert Ruby booleans to PDF booleans" do
|
13
|
+
Prawn::Core::PdfObject(true).should == "true"
|
14
|
+
Prawn::Core::PdfObject(false).should == "false"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should convert a Ruby number to PDF number" do
|
18
|
+
Prawn::Core::PdfObject(1).should == "1"
|
19
|
+
Prawn::Core::PdfObject(1.214112421).should == "1.214112421"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should convert a Ruby time object to a PDF timestamp" do
|
23
|
+
t = Time.now
|
24
|
+
Prawn::Core::PdfObject(t).should == t.strftime("(D:%Y%m%d%H%M%S%z").chop.chop + "'00')"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should convert a Ruby string to PDF string when inside a content stream" do
|
28
|
+
s = "I can has a string"
|
29
|
+
PDF::Inspector.parse(Prawn::Core::PdfObject(s, true)).should == s
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should convert a Ruby string to a UTF-16 PDF string when outside a content stream" do
|
33
|
+
s = "I can has a string"
|
34
|
+
s_utf16 = "\xFE\xFF" + s.unpack("U*").pack("n*")
|
35
|
+
PDF::Inspector.parse(Prawn::Core::PdfObject(s, false)).should == s_utf16
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should convert a Ruby string with characters outside the BMP to its " +
|
39
|
+
"UTF-16 representation with a BOM" do
|
40
|
+
# U+10192 ROMAN SEMUNCIA SIGN
|
41
|
+
semuncia = [65938].pack("U")
|
42
|
+
Prawn::Core::PdfObject(semuncia, false).upcase.should == "<FEFFD800DD92>"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should pass through bytes regardless of content stream status for ByteString" do
|
46
|
+
Prawn::Core::PdfObject(Prawn::Core::ByteString.new("\xDE\xAD\xBE\xEF")).upcase.
|
47
|
+
should == "<DEADBEEF>"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should escape parens when converting from Ruby string to PDF" do
|
51
|
+
s = 'I )(can has a string'
|
52
|
+
PDF::Inspector.parse(Prawn::Core::PdfObject(s, true)).should == s
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should handle ruby escaped parens when converting to PDF string" do
|
56
|
+
s = 'I can \\)( has string'
|
57
|
+
PDF::Inspector.parse(Prawn::Core::PdfObject(s, true)).should == s
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should escape various strings correctly when converting a LiteralString" do
|
61
|
+
ls = Prawn::Core::LiteralString.new("abc")
|
62
|
+
Prawn::Core::PdfObject(ls).should == "(abc)"
|
63
|
+
|
64
|
+
ls = Prawn::Core::LiteralString.new("abc\x0Ade") # should escape \n
|
65
|
+
Prawn::Core::PdfObject(ls).should == "(abc\x5C\x0Ade)"
|
66
|
+
|
67
|
+
ls = Prawn::Core::LiteralString.new("abc\x0Dde") # should escape \r
|
68
|
+
Prawn::Core::PdfObject(ls).should == "(abc\x5C\x0Dde)"
|
69
|
+
|
70
|
+
ls = Prawn::Core::LiteralString.new("abc\x09de") # should escape \t
|
71
|
+
Prawn::Core::PdfObject(ls).should == "(abc\x5C\x09de)"
|
72
|
+
|
73
|
+
ls = Prawn::Core::LiteralString.new("abc\x08de") # should escape \b
|
74
|
+
Prawn::Core::PdfObject(ls).should == "(abc\x5C\x08de)"
|
75
|
+
|
76
|
+
ls = Prawn::Core::LiteralString.new("abc\x0Cde") # should escape \f
|
77
|
+
Prawn::Core::PdfObject(ls).should == "(abc\x5C\x0Cde)"
|
78
|
+
|
79
|
+
ls = Prawn::Core::LiteralString.new("abc(de") # should escape \(
|
80
|
+
Prawn::Core::PdfObject(ls).should == "(abc\x5C(de)"
|
81
|
+
|
82
|
+
ls = Prawn::Core::LiteralString.new("abc)de") # should escape \)
|
83
|
+
Prawn::Core::PdfObject(ls).should == "(abc\x5C)de)"
|
84
|
+
|
85
|
+
ls = Prawn::Core::LiteralString.new("abc\x5Cde") # should escape \\
|
86
|
+
Prawn::Core::PdfObject(ls).should == "(abc\x5C\x5Cde)"
|
87
|
+
Prawn::Core::PdfObject(ls).size.should == 9
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should escape strings correctly when converting a LiteralString that is not utf-8" do
|
91
|
+
data = "\x43\xaf\xc9\x7f\xef\xf\xe6\xa8\xcb\x5c\xaf\xd0"
|
92
|
+
ls = Prawn::Core::LiteralString.new(data)
|
93
|
+
Prawn::Core::PdfObject(ls).should == "(\x43\xaf\xc9\x7f\xef\xf\xe6\xa8\xcb\x5c\x5c\xaf\xd0)"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should convert a Ruby symbol to PDF name" do
|
97
|
+
Prawn::Core::PdfObject(:my_symbol).should == "/my_symbol"
|
98
|
+
Prawn::Core::PdfObject(:"A;Name_With-Various***Characters?").should ==
|
99
|
+
"/A;Name_With-Various***Characters?"
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should convert a whitespace or delimiter containing Ruby symbol to a PDF name" do
|
103
|
+
Prawn::Core::PdfObject(:"my symbol").should == "/my#20symbol"
|
104
|
+
Prawn::Core::PdfObject(:"my#symbol").should == "/my#23symbol"
|
105
|
+
Prawn::Core::PdfObject(:"my/symbol").should == "/my#2Fsymbol"
|
106
|
+
Prawn::Core::PdfObject(:"my(symbol").should == "/my#28symbol"
|
107
|
+
Prawn::Core::PdfObject(:"my)symbol").should == "/my#29symbol"
|
108
|
+
Prawn::Core::PdfObject(:"my<symbol").should == "/my#3Csymbol"
|
109
|
+
Prawn::Core::PdfObject(:"my>symbol").should == "/my#3Esymbol"
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should convert a Ruby array to PDF Array when inside a content stream" do
|
113
|
+
Prawn::Core::PdfObject([1,2,3]).should == "[1 2 3]"
|
114
|
+
PDF::Inspector.parse(Prawn::Core::PdfObject([[1,2],:foo,"Bar"], true)).should ==
|
115
|
+
[[1,2],:foo, "Bar"]
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should convert a Ruby array to PDF Array when outside a content stream" do
|
119
|
+
bar = "\xFE\xFF" + "Bar".unpack("U*").pack("n*")
|
120
|
+
Prawn::Core::PdfObject([1,2,3]).should == "[1 2 3]"
|
121
|
+
PDF::Inspector.parse(Prawn::Core::PdfObject([[1,2],:foo,"Bar"], false)).should ==
|
122
|
+
[[1,2],:foo, bar]
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should convert a Ruby hash to a PDF Dictionary when inside a content stream" do
|
126
|
+
dict = Prawn::Core::PdfObject( {:foo => :bar,
|
127
|
+
"baz" => [1,2,3],
|
128
|
+
:bang => {:a => "what", :b => [:you, :say] }}, true )
|
129
|
+
|
130
|
+
res = PDF::Inspector.parse(dict)
|
131
|
+
|
132
|
+
res[:foo].should == :bar
|
133
|
+
res[:baz].should == [1,2,3]
|
134
|
+
res[:bang].should == { :a => "what", :b => [:you, :say] }
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should convert a Ruby hash to a PDF Dictionary when outside a content stream" do
|
139
|
+
what = "\xFE\xFF" + "what".unpack("U*").pack("n*")
|
140
|
+
dict = Prawn::Core::PdfObject( {:foo => :bar,
|
141
|
+
"baz" => [1,2,3],
|
142
|
+
:bang => {:a => "what", :b => [:you, :say] }}, false )
|
143
|
+
|
144
|
+
res = PDF::Inspector.parse(dict)
|
145
|
+
|
146
|
+
res[:foo].should == :bar
|
147
|
+
res[:baz].should == [1,2,3]
|
148
|
+
res[:bang].should == { :a => what, :b => [:you, :say] }
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should not allow keys other than strings or symbols for PDF dicts" do
|
153
|
+
lambda { Prawn::Core::PdfObject(:foo => :bar, :baz => :bang, 1 => 4) }.
|
154
|
+
should.raise(Prawn::Errors::FailedObjectConversion)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should convert a Prawn::Reference to a PDF indirect object reference" do
|
158
|
+
ref = Prawn::Core::Reference(1,true)
|
159
|
+
Prawn::Core::PdfObject(ref).should == ref.to_s
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should convert a NameTree::Node to a PDF hash" do
|
163
|
+
node = Prawn::Core::NameTree::Node.new(Prawn::Document.new, 10)
|
164
|
+
node.add "hello", 1.0
|
165
|
+
node.add "world", 2.0
|
166
|
+
data = Prawn::Core::PdfObject(node)
|
167
|
+
res = PDF::Inspector.parse(data)
|
168
|
+
res.should == {:Names => ["hello", 1.0, "world", 2.0]}
|
169
|
+
end
|
170
|
+
end
|