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