prawn 1.0.0.rc1 → 1.0.0.rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +18 -0
- data/README.md +5 -3
- data/Rakefile +8 -14
- data/data/pdfs/nested_pages.pdf +13 -13
- data/lib/prawn.rb +3 -1
- data/lib/prawn/compatibility.rb +46 -10
- data/lib/prawn/core.rb +3 -1
- data/lib/prawn/core/document_state.rb +2 -1
- data/lib/prawn/core/object_store.rb +61 -5
- data/lib/prawn/core/page.rb +3 -6
- data/lib/prawn/core/pdf_object.rb +21 -4
- data/lib/prawn/core/reference.rb +6 -2
- data/lib/prawn/core/text.rb +4 -4
- data/lib/prawn/core/text/formatted/line_wrap.rb +23 -8
- data/lib/prawn/document.rb +21 -15
- data/lib/prawn/document/bounding_box.rb +3 -3
- data/lib/prawn/document/column_box.rb +22 -4
- data/lib/prawn/document/snapshot.rb +1 -1
- data/lib/prawn/encoding.rb +1 -1
- data/lib/prawn/errors.rb +4 -0
- data/lib/prawn/font.rb +1 -1
- data/lib/prawn/font/afm.rb +30 -72
- data/lib/prawn/font/ttf.rb +6 -33
- data/lib/prawn/graphics.rb +148 -23
- data/lib/prawn/graphics/color.rb +8 -1
- data/lib/prawn/graphics/patterns.rb +137 -0
- data/lib/prawn/images.rb +25 -19
- data/lib/prawn/images/jpg.rb +4 -4
- data/lib/prawn/images/png.rb +18 -12
- data/lib/prawn/security.rb +6 -4
- data/lib/prawn/soft_mask.rb +94 -0
- data/lib/prawn/table.rb +136 -31
- data/lib/prawn/table/cell.rb +260 -29
- data/lib/prawn/table/cell/span_dummy.rb +88 -0
- data/lib/prawn/table/cell/text.rb +36 -14
- data/lib/prawn/table/cells.rb +91 -41
- data/lib/prawn/text.rb +3 -2
- data/lib/prawn/text/formatted/box.rb +14 -5
- data/lib/prawn/text/formatted/fragment.rb +33 -22
- data/lib/prawn/text/formatted/parser.rb +5 -2
- 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 +430 -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 +17 -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 +43 -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 +26 -0
- data/manual/manual/foreword.rb +13 -0
- data/manual/manual/how_to_read_this_manual.rb +41 -0
- data/manual/manual/manual.rb +36 -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 +23 -0
- data/manual/templates/page_template.rb +47 -0
- data/manual/templates/templates.rb +26 -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 +50 -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/manual/text/win_ansi_charset.rb +59 -0
- data/prawn.gemspec +10 -7
- data/spec/bounding_box_spec.rb +107 -17
- data/spec/cell_spec.rb +66 -40
- data/spec/column_box_spec.rb +33 -0
- data/spec/document_spec.rb +45 -24
- data/spec/extensions/encoding_helpers.rb +6 -0
- data/spec/extensions/mocha.rb +1 -0
- data/spec/font_spec.rb +71 -53
- data/spec/formatted_text_arranger_spec.rb +19 -19
- data/spec/formatted_text_box_spec.rb +16 -16
- data/spec/formatted_text_fragment_spec.rb +6 -6
- data/spec/graphics_spec.rb +96 -31
- data/spec/grid_spec.rb +2 -2
- data/spec/images_spec.rb +18 -10
- data/spec/jpg_spec.rb +1 -1
- data/spec/line_wrap_spec.rb +14 -14
- data/spec/measurement_units_spec.rb +2 -2
- data/spec/name_tree_spec.rb +6 -6
- data/spec/object_store_spec.rb +17 -17
- data/spec/outline_spec.rb +35 -17
- data/spec/pdf_object_spec.rb +3 -1
- data/spec/png_spec.rb +22 -19
- data/spec/reference_spec.rb +24 -1
- data/spec/repeater_spec.rb +9 -9
- data/spec/security_spec.rb +3 -3
- data/spec/snapshot_spec.rb +3 -3
- data/spec/soft_mask_spec.rb +117 -0
- data/spec/span_spec.rb +4 -4
- data/spec/spec_helper.rb +12 -6
- data/spec/stamp_spec.rb +12 -12
- data/spec/stroke_styles_spec.rb +5 -5
- data/spec/table_spec.rb +458 -88
- data/spec/template_spec.rb +108 -54
- data/spec/text_at_spec.rb +17 -17
- data/spec/text_box_spec.rb +76 -45
- data/spec/text_rendering_mode_spec.rb +5 -5
- data/spec/text_spacing_spec.rb +4 -4
- data/spec/text_spec.rb +44 -40
- metadata +419 -250
- data/lib/prawn/graphics/gradient.rb +0 -84
- data/lib/prawn/security/arcfour.rb +0 -51
data/spec/cell_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
4
|
|
5
5
|
module CellHelpers
|
6
6
|
|
@@ -10,10 +10,6 @@ module CellHelpers
|
|
10
10
|
Prawn::Table::Cell::Text.new(@pdf, at, options)
|
11
11
|
end
|
12
12
|
|
13
|
-
def close?(actual, expected, epsilon=0.01)
|
14
|
-
(actual - expected).abs < epsilon
|
15
|
-
end
|
16
|
-
|
17
13
|
end
|
18
14
|
|
19
15
|
describe "Prawn::Table::Cell" do
|
@@ -30,13 +26,18 @@ describe "Prawn::Table::Cell" do
|
|
30
26
|
end
|
31
27
|
|
32
28
|
it "should return a Cell" do
|
33
|
-
@pdf.cell(:content => "text").should
|
29
|
+
@pdf.cell(:content => "text").should be_a_kind_of Prawn::Table::Cell
|
30
|
+
end
|
31
|
+
|
32
|
+
it "accepts :content => nil in a hash" do
|
33
|
+
@pdf.cell(:content => nil).should be_a_kind_of(Prawn::Table::Cell::Text)
|
34
|
+
@pdf.make_cell(:content => nil).should be_a_kind_of(Prawn::Table::Cell::Text)
|
34
35
|
end
|
35
36
|
|
36
37
|
it "should convert nil, Numeric, and Date values to strings" do
|
37
38
|
[nil, 123, 123.45, Date.today].each do |value|
|
38
39
|
c = @pdf.cell(:content => value)
|
39
|
-
c.should
|
40
|
+
c.should be_a_kind_of Prawn::Table::Cell::Text
|
40
41
|
c.content.should == value.to_s
|
41
42
|
end
|
42
43
|
end
|
@@ -45,7 +46,7 @@ describe "Prawn::Table::Cell" do
|
|
45
46
|
# used for table([[{:text => "...", :font_style => :bold, ...}, ...]])
|
46
47
|
c = Prawn::Table::Cell.make(@pdf,
|
47
48
|
{:content => 'hello', :font_style => :bold})
|
48
|
-
c.should
|
49
|
+
c.should be_a_kind_of Prawn::Table::Cell::Text
|
49
50
|
c.content.should == "hello"
|
50
51
|
c.font.name.should == 'Helvetica-Bold'
|
51
52
|
end
|
@@ -56,22 +57,22 @@ describe "Prawn::Table::Cell" do
|
|
56
57
|
@pdf.expects(:move_down)
|
57
58
|
@pdf.expects(:draw_text!).with { |text, options| text == "hello world" }
|
58
59
|
|
59
|
-
@pdf.cell(:content => "hello world",
|
60
|
+
@pdf.cell(:content => "hello world",
|
60
61
|
:at => [10, 20],
|
61
62
|
:padding => [30, 40],
|
62
|
-
:size => 7,
|
63
|
+
:size => 7,
|
63
64
|
:font_style => :bold)
|
64
65
|
end
|
65
66
|
end
|
66
|
-
|
67
|
+
|
67
68
|
describe "Prawn::Document#make_cell" do
|
68
69
|
it "should not draw the cell" do
|
69
70
|
Prawn::Table::Cell::Text.any_instance.expects(:draw).never
|
70
71
|
@pdf.make_cell("text")
|
71
72
|
end
|
72
|
-
|
73
|
+
|
73
74
|
it "should return a Cell" do
|
74
|
-
@pdf.make_cell("text", :size => 7).should
|
75
|
+
@pdf.make_cell("text", :size => 7).should be_a_kind_of Prawn::Table::Cell
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
@@ -103,7 +104,7 @@ describe "Prawn::Table::Cell" do
|
|
103
104
|
|
104
105
|
it "should incorporate padding when specified" do
|
105
106
|
c = cell(:content => "text", :padding => [1, 2, 3, 4])
|
106
|
-
c.width.should.
|
107
|
+
c.width.should be_within(0.01).of(@pdf.width_of("text") + 6)
|
107
108
|
end
|
108
109
|
|
109
110
|
it "should allow width to be reset after it has been calculated" do
|
@@ -117,7 +118,7 @@ describe "Prawn::Table::Cell" do
|
|
117
118
|
it "should return proper width with size set" do
|
118
119
|
text = "text " * 4
|
119
120
|
c = cell(:content => text, :size => 7)
|
120
|
-
c.width.should ==
|
121
|
+
c.width.should ==
|
121
122
|
@pdf.width_of(text, :size => 7) + c.padding[1] + c.padding[3]
|
122
123
|
end
|
123
124
|
|
@@ -128,7 +129,7 @@ describe "Prawn::Table::Cell" do
|
|
128
129
|
|
129
130
|
it "content_width should exclude padding even with manual :width" do
|
130
131
|
c = cell(:content => "text", :padding => 10, :width => 400)
|
131
|
-
c.content_width.should
|
132
|
+
c.content_width.should be_within(0.01).of(380)
|
132
133
|
end
|
133
134
|
|
134
135
|
it "should have a reasonable minimum width that can fit @content" do
|
@@ -136,9 +137,9 @@ describe "Prawn::Table::Cell" do
|
|
136
137
|
min_content_width = c.min_width - c.padding[1] - c.padding[3]
|
137
138
|
|
138
139
|
lambda { @pdf.height_of("text", :width => min_content_width) }.
|
139
|
-
|
140
|
+
should_not raise_error(Prawn::Errors::CannotFit)
|
140
141
|
|
141
|
-
@pdf.height_of("text", :width => min_content_width).should
|
142
|
+
@pdf.height_of("text", :width => min_content_width).should be <
|
142
143
|
(5 * @pdf.height_of("text"))
|
143
144
|
end
|
144
145
|
|
@@ -147,14 +148,14 @@ describe "Prawn::Table::Cell" do
|
|
147
148
|
c.padding = 0
|
148
149
|
|
149
150
|
# Make sure we use the new value of padding in calculating min_width
|
150
|
-
c.min_width.should
|
151
|
+
c.min_width.should be < 100
|
151
152
|
end
|
152
153
|
|
153
154
|
it "should defer min_width's evaluation of size" do
|
154
155
|
c = cell(:content => "text", :size => 50)
|
155
156
|
c.size = 8
|
156
157
|
c.padding = 0
|
157
|
-
c.min_width.should
|
158
|
+
c.min_width.should be < 10
|
158
159
|
end
|
159
160
|
|
160
161
|
end
|
@@ -164,7 +165,7 @@ describe "Prawn::Table::Cell" do
|
|
164
165
|
|
165
166
|
it "should be calculated for text" do
|
166
167
|
c = cell(:content => "text")
|
167
|
-
c.height.should ==
|
168
|
+
c.height.should ==
|
168
169
|
@pdf.height_of("text", :width => @pdf.width_of("text")) +
|
169
170
|
c.padding[0] + c.padding[3]
|
170
171
|
end
|
@@ -176,8 +177,8 @@ describe "Prawn::Table::Cell" do
|
|
176
177
|
|
177
178
|
it "should incorporate :padding when specified" do
|
178
179
|
c = cell(:content => "text", :padding => [1, 2, 3, 4])
|
179
|
-
c.height.should.
|
180
|
-
@pdf.height_of("text", :width => @pdf.width_of("text"))
|
180
|
+
c.height.should be_within(0.01).of(1 + 3 +
|
181
|
+
@pdf.height_of("text", :width => @pdf.width_of("text")))
|
181
182
|
end
|
182
183
|
|
183
184
|
it "should allow height to be reset after it has been calculated" do
|
@@ -211,10 +212,10 @@ describe "Prawn::Table::Cell" do
|
|
211
212
|
c = cell(:content => "text", :padding => 10)
|
212
213
|
c.content_height.should == @pdf.height_of("text")
|
213
214
|
end
|
214
|
-
|
215
|
+
|
215
216
|
it "content_height should exclude padding even with manual :height" do
|
216
217
|
c = cell(:content => "text", :padding => 10, :height => 400)
|
217
|
-
c.content_height.should
|
218
|
+
c.content_height.should be_within(0.01).of(380)
|
218
219
|
end
|
219
220
|
end
|
220
221
|
|
@@ -235,7 +236,7 @@ describe "Prawn::Table::Cell" do
|
|
235
236
|
c = cell(:content => "text", :padding => [20, 30])
|
236
237
|
c.padding.should == [20, 30, 20, 30]
|
237
238
|
end
|
238
|
-
|
239
|
+
|
239
240
|
it "should accept [t,h,b]" do
|
240
241
|
c = cell(:content => "text", :padding => [10, 20, 30])
|
241
242
|
c.padding.should == [10, 20, 30, 20]
|
@@ -249,7 +250,7 @@ describe "Prawn::Table::Cell" do
|
|
249
250
|
it "should reject other formats" do
|
250
251
|
lambda{
|
251
252
|
cell(:content => "text", :padding => [10])
|
252
|
-
}.should
|
253
|
+
}.should raise_error(ArgumentError)
|
253
254
|
end
|
254
255
|
end
|
255
256
|
|
@@ -263,10 +264,10 @@ describe "Prawn::Table::Cell" do
|
|
263
264
|
@pdf.stubs(:fill_color)
|
264
265
|
@pdf.expects(:fill_color).with('123456')
|
265
266
|
@pdf.expects(:fill_rectangle).checking do |(x, y), w, h|
|
266
|
-
x.should
|
267
|
-
y.should.
|
268
|
-
w.should.
|
269
|
-
h.should.
|
267
|
+
x.should be_within(0.01).of(0)
|
268
|
+
y.should be_within(0.01).of(@pdf.cursor)
|
269
|
+
w.should be_within(0.01).of(29.344)
|
270
|
+
h.should be_within(0.01).of(23.872)
|
270
271
|
end
|
271
272
|
@pdf.cell(:content => "text", :background_color => '123456')
|
272
273
|
end
|
@@ -279,10 +280,10 @@ describe "Prawn::Table::Cell" do
|
|
279
280
|
@pdf.stubs(:fill_color)
|
280
281
|
@pdf.expects(:fill_color).with('123456')
|
281
282
|
@pdf.expects(:fill_rectangle).checking do |(x, y), w, h|
|
282
|
-
x.should.
|
283
|
-
y.should.
|
284
|
-
w.should.
|
285
|
-
h.should.
|
283
|
+
x.should be_within(0.01).of(12.0)
|
284
|
+
y.should be_within(0.01).of(34.0)
|
285
|
+
w.should be_within(0.01).of(29.344)
|
286
|
+
h.should be_within(0.01).of(23.872)
|
286
287
|
end
|
287
288
|
c = @pdf.make_cell(:content => "text", :background_color => '123456')
|
288
289
|
c.draw([12.0, 34.0])
|
@@ -408,8 +409,34 @@ describe "Prawn::Table::Cell" do
|
|
408
409
|
:border_width => [2, 3, 4, 5])
|
409
410
|
c.border_widths.should == [2, 3, 4, 5]
|
410
411
|
end
|
412
|
+
|
413
|
+
it "should set default border lines to :solid" do
|
414
|
+
c = @pdf.cell(:content => "text")
|
415
|
+
c.border_top_line.should == :solid
|
416
|
+
c.border_right_line.should == :solid
|
417
|
+
c.border_bottom_line.should == :solid
|
418
|
+
c.border_left_line.should == :solid
|
419
|
+
c.border_lines.should == [:solid] * 4
|
420
|
+
end
|
421
|
+
|
422
|
+
it "should set border line with :border_..._line" do
|
423
|
+
c = @pdf.cell(:content => "text", :border_bottom_line => :dotted)
|
424
|
+
c.border_bottom_line.should == :dotted
|
425
|
+
c.border_lines[2].should == :dotted
|
426
|
+
end
|
427
|
+
|
428
|
+
it "should set border lines with :border_lines" do
|
429
|
+
c = @pdf.cell(:content => "text",
|
430
|
+
:border_lines => [:solid, :dotted, :dashed, :solid])
|
431
|
+
c.border_lines.should == [:solid, :dotted, :dashed, :solid]
|
432
|
+
end
|
411
433
|
end
|
412
434
|
|
435
|
+
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
|
413
440
|
describe "Text cell attributes" do
|
414
441
|
include CellHelpers
|
415
442
|
|
@@ -498,7 +525,6 @@ describe "Prawn::Table::Cell" do
|
|
498
525
|
c.content_width.should == font.compute_width_of("text")
|
499
526
|
end
|
500
527
|
end
|
501
|
-
|
502
528
|
end
|
503
529
|
|
504
530
|
describe "Image cells" do
|
@@ -509,11 +535,11 @@ describe "Image cells" do
|
|
509
535
|
describe "with default options" do
|
510
536
|
before(:each) do
|
511
537
|
@cell = Prawn::Table::Cell.make(@pdf,
|
512
|
-
:image => "#{Prawn::
|
538
|
+
:image => "#{Prawn::DATADIR}/images/prawn.png")
|
513
539
|
end
|
514
540
|
|
515
541
|
it "should create a Cell::Image" do
|
516
|
-
@cell.should
|
542
|
+
@cell.should be_a_kind_of(Prawn::Table::Cell::Image)
|
517
543
|
end
|
518
544
|
|
519
545
|
it "should pull the natural width and height from the image" do
|
@@ -525,7 +551,7 @@ describe "Image cells" do
|
|
525
551
|
describe "hash syntax" do
|
526
552
|
before(:each) do
|
527
553
|
@table = @pdf.make_table([[{
|
528
|
-
:image => "#{Prawn::
|
554
|
+
:image => "#{Prawn::DATADIR}/images/prawn.png",
|
529
555
|
:scale => 2,
|
530
556
|
:fit => [100, 200],
|
531
557
|
:image_width => 123,
|
@@ -538,7 +564,7 @@ describe "Image cells" do
|
|
538
564
|
|
539
565
|
|
540
566
|
it "should create a Cell::Image" do
|
541
|
-
@cell.should
|
567
|
+
@cell.should be_a_kind_of(Prawn::Table::Cell::Image)
|
542
568
|
end
|
543
569
|
|
544
570
|
it "should pass through image options" do
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
describe "A column box" do
|
6
|
+
it "has sensible left and right values" do
|
7
|
+
create_pdf
|
8
|
+
@pdf.column_box [0, @pdf.cursor], :width => @pdf.bounds.width,
|
9
|
+
:height => 200, :columns => 3, :spacer => 25 do
|
10
|
+
left = @pdf.bounds.left
|
11
|
+
right = @pdf.bounds.right
|
12
|
+
|
13
|
+
@pdf.bounds.move_past_bottom # next column
|
14
|
+
|
15
|
+
@pdf.bounds.left.should be > left
|
16
|
+
@pdf.bounds.left.should be > right
|
17
|
+
@pdf.bounds.right.should be > @pdf.bounds.left
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "includes spacers between columns but not at the end" do
|
22
|
+
create_pdf
|
23
|
+
@pdf.column_box [0, @pdf.cursor], :width => 500,
|
24
|
+
:height => 200, :columns => 3, :spacer => 25 do
|
25
|
+
@pdf.bounds.width.should == 150 # (500 - (25 * 2)) / 3
|
26
|
+
|
27
|
+
@pdf.bounds.move_past_bottom
|
28
|
+
@pdf.bounds.move_past_bottom
|
29
|
+
|
30
|
+
@pdf.bounds.right.should == 500
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/document_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe "Prawn::Document.new" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "The cursor" do
|
15
|
-
it "should
|
15
|
+
it "should == pdf.y - bounds.absolute_bottom" do
|
16
16
|
pdf = Prawn::Document.new
|
17
17
|
pdf.cursor.should == pdf.bounds.top
|
18
18
|
|
@@ -34,7 +34,7 @@ describe "when generating a document from a subclass" do
|
|
34
34
|
custom_document = Class.new(Prawn::Document)
|
35
35
|
custom_document.generate(Tempfile.new("generate_test").path) do |e|
|
36
36
|
e.class.should == custom_document
|
37
|
-
e.should
|
37
|
+
e.should be_a_kind_of(Prawn::Document)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -45,20 +45,20 @@ describe "when generating a document from a subclass" do
|
|
45
45
|
Prawn::Document.extensions << mod1 << mod2
|
46
46
|
|
47
47
|
custom_document = Class.new(Prawn::Document)
|
48
|
-
|
48
|
+
custom_document.extensions.should == [mod1, mod2]
|
49
49
|
|
50
50
|
# remove the extensions we added to prawn document
|
51
51
|
Prawn::Document.extensions.delete(mod1)
|
52
52
|
Prawn::Document.extensions.delete(mod2)
|
53
53
|
|
54
|
-
|
55
|
-
|
54
|
+
Prawn::Document.new.respond_to?(:test_extensions1).should be_false
|
55
|
+
Prawn::Document.new.respond_to?(:test_extensions2).should be_false
|
56
56
|
|
57
57
|
# verify these still exist on custom class
|
58
|
-
|
58
|
+
custom_document.extensions.should == [mod1, mod2]
|
59
59
|
|
60
|
-
|
61
|
-
|
60
|
+
custom_document.new.respond_to?(:test_extensions1).should be_true
|
61
|
+
custom_document.new.respond_to?(:test_extensions2).should be_true
|
62
62
|
end
|
63
63
|
|
64
64
|
end
|
@@ -89,7 +89,7 @@ describe "When beginning each new page" do
|
|
89
89
|
|
90
90
|
describe "Background template feature" do
|
91
91
|
before(:each) do
|
92
|
-
@filename = "#{Prawn::
|
92
|
+
@filename = "#{Prawn::DATADIR}/images/pigs.jpg"
|
93
93
|
@pdf = Prawn::Document.new(:background => @filename)
|
94
94
|
end
|
95
95
|
it "should place a background image if it is in options block" do
|
@@ -235,11 +235,11 @@ describe "Document compression" do
|
|
235
235
|
doc_uncompressed = Prawn::Document.new
|
236
236
|
doc_compressed = Prawn::Document.new(:compress => true)
|
237
237
|
[doc_compressed, doc_uncompressed].each do |pdf|
|
238
|
-
pdf.font "#{Prawn::
|
238
|
+
pdf.font "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
|
239
239
|
pdf.text "更可怕的是,同质化竞争对手可以按照URL中后面这个ID来遍历" * 10
|
240
240
|
end
|
241
241
|
|
242
|
-
doc_compressed.render.length.should
|
242
|
+
doc_compressed.render.length.should be < doc_uncompressed.render.length
|
243
243
|
end
|
244
244
|
|
245
245
|
end
|
@@ -266,7 +266,7 @@ describe "When reopening pages" do
|
|
266
266
|
# MalformedPDFError raised if content stream actual length does not match
|
267
267
|
# dictionary length
|
268
268
|
lambda{ PDF::Inspector::Page.analyze(@pdf.render) }.
|
269
|
-
|
269
|
+
should_not raise_error(PDF::Reader::MalformedPDFError)
|
270
270
|
end
|
271
271
|
|
272
272
|
it "should insert pages after the current page when calling start_new_page" do
|
@@ -358,8 +358,8 @@ describe "The mask() feature" do
|
|
358
358
|
@pdf.mask(:y, :line_width) do
|
359
359
|
@pdf.y = y + 1
|
360
360
|
@pdf.line_width = line_width + 1
|
361
|
-
@pdf.y.
|
362
|
-
@pdf.line_width.
|
361
|
+
@pdf.y.should_not == y
|
362
|
+
@pdf.line_width.should_not == line_width
|
363
363
|
end
|
364
364
|
@pdf.y.should == y
|
365
365
|
@pdf.line_width.should == line_width
|
@@ -391,14 +391,14 @@ describe "The group() feature" do
|
|
391
391
|
pages[1][:strings].should == ["Hello", "World"]
|
392
392
|
end
|
393
393
|
|
394
|
-
it "should
|
394
|
+
it "should raise_error CannotGroup if the content is too tall" do
|
395
395
|
lambda {
|
396
396
|
Prawn::Document.new do
|
397
397
|
group do
|
398
398
|
100.times { text "Too long" }
|
399
399
|
end
|
400
400
|
end.render
|
401
|
-
}.should
|
401
|
+
}.should raise_error(Prawn::Errors::CannotGroup)
|
402
402
|
end
|
403
403
|
|
404
404
|
it "should group within individual column boxes" do
|
@@ -478,7 +478,7 @@ describe "The :optimize_objects option" do
|
|
478
478
|
wasteful_pdf = Prawn::Document.new(&@wasteful_doc)
|
479
479
|
frugal_pdf = Prawn::Document.new(:optimize_objects => true,
|
480
480
|
&@wasteful_doc)
|
481
|
-
frugal_pdf.render.size.should
|
481
|
+
frugal_pdf.render.size.should be < wasteful_pdf.render.size
|
482
482
|
end
|
483
483
|
|
484
484
|
it "should default to :false" do
|
@@ -676,6 +676,27 @@ describe "The number_pages method" do
|
|
676
676
|
end
|
677
677
|
end
|
678
678
|
end
|
679
|
+
|
680
|
+
context "height option" do
|
681
|
+
before do
|
682
|
+
@pdf.start_new_page
|
683
|
+
end
|
684
|
+
|
685
|
+
it "with 10 height" do
|
686
|
+
@pdf.expects(:text_box).with("1 1", { :height => 10 })
|
687
|
+
@pdf.number_pages "<page> <total>", :height => 10
|
688
|
+
end
|
689
|
+
|
690
|
+
it "with nil height" do
|
691
|
+
@pdf.expects(:text_box).with("1 1", { :height => nil })
|
692
|
+
@pdf.number_pages "<page> <total>", :height => nil
|
693
|
+
end
|
694
|
+
|
695
|
+
it "with no height" do
|
696
|
+
@pdf.expects(:text_box).with("1 1", { :height => 50 })
|
697
|
+
@pdf.number_pages "<page> <total>"
|
698
|
+
end
|
699
|
+
end
|
679
700
|
end
|
680
701
|
|
681
702
|
describe "The page_match? method" do
|
@@ -685,31 +706,31 @@ describe "The page_match? method" do
|
|
685
706
|
end
|
686
707
|
|
687
708
|
it "returns nil given no filter" do
|
688
|
-
|
709
|
+
@pdf.page_match?(:nil, 1).should be_false
|
689
710
|
end
|
690
711
|
|
691
712
|
it "must provide an :all filter" do
|
692
|
-
|
713
|
+
(1..@pdf.page_count).all? { |i| @pdf.page_match?(:all, i) }.should be_true
|
693
714
|
end
|
694
715
|
|
695
716
|
it "must provide an :odd filter" do
|
696
717
|
odd, even = (1..@pdf.page_count).partition { |e| e % 2 == 1 }
|
697
|
-
|
698
|
-
|
718
|
+
odd.all? { |i| @pdf.page_match?(:odd, i) }.should be_true
|
719
|
+
even.any? { |i| @pdf.page_match?(:odd, i) }.should be_false
|
699
720
|
end
|
700
721
|
|
701
722
|
it "must be able to filter by an array of page numbers" do
|
702
723
|
fltr = [1,2,7]
|
703
|
-
|
724
|
+
(1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [1,2,7]
|
704
725
|
end
|
705
726
|
|
706
727
|
it "must be able to filter by a range of page numbers" do
|
707
728
|
fltr = 2..4
|
708
|
-
|
729
|
+
(1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [2,3,4]
|
709
730
|
end
|
710
731
|
|
711
732
|
it "must be able to filter by an arbitrary proc" do
|
712
733
|
fltr = lambda { |x| x == 1 or x % 3 == 0 }
|
713
|
-
|
734
|
+
(1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [1,3,6,9]
|
714
735
|
end
|
715
736
|
end
|