prawn 0.11.1.pre → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +2 -340
- data/HACKING +1 -1
- data/LICENSE +3 -3
- data/Rakefile +17 -6
- data/data/encodings/win_ansi.txt +1 -1
- data/data/images/prawn.png +0 -0
- data/data/pdfs/form.pdf +820 -0
- data/data/pdfs/multipage_template.pdf +127 -0
- data/examples/bounding_box/bounding_boxes.rb +4 -3
- data/examples/bounding_box/indentation.rb +2 -1
- data/examples/bounding_box/russian_boxes.rb +3 -2
- data/examples/bounding_box/stretched_nesting.rb +2 -1
- data/examples/general/background.rb +2 -1
- data/examples/general/canvas.rb +2 -1
- data/examples/general/context_sensitive_headers.rb +2 -1
- data/examples/general/float.rb +2 -1
- data/examples/general/margin.rb +2 -1
- data/examples/general/measurement_units.rb +2 -1
- data/examples/general/metadata-info.rb +2 -1
- data/examples/general/multi_page_layout.rb +2 -1
- data/examples/general/outlines.rb +2 -1
- data/examples/general/page_geometry.rb +2 -1
- data/examples/general/page_numbering.rb +27 -2
- data/examples/general/page_templates.rb +20 -0
- data/examples/general/repeaters.rb +2 -1
- data/examples/general/stamp.rb +4 -3
- data/examples/general/templates.rb +2 -1
- data/examples/graphics/basic_images.rb +2 -1
- data/examples/graphics/cmyk.rb +2 -1
- data/examples/graphics/curves.rb +4 -3
- data/examples/graphics/gradient.rb +23 -0
- data/examples/graphics/hexagon.rb +3 -2
- data/examples/graphics/image_fit.rb +3 -2
- data/examples/graphics/image_flow.rb +2 -1
- data/examples/graphics/image_position.rb +3 -2
- data/examples/graphics/line.rb +2 -1
- data/examples/graphics/png_types.rb +3 -2
- data/examples/graphics/polygons.rb +3 -2
- data/examples/graphics/remote_images.rb +2 -1
- data/examples/graphics/rounded_polygons.rb +2 -1
- data/examples/graphics/rounded_rectangle.rb +2 -1
- data/examples/graphics/ruport_style_helpers.rb +3 -2
- data/examples/graphics/stroke_bounds.rb +2 -1
- data/examples/graphics/stroke_cap_and_join.rb +2 -1
- data/examples/graphics/stroke_dash.rb +2 -1
- data/examples/graphics/transformations.rb +2 -1
- data/examples/graphics/transparency.rb +4 -3
- data/examples/grid/bounding_boxes.rb +2 -1
- data/examples/grid/column_gutter_grid.rb +2 -1
- data/examples/grid/multi_boxes.rb +2 -1
- data/examples/grid/show_grid.rb +2 -1
- data/examples/grid/simple_grid.rb +2 -1
- data/examples/m17n/chinese_text_wrapping.rb +2 -1
- data/examples/m17n/euro.rb +3 -2
- data/examples/m17n/full_win_ansi_character_list.rb +20 -0
- data/examples/m17n/sjis.rb +2 -1
- data/examples/m17n/utf8.rb +3 -2
- data/examples/m17n/win_ansi_charset.rb +2 -1
- data/examples/security/hello_foo.rb +2 -1
- data/examples/table/bill.rb +2 -1
- data/examples/table/borders.rb +25 -0
- data/examples/table/cell.rb +3 -2
- data/examples/table/checkerboard.rb +2 -1
- data/examples/table/header.rb +3 -2
- data/examples/table/inline_format_table.rb +2 -1
- data/examples/table/multi_page_table.rb +2 -1
- data/examples/table/simple_table.rb +2 -1
- data/examples/table/subtable.rb +2 -1
- data/examples/table/widths.rb +2 -1
- data/examples/text/alignment.rb +2 -1
- data/examples/text/character_spacing.rb +2 -1
- data/examples/text/dfont.rb +2 -1
- data/examples/text/family_based_styling.rb +3 -2
- data/examples/text/font_calculations.rb +2 -1
- data/examples/text/font_size.rb +2 -1
- data/examples/text/hyphenation.rb +2 -2
- data/examples/text/indent_paragraphs.rb +7 -5
- data/examples/text/inline_format.rb +7 -6
- data/examples/text/kerning.rb +2 -1
- data/examples/text/rendering_mode.rb +21 -0
- data/examples/text/rotated.rb +2 -1
- data/examples/text/shaped_text_box.rb +2 -1
- data/examples/text/simple_text.rb +2 -1
- data/examples/text/simple_text_ttf.rb +2 -1
- data/examples/text/span.rb +3 -2
- data/examples/text/text_box.rb +7 -5
- data/examples/text/text_box_returning_excess.rb +4 -3
- data/examples/text/text_flow.rb +2 -1
- data/lib/prawn.rb +1 -1
- data/lib/prawn/core/object_store.rb +42 -14
- data/lib/prawn/core/page.rb +22 -8
- data/lib/prawn/core/text.rb +141 -13
- data/lib/prawn/core/text/formatted/arranger.rb +39 -12
- data/lib/prawn/core/text/formatted/line_wrap.rb +205 -60
- data/lib/prawn/core/text/formatted/wrap.rb +72 -35
- data/lib/prawn/document.rb +174 -70
- data/lib/prawn/document/bounding_box.rb +122 -83
- data/lib/prawn/document/column_box.rb +113 -0
- data/lib/prawn/document/graphics_state.rb +90 -2
- data/lib/prawn/document/internals.rb +5 -3
- data/lib/prawn/errors.rb +5 -0
- data/lib/prawn/font.rb +4 -4
- data/lib/prawn/font/afm.rb +11 -0
- data/lib/prawn/font/ttf.rb +5 -0
- data/lib/prawn/graphics.rb +77 -14
- data/lib/prawn/graphics/cap_style.rb +13 -5
- data/lib/prawn/graphics/color.rb +54 -35
- data/lib/prawn/graphics/dash.rb +27 -16
- data/lib/prawn/graphics/gradient.rb +84 -0
- data/lib/prawn/graphics/join_style.rb +12 -3
- data/lib/prawn/graphics/transparency.rb +4 -4
- data/lib/prawn/images.rb +18 -160
- data/lib/prawn/images/jpg.rb +39 -0
- data/lib/prawn/images/png.rb +130 -0
- data/lib/prawn/repeater.rb +6 -13
- data/lib/prawn/security.rb +6 -1
- data/lib/prawn/stamp.rb +12 -4
- data/lib/prawn/table.rb +36 -4
- data/lib/prawn/table/cell.rb +224 -63
- data/lib/prawn/table/cell/text.rb +20 -10
- data/lib/prawn/table/cells.rb +23 -6
- data/lib/prawn/text.rb +54 -91
- data/lib/prawn/text/box.rb +29 -283
- data/lib/prawn/text/formatted/box.rb +349 -24
- data/lib/prawn/text/formatted/fragment.rb +63 -2
- data/lib/prawn/text/formatted/parser.rb +2 -1
- data/prawn.gemspec +21 -5
- data/spec/bounding_box_spec.rb +61 -28
- data/spec/cell_spec.rb +168 -30
- data/spec/document_spec.rb +187 -3
- data/spec/extensions/mocha.rb +45 -0
- data/spec/font_spec.rb +32 -1
- data/spec/formatted_text_arranger_spec.rb +35 -40
- data/spec/formatted_text_box_spec.rb +287 -443
- data/spec/formatted_text_fragment_spec.rb +87 -0
- data/spec/graphics_spec.rb +128 -12
- data/spec/grid_spec.rb +1 -1
- data/spec/images_spec.rb +11 -3
- data/spec/inline_formatted_text_parser_spec.rb +8 -0
- data/spec/line_wrap_spec.rb +200 -208
- data/spec/object_store_spec.rb +10 -0
- data/spec/outline_spec.rb +7 -3
- data/spec/repeater_spec.rb +58 -10
- data/spec/security_spec.rb +6 -0
- data/spec/spec_helper.rb +12 -8
- data/spec/stamp_spec.rb +52 -1
- data/spec/stroke_styles_spec.rb +30 -0
- data/spec/table_spec.rb +93 -3
- data/spec/template_spec.rb +132 -6
- data/spec/text_at_spec.rb +14 -4
- data/spec/text_box_spec.rb +309 -70
- data/spec/text_rendering_mode_spec.rb +45 -0
- data/spec/text_spec.rb +60 -17
- data/spec/text_with_inline_formatting_spec.rb +4 -162
- metadata +241 -241
- data/lib/prawn/core/text/line_wrap.rb +0 -211
- data/lib/prawn/core/text/wrap.rb +0 -82
- data/vendor/pdf-inspector/README +0 -18
- data/vendor/pdf-inspector/lib/pdf/inspector.rb +0 -26
- data/vendor/pdf-inspector/lib/pdf/inspector/extgstate.rb +0 -18
- data/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +0 -131
- data/vendor/pdf-inspector/lib/pdf/inspector/page.rb +0 -25
- data/vendor/pdf-inspector/lib/pdf/inspector/text.rb +0 -46
- data/vendor/pdf-inspector/lib/pdf/inspector/xobject.rb +0 -19
- data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
- data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
- data/vendor/ttfunk/example.rb +0 -45
- data/vendor/ttfunk/lib/ttfunk.rb +0 -102
- data/vendor/ttfunk/lib/ttfunk/directory.rb +0 -17
- data/vendor/ttfunk/lib/ttfunk/encoding/mac_roman.rb +0 -88
- data/vendor/ttfunk/lib/ttfunk/encoding/windows_1252.rb +0 -69
- data/vendor/ttfunk/lib/ttfunk/reader.rb +0 -44
- data/vendor/ttfunk/lib/ttfunk/resource_file.rb +0 -78
- data/vendor/ttfunk/lib/ttfunk/subset.rb +0 -18
- data/vendor/ttfunk/lib/ttfunk/subset/base.rb +0 -141
- data/vendor/ttfunk/lib/ttfunk/subset/mac_roman.rb +0 -50
- data/vendor/ttfunk/lib/ttfunk/subset/unicode.rb +0 -48
- data/vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb +0 -63
- data/vendor/ttfunk/lib/ttfunk/subset/windows_1252.rb +0 -55
- data/vendor/ttfunk/lib/ttfunk/subset_collection.rb +0 -72
- data/vendor/ttfunk/lib/ttfunk/table.rb +0 -46
- data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +0 -34
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format00.rb +0 -54
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format04.rb +0 -126
- data/vendor/ttfunk/lib/ttfunk/table/cmap/subtable.rb +0 -79
- data/vendor/ttfunk/lib/ttfunk/table/glyf.rb +0 -64
- data/vendor/ttfunk/lib/ttfunk/table/glyf/compound.rb +0 -81
- data/vendor/ttfunk/lib/ttfunk/table/glyf/simple.rb +0 -37
- data/vendor/ttfunk/lib/ttfunk/table/head.rb +0 -44
- data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +0 -41
- data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +0 -47
- data/vendor/ttfunk/lib/ttfunk/table/kern.rb +0 -79
- data/vendor/ttfunk/lib/ttfunk/table/kern/format0.rb +0 -62
- data/vendor/ttfunk/lib/ttfunk/table/loca.rb +0 -43
- data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +0 -40
- data/vendor/ttfunk/lib/ttfunk/table/name.rb +0 -125
- data/vendor/ttfunk/lib/ttfunk/table/os2.rb +0 -78
- data/vendor/ttfunk/lib/ttfunk/table/post.rb +0 -91
- data/vendor/ttfunk/lib/ttfunk/table/post/format10.rb +0 -43
- data/vendor/ttfunk/lib/ttfunk/table/post/format20.rb +0 -35
- data/vendor/ttfunk/lib/ttfunk/table/post/format25.rb +0 -23
- data/vendor/ttfunk/lib/ttfunk/table/post/format30.rb +0 -17
- data/vendor/ttfunk/lib/ttfunk/table/post/format40.rb +0 -17
- data/vendor/ttfunk/lib/ttfunk/table/simple.rb +0 -14
@@ -90,7 +90,7 @@ module Prawn
|
|
90
90
|
|
91
91
|
string = hash[:text].gsub("&", "&").gsub(">", ">").gsub("<", "<")
|
92
92
|
prefix + string + suffix
|
93
|
-
end.join
|
93
|
+
end.join
|
94
94
|
end
|
95
95
|
|
96
96
|
def self.array_paragraphs(array) #:nodoc:
|
@@ -111,6 +111,7 @@ module Prawn
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
paragraphs << paragraph unless paragraph.empty?
|
114
|
+
paragraphs
|
114
115
|
end
|
115
116
|
|
116
117
|
private
|
data/prawn.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# Version numbering: http://wiki.github.com/sandal/prawn/development-roadmap
|
2
|
-
PRAWN_VERSION = "0.11.1
|
2
|
+
PRAWN_VERSION = "0.11.1"
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = "prawn"
|
6
6
|
spec.version = PRAWN_VERSION
|
7
7
|
spec.platform = Gem::Platform::RUBY
|
8
8
|
spec.summary = "A fast and nimble PDF generator for Ruby"
|
9
|
-
spec.files = Dir.glob("{examples,lib,spec,
|
9
|
+
spec.files = Dir.glob("{examples,lib,spec,data}/**/**/*") +
|
10
10
|
["Rakefile", "prawn.gemspec"]
|
11
11
|
spec.require_path = "lib"
|
12
12
|
spec.required_ruby_version = '>= 1.8.7'
|
@@ -17,12 +17,28 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.extra_rdoc_files = %w{HACKING README LICENSE COPYING}
|
18
18
|
spec.rdoc_options << '--title' << 'Prawn Documentation' <<
|
19
19
|
'--main' << 'README' << '-q'
|
20
|
-
spec.
|
21
|
-
spec.email = "
|
20
|
+
spec.authors = ["Gregory Brown","Brad Ediger","Daniel Nelson","Jonathen Greenberg","James Healy"]
|
21
|
+
spec.email = ["gregory.t.brown@gmail.com","brad@bradediger.com","dnelson@bluejade.com","greenberg@entryway.net","jimmy@deefa.com"]
|
22
22
|
spec.rubyforge_project = "prawn"
|
23
|
-
spec.add_dependency('pdf-reader', '>=0.
|
23
|
+
spec.add_dependency('pdf-reader', '>=0.9.0')
|
24
|
+
spec.add_dependency('ttfunk', '~>1.0.0')
|
24
25
|
spec.homepage = "http://prawn.majesticseacreature.com"
|
25
26
|
spec.description = <<END_DESC
|
26
27
|
Prawn is a fast, tiny, and nimble PDF generator for Ruby
|
28
|
+
END_DESC
|
29
|
+
spec.post_install_message = <<END_DESC
|
30
|
+
|
31
|
+
********************************************
|
32
|
+
|
33
|
+
|
34
|
+
A lot has changed since 0.8.4
|
35
|
+
|
36
|
+
Please read the changelog for details:
|
37
|
+
|
38
|
+
https://github.com/sandal/prawn/wiki/CHANGELOG
|
39
|
+
|
40
|
+
|
41
|
+
********************************************
|
42
|
+
|
27
43
|
END_DESC
|
28
44
|
end
|
data/spec/bounding_box_spec.rb
CHANGED
@@ -9,26 +9,26 @@ describe "A bounding box" do
|
|
9
9
|
@y = 125
|
10
10
|
@width = 50
|
11
11
|
@height = 75
|
12
|
-
@box = Prawn::Document::BoundingBox.new(nil, [@x,@y],
|
13
|
-
|
12
|
+
@box = Prawn::Document::BoundingBox.new(nil, nil, [@x,@y],
|
13
|
+
:width => @width, :height => @height )
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should have an anchor at (x, y - height)" do
|
17
|
-
@box.anchor.should == [@x,@y-@height]
|
17
|
+
@box.anchor.should == [@x,@y-@height]
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should have a left boundary of 0" do
|
21
21
|
@box.left.should == 0
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it "should have a right boundary equal to the width" do
|
25
25
|
@box.right.should == @width
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
it "should have a top boundary of height" do
|
29
29
|
@box.top.should == @height
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
it "should have a bottom boundary of 0" do
|
33
33
|
@box.bottom.should == 0
|
34
34
|
end
|
@@ -52,15 +52,15 @@ describe "A bounding box" do
|
|
52
52
|
it "should have an absolute left boundary of x" do
|
53
53
|
@box.absolute_left.should == @x
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
it "should have an absolute right boundary of x + width" do
|
57
57
|
@box.absolute_right.should == @x + @width
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
it "should have an absolute top boundary of y" do
|
61
61
|
@box.absolute_top.should == @y
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
it "should have an absolute bottom boundary of y - height" do
|
65
65
|
@box.absolute_bottom.should == @y - @height
|
66
66
|
end
|
@@ -82,16 +82,16 @@ describe "A bounding box" do
|
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should require width to be set" do
|
85
|
-
|
86
|
-
Prawn::Document::BoundingBox.new(nil, [100,100])
|
87
|
-
end
|
85
|
+
lambda do
|
86
|
+
Prawn::Document::BoundingBox.new(nil, nil, [100,100])
|
87
|
+
end.should.raise(ArgumentError)
|
88
88
|
end
|
89
89
|
|
90
90
|
end
|
91
91
|
|
92
|
-
describe "drawing bounding boxes" do
|
93
|
-
|
94
|
-
before(:each) { create_pdf }
|
92
|
+
describe "drawing bounding boxes" do
|
93
|
+
|
94
|
+
before(:each) { create_pdf }
|
95
95
|
|
96
96
|
it "should restore the margin box when bounding box exits" do
|
97
97
|
margin_box = @pdf.bounds
|
@@ -105,7 +105,7 @@ describe "drawing bounding boxes" do
|
|
105
105
|
end
|
106
106
|
|
107
107
|
it "should restore the parent bounding box when calls are nested" do
|
108
|
-
@pdf.bounding_box [100,500], :width => 300, :height => 300 do
|
108
|
+
@pdf.bounding_box [100,500], :width => 300, :height => 300 do
|
109
109
|
|
110
110
|
@pdf.bounds.absolute_top.should == 500 + @pdf.margin_box.absolute_bottom
|
111
111
|
@pdf.bounds.absolute_left.should == 100 + @pdf.margin_box.absolute_left
|
@@ -121,14 +121,14 @@ describe "drawing bounding boxes" do
|
|
121
121
|
@pdf.bounds.absolute_left.should == 100 + @pdf.margin_box.absolute_left
|
122
122
|
|
123
123
|
end
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should calculate a height if none is specified" do
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should calculate a height if none is specified" do
|
127
127
|
@pdf.bounding_box([100, 500], :width => 100) do
|
128
|
-
@pdf.text "The rain in Spain falls mainly on the plains."
|
129
|
-
end
|
130
|
-
|
131
|
-
@pdf.y.should.be.close 458.384, 0.001
|
128
|
+
@pdf.text "The rain in Spain falls mainly on the plains."
|
129
|
+
end
|
130
|
+
|
131
|
+
@pdf.y.should.be.close 458.384, 0.001
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should keep track of the max height the box was stretched to" do
|
@@ -137,9 +137,9 @@ describe "drawing bounding boxes" do
|
|
137
137
|
@pdf.move_up 15
|
138
138
|
end
|
139
139
|
|
140
|
-
|
140
|
+
box.height.should == 100
|
141
141
|
end
|
142
|
-
|
142
|
+
|
143
143
|
end
|
144
144
|
|
145
145
|
describe "Indentation" do
|
@@ -175,16 +175,49 @@ describe "Indentation" do
|
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
|
+
it "should maintain left indentation across a page break" do
|
179
|
+
original_left = @pdf.bounds.absolute_left
|
180
|
+
|
181
|
+
@pdf.indent(20) do
|
182
|
+
@pdf.bounds.absolute_left.should == original_left + 20
|
183
|
+
@pdf.start_new_page
|
184
|
+
@pdf.bounds.absolute_left.should == original_left + 20
|
185
|
+
end
|
186
|
+
|
187
|
+
@pdf.bounds.absolute_left.should == original_left
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should maintain right indentation across a page break" do
|
191
|
+
original_width = @pdf.bounds.width
|
192
|
+
|
193
|
+
@pdf.indent(0, 20) do
|
194
|
+
@pdf.bounds.width.should == original_width - 20
|
195
|
+
@pdf.start_new_page
|
196
|
+
@pdf.bounds.width.should == original_width - 20
|
197
|
+
end
|
198
|
+
|
199
|
+
@pdf.bounds.width.should == original_width
|
200
|
+
end
|
201
|
+
|
202
|
+
it "optionally allows adjustment of the right bound as well" do
|
203
|
+
@pdf.bounding_box([100,100], :width => 200) do
|
204
|
+
@pdf.indent(20, 30) do
|
205
|
+
@pdf.bounds.absolute_left.should == 120
|
206
|
+
@pdf.bounds.width.should == 150
|
207
|
+
end
|
208
|
+
@pdf.bounds.absolute_left.should == 100
|
209
|
+
@pdf.bounds.width.should == 200
|
210
|
+
end
|
211
|
+
end
|
178
212
|
end
|
179
213
|
|
180
214
|
describe "A canvas" do
|
181
215
|
before(:each) { create_pdf }
|
182
|
-
|
216
|
+
|
183
217
|
it "should use whatever the last set y position is" do
|
184
218
|
@pdf.canvas do
|
185
219
|
@pdf.bounding_box([100,500],:width => 200) { @pdf.move_down 50 }
|
186
220
|
end
|
187
221
|
@pdf.y.should == 450
|
188
222
|
end
|
189
|
-
end
|
190
|
-
|
223
|
+
end
|
data/spec/cell_spec.rb
CHANGED
@@ -34,10 +34,21 @@ describe "Prawn::Table::Cell" do
|
|
34
34
|
@pdf.cell(:content => "text").should.be.a.kind_of Prawn::Table::Cell
|
35
35
|
end
|
36
36
|
|
37
|
-
it "should
|
38
|
-
|
37
|
+
it "should convert nil, Numeric, and Date values to strings" do
|
38
|
+
[nil, 123, 123.45, Date.today].each do |value|
|
39
|
+
c = @pdf.cell(:content => value)
|
40
|
+
c.should.be.a.kind_of Prawn::Table::Cell::Text
|
41
|
+
c.content.should == value.to_s
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should allow inline styling with a hash argument" do
|
46
|
+
# used for table([[{:text => "...", :font_style => :bold, ...}, ...]])
|
47
|
+
c = Prawn::Table::Cell.make(@pdf,
|
48
|
+
{:content => 'hello', :font_style => :bold})
|
39
49
|
c.should.be.a.kind_of Prawn::Table::Cell::Text
|
40
|
-
c.content.should == ""
|
50
|
+
c.content.should == "hello"
|
51
|
+
c.font.name.should == 'Helvetica-Bold'
|
41
52
|
end
|
42
53
|
|
43
54
|
it "should draw text at the given point plus padding, with the given " +
|
@@ -50,7 +61,7 @@ describe "Prawn::Table::Cell" do
|
|
50
61
|
:at => [10, 20],
|
51
62
|
:padding => [30, 40],
|
52
63
|
:size => 7,
|
53
|
-
:
|
64
|
+
:font_style => :bold)
|
54
65
|
end
|
55
66
|
end
|
56
67
|
|
@@ -65,6 +76,19 @@ describe "Prawn::Table::Cell" do
|
|
65
76
|
end
|
66
77
|
end
|
67
78
|
|
79
|
+
describe "#style" do
|
80
|
+
include CellHelpers
|
81
|
+
|
82
|
+
it "should set each property in turn" do
|
83
|
+
c = cell(:content => "text")
|
84
|
+
|
85
|
+
c.expects(:padding=).with(50)
|
86
|
+
c.expects(:size=).with(7)
|
87
|
+
|
88
|
+
c.style(:padding => 50, :size => 7)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
68
92
|
describe "cell width" do
|
69
93
|
include CellHelpers
|
70
94
|
|
@@ -119,6 +143,21 @@ describe "Prawn::Table::Cell" do
|
|
119
143
|
(5 * @pdf.height_of("text"))
|
120
144
|
end
|
121
145
|
|
146
|
+
it "should defer min_width's evaluation of padding" do
|
147
|
+
c = cell(:content => "text", :padding => 100)
|
148
|
+
c.padding = 0
|
149
|
+
|
150
|
+
# Make sure we use the new value of padding in calculating min_width
|
151
|
+
c.min_width.should.be < 100
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should defer min_width's evaluation of size" do
|
155
|
+
c = cell(:content => "text", :size => 50)
|
156
|
+
c.size = 8
|
157
|
+
c.padding = 0
|
158
|
+
c.min_width.should.be < 10
|
159
|
+
end
|
160
|
+
|
122
161
|
end
|
123
162
|
|
124
163
|
describe "cell height" do
|
@@ -224,12 +263,31 @@ describe "Prawn::Table::Cell" do
|
|
224
263
|
|
225
264
|
@pdf.stubs(:fill_color)
|
226
265
|
@pdf.expects(:fill_color).with('123456')
|
227
|
-
@pdf.expects(:fill_rectangle).
|
228
|
-
close
|
229
|
-
|
266
|
+
@pdf.expects(:fill_rectangle).checking do |(x, y), w, h|
|
267
|
+
x.should.be.close(0, 0.01)
|
268
|
+
y.should.be.close(@pdf.cursor, 0.01)
|
269
|
+
w.should.be.close(29.344, 0.01)
|
270
|
+
h.should.be.close(23.872, 0.01)
|
230
271
|
end
|
231
272
|
@pdf.cell(:content => "text", :background_color => '123456')
|
232
273
|
end
|
274
|
+
|
275
|
+
it "should draw the background in the right place if cell is drawn at a " +
|
276
|
+
"different location" do
|
277
|
+
@pdf.stubs(:mask).yields
|
278
|
+
@pdf.expects(:mask).with(:fill_color).yields
|
279
|
+
|
280
|
+
@pdf.stubs(:fill_color)
|
281
|
+
@pdf.expects(:fill_color).with('123456')
|
282
|
+
@pdf.expects(:fill_rectangle).checking do |(x, y), w, h|
|
283
|
+
x.should.be.close(12.0, 0.01)
|
284
|
+
y.should.be.close(34.0, 0.01)
|
285
|
+
w.should.be.close(29.344, 0.01)
|
286
|
+
h.should.be.close(23.872, 0.01)
|
287
|
+
end
|
288
|
+
c = @pdf.make_cell(:content => "text", :background_color => '123456')
|
289
|
+
c.draw([12.0, 34.0])
|
290
|
+
end
|
233
291
|
end
|
234
292
|
|
235
293
|
describe "color" do
|
@@ -263,33 +321,94 @@ describe "Prawn::Table::Cell" do
|
|
263
321
|
# do any FP closeness arithmetic. Can plug in that math later if this goes
|
264
322
|
# wrong.
|
265
323
|
it "should draw top border when requested" do
|
266
|
-
@pdf.expects(:stroke_line).
|
267
|
-
|
268
|
-
|
269
|
-
|
324
|
+
@pdf.expects(:stroke_line).checking do |from, to|
|
325
|
+
@pdf.map_to_absolute(from).map{|x| x.round}.should == [36, 756]
|
326
|
+
@pdf.map_to_absolute(to).map{|x| x.round}.should == [65, 756]
|
327
|
+
end
|
270
328
|
@pdf.cell(:content => "text", :borders => [:top])
|
271
329
|
end
|
272
330
|
|
273
331
|
it "should draw bottom border when requested" do
|
274
|
-
@pdf.expects(:stroke_line).
|
275
|
-
|
276
|
-
|
332
|
+
@pdf.expects(:stroke_line).checking do |from, to|
|
333
|
+
@pdf.map_to_absolute(from).map{|x| x.round}.should == [36, 732]
|
334
|
+
@pdf.map_to_absolute(to).map{|x| x.round}.should == [65, 732]
|
335
|
+
end
|
277
336
|
@pdf.cell(:content => "text", :borders => [:bottom])
|
278
337
|
end
|
279
338
|
|
280
339
|
it "should draw left border when requested" do
|
281
|
-
@pdf.expects(:stroke_line).
|
282
|
-
|
283
|
-
|
340
|
+
@pdf.expects(:stroke_line).checking do |from, to|
|
341
|
+
@pdf.map_to_absolute(from).map{|x| x.round}.should == [36, 756]
|
342
|
+
@pdf.map_to_absolute(to).map{|x| x.round}.should == [36, 732]
|
343
|
+
end
|
284
344
|
@pdf.cell(:content => "text", :borders => [:left])
|
285
345
|
end
|
286
346
|
|
287
347
|
it "should draw right border when requested" do
|
288
|
-
@pdf.expects(:stroke_line).
|
289
|
-
|
290
|
-
|
348
|
+
@pdf.expects(:stroke_line).checking do |from, to|
|
349
|
+
@pdf.map_to_absolute(from).map{|x| x.round}.should == [65, 756]
|
350
|
+
@pdf.map_to_absolute(to).map{|x| x.round}.should == [65, 732]
|
351
|
+
end
|
291
352
|
@pdf.cell(:content => "text", :borders => [:right])
|
292
353
|
end
|
354
|
+
|
355
|
+
it "should draw borders at the same location when in or out of bbox" do
|
356
|
+
@pdf.expects(:stroke_line).checking do |from, to|
|
357
|
+
@pdf.map_to_absolute(from).map{|x| x.round}.should == [36, 756]
|
358
|
+
@pdf.map_to_absolute(to).map{|x| x.round}.should == [65, 756]
|
359
|
+
end
|
360
|
+
@pdf.bounding_box([0, @pdf.cursor], :width => @pdf.bounds.width) do
|
361
|
+
@pdf.cell(:content => "text", :borders => [:top])
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
it "should set border color with :border_..._color" do
|
366
|
+
@pdf.ignores(:stroke_color=).with("000000")
|
367
|
+
@pdf.expects(:stroke_color=).with("ff0000")
|
368
|
+
|
369
|
+
c = @pdf.cell(:content => "text", :border_top_color => "ff0000")
|
370
|
+
c.border_top_color.should == "ff0000"
|
371
|
+
c.border_colors[0].should == "ff0000"
|
372
|
+
end
|
373
|
+
|
374
|
+
it "should set border colors with :border_color" do
|
375
|
+
@pdf.ignores(:stroke_color=).with("000000")
|
376
|
+
@pdf.expects(:stroke_color=).with("ff0000")
|
377
|
+
@pdf.expects(:stroke_color=).with("00ff00")
|
378
|
+
@pdf.expects(:stroke_color=).with("0000ff")
|
379
|
+
@pdf.expects(:stroke_color=).with("ff00ff")
|
380
|
+
|
381
|
+
c = @pdf.cell(:content => "text",
|
382
|
+
:border_color => %w[ff0000 00ff00 0000ff ff00ff])
|
383
|
+
|
384
|
+
c.border_colors.should == %w[ff0000 00ff00 0000ff ff00ff]
|
385
|
+
end
|
386
|
+
|
387
|
+
it "border_..._width should return 0 if border not selected" do
|
388
|
+
c = @pdf.cell(:content => "text", :borders => [:top])
|
389
|
+
c.border_bottom_width.should == 0
|
390
|
+
end
|
391
|
+
|
392
|
+
it "should set border width with :border_..._width" do
|
393
|
+
@pdf.ignores(:line_width=).with(1)
|
394
|
+
@pdf.expects(:line_width=).with(2)
|
395
|
+
|
396
|
+
c = @pdf.cell(:content => "text", :border_bottom_width => 2)
|
397
|
+
c.border_bottom_width.should == 2
|
398
|
+
c.border_widths[2].should == 2
|
399
|
+
end
|
400
|
+
|
401
|
+
it "should set border widths with :border_width" do
|
402
|
+
@pdf.ignores(:line_width=).with(1)
|
403
|
+
@pdf.expects(:line_width=).with(2)
|
404
|
+
@pdf.expects(:line_width=).with(3)
|
405
|
+
@pdf.expects(:line_width=).with(4)
|
406
|
+
@pdf.expects(:line_width=).with(5)
|
407
|
+
|
408
|
+
c = @pdf.cell(:content => "text",
|
409
|
+
:border_width => [2, 3, 4, 5])
|
410
|
+
c.border_widths.should == [2, 3, 4, 5]
|
411
|
+
end
|
293
412
|
end
|
294
413
|
|
295
414
|
describe "Text cell attributes" do
|
@@ -300,8 +419,22 @@ describe "Prawn::Table::Cell" do
|
|
300
419
|
|
301
420
|
box = Prawn::Text::Box.new("text", :document => @pdf)
|
302
421
|
|
303
|
-
Prawn::Text::Box.expects(:new).
|
304
|
-
text == "text"
|
422
|
+
Prawn::Text::Box.expects(:new).checking do |text, options|
|
423
|
+
text.should == "text"
|
424
|
+
options[:align].should == :right
|
425
|
+
end.at_least_once.returns(box)
|
426
|
+
|
427
|
+
c.draw
|
428
|
+
end
|
429
|
+
|
430
|
+
it "should use font_style for Text::Box#style" do
|
431
|
+
c = cell(:content => "text", :font_style => :bold)
|
432
|
+
|
433
|
+
box = Prawn::Text::Box.new("text", :document => @pdf)
|
434
|
+
|
435
|
+
Prawn::Text::Box.expects(:new).checking do |text, options|
|
436
|
+
text.should == "text"
|
437
|
+
options[:style].should == :bold
|
305
438
|
end.at_least_once.returns(box)
|
306
439
|
|
307
440
|
c.draw
|
@@ -312,10 +445,15 @@ describe "Prawn::Table::Cell" do
|
|
312
445
|
|
313
446
|
box = Prawn::Text::Formatted::Box.new([], :document => @pdf)
|
314
447
|
|
315
|
-
Prawn::Text::Formatted::Box.expects(:new).
|
316
|
-
array[0][:text] == "foo "
|
317
|
-
|
318
|
-
|
448
|
+
Prawn::Text::Formatted::Box.expects(:new).checking do |array, options|
|
449
|
+
array[0][:text].should == "foo "
|
450
|
+
array[0][:styles].should == []
|
451
|
+
|
452
|
+
array[1][:text].should == "bar"
|
453
|
+
array[1][:styles].should == [:bold]
|
454
|
+
|
455
|
+
array[2][:text].should == " baz"
|
456
|
+
array[2][:styles].should == []
|
319
457
|
end.at_least_once.returns(box)
|
320
458
|
|
321
459
|
c.draw
|
@@ -326,9 +464,9 @@ describe "Prawn::Table::Cell" do
|
|
326
464
|
describe "Font handling" do
|
327
465
|
include CellHelpers
|
328
466
|
|
329
|
-
it "should allow only :
|
467
|
+
it "should allow only :font_style to be specified, defaulting to the " +
|
330
468
|
"document's font" do
|
331
|
-
c = cell(:content => "text", :
|
469
|
+
c = cell(:content => "text", :font_style => :bold)
|
332
470
|
c.font.name.should == 'Helvetica-Bold'
|
333
471
|
end
|
334
472
|
|
@@ -339,7 +477,7 @@ describe "Prawn::Table::Cell" do
|
|
339
477
|
|
340
478
|
it "should allow style to be changed after initialize" do
|
341
479
|
c = cell(:content => "text")
|
342
|
-
c.
|
480
|
+
c.font_style = :bold
|
343
481
|
c.font.name.should == 'Helvetica-Bold'
|
344
482
|
end
|
345
483
|
|
@@ -350,7 +488,7 @@ describe "Prawn::Table::Cell" do
|
|
350
488
|
|
351
489
|
it "should use the metrics of the selected font (even if it is a variant " +
|
352
490
|
"of the document's font) to calculate width" do
|
353
|
-
c = cell(:content => "text", :
|
491
|
+
c = cell(:content => "text", :font_style => :bold)
|
354
492
|
font = @pdf.find_font('Helvetica-Bold')
|
355
493
|
c.content_width.should == font.compute_width_of("text")
|
356
494
|
end
|