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
@@ -75,7 +75,7 @@ describe "Text::Formatted::Fragment#word_spacing=" do
|
|
75
75
|
@fragment.ascender = 17
|
76
76
|
@fragment.word_spacing = 10
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
it "should account for word_spacing in #width" do
|
80
80
|
@fragment.width.should == 110
|
81
81
|
end
|
@@ -122,7 +122,7 @@ describe "Text::Formatted::Fragment" do
|
|
122
122
|
@fragment.descender = 7
|
123
123
|
@fragment.ascender = 17
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
describe "#width" do
|
127
127
|
it "should return the width" do
|
128
128
|
@fragment.width.should == 100
|
@@ -224,13 +224,13 @@ describe "Text::Formatted::Fragment that is a subscript" do
|
|
224
224
|
@fragment.ascender = 17
|
225
225
|
end
|
226
226
|
describe "#subscript?" do
|
227
|
-
it "should
|
228
|
-
@fragment.should
|
227
|
+
it "should be true" do
|
228
|
+
@fragment.should.be.subscript
|
229
229
|
end
|
230
230
|
end
|
231
231
|
describe "#y_offset" do
|
232
232
|
it "should return a negative value" do
|
233
|
-
@fragment.y_offset.should
|
233
|
+
@fragment.y_offset.should.be < 0
|
234
234
|
end
|
235
235
|
end
|
236
236
|
end
|
@@ -252,13 +252,13 @@ describe "Text::Formatted::Fragment that is a superscript" do
|
|
252
252
|
@fragment.ascender = 17
|
253
253
|
end
|
254
254
|
describe "#superscript?" do
|
255
|
-
it "should
|
256
|
-
@fragment.should
|
255
|
+
it "should be true" do
|
256
|
+
@fragment.should.be.superscript
|
257
257
|
end
|
258
258
|
end
|
259
259
|
describe "#y_offset" do
|
260
260
|
it "should return a positive value" do
|
261
|
-
@fragment.y_offset.should
|
261
|
+
@fragment.y_offset.should.be > 0
|
262
262
|
end
|
263
263
|
end
|
264
264
|
end
|
data/spec/graphics_spec.rb
CHANGED
@@ -68,7 +68,7 @@ describe "When drawing a line" do
|
|
68
68
|
end
|
69
69
|
it "should require a y coordinate" do
|
70
70
|
lambda { @pdf.vertical_line(400,500) }.
|
71
|
-
should
|
71
|
+
should.raise(ArgumentError)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -121,7 +121,7 @@ describe "When drawing a curve" do
|
|
121
121
|
curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
122
122
|
curve.coords.should == [100.0, 100.0, 20.0, 90.0, 90.0, 75.0, 50.0, 50.0]
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
|
126
126
|
end
|
127
127
|
|
@@ -141,19 +141,19 @@ describe "When drawing a rounded rectangle" do
|
|
141
141
|
line_points.zip(curves).flatten.each_slice(2) {|p| @all_coords << p }
|
142
142
|
@all_coords.unshift @original_point
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
it "should draw a rectangle by connecting lines with rounded bezier curves" do
|
146
|
-
@all_coords.should == [[60.0, 550.0],[90.0, 550.0], [95.523, 550.0], [100.0, 545.523], [100.0, 540.0],
|
147
|
-
[100.0, 460.0], [100.0, 454.477], [95.523, 450.0], [90.0, 450.0],
|
148
|
-
[60.0, 450.0], [54.477, 450.0], [50.0, 454.477], [50.0, 460.0],
|
146
|
+
@all_coords.should == [[60.0, 550.0],[90.0, 550.0], [95.523, 550.0], [100.0, 545.523], [100.0, 540.0],
|
147
|
+
[100.0, 460.0], [100.0, 454.477], [95.523, 450.0], [90.0, 450.0],
|
148
|
+
[60.0, 450.0], [54.477, 450.0], [50.0, 454.477], [50.0, 460.0],
|
149
149
|
[50.0, 540.0], [50.0, 545.523], [54.477, 550.0], [60.0, 550.0]]
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
it "should start and end with the same point" do
|
153
153
|
@original_point.should == @all_coords.last
|
154
154
|
end
|
155
|
-
|
156
|
-
|
155
|
+
|
156
|
+
|
157
157
|
end
|
158
158
|
|
159
159
|
describe "When drawing an ellipse" do
|
@@ -163,29 +163,6 @@ describe "When drawing an ellipse" do
|
|
163
163
|
@curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
164
164
|
end
|
165
165
|
|
166
|
-
it "should use a Bézier approximation" do
|
167
|
-
@curve.coords.should ==
|
168
|
-
[125.0, 100.0,
|
169
|
-
|
170
|
-
125.0, 127.614,
|
171
|
-
113.807, 150,
|
172
|
-
100.0, 150.0,
|
173
|
-
|
174
|
-
86.193, 150.0,
|
175
|
-
75.0, 127.614,
|
176
|
-
75.0, 100.0,
|
177
|
-
|
178
|
-
75.0, 72.386,
|
179
|
-
86.193, 50.0,
|
180
|
-
100.0, 50.0,
|
181
|
-
|
182
|
-
113.807, 50.0,
|
183
|
-
125.0, 72.386,
|
184
|
-
125.0, 100.0,
|
185
|
-
|
186
|
-
100.0, 100.0]
|
187
|
-
end
|
188
|
-
|
189
166
|
it "should move the pointer to the center of the ellipse after drawing" do
|
190
167
|
@curve.coords[-2..-1].should == [100,100]
|
191
168
|
end
|
@@ -268,7 +245,7 @@ describe "When setting colors" do
|
|
268
245
|
colors.fill_color.should == [0.8,1.0,0.0]
|
269
246
|
colors.stroke_color.should == [1.0,0.0,0.8]
|
270
247
|
end
|
271
|
-
|
248
|
+
|
272
249
|
it "should set the color space when setting colors on new pages to please fussy readers" do
|
273
250
|
@pdf.stroke_color "000000"
|
274
251
|
@pdf.stroke { @pdf.rectangle([10, 10], 10, 10) }
|
@@ -280,79 +257,37 @@ describe "When setting colors" do
|
|
280
257
|
end
|
281
258
|
end
|
282
259
|
|
283
|
-
describe "
|
260
|
+
describe "Gradients" do
|
284
261
|
before(:each) { create_pdf }
|
285
262
|
|
286
|
-
|
287
|
-
|
288
|
-
@pdf.
|
289
|
-
[@pdf.bounds.width, @pdf.bounds.height], 'FF0000', '0000FF'
|
290
|
-
|
291
|
-
grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
|
292
|
-
pattern = grad.patterns.values.first
|
293
|
-
|
294
|
-
pattern.should_not be_nil
|
295
|
-
pattern[:Shading][:ShadingType].should == 2
|
296
|
-
pattern[:Shading][:Coords].should == [0, 0, @pdf.bounds.width, 0]
|
297
|
-
pattern[:Shading][:Function][:C0].zip([1, 0, 0]).all?{ |x1, x2|
|
298
|
-
(x1-x2).abs < 0.01
|
299
|
-
}.should be_true
|
300
|
-
pattern[:Shading][:Function][:C1].zip([0, 0, 1]).all?{ |x1, x2|
|
301
|
-
(x1-x2).abs < 0.01
|
302
|
-
}.should be_true
|
303
|
-
end
|
263
|
+
it "should create a /Pattern resource" do
|
264
|
+
@pdf.fill_gradient [0, @pdf.bounds.height],
|
265
|
+
@pdf.bounds.width, @pdf.bounds.height, 'FF0000', '0000FF'
|
304
266
|
|
305
|
-
|
306
|
-
|
307
|
-
[@pdf.bounds.width, @pdf.bounds.height], 'FF0000', '0000FF'
|
267
|
+
grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
|
268
|
+
pattern = grad.patterns[:SP1]
|
308
269
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
@pdf.stroke_gradient [0, @pdf.bounds.height],
|
315
|
-
[@pdf.bounds.width, @pdf.bounds.height], 'FF0000', '0000FF'
|
316
|
-
|
317
|
-
str = @pdf.render
|
318
|
-
str.should =~ %r{/Pattern\s+CS\s*/SP-?\d+\s+SCN}
|
319
|
-
end
|
270
|
+
pattern.should.not.be.nil
|
271
|
+
assert pattern[:Shading][:Function][:C0].zip([1, 0, 0]).
|
272
|
+
all?{ |x1, x2| (x1-x2).abs < 0.01 }
|
273
|
+
assert pattern[:Shading][:Function][:C1].zip([0, 0, 1]).
|
274
|
+
all?{ |x1, x2| (x1-x2).abs < 0.01 }
|
320
275
|
end
|
321
276
|
|
322
|
-
|
323
|
-
|
324
|
-
@pdf.
|
325
|
-
[@pdf.bounds.width, @pdf.bounds.height], 20, 'FF0000', '0000FF'
|
326
|
-
|
327
|
-
grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
|
328
|
-
pattern = grad.patterns.values.first
|
329
|
-
|
330
|
-
pattern.should_not be_nil
|
331
|
-
pattern[:Shading][:ShadingType].should == 3
|
332
|
-
pattern[:Shading][:Coords].should == [0, 0, 10, @pdf.bounds.width, 0, 20]
|
333
|
-
pattern[:Shading][:Function][:C0].zip([1, 0, 0]).all?{ |x1, x2|
|
334
|
-
(x1-x2).abs < 0.01
|
335
|
-
}.should be_true
|
336
|
-
pattern[:Shading][:Function][:C1].zip([0, 0, 1]).all?{ |x1, x2|
|
337
|
-
(x1-x2).abs < 0.01
|
338
|
-
}.should be_true
|
339
|
-
end
|
340
|
-
|
341
|
-
it "fill_gradient should set fill color to the pattern" do
|
342
|
-
@pdf.fill_gradient [0, @pdf.bounds.height], 10,
|
343
|
-
[@pdf.bounds.width, @pdf.bounds.height], 20, 'FF0000', '0000FF'
|
277
|
+
it "fill_gradient should set fill color to the pattern" do
|
278
|
+
@pdf.fill_gradient [0, @pdf.bounds.height],
|
279
|
+
@pdf.bounds.width, @pdf.bounds.height, 'FF0000', '0000FF'
|
344
280
|
|
345
|
-
|
346
|
-
|
347
|
-
|
281
|
+
str = @pdf.render
|
282
|
+
str.should =~ %r{/Pattern\s+cs\s*/SP1\s+scn}
|
283
|
+
end
|
348
284
|
|
349
|
-
|
350
|
-
|
351
|
-
|
285
|
+
it "stroke_gradient should set stroke color to the pattern" do
|
286
|
+
@pdf.stroke_gradient [0, @pdf.bounds.height],
|
287
|
+
@pdf.bounds.width, @pdf.bounds.height, 'FF0000', '0000FF'
|
352
288
|
|
353
|
-
|
354
|
-
|
355
|
-
end
|
289
|
+
str = @pdf.render
|
290
|
+
str.should =~ %r{/Pattern\s+CS\s*/SP1\s+SCN}
|
356
291
|
end
|
357
292
|
end
|
358
293
|
|
@@ -375,86 +310,86 @@ describe "When using painting shortcuts" do
|
|
375
310
|
|
376
311
|
it "should not break method_missing" do
|
377
312
|
lambda { @pdf.i_have_a_pretty_girlfriend_named_jia }.
|
378
|
-
should
|
313
|
+
should.raise(NoMethodError)
|
379
314
|
end
|
380
315
|
end
|
381
316
|
|
382
317
|
describe "When using graphics states" do
|
383
318
|
before(:each) { create_pdf }
|
384
|
-
|
319
|
+
|
385
320
|
it "should add the right content on save_graphics_state" do
|
386
321
|
@pdf.expects(:add_content).with('q')
|
387
|
-
|
322
|
+
|
388
323
|
@pdf.save_graphics_state
|
389
324
|
end
|
390
|
-
|
325
|
+
|
391
326
|
it "should add the right content on restore_graphics_state" do
|
392
327
|
@pdf.expects(:add_content).with('Q')
|
393
|
-
|
328
|
+
|
394
329
|
@pdf.restore_graphics_state
|
395
330
|
end
|
396
|
-
|
331
|
+
|
397
332
|
it "should save and restore when save_graphics_state is used with a block" do
|
398
333
|
state = sequence "state"
|
399
334
|
@pdf.expects(:add_content).with('q').in_sequence(state)
|
400
335
|
@pdf.expects(:foo).in_sequence(state)
|
401
336
|
@pdf.expects(:add_content).with('Q').in_sequence(state)
|
402
|
-
|
337
|
+
|
403
338
|
@pdf.save_graphics_state do
|
404
339
|
@pdf.foo
|
405
340
|
end
|
406
341
|
end
|
407
|
-
|
342
|
+
|
408
343
|
it "should add the previous color space when restoring to a graphic state with different color space" do
|
409
344
|
@pdf.stroke_color '000000'
|
410
345
|
@pdf.save_graphics_state
|
411
346
|
@pdf.stroke_color 0, 0, 0, 0
|
412
|
-
@pdf.restore_graphics_state
|
347
|
+
@pdf.restore_graphics_state
|
413
348
|
@pdf.stroke_color 0, 0, 100, 0
|
414
349
|
@pdf.graphic_state.color_space.should == {:stroke=>:DeviceCMYK}
|
415
350
|
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
416
351
|
colors.color_space.should == :DeviceCMYK
|
417
352
|
colors.stroke_color_space_count[:DeviceCMYK].should == 2
|
418
353
|
end
|
419
|
-
|
354
|
+
|
420
355
|
it "should use the correct dash setting after restoring and starting new page" do
|
421
356
|
@pdf.dash 5
|
422
357
|
@pdf.save_graphics_state
|
423
358
|
@pdf.dash 10
|
424
359
|
@pdf.graphic_state.dash[:dash].should == 10
|
425
|
-
@pdf.restore_graphics_state
|
360
|
+
@pdf.restore_graphics_state
|
426
361
|
@pdf.start_new_page
|
427
362
|
@pdf.graphic_state.dash[:dash].should == 5
|
428
363
|
end
|
429
|
-
|
364
|
+
|
430
365
|
it "the current graphic state should keep track of previous unchanged settings" do
|
431
366
|
@pdf.stroke_color '000000'
|
432
367
|
@pdf.save_graphics_state
|
433
368
|
@pdf.dash 5
|
434
369
|
@pdf.save_graphics_state
|
435
370
|
@pdf.cap_style :round
|
436
|
-
@pdf.save_graphics_state
|
371
|
+
@pdf.save_graphics_state
|
437
372
|
@pdf.fill_color 0, 0, 100, 0
|
438
373
|
@pdf.save_graphics_state
|
439
|
-
|
440
|
-
@pdf.graphic_state.stroke_color.should == "000000"
|
374
|
+
|
375
|
+
@pdf.graphic_state.stroke_color.should == "000000"
|
441
376
|
@pdf.graphic_state.join_style.should == :miter
|
442
|
-
@pdf.graphic_state.fill_color.should == [0, 0, 100, 0]
|
443
|
-
@pdf.graphic_state.cap_style.should == :round
|
444
|
-
@pdf.graphic_state.color_space.should == {:fill=>:DeviceCMYK, :stroke=>:DeviceRGB}
|
377
|
+
@pdf.graphic_state.fill_color.should == [0, 0, 100, 0]
|
378
|
+
@pdf.graphic_state.cap_style.should == :round
|
379
|
+
@pdf.graphic_state.color_space.should == {:fill=>:DeviceCMYK, :stroke=>:DeviceRGB}
|
445
380
|
@pdf.graphic_state.dash.should == {:space=>5, :phase=>0, :dash=>5}
|
446
381
|
@pdf.graphic_state.line_width.should == 1
|
447
382
|
end
|
448
|
-
|
449
|
-
|
450
|
-
|
383
|
+
|
384
|
+
|
385
|
+
|
451
386
|
it "should not add extra graphic space closings when rendering multiple times" do
|
452
387
|
@pdf.render
|
453
388
|
state = PDF::Inspector::Graphics::State.analyze(@pdf.render)
|
454
389
|
state.save_graphics_state_count.should == 1
|
455
390
|
state.restore_graphics_state_count.should == 1
|
456
391
|
end
|
457
|
-
|
392
|
+
|
458
393
|
it "should add extra graphic state enclosings when content is added on multiple renderings" do
|
459
394
|
@pdf.render
|
460
395
|
@pdf.text "Adding a bit more content"
|
@@ -462,7 +397,7 @@ describe "When using graphics states" do
|
|
462
397
|
state.save_graphics_state_count.should == 2
|
463
398
|
state.restore_graphics_state_count.should == 2
|
464
399
|
end
|
465
|
-
|
400
|
+
|
466
401
|
it "adds extra graphic state enclosings when new settings are applied on multiple renderings" do
|
467
402
|
@pdf.render
|
468
403
|
@pdf.stroke_color 0, 0, 0, 0
|
@@ -470,30 +405,12 @@ describe "When using graphics states" do
|
|
470
405
|
state.save_graphics_state_count.should == 2
|
471
406
|
state.restore_graphics_state_count.should == 2
|
472
407
|
end
|
473
|
-
|
474
|
-
|
475
|
-
it "should
|
476
|
-
|
408
|
+
|
409
|
+
|
410
|
+
it "should raise error if closing an empty graphic stack" do
|
411
|
+
assert_raise Prawn::Errors::EmptyGraphicStateStack do
|
477
412
|
@pdf.render
|
478
413
|
@pdf.restore_graphics_state
|
479
|
-
}.should raise_error(PDF::Core::Errors::EmptyGraphicStateStack)
|
480
|
-
end
|
481
|
-
|
482
|
-
it "should copy mutable attributes when passing a previous_state to the initializer" do
|
483
|
-
new_state = PDF::Core::GraphicState.new(@pdf.graphic_state)
|
484
|
-
|
485
|
-
[:color_space, :dash, :fill_color, :stroke_color].each do |attr|
|
486
|
-
new_state.send(attr).should == @pdf.graphic_state.send(attr)
|
487
|
-
new_state.send(attr).should_not equal(@pdf.graphic_state.send(attr))
|
488
|
-
end
|
489
|
-
end
|
490
|
-
|
491
|
-
it "should copy mutable attributes when duping" do
|
492
|
-
new_state = @pdf.graphic_state.dup
|
493
|
-
|
494
|
-
[:color_space, :dash, :fill_color, :stroke_color].each do |attr|
|
495
|
-
new_state.send(attr).should == @pdf.graphic_state.send(attr)
|
496
|
-
new_state.send(attr).should_not equal(@pdf.graphic_state.send(attr))
|
497
414
|
end
|
498
415
|
end
|
499
416
|
end
|
@@ -503,19 +420,19 @@ describe "When using transformation matrix" do
|
|
503
420
|
|
504
421
|
# Note: The (approximate) number of significant decimal digits of precision in fractional
|
505
422
|
# part is 5 (PDF Reference, Third Edition, p. 706)
|
506
|
-
|
423
|
+
|
507
424
|
it "should send the right content on transformation_matrix" do
|
508
425
|
@pdf.expects(:add_content).with('1.00000 0.00000 0.12346 -1.00000 5.50000 20.00000 cm')
|
509
426
|
@pdf.transformation_matrix 1, 0, 0.123456789, -1.0, 5.5, 20
|
510
427
|
end
|
511
|
-
|
428
|
+
|
512
429
|
it "should use fixed digits with very small number" do
|
513
430
|
values = Array.new(6, 0.000000000001)
|
514
431
|
string = Array.new(6, "0.00000").join " "
|
515
432
|
@pdf.expects(:add_content).with("#{string} cm")
|
516
433
|
@pdf.transformation_matrix *values
|
517
434
|
end
|
518
|
-
|
435
|
+
|
519
436
|
it "should be received by the inspector" do
|
520
437
|
@pdf.transformation_matrix 1, 0, 0, -1, 5.5, 20
|
521
438
|
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
@@ -526,7 +443,7 @@ describe "When using transformation matrix" do
|
|
526
443
|
values = Array.new(6, 0.000000000001)
|
527
444
|
string = Array.new(6, "0.00000").join " "
|
528
445
|
process = sequence "process"
|
529
|
-
|
446
|
+
|
530
447
|
@pdf.expects(:save_graphics_state).with().in_sequence(process)
|
531
448
|
@pdf.expects(:add_content).with("#{string} cm").in_sequence(process)
|
532
449
|
@pdf.expects(:do_something).with().in_sequence(process)
|
@@ -535,7 +452,7 @@ describe "When using transformation matrix" do
|
|
535
452
|
@pdf.do_something
|
536
453
|
end
|
537
454
|
end
|
538
|
-
|
455
|
+
|
539
456
|
end
|
540
457
|
|
541
458
|
describe "When using transformations shortcuts" do
|
@@ -592,10 +509,10 @@ describe "When using transformations shortcuts" do
|
|
592
509
|
reduce_precision(@cos), 0, 0]
|
593
510
|
end
|
594
511
|
|
595
|
-
it "should
|
512
|
+
it "should raise BlockRequired if no block is given" do
|
596
513
|
lambda {
|
597
514
|
@pdf.rotate(@angle, :origin => [@x, @y])
|
598
|
-
}.should
|
515
|
+
}.should.raise(Prawn::Errors::BlockRequired)
|
599
516
|
end
|
600
517
|
|
601
518
|
def reduce_precision(float)
|
@@ -648,10 +565,10 @@ describe "When using transformations shortcuts" do
|
|
648
565
|
matrices.matrices[1].should == [@factor, 0, 0, @factor, 0, 0]
|
649
566
|
end
|
650
567
|
|
651
|
-
it "should
|
568
|
+
it "should raise BlockRequired if no block is given" do
|
652
569
|
lambda {
|
653
570
|
@pdf.scale(@factor, :origin => [@x, @y])
|
654
|
-
}.should
|
571
|
+
}.should.raise(Prawn::Errors::BlockRequired)
|
655
572
|
end
|
656
573
|
|
657
574
|
def reduce_precision(float)
|
data/spec/grid_spec.rb
CHANGED
@@ -1,57 +1,46 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
3
3
|
|
4
4
|
describe "A document's grid" do
|
5
5
|
before do
|
6
6
|
@pdf = Prawn::Document.new
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
it "should allow definition of a grid" do
|
10
10
|
@pdf.define_grid(:columns => 5, :rows => 8, :gutter => 0.1)
|
11
11
|
@pdf.grid.columns.should == 5
|
12
12
|
@pdf.grid.rows.should == 8
|
13
13
|
@pdf.grid.gutter.should == 0.1
|
14
14
|
end
|
15
|
-
|
16
|
-
it "should allow re-definition of a grid" do
|
17
|
-
@pdf.define_grid(:columns => 5, :rows => 8, :gutter => 0.1)
|
18
|
-
@pdf.grid.columns.should == 5
|
19
|
-
@pdf.grid.rows.should == 8
|
20
|
-
@pdf.grid.gutter.should == 0.1
|
21
|
-
@pdf.define_grid(:columns => 3, :rows => 6, :gutter => 0.1)
|
22
|
-
@pdf.grid.columns.should == 3
|
23
|
-
@pdf.grid.rows.should == 6
|
24
|
-
@pdf.grid.gutter.should == 0.1
|
25
|
-
end
|
26
|
-
|
15
|
+
|
27
16
|
describe "when a grid is defined" do
|
28
17
|
before do
|
29
18
|
@num_columns = 5
|
30
19
|
@num_rows = 8
|
31
20
|
@gutter = 10.0
|
32
21
|
@pdf.define_grid(
|
33
|
-
:columns => @num_columns,
|
34
|
-
:rows => @num_rows,
|
22
|
+
:columns => @num_columns,
|
23
|
+
:rows => @num_rows,
|
35
24
|
:gutter => @gutter
|
36
25
|
)
|
37
26
|
end
|
38
|
-
|
27
|
+
|
39
28
|
it "should compute the column width" do
|
40
|
-
(@pdf.grid.column_width * @num_columns.to_f +
|
29
|
+
(@pdf.grid.column_width * @num_columns.to_f +
|
41
30
|
@gutter * (@num_columns - 1).to_f).should == @pdf.bounds.width
|
42
31
|
end
|
43
|
-
|
32
|
+
|
44
33
|
it "should compute the row height" do
|
45
|
-
(@pdf.grid.row_height * @num_rows.to_f +
|
34
|
+
(@pdf.grid.row_height * @num_rows.to_f +
|
46
35
|
@gutter * (@num_rows - 1).to_f).should == @pdf.bounds.height
|
47
36
|
end
|
48
37
|
|
49
38
|
it "should give the edges of a grid box" do
|
50
|
-
grid_width = (@pdf.bounds.width.to_f -
|
39
|
+
grid_width = (@pdf.bounds.width.to_f -
|
51
40
|
(@gutter * (@num_columns - 1).to_f )) / @num_columns.to_f
|
52
|
-
grid_height = (@pdf.bounds.height.to_f -
|
41
|
+
grid_height = (@pdf.bounds.height.to_f -
|
53
42
|
(@gutter * (@num_rows - 1).to_f ))/ @num_rows.to_f
|
54
|
-
|
43
|
+
|
55
44
|
exp_tl_x = (grid_width + @gutter.to_f) * 4.0
|
56
45
|
exp_tl_y = @pdf.bounds.height.to_f - (grid_height + @gutter.to_f)
|
57
46
|
|
@@ -73,9 +62,9 @@ describe "A document's grid" do
|
|
73
62
|
@pdf.grid.show_all('cccccc')
|
74
63
|
|
75
64
|
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
76
|
-
colors.fill_color.
|
77
|
-
colors.stroke_color.
|
78
|
-
|
65
|
+
colors.fill_color.should.not == [0.8,0.8,0.8]
|
66
|
+
colors.stroke_color.should.not == [0.8,0.8,0.8]
|
67
|
+
|
79
68
|
# Hardcoded default color as I haven't been able to come up with a stable converter
|
80
69
|
# between fill_color without lots code.
|
81
70
|
#colors.fill_color.should == [0.0,0.0,0.0]
|