prawn 0.11.1 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +10 -0
- data/COPYING +2 -2
- data/GPLv2 +340 -0
- data/GPLv3 +674 -0
- data/Gemfile +11 -0
- data/LICENSE +1 -1
- data/Rakefile +29 -38
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.color +0 -0
- data/data/images/dice.alpha +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.alpha +0 -0
- data/data/images/page_white_text.color +0 -0
- data/data/pdfs/nested_pages.pdf +13 -13
- data/lib/prawn/document/bounding_box.rb +87 -12
- data/lib/prawn/document/column_box.rb +57 -28
- data/lib/prawn/document/graphics_state.rb +11 -74
- data/lib/prawn/document/internals.rb +25 -23
- data/lib/prawn/document/snapshot.rb +11 -8
- data/lib/prawn/document/span.rb +12 -10
- data/lib/prawn/document.rb +250 -194
- data/lib/prawn/encoding.rb +9 -10
- data/lib/prawn/errors.rb +18 -29
- data/lib/prawn/font/afm.rb +52 -41
- data/lib/prawn/font/dfont.rb +4 -3
- data/lib/prawn/font/ttf.rb +44 -48
- data/lib/prawn/font.rb +138 -88
- data/lib/prawn/font_metric_cache.rb +47 -0
- data/lib/prawn/graphics/cap_style.rb +4 -3
- data/lib/prawn/graphics/color.rb +13 -5
- data/lib/prawn/graphics/dash.rb +53 -31
- data/lib/prawn/graphics/join_style.rb +9 -7
- data/lib/prawn/graphics/patterns.rb +138 -0
- data/lib/prawn/graphics/transformation.rb +10 -9
- data/lib/prawn/graphics/transparency.rb +3 -1
- data/lib/prawn/graphics.rb +316 -61
- data/lib/prawn/image_handler.rb +36 -0
- data/lib/prawn/images/image.rb +49 -0
- data/lib/prawn/images/jpg.rb +21 -15
- data/lib/prawn/images/png.rb +62 -119
- data/lib/prawn/images.rb +89 -108
- data/lib/prawn/layout/grid.rb +66 -54
- data/lib/prawn/layout.rb +10 -15
- data/lib/prawn/measurement_extensions.rb +10 -6
- data/lib/prawn/measurements.rb +27 -21
- data/lib/prawn/outline.rb +6 -308
- data/lib/prawn/repeater.rb +11 -9
- data/lib/prawn/security/arcfour.rb +1 -0
- data/lib/prawn/security.rb +55 -33
- data/lib/prawn/soft_mask.rb +96 -0
- data/lib/prawn/stamp.rb +5 -3
- data/lib/prawn/table/cell/image.rb +69 -0
- data/lib/prawn/table/cell/in_table.rb +4 -2
- data/lib/prawn/table/cell/span_dummy.rb +93 -0
- data/lib/prawn/table/cell/subtable.rb +2 -2
- data/lib/prawn/table/cell/text.rb +44 -26
- data/lib/prawn/table/cell.rb +302 -50
- data/lib/prawn/table/cells.rb +147 -49
- data/lib/prawn/table/column_width_calculator.rb +61 -0
- data/lib/prawn/table.rb +297 -118
- data/lib/prawn/text/box.rb +21 -5
- data/lib/prawn/text/formatted/arranger.rb +290 -0
- data/lib/prawn/text/formatted/box.rb +103 -59
- data/lib/prawn/text/formatted/fragment.rb +34 -23
- data/lib/prawn/text/formatted/line_wrap.rb +266 -0
- data/lib/prawn/text/formatted/parser.rb +15 -5
- data/lib/prawn/text/formatted/wrap.rb +150 -0
- data/lib/prawn/text/formatted.rb +5 -4
- data/lib/prawn/text.rb +38 -24
- data/lib/prawn/utilities.rb +46 -0
- data/lib/prawn.rb +85 -20
- 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 +32 -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/document_and_page_options/print_scaling.rb +20 -0
- data/manual/example_file.rb +111 -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 +30 -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 +36 -0
- data/manual/manual/foreword.rb +85 -0
- data/manual/manual/how_to_read_this_manual.rb +41 -0
- data/manual/manual/manual.rb +34 -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/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 +31 -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 +27 -17
- data/spec/acceptance/png.rb +23 -0
- data/spec/annotations_spec.rb +16 -32
- data/spec/bounding_box_spec.rb +284 -2
- data/spec/cell_spec.rb +169 -38
- data/spec/column_box_spec.rb +65 -0
- data/spec/data/curves.pdf +66 -0
- data/spec/destinations_spec.rb +5 -5
- data/spec/document_spec.rb +212 -113
- data/spec/extensions/encoding_helpers.rb +9 -0
- data/spec/extensions/mocha.rb +2 -3
- data/spec/font_metric_cache_spec.rb +52 -0
- data/spec/font_spec.rb +205 -95
- data/spec/formatted_text_arranger_spec.rb +43 -43
- data/spec/formatted_text_box_spec.rb +63 -24
- data/spec/formatted_text_fragment_spec.rb +8 -8
- data/spec/graphics_spec.rb +175 -68
- data/spec/grid_spec.rb +26 -15
- data/spec/image_handler_spec.rb +54 -0
- data/spec/images_spec.rb +58 -30
- data/spec/inline_formatted_text_parser_spec.rb +73 -19
- 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/object_store_spec.rb +17 -106
- data/spec/outline_spec.rb +103 -63
- data/spec/png_spec.rb +25 -25
- data/spec/reference_spec.rb +8 -65
- data/spec/repeater_spec.rb +25 -11
- data/spec/security_spec.rb +44 -12
- data/spec/snapshot_spec.rb +38 -6
- data/spec/soft_mask_spec.rb +117 -0
- data/spec/span_spec.rb +10 -15
- data/spec/spec_helper.rb +32 -8
- data/spec/stamp_spec.rb +29 -30
- data/spec/stroke_styles_spec.rb +36 -18
- data/spec/table/span_dummy_spec.rb +17 -0
- data/spec/table_spec.rb +850 -104
- data/spec/text_at_spec.rb +19 -33
- data/spec/text_box_spec.rb +117 -64
- data/spec/text_rendering_mode_spec.rb +5 -5
- data/spec/text_spacing_spec.rb +20 -2
- data/spec/text_spec.rb +111 -59
- data/spec/transparency_spec.rb +5 -5
- metadata +477 -328
- data/HACKING +0 -50
- data/README +0 -141
- 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.dat +0 -0
- data/data/images/dice.dat +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/examples/bounding_box/bounding_boxes.rb +0 -44
- data/examples/bounding_box/indentation.rb +0 -35
- data/examples/bounding_box/russian_boxes.rb +0 -37
- data/examples/bounding_box/stretched_nesting.rb +0 -68
- data/examples/example_helper.rb +0 -8
- data/examples/general/background.rb +0 -24
- data/examples/general/canvas.rb +0 -16
- data/examples/general/context_sensitive_headers.rb +0 -38
- data/examples/general/float.rb +0 -12
- data/examples/general/margin.rb +0 -37
- data/examples/general/measurement_units.rb +0 -52
- data/examples/general/metadata-info.rb +0 -17
- data/examples/general/multi_page_layout.rb +0 -19
- data/examples/general/outlines.rb +0 -67
- data/examples/general/page_geometry.rb +0 -32
- data/examples/general/page_numbering.rb +0 -40
- data/examples/general/page_templates.rb +0 -20
- data/examples/general/repeaters.rb +0 -48
- data/examples/general/stamp.rb +0 -42
- data/examples/general/templates.rb +0 -14
- data/examples/graphics/basic_images.rb +0 -24
- data/examples/graphics/cmyk.rb +0 -13
- data/examples/graphics/curves.rb +0 -12
- data/examples/graphics/gradient.rb +0 -23
- data/examples/graphics/hexagon.rb +0 -14
- data/examples/graphics/image_fit.rb +0 -16
- data/examples/graphics/image_flow.rb +0 -38
- data/examples/graphics/image_position.rb +0 -18
- data/examples/graphics/line.rb +0 -33
- data/examples/graphics/png_types.rb +0 -23
- data/examples/graphics/polygons.rb +0 -17
- data/examples/graphics/remote_images.rb +0 -13
- data/examples/graphics/rounded_polygons.rb +0 -20
- data/examples/graphics/rounded_rectangle.rb +0 -21
- data/examples/graphics/ruport_style_helpers.rb +0 -20
- data/examples/graphics/stroke_bounds.rb +0 -21
- data/examples/graphics/stroke_cap_and_join.rb +0 -46
- data/examples/graphics/stroke_dash.rb +0 -43
- data/examples/graphics/transformations.rb +0 -53
- data/examples/graphics/transparency.rb +0 -27
- data/examples/grid/bounding_boxes.rb +0 -22
- data/examples/grid/column_gutter_grid.rb +0 -21
- data/examples/grid/multi_boxes.rb +0 -52
- data/examples/grid/show_grid.rb +0 -14
- data/examples/grid/simple_grid.rb +0 -21
- data/examples/m17n/chinese_text_wrapping.rb +0 -18
- data/examples/m17n/euro.rb +0 -16
- data/examples/m17n/full_win_ansi_character_list.rb +0 -20
- data/examples/m17n/sjis.rb +0 -29
- data/examples/m17n/utf8.rb +0 -14
- data/examples/security/hello_foo.rb +0 -9
- data/examples/table/bill.rb +0 -54
- data/examples/table/borders.rb +0 -25
- data/examples/table/cell.rb +0 -13
- data/examples/table/checkerboard.rb +0 -23
- data/examples/table/header.rb +0 -15
- data/examples/table/inline_format_table.rb +0 -13
- data/examples/table/multi_page_table.rb +0 -10
- data/examples/table/simple_table.rb +0 -25
- data/examples/table/subtable.rb +0 -13
- data/examples/table/widths.rb +0 -21
- data/examples/text/alignment.rb +0 -19
- data/examples/text/character_spacing.rb +0 -13
- data/examples/text/dfont.rb +0 -49
- data/examples/text/family_based_styling.rb +0 -25
- data/examples/text/font_calculations.rb +0 -92
- data/examples/text/font_size.rb +0 -34
- data/examples/text/hyphenation.rb +0 -45
- data/examples/text/indent_paragraphs.rb +0 -24
- data/examples/text/inline_format.rb +0 -104
- data/examples/text/kerning.rb +0 -31
- data/examples/text/rendering_mode.rb +0 -21
- data/examples/text/rotated.rb +0 -99
- data/examples/text/shaped_text_box.rb +0 -32
- data/examples/text/simple_text.rb +0 -18
- data/examples/text/simple_text_ttf.rb +0 -18
- data/examples/text/span.rb +0 -30
- data/examples/text/text_box.rb +0 -90
- data/examples/text/text_box_returning_excess.rb +0 -52
- data/examples/text/text_flow.rb +0 -68
- data/lib/prawn/compatibility.rb +0 -51
- data/lib/prawn/core/annotations.rb +0 -61
- data/lib/prawn/core/byte_string.rb +0 -9
- data/lib/prawn/core/destinations.rb +0 -90
- data/lib/prawn/core/document_state.rb +0 -78
- data/lib/prawn/core/literal_string.rb +0 -16
- data/lib/prawn/core/name_tree.rb +0 -165
- data/lib/prawn/core/object_store.rb +0 -264
- data/lib/prawn/core/page.rb +0 -213
- data/lib/prawn/core/pdf_object.rb +0 -108
- data/lib/prawn/core/reference.rb +0 -112
- data/lib/prawn/core/text/formatted/arranger.rb +0 -293
- data/lib/prawn/core/text/formatted/line_wrap.rb +0 -272
- data/lib/prawn/core/text/formatted/wrap.rb +0 -149
- data/lib/prawn/core/text.rb +0 -268
- data/lib/prawn/core.rb +0 -85
- data/lib/prawn/document/page_geometry.rb +0 -136
- data/lib/prawn/graphics/gradient.rb +0 -84
- data/spec/name_tree_spec.rb +0 -112
- data/spec/pdf_object_spec.rb +0 -170
- data/spec/template_spec.rb +0 -291
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,12 +470,30 @@ 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
|
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))
|
390
497
|
end
|
391
498
|
end
|
392
499
|
end
|
@@ -396,19 +503,19 @@ describe "When using transformation matrix" do
|
|
396
503
|
|
397
504
|
# Note: The (approximate) number of significant decimal digits of precision in fractional
|
398
505
|
# part is 5 (PDF Reference, Third Edition, p. 706)
|
399
|
-
|
506
|
+
|
400
507
|
it "should send the right content on transformation_matrix" do
|
401
508
|
@pdf.expects(:add_content).with('1.00000 0.00000 0.12346 -1.00000 5.50000 20.00000 cm')
|
402
509
|
@pdf.transformation_matrix 1, 0, 0.123456789, -1.0, 5.5, 20
|
403
510
|
end
|
404
|
-
|
511
|
+
|
405
512
|
it "should use fixed digits with very small number" do
|
406
513
|
values = Array.new(6, 0.000000000001)
|
407
514
|
string = Array.new(6, "0.00000").join " "
|
408
515
|
@pdf.expects(:add_content).with("#{string} cm")
|
409
516
|
@pdf.transformation_matrix *values
|
410
517
|
end
|
411
|
-
|
518
|
+
|
412
519
|
it "should be received by the inspector" do
|
413
520
|
@pdf.transformation_matrix 1, 0, 0, -1, 5.5, 20
|
414
521
|
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
@@ -419,7 +526,7 @@ describe "When using transformation matrix" do
|
|
419
526
|
values = Array.new(6, 0.000000000001)
|
420
527
|
string = Array.new(6, "0.00000").join " "
|
421
528
|
process = sequence "process"
|
422
|
-
|
529
|
+
|
423
530
|
@pdf.expects(:save_graphics_state).with().in_sequence(process)
|
424
531
|
@pdf.expects(:add_content).with("#{string} cm").in_sequence(process)
|
425
532
|
@pdf.expects(:do_something).with().in_sequence(process)
|
@@ -428,7 +535,7 @@ describe "When using transformation matrix" do
|
|
428
535
|
@pdf.do_something
|
429
536
|
end
|
430
537
|
end
|
431
|
-
|
538
|
+
|
432
539
|
end
|
433
540
|
|
434
541
|
describe "When using transformations shortcuts" do
|
@@ -485,10 +592,10 @@ describe "When using transformations shortcuts" do
|
|
485
592
|
reduce_precision(@cos), 0, 0]
|
486
593
|
end
|
487
594
|
|
488
|
-
it "should
|
595
|
+
it "should raise_error BlockRequired if no block is given" do
|
489
596
|
lambda {
|
490
597
|
@pdf.rotate(@angle, :origin => [@x, @y])
|
491
|
-
}.should
|
598
|
+
}.should raise_error(Prawn::Errors::BlockRequired)
|
492
599
|
end
|
493
600
|
|
494
601
|
def reduce_precision(float)
|
@@ -541,10 +648,10 @@ describe "When using transformations shortcuts" do
|
|
541
648
|
matrices.matrices[1].should == [@factor, 0, 0, @factor, 0, 0]
|
542
649
|
end
|
543
650
|
|
544
|
-
it "should
|
651
|
+
it "should raise_error BlockRequired if no block is given" do
|
545
652
|
lambda {
|
546
653
|
@pdf.scale(@factor, :origin => [@x, @y])
|
547
|
-
}.should
|
654
|
+
}.should raise_error(Prawn::Errors::BlockRequired)
|
548
655
|
end
|
549
656
|
|
550
657
|
def reduce_precision(float)
|
data/spec/grid_spec.rb
CHANGED
@@ -1,46 +1,57 @@
|
|
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
|
-
|
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
|
+
|
16
27
|
describe "when a grid is defined" do
|
17
28
|
before do
|
18
29
|
@num_columns = 5
|
19
30
|
@num_rows = 8
|
20
31
|
@gutter = 10.0
|
21
32
|
@pdf.define_grid(
|
22
|
-
:columns => @num_columns,
|
23
|
-
:rows => @num_rows,
|
33
|
+
:columns => @num_columns,
|
34
|
+
:rows => @num_rows,
|
24
35
|
:gutter => @gutter
|
25
36
|
)
|
26
37
|
end
|
27
|
-
|
38
|
+
|
28
39
|
it "should compute the column width" do
|
29
|
-
(@pdf.grid.column_width * @num_columns.to_f +
|
40
|
+
(@pdf.grid.column_width * @num_columns.to_f +
|
30
41
|
@gutter * (@num_columns - 1).to_f).should == @pdf.bounds.width
|
31
42
|
end
|
32
|
-
|
43
|
+
|
33
44
|
it "should compute the row height" do
|
34
|
-
(@pdf.grid.row_height * @num_rows.to_f +
|
45
|
+
(@pdf.grid.row_height * @num_rows.to_f +
|
35
46
|
@gutter * (@num_rows - 1).to_f).should == @pdf.bounds.height
|
36
47
|
end
|
37
48
|
|
38
49
|
it "should give the edges of a grid box" do
|
39
|
-
grid_width = (@pdf.bounds.width.to_f -
|
50
|
+
grid_width = (@pdf.bounds.width.to_f -
|
40
51
|
(@gutter * (@num_columns - 1).to_f )) / @num_columns.to_f
|
41
|
-
grid_height = (@pdf.bounds.height.to_f -
|
52
|
+
grid_height = (@pdf.bounds.height.to_f -
|
42
53
|
(@gutter * (@num_rows - 1).to_f ))/ @num_rows.to_f
|
43
|
-
|
54
|
+
|
44
55
|
exp_tl_x = (grid_width + @gutter.to_f) * 4.0
|
45
56
|
exp_tl_y = @pdf.bounds.height.to_f - (grid_height + @gutter.to_f)
|
46
57
|
|
@@ -62,9 +73,9 @@ describe "A document's grid" do
|
|
62
73
|
@pdf.grid.show_all('cccccc')
|
63
74
|
|
64
75
|
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
65
|
-
colors.fill_color.
|
66
|
-
colors.stroke_color.
|
67
|
-
|
76
|
+
colors.fill_color.should_not == [0.8,0.8,0.8]
|
77
|
+
colors.stroke_color.should_not == [0.8,0.8,0.8]
|
78
|
+
|
68
79
|
# Hardcoded default color as I haven't been able to come up with a stable converter
|
69
80
|
# between fill_color without lots code.
|
70
81
|
#colors.fill_color.should == [0.0,0.0,0.0]
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
describe "ImageHandler" do
|
6
|
+
let(:image_handler) { Prawn::ImageHandler.new }
|
7
|
+
|
8
|
+
let(:handler_a) { mock("Handler A") }
|
9
|
+
let(:handler_b) { mock("Handler B") }
|
10
|
+
|
11
|
+
it "finds the image handler for an image" do
|
12
|
+
handler_a.expects(:can_render? => true)
|
13
|
+
|
14
|
+
image_handler.register(handler_a)
|
15
|
+
image_handler.register(handler_b)
|
16
|
+
|
17
|
+
handler = image_handler.find("arbitrary blob")
|
18
|
+
handler.should == handler_a
|
19
|
+
end
|
20
|
+
|
21
|
+
it "can prepend handlers" do
|
22
|
+
handler_b.expects(:can_render? => true)
|
23
|
+
|
24
|
+
image_handler.register(handler_a)
|
25
|
+
image_handler.register!(handler_b)
|
26
|
+
|
27
|
+
handler = image_handler.find("arbitrary blob")
|
28
|
+
handler.should == handler_b
|
29
|
+
end
|
30
|
+
|
31
|
+
it "can unregister a handler" do
|
32
|
+
handler_b.expects(:can_render? => true)
|
33
|
+
|
34
|
+
image_handler.register(handler_a)
|
35
|
+
image_handler.register(handler_b)
|
36
|
+
|
37
|
+
image_handler.unregister(handler_a)
|
38
|
+
|
39
|
+
handler = image_handler.find('arbitrary blob')
|
40
|
+
handler.should == handler_b
|
41
|
+
end
|
42
|
+
|
43
|
+
it "raises an error when no matching handler is found" do
|
44
|
+
handler_a.expects(:can_render? => false)
|
45
|
+
handler_b.expects(:can_render? => false)
|
46
|
+
|
47
|
+
image_handler.register(handler_a)
|
48
|
+
image_handler.register(handler_b)
|
49
|
+
|
50
|
+
expect { image_handler.find("arbitrary blob") }.
|
51
|
+
to(raise_error(Prawn::Errors::UnsupportedImageType))
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|