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
@@ -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_error(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,6 +163,29 @@ 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
|
+
|
166
189
|
it "should move the pointer to the center of the ellipse after drawing" do
|
167
190
|
@curve.coords[-2..-1].should == [100,100]
|
168
191
|
end
|
@@ -183,6 +206,30 @@ describe "When drawing a circle" do
|
|
183
206
|
end
|
184
207
|
end
|
185
208
|
|
209
|
+
describe "When filling" do
|
210
|
+
before(:each) { create_pdf }
|
211
|
+
|
212
|
+
it "should default to the f operator (nonzero winding number rule)" do
|
213
|
+
@pdf.expects(:add_content).with("f")
|
214
|
+
@pdf.fill
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should use f* for :fill_rule => :even_odd" do
|
218
|
+
@pdf.expects(:add_content).with("f*")
|
219
|
+
@pdf.fill(:fill_rule => :even_odd)
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should use b by default for fill_and_stroke (nonzero winding number)" do
|
223
|
+
@pdf.expects(:add_content).with("b")
|
224
|
+
@pdf.fill_and_stroke
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should use b* for fill_and_stroke(:fill_rule => :even_odd)" do
|
228
|
+
@pdf.expects(:add_content).with("b*")
|
229
|
+
@pdf.fill_and_stroke(:fill_rule => :even_odd)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
186
233
|
describe "When setting colors" do
|
187
234
|
|
188
235
|
before(:each) { create_pdf }
|
@@ -221,7 +268,7 @@ describe "When setting colors" do
|
|
221
268
|
colors.fill_color.should == [0.8,1.0,0.0]
|
222
269
|
colors.stroke_color.should == [1.0,0.0,0.8]
|
223
270
|
end
|
224
|
-
|
271
|
+
|
225
272
|
it "should set the color space when setting colors on new pages to please fussy readers" do
|
226
273
|
@pdf.stroke_color "000000"
|
227
274
|
@pdf.stroke { @pdf.rectangle([10, 10], 10, 10) }
|
@@ -233,37 +280,79 @@ describe "When setting colors" do
|
|
233
280
|
end
|
234
281
|
end
|
235
282
|
|
236
|
-
describe "
|
283
|
+
describe "Patterns" do
|
237
284
|
before(:each) { create_pdf }
|
238
285
|
|
239
|
-
|
240
|
-
|
241
|
-
@pdf.
|
286
|
+
describe 'linear gradients' do
|
287
|
+
it "should create a /Pattern resource" do
|
288
|
+
@pdf.fill_gradient [0, @pdf.bounds.height],
|
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
|
242
304
|
|
243
|
-
|
244
|
-
|
305
|
+
it "fill_gradient should set fill color to the pattern" do
|
306
|
+
@pdf.fill_gradient [0, @pdf.bounds.height],
|
307
|
+
[@pdf.bounds.width, @pdf.bounds.height], 'FF0000', '0000FF'
|
245
308
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
assert pattern[:Shading][:Function][:C1].zip([0, 0, 1]).
|
250
|
-
all?{ |x1, x2| (x1-x2).abs < 0.01 }
|
251
|
-
end
|
309
|
+
str = @pdf.render
|
310
|
+
str.should =~ %r{/Pattern\s+cs\s*/SP-?\d+\s+scn}
|
311
|
+
end
|
252
312
|
|
253
|
-
|
254
|
-
|
255
|
-
|
313
|
+
it "stroke_gradient should set stroke color to the pattern" do
|
314
|
+
@pdf.stroke_gradient [0, @pdf.bounds.height],
|
315
|
+
[@pdf.bounds.width, @pdf.bounds.height], 'FF0000', '0000FF'
|
256
316
|
|
257
|
-
|
258
|
-
|
317
|
+
str = @pdf.render
|
318
|
+
str.should =~ %r{/Pattern\s+CS\s*/SP-?\d+\s+SCN}
|
319
|
+
end
|
259
320
|
end
|
260
321
|
|
261
|
-
|
262
|
-
|
263
|
-
@pdf.
|
322
|
+
describe 'radial gradients' do
|
323
|
+
it "should create a /Pattern resource" do
|
324
|
+
@pdf.fill_gradient [0, @pdf.bounds.height], 10,
|
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'
|
344
|
+
|
345
|
+
str = @pdf.render
|
346
|
+
str.should =~ %r{/Pattern\s+cs\s*/SP-?\d+\s+scn}
|
347
|
+
end
|
348
|
+
|
349
|
+
it "stroke_gradient should set stroke color to the pattern" do
|
350
|
+
@pdf.stroke_gradient [0, @pdf.bounds.height], 10,
|
351
|
+
[@pdf.bounds.width, @pdf.bounds.height], 20, 'FF0000', '0000FF'
|
264
352
|
|
265
|
-
|
266
|
-
|
353
|
+
str = @pdf.render
|
354
|
+
str.should =~ %r{/Pattern\s+CS\s*/SP-?\d+\s+SCN}
|
355
|
+
end
|
267
356
|
end
|
268
357
|
end
|
269
358
|
|
@@ -286,86 +375,86 @@ describe "When using painting shortcuts" do
|
|
286
375
|
|
287
376
|
it "should not break method_missing" do
|
288
377
|
lambda { @pdf.i_have_a_pretty_girlfriend_named_jia }.
|
289
|
-
should
|
378
|
+
should raise_error(NoMethodError)
|
290
379
|
end
|
291
380
|
end
|
292
381
|
|
293
382
|
describe "When using graphics states" do
|
294
383
|
before(:each) { create_pdf }
|
295
|
-
|
384
|
+
|
296
385
|
it "should add the right content on save_graphics_state" do
|
297
386
|
@pdf.expects(:add_content).with('q')
|
298
|
-
|
387
|
+
|
299
388
|
@pdf.save_graphics_state
|
300
389
|
end
|
301
|
-
|
390
|
+
|
302
391
|
it "should add the right content on restore_graphics_state" do
|
303
392
|
@pdf.expects(:add_content).with('Q')
|
304
|
-
|
393
|
+
|
305
394
|
@pdf.restore_graphics_state
|
306
395
|
end
|
307
|
-
|
396
|
+
|
308
397
|
it "should save and restore when save_graphics_state is used with a block" do
|
309
398
|
state = sequence "state"
|
310
399
|
@pdf.expects(:add_content).with('q').in_sequence(state)
|
311
400
|
@pdf.expects(:foo).in_sequence(state)
|
312
401
|
@pdf.expects(:add_content).with('Q').in_sequence(state)
|
313
|
-
|
402
|
+
|
314
403
|
@pdf.save_graphics_state do
|
315
404
|
@pdf.foo
|
316
405
|
end
|
317
406
|
end
|
318
|
-
|
407
|
+
|
319
408
|
it "should add the previous color space when restoring to a graphic state with different color space" do
|
320
409
|
@pdf.stroke_color '000000'
|
321
410
|
@pdf.save_graphics_state
|
322
411
|
@pdf.stroke_color 0, 0, 0, 0
|
323
|
-
@pdf.restore_graphics_state
|
412
|
+
@pdf.restore_graphics_state
|
324
413
|
@pdf.stroke_color 0, 0, 100, 0
|
325
414
|
@pdf.graphic_state.color_space.should == {:stroke=>:DeviceCMYK}
|
326
415
|
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
327
416
|
colors.color_space.should == :DeviceCMYK
|
328
417
|
colors.stroke_color_space_count[:DeviceCMYK].should == 2
|
329
418
|
end
|
330
|
-
|
419
|
+
|
331
420
|
it "should use the correct dash setting after restoring and starting new page" do
|
332
421
|
@pdf.dash 5
|
333
422
|
@pdf.save_graphics_state
|
334
423
|
@pdf.dash 10
|
335
424
|
@pdf.graphic_state.dash[:dash].should == 10
|
336
|
-
@pdf.restore_graphics_state
|
425
|
+
@pdf.restore_graphics_state
|
337
426
|
@pdf.start_new_page
|
338
427
|
@pdf.graphic_state.dash[:dash].should == 5
|
339
428
|
end
|
340
|
-
|
429
|
+
|
341
430
|
it "the current graphic state should keep track of previous unchanged settings" do
|
342
431
|
@pdf.stroke_color '000000'
|
343
432
|
@pdf.save_graphics_state
|
344
433
|
@pdf.dash 5
|
345
434
|
@pdf.save_graphics_state
|
346
435
|
@pdf.cap_style :round
|
347
|
-
@pdf.save_graphics_state
|
436
|
+
@pdf.save_graphics_state
|
348
437
|
@pdf.fill_color 0, 0, 100, 0
|
349
438
|
@pdf.save_graphics_state
|
350
|
-
|
351
|
-
@pdf.graphic_state.stroke_color.should == "000000"
|
439
|
+
|
440
|
+
@pdf.graphic_state.stroke_color.should == "000000"
|
352
441
|
@pdf.graphic_state.join_style.should == :miter
|
353
|
-
@pdf.graphic_state.fill_color.should == [0, 0, 100, 0]
|
354
|
-
@pdf.graphic_state.cap_style.should == :round
|
355
|
-
@pdf.graphic_state.color_space.should == {:fill=>:DeviceCMYK, :stroke=>:DeviceRGB}
|
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}
|
356
445
|
@pdf.graphic_state.dash.should == {:space=>5, :phase=>0, :dash=>5}
|
357
446
|
@pdf.graphic_state.line_width.should == 1
|
358
447
|
end
|
359
|
-
|
360
|
-
|
361
|
-
|
448
|
+
|
449
|
+
|
450
|
+
|
362
451
|
it "should not add extra graphic space closings when rendering multiple times" do
|
363
452
|
@pdf.render
|
364
453
|
state = PDF::Inspector::Graphics::State.analyze(@pdf.render)
|
365
454
|
state.save_graphics_state_count.should == 1
|
366
455
|
state.restore_graphics_state_count.should == 1
|
367
456
|
end
|
368
|
-
|
457
|
+
|
369
458
|
it "should add extra graphic state enclosings when content is added on multiple renderings" do
|
370
459
|
@pdf.render
|
371
460
|
@pdf.text "Adding a bit more content"
|
@@ -373,7 +462,7 @@ describe "When using graphics states" do
|
|
373
462
|
state.save_graphics_state_count.should == 2
|
374
463
|
state.restore_graphics_state_count.should == 2
|
375
464
|
end
|
376
|
-
|
465
|
+
|
377
466
|
it "adds extra graphic state enclosings when new settings are applied on multiple renderings" do
|
378
467
|
@pdf.render
|
379
468
|
@pdf.stroke_color 0, 0, 0, 0
|
@@ -381,13 +470,13 @@ describe "When using graphics states" do
|
|
381
470
|
state.save_graphics_state_count.should == 2
|
382
471
|
state.restore_graphics_state_count.should == 2
|
383
472
|
end
|
384
|
-
|
385
|
-
|
386
|
-
it "should
|
387
|
-
|
473
|
+
|
474
|
+
|
475
|
+
it "should raise_error error if closing an empty graphic stack" do
|
476
|
+
lambda {
|
388
477
|
@pdf.render
|
389
478
|
@pdf.restore_graphics_state
|
390
|
-
|
479
|
+
}.should raise_error(PDF::Core::Errors::EmptyGraphicStateStack)
|
391
480
|
end
|
392
481
|
end
|
393
482
|
|
@@ -396,19 +485,19 @@ describe "When using transformation matrix" do
|
|
396
485
|
|
397
486
|
# Note: The (approximate) number of significant decimal digits of precision in fractional
|
398
487
|
# part is 5 (PDF Reference, Third Edition, p. 706)
|
399
|
-
|
488
|
+
|
400
489
|
it "should send the right content on transformation_matrix" do
|
401
490
|
@pdf.expects(:add_content).with('1.00000 0.00000 0.12346 -1.00000 5.50000 20.00000 cm')
|
402
491
|
@pdf.transformation_matrix 1, 0, 0.123456789, -1.0, 5.5, 20
|
403
492
|
end
|
404
|
-
|
493
|
+
|
405
494
|
it "should use fixed digits with very small number" do
|
406
495
|
values = Array.new(6, 0.000000000001)
|
407
496
|
string = Array.new(6, "0.00000").join " "
|
408
497
|
@pdf.expects(:add_content).with("#{string} cm")
|
409
498
|
@pdf.transformation_matrix *values
|
410
499
|
end
|
411
|
-
|
500
|
+
|
412
501
|
it "should be received by the inspector" do
|
413
502
|
@pdf.transformation_matrix 1, 0, 0, -1, 5.5, 20
|
414
503
|
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
@@ -419,7 +508,7 @@ describe "When using transformation matrix" do
|
|
419
508
|
values = Array.new(6, 0.000000000001)
|
420
509
|
string = Array.new(6, "0.00000").join " "
|
421
510
|
process = sequence "process"
|
422
|
-
|
511
|
+
|
423
512
|
@pdf.expects(:save_graphics_state).with().in_sequence(process)
|
424
513
|
@pdf.expects(:add_content).with("#{string} cm").in_sequence(process)
|
425
514
|
@pdf.expects(:do_something).with().in_sequence(process)
|
@@ -428,7 +517,7 @@ describe "When using transformation matrix" do
|
|
428
517
|
@pdf.do_something
|
429
518
|
end
|
430
519
|
end
|
431
|
-
|
520
|
+
|
432
521
|
end
|
433
522
|
|
434
523
|
describe "When using transformations shortcuts" do
|
@@ -485,10 +574,10 @@ describe "When using transformations shortcuts" do
|
|
485
574
|
reduce_precision(@cos), 0, 0]
|
486
575
|
end
|
487
576
|
|
488
|
-
it "should
|
577
|
+
it "should raise_error BlockRequired if no block is given" do
|
489
578
|
lambda {
|
490
579
|
@pdf.rotate(@angle, :origin => [@x, @y])
|
491
|
-
}.should
|
580
|
+
}.should raise_error(Prawn::Errors::BlockRequired)
|
492
581
|
end
|
493
582
|
|
494
583
|
def reduce_precision(float)
|
@@ -541,10 +630,10 @@ describe "When using transformations shortcuts" do
|
|
541
630
|
matrices.matrices[1].should == [@factor, 0, 0, @factor, 0, 0]
|
542
631
|
end
|
543
632
|
|
544
|
-
it "should
|
633
|
+
it "should raise_error BlockRequired if no block is given" do
|
545
634
|
lambda {
|
546
635
|
@pdf.scale(@factor, :origin => [@x, @y])
|
547
|
-
}.should
|
636
|
+
}.should raise_error(Prawn::Errors::BlockRequired)
|
548
637
|
end
|
549
638
|
|
550
639
|
def reduce_precision(float)
|