prawn 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +6 -10
- data/Rakefile +4 -13
- data/data/encodings/win_ansi.txt +29 -0
- data/data/images/fractal.jpg +0 -0
- data/data/images/letterhead.jpg +0 -0
- data/examples/bounding_box/bounding_boxes.rb +44 -0
- data/examples/bounding_box/lazy_bounding_boxes.rb +28 -0
- data/examples/bounding_box/padded_box.rb +24 -0
- data/examples/{russian_boxes.rb → bounding_box/russian_boxes.rb} +9 -6
- data/examples/general/background.rb +20 -0
- data/examples/{canvas.rb → general/canvas.rb} +6 -2
- data/examples/general/measurement_units.rb +52 -0
- data/examples/{multi_page_layout.rb → general/multi_page_layout.rb} +6 -3
- data/examples/{page_geometry.rb → general/page_geometry.rb} +6 -2
- data/examples/{image.rb → graphics/basic_images.rb} +8 -4
- data/examples/graphics/cmyk.rb +13 -0
- data/examples/graphics/curves.rb +12 -0
- data/examples/{hexagon.rb → graphics/hexagon.rb} +5 -5
- data/examples/graphics/image_fit.rb +16 -0
- data/examples/graphics/image_flow.rb +38 -0
- data/examples/graphics/image_position.rb +18 -0
- data/examples/{line.rb → graphics/line.rb} +4 -2
- data/examples/{png_types.rb → graphics/png_types.rb} +4 -4
- data/examples/{polygons.rb → graphics/polygons.rb} +5 -4
- data/examples/graphics/remote_images.rb +12 -0
- data/examples/{ruport_helpers.rb → graphics/ruport_style_helpers.rb} +8 -5
- data/examples/graphics/stroke_bounds.rb +23 -0
- data/examples/{chinese_text_wrapping.rb → m17n/chinese_text_wrapping.rb} +7 -4
- data/examples/m17n/euro.rb +16 -0
- data/examples/m17n/sjis.rb +29 -0
- data/examples/m17n/utf8.rb +14 -0
- data/examples/m17n/win_ansi_charset.rb +55 -0
- data/examples/{addressbook.csv → table/addressbook.csv} +0 -0
- data/examples/{cell.rb → table/cell.rb} +8 -6
- data/examples/{currency.csv → table/currency.csv} +0 -0
- data/examples/{fancy_table.rb → table/fancy_table.rb} +9 -6
- data/examples/{ruport_formatter.rb → table/ruport_formatter.rb} +6 -3
- data/examples/{table.rb → table/table.rb} +6 -2
- data/examples/table/table_alignment.rb +18 -0
- data/examples/table/table_border_color.rb +17 -0
- data/examples/table/table_colspan.rb +19 -0
- data/examples/table/table_header_color.rb +19 -0
- data/examples/table/table_header_underline.rb +15 -0
- data/examples/{alignment.rb → text/alignment.rb} +5 -2
- data/examples/text/family_based_styling.rb +25 -0
- data/examples/{flowing_text_with_header_and_footer.rb → text/flowing_text_with_header_and_footer.rb} +19 -8
- data/examples/text/font_calculations.rb +91 -0
- data/examples/text/font_size.rb +34 -0
- data/examples/{kerning.rb → text/kerning.rb} +5 -1
- data/examples/text/simple_text.rb +18 -0
- data/examples/text/simple_text_ttf.rb +18 -0
- data/examples/{span.rb → text/span.rb} +5 -2
- data/examples/text/text_box.rb +26 -0
- data/examples/{text_flow.rb → text/text_flow.rb} +5 -2
- data/lib/prawn.rb +26 -20
- data/lib/prawn/compatibility.rb +5 -8
- data/lib/prawn/document.rb +29 -13
- data/lib/prawn/document/annotations.rb +63 -0
- data/lib/prawn/document/bounding_box.rb +18 -3
- data/lib/prawn/document/destinations.rb +81 -0
- data/lib/prawn/document/internals.rb +16 -2
- data/lib/prawn/document/page_geometry.rb +58 -57
- data/lib/prawn/document/span.rb +8 -0
- data/lib/prawn/document/table.rb +81 -31
- data/lib/prawn/document/text.rb +66 -21
- data/lib/prawn/document/text/box.rb +77 -0
- data/lib/prawn/encoding.rb +121 -0
- data/lib/prawn/errors.rb +4 -0
- data/lib/prawn/font.rb +70 -42
- data/lib/prawn/font/metrics.rb +64 -119
- data/lib/prawn/graphics.rb +105 -87
- data/lib/prawn/graphics/cell.rb +55 -28
- data/lib/prawn/graphics/color.rb +8 -0
- data/lib/prawn/images.rb +55 -12
- data/lib/prawn/images/jpg.rb +2 -1
- data/lib/prawn/images/png.rb +2 -1
- data/lib/prawn/literal_string.rb +14 -0
- data/lib/prawn/measurement_extensions.rb +46 -0
- data/lib/prawn/measurements.rb +71 -0
- data/lib/prawn/name_tree.rb +165 -0
- data/lib/prawn/pdf_object.rb +8 -1
- data/spec/annotations_spec.rb +90 -0
- data/spec/destinations_spec.rb +15 -0
- data/spec/document_spec.rb +39 -2
- data/spec/font_spec.rb +22 -0
- data/spec/graphics_spec.rb +99 -87
- data/spec/images_spec.rb +29 -1
- data/spec/measurement_units_spec.rb +23 -0
- data/spec/metrics_spec.rb +3 -2
- data/spec/name_tree_spec.rb +103 -0
- data/spec/pdf_object_spec.rb +15 -5
- data/spec/png_spec.rb +14 -14
- data/spec/spec_helper.rb +8 -6
- data/spec/table_spec.rb +40 -0
- data/spec/text_spec.rb +6 -4
- data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
- data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
- data/vendor/ttfunk/example.rb +5 -0
- data/vendor/ttfunk/lib/ttfunk.rb +48 -0
- data/vendor/ttfunk/lib/ttfunk/table.rb +27 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +94 -0
- data/vendor/ttfunk/lib/ttfunk/table/directory.rb +25 -0
- data/vendor/ttfunk/lib/ttfunk/table/head.rb +25 -0
- data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +27 -0
- data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +20 -0
- data/vendor/ttfunk/lib/ttfunk/table/kern.rb +48 -0
- data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +17 -0
- data/vendor/ttfunk/lib/ttfunk/table/name.rb +52 -0
- metadata +93 -62
- data/examples/bounding_boxes.rb +0 -30
- data/examples/curves.rb +0 -10
- data/examples/family_based_styling.rb +0 -21
- data/examples/font_size.rb +0 -19
- data/examples/image2.rb +0 -13
- data/examples/image_flow.rb +0 -29
- data/examples/lazy_bounding_boxes.rb +0 -19
- data/examples/remote_images.rb +0 -7
- data/examples/simple_text.rb +0 -15
- data/examples/simple_text_ttf.rb +0 -16
- data/examples/sjis.rb +0 -21
- data/examples/utf8.rb +0 -12
- data/vendor/font_ttf/ttf.rb +0 -20
- data/vendor/font_ttf/ttf/datatypes.rb +0 -189
- data/vendor/font_ttf/ttf/encodings.rb +0 -140
- data/vendor/font_ttf/ttf/exceptions.rb +0 -28
- data/vendor/font_ttf/ttf/file.rb +0 -290
- data/vendor/font_ttf/ttf/fontchunk.rb +0 -77
- data/vendor/font_ttf/ttf/table/cmap.rb +0 -408
- data/vendor/font_ttf/ttf/table/cvt.rb +0 -49
- data/vendor/font_ttf/ttf/table/fpgm.rb +0 -48
- data/vendor/font_ttf/ttf/table/gasp.rb +0 -88
- data/vendor/font_ttf/ttf/table/glyf.rb +0 -452
- data/vendor/font_ttf/ttf/table/head.rb +0 -86
- data/vendor/font_ttf/ttf/table/hhea.rb +0 -96
- data/vendor/font_ttf/ttf/table/hmtx.rb +0 -98
- data/vendor/font_ttf/ttf/table/kern.rb +0 -186
- data/vendor/font_ttf/ttf/table/loca.rb +0 -75
- data/vendor/font_ttf/ttf/table/maxp.rb +0 -81
- data/vendor/font_ttf/ttf/table/name.rb +0 -222
- data/vendor/font_ttf/ttf/table/os2.rb +0 -172
- data/vendor/font_ttf/ttf/table/post.rb +0 -120
- data/vendor/font_ttf/ttf/table/prep.rb +0 -27
- data/vendor/font_ttf/ttf/table/vhea.rb +0 -45
- data/vendor/font_ttf/ttf/table/vmtx.rb +0 -36
data/spec/images_spec.rb
CHANGED
@@ -17,7 +17,6 @@ describe "the image() function" do
|
|
17
17
|
images = PDF::Inspector::XObject.analyze(output)
|
18
18
|
# there should be 2 images in the page resources
|
19
19
|
images.page_xobjects.first.size.should == 2
|
20
|
-
|
21
20
|
# but only 1 image xobject
|
22
21
|
output.scan(/\/Type \/XObject/).size.should == 1
|
23
22
|
end
|
@@ -36,5 +35,34 @@ describe "the image() function" do
|
|
36
35
|
|
37
36
|
info.height.should == 453
|
38
37
|
end
|
38
|
+
|
39
|
+
describe ":fit option" do
|
40
|
+
it "should fit inside the defined constraints" do
|
41
|
+
info = @pdf.image @filename, :fit => [100,400]
|
42
|
+
info.scaled_width.should <= 100
|
43
|
+
info.scaled_height.should <= 400
|
44
|
+
|
45
|
+
info = @pdf.image @filename, :fit => [400,100]
|
46
|
+
info.scaled_width.should <= 400
|
47
|
+
info.scaled_height.should <= 100
|
48
|
+
|
49
|
+
info = @pdf.image @filename, :fit => [604,453]
|
50
|
+
info.scaled_width.should == 604
|
51
|
+
info.scaled_height.should == 453
|
52
|
+
end
|
53
|
+
it "should move text position" do
|
54
|
+
@y = @pdf.y
|
55
|
+
info = @pdf.image @filename, :fit => [100,400]
|
56
|
+
@pdf.y.should < @y
|
57
|
+
end
|
58
|
+
end
|
59
|
+
describe ":at option" do
|
60
|
+
it "should not move text position" do
|
61
|
+
@y = @pdf.y
|
62
|
+
info = @pdf.image @filename, :at => [100,400]
|
63
|
+
@pdf.y.should == @y
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
39
67
|
end
|
40
68
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
2
|
+
require "prawn/measurement_extensions"
|
3
|
+
|
4
|
+
describe "Measurement units" do
|
5
|
+
|
6
|
+
it "should convert units to PostScriptPoints" do
|
7
|
+
1.mm.should.be.close(2.834645669, 0.000000001)
|
8
|
+
1.mm.should == (72 / 25.4)
|
9
|
+
2.mm.should == (2 * 72 / 25.4)
|
10
|
+
3.mm.should == 3 * 72 / 25.4
|
11
|
+
-3.mm.should == -3 * 72/25.4
|
12
|
+
1.cm.should == 10 * 72 / 25.4
|
13
|
+
1.dm.should == 100 * 72 / 25.4
|
14
|
+
1.m.should == 1000 * 72 / 25.4
|
15
|
+
|
16
|
+
1.in.should == 72
|
17
|
+
1.ft.should == 72 * 12
|
18
|
+
1.yd.should == 72 * 12 * 3
|
19
|
+
1.pt.should == 1
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
data/spec/metrics_spec.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
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
|
+
require "iconv"
|
4
5
|
|
5
6
|
describe "adobe font metrics" do
|
6
7
|
|
7
8
|
setup do
|
8
9
|
@times = Prawn::Font::Metrics["Times-Roman"]
|
9
|
-
@iconv = Iconv.new('ISO-8859-1', 'utf-8')
|
10
|
+
@iconv = ::Iconv.new('ISO-8859-1', 'utf-8')
|
10
11
|
end
|
11
12
|
|
12
13
|
it "should calculate string width taking into account accented characters" do
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
2
|
+
|
3
|
+
def tree_dump(tree)
|
4
|
+
if tree.is_a?(Prawn::NameTree::Node)
|
5
|
+
"[" + tree.children.map { |child| tree_dump(child) }.join(",") + "]"
|
6
|
+
else
|
7
|
+
"#{tree.name}=#{tree.value}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def tree_add(tree, *args)
|
12
|
+
args.each do |(name, value)|
|
13
|
+
tree.add(name, value)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def tree_value(name, value)
|
18
|
+
Prawn::NameTree::Value.new(name, value)
|
19
|
+
end
|
20
|
+
|
21
|
+
class RefExposingDocument < Prawn::Document
|
22
|
+
attr_reader :objects
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "Name Tree" do
|
26
|
+
before(:each) { create_pdf(RefExposingDocument) }
|
27
|
+
|
28
|
+
it "should have no children when first initialized" do
|
29
|
+
node = Prawn::NameTree::Node.new(@pdf, 3)
|
30
|
+
node.children.length.should == 0
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should have no subtrees while child limit is not reached" do
|
34
|
+
node = Prawn::NameTree::Node.new(@pdf, 3)
|
35
|
+
tree_add(node, ["one", 1], ["two", 2], ["three", 3])
|
36
|
+
tree_dump(node).should == "[one=1,three=3,two=2]"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should split into subtrees when limit is exceeded" do
|
40
|
+
node = Prawn::NameTree::Node.new(@pdf, 3)
|
41
|
+
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
42
|
+
tree_dump(node).should == "[[four=4,one=1],[three=3,two=2]]"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should create a two new references when root is split" do
|
46
|
+
ref_count = @pdf.objects.length
|
47
|
+
node = Prawn::NameTree::Node.new(@pdf, 3)
|
48
|
+
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
49
|
+
@pdf.objects.length.should.equal ref_count+2
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should create a one new reference when subtree is split" do
|
53
|
+
node = Prawn::NameTree::Node.new(@pdf, 3)
|
54
|
+
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
55
|
+
|
56
|
+
ref_count = @pdf.objects.length # save when root is split
|
57
|
+
tree_add(node, ["five", 5], ["six", 6], ["seven", 7])
|
58
|
+
tree_dump(node).should == "[[five=5,four=4,one=1],[seven=7,six=6],[three=3,two=2]]"
|
59
|
+
@pdf.objects.length.should.equal ref_count+1
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should keep tree balanced when subtree split cascades to root" do
|
63
|
+
node = Prawn::NameTree::Node.new(@pdf, 3)
|
64
|
+
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
65
|
+
tree_add(node, ["five", 5], ["six", 6], ["seven", 7], ["eight", 8])
|
66
|
+
tree_dump(node).should == "[[[eight=8,five=5],[four=4,one=1]],[[seven=7,six=6],[three=3,two=2]]]"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should emit only :Names key with to_hash if root is only node" do
|
70
|
+
node = Prawn::NameTree::Node.new(@pdf, 3)
|
71
|
+
tree_add(node, ["one", 1], ["two", 2], ["three", 3])
|
72
|
+
node.to_hash.should.equal(
|
73
|
+
{ :Names => [tree_value("one", 1), tree_value("three", 3), tree_value("two", 2)] }
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should emit only :Kids key with to_hash if root has children" do
|
78
|
+
node = Prawn::NameTree::Node.new(@pdf, 3)
|
79
|
+
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
80
|
+
node.to_hash.should.equal({ :Kids => node.children.map { |child| child.ref } })
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should emit :Limits and :Names keys with to_hash for leaf node" do
|
84
|
+
node = Prawn::NameTree::Node.new(@pdf, 3)
|
85
|
+
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
86
|
+
node.children.first.to_hash.should.equal(
|
87
|
+
{ :Limits => %w(four one),
|
88
|
+
:Names => [tree_value("four", 4), tree_value("one", 1)] }
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should emit :Limits and :Kids keys with to_hash for inner node" do
|
93
|
+
node = Prawn::NameTree::Node.new(@pdf, 3)
|
94
|
+
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
95
|
+
tree_add(node, ["five", 5], ["six", 6], ["seven", 7], ["eight", 8])
|
96
|
+
tree_add(node, ["nine", 9], ["ten", 10], ["eleven", 11], ["twelve", 12])
|
97
|
+
tree_add(node, ["thirteen", 13], ["fourteen", 14], ["fifteen", 15], ["sixteen", 16])
|
98
|
+
node.children.first.to_hash.should.equal(
|
99
|
+
{ :Limits => %w(eight one),
|
100
|
+
:Kids => node.children.first.children.map { |child| child.ref } }
|
101
|
+
)
|
102
|
+
end
|
103
|
+
end
|
data/spec/pdf_object_spec.rb
CHANGED
@@ -58,14 +58,15 @@ describe "PDF Object Serialization" do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should convert a Ruby array to PDF Array when outside a content stream" do
|
61
|
+
bar = "\xFE\xFF" + "Bar".unpack("U*").pack("n*")
|
61
62
|
Prawn::PdfObject([1,2,3]).should == "[1 2 3]"
|
62
63
|
PDF::Inspector.parse(Prawn::PdfObject([[1,2],:foo,"Bar"], false)).should ==
|
63
|
-
[[1,2],:foo,
|
64
|
+
[[1,2],:foo, bar]
|
64
65
|
end
|
65
66
|
|
66
67
|
it "should convert a Ruby hash to a PDF Dictionary when inside a content stream" do
|
67
68
|
dict = Prawn::PdfObject( {:foo => :bar,
|
68
|
-
"baz"
|
69
|
+
"baz" => [1,2,3],
|
69
70
|
:bang => {:a => "what", :b => [:you, :say] }}, true )
|
70
71
|
|
71
72
|
res = PDF::Inspector.parse(dict)
|
@@ -77,15 +78,16 @@ describe "PDF Object Serialization" do
|
|
77
78
|
end
|
78
79
|
|
79
80
|
it "should convert a Ruby hash to a PDF Dictionary when outside a content stream" do
|
81
|
+
what = "\xFE\xFF" + "what".unpack("U*").pack("n*")
|
80
82
|
dict = Prawn::PdfObject( {:foo => :bar,
|
81
|
-
"baz"
|
83
|
+
"baz" => [1,2,3],
|
82
84
|
:bang => {:a => "what", :b => [:you, :say] }}, false )
|
83
85
|
|
84
86
|
res = PDF::Inspector.parse(dict)
|
85
87
|
|
86
88
|
res[:foo].should == :bar
|
87
89
|
res[:baz].should == [1,2,3]
|
88
|
-
res[:bang].should == { :a =>
|
90
|
+
res[:bang].should == { :a => what, :b => [:you, :say] }
|
89
91
|
|
90
92
|
end
|
91
93
|
|
@@ -98,5 +100,13 @@ describe "PDF Object Serialization" do
|
|
98
100
|
ref = Prawn::Reference(1,true)
|
99
101
|
Prawn::PdfObject(ref).should == ref.to_s
|
100
102
|
end
|
101
|
-
|
103
|
+
|
104
|
+
it "should convert a NameTree::Node to a PDF hash" do
|
105
|
+
node = Prawn::NameTree::Node.new(Prawn::Document.new, 10)
|
106
|
+
node.add "hello", 1.0
|
107
|
+
node.add "world", 2.0
|
108
|
+
data = Prawn::PdfObject(node)
|
109
|
+
res = PDF::Inspector.parse(data)
|
110
|
+
res.should == {:Names => ["hello", 1.0, "world", 2.0]}
|
111
|
+
end
|
102
112
|
end
|
data/spec/png_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe "When reading a greyscale PNG file (color type 0)" do
|
|
14
14
|
before(:each) do
|
15
15
|
@filename = "#{Prawn::BASEDIR}/data/images/web-links.png"
|
16
16
|
@data_filename = "#{Prawn::BASEDIR}/data/images/web-links.dat"
|
17
|
-
@img_data = File.
|
17
|
+
@img_data = File.binread(@filename)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should read the attributes from the header chunk correctly" do
|
@@ -31,7 +31,7 @@ describe "When reading a greyscale PNG file (color type 0)" do
|
|
31
31
|
|
32
32
|
it "should read the image data chunk correctly" do
|
33
33
|
png = Prawn::Images::PNG.new(@img_data)
|
34
|
-
data = File.
|
34
|
+
data = File.binread(@data_filename)
|
35
35
|
png.img_data.should == data
|
36
36
|
end
|
37
37
|
end
|
@@ -40,7 +40,7 @@ describe "When reading a greyscale PNG file with transparency (color type 0)" do
|
|
40
40
|
|
41
41
|
before(:each) do
|
42
42
|
@filename = "#{Prawn::BASEDIR}/data/images/ruport_type0.png"
|
43
|
-
@img_data = File.
|
43
|
+
@img_data = File.binread(@filename)
|
44
44
|
end
|
45
45
|
|
46
46
|
# In a greyscale type 0 PNG image, the tRNS chunk should contain a single value
|
@@ -58,7 +58,7 @@ describe "When reading an RGB PNG file (color type 2)" do
|
|
58
58
|
before(:each) do
|
59
59
|
@filename = "#{Prawn::BASEDIR}/data/images/ruport.png"
|
60
60
|
@data_filename = "#{Prawn::BASEDIR}/data/images/ruport_data.dat"
|
61
|
-
@img_data = File.
|
61
|
+
@img_data = File.binread(@filename)
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should read the attributes from the header chunk correctly" do
|
@@ -75,7 +75,7 @@ describe "When reading an RGB PNG file (color type 2)" do
|
|
75
75
|
|
76
76
|
it "should read the image data chunk correctly" do
|
77
77
|
png = Prawn::Images::PNG.new(@img_data)
|
78
|
-
data = File.
|
78
|
+
data = File.binread(@data_filename)
|
79
79
|
png.img_data.should == data
|
80
80
|
end
|
81
81
|
end
|
@@ -84,7 +84,7 @@ describe "When reading an RGB PNG file with transparency (color type 2)" do
|
|
84
84
|
|
85
85
|
before(:each) do
|
86
86
|
@filename = "#{Prawn::BASEDIR}/data/images/arrow2.png"
|
87
|
-
@img_data = File.
|
87
|
+
@img_data = File.binread(@filename)
|
88
88
|
end
|
89
89
|
|
90
90
|
# In a RGB type 2 PNG image, the tRNS chunk should contain a single RGB value
|
@@ -105,7 +105,7 @@ describe "When reading an indexed color PNG file (color type 3)" do
|
|
105
105
|
before(:each) do
|
106
106
|
@filename = "#{Prawn::BASEDIR}/data/images/rails.png"
|
107
107
|
@data_filename = "#{Prawn::BASEDIR}/data/images/rails.dat"
|
108
|
-
@img_data = File.
|
108
|
+
@img_data = File.binread(@filename)
|
109
109
|
end
|
110
110
|
|
111
111
|
it "should read the attributes from the header chunk correctly" do
|
@@ -122,7 +122,7 @@ describe "When reading an indexed color PNG file (color type 3)" do
|
|
122
122
|
|
123
123
|
it "should read the image data chunk correctly" do
|
124
124
|
png = Prawn::Images::PNG.new(@img_data)
|
125
|
-
data = File.
|
125
|
+
data = File.binread(@data_filename)
|
126
126
|
png.img_data.should == data
|
127
127
|
end
|
128
128
|
end
|
@@ -133,7 +133,7 @@ describe "When reading a greyscale+alpha PNG file (color type 4)" do
|
|
133
133
|
@filename = "#{Prawn::BASEDIR}/data/images/page_white_text.png"
|
134
134
|
@data_filename = "#{Prawn::BASEDIR}/data/images/page_white_text.dat"
|
135
135
|
@alpha_data_filename = "#{Prawn::BASEDIR}/data/images/page_white_text.alpha"
|
136
|
-
@img_data = File.
|
136
|
+
@img_data = File.binread(@filename)
|
137
137
|
end
|
138
138
|
|
139
139
|
it "should read the attributes from the header chunk correctly" do
|
@@ -150,13 +150,13 @@ describe "When reading a greyscale+alpha PNG file (color type 4)" do
|
|
150
150
|
|
151
151
|
it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
|
152
152
|
png = Prawn::Images::PNG.new(@img_data)
|
153
|
-
data = File.
|
153
|
+
data = File.binread(@data_filename)
|
154
154
|
png.img_data.should == data
|
155
155
|
end
|
156
156
|
|
157
157
|
it "should correctly extract the alpha channel data from the image data chunk" do
|
158
158
|
png = Prawn::Images::PNG.new(@img_data)
|
159
|
-
data = File.
|
159
|
+
data = File.binread(@alpha_data_filename)
|
160
160
|
png.alpha_channel.should == data
|
161
161
|
end
|
162
162
|
end
|
@@ -167,7 +167,7 @@ describe "When reading an RGB+alpha PNG file (color type 6)" do
|
|
167
167
|
@filename = "#{Prawn::BASEDIR}/data/images/dice.png"
|
168
168
|
@data_filename = "#{Prawn::BASEDIR}/data/images/dice.dat"
|
169
169
|
@alpha_data_filename = "#{Prawn::BASEDIR}/data/images/dice.alpha"
|
170
|
-
@img_data = File.
|
170
|
+
@img_data = File.binread(@filename)
|
171
171
|
end
|
172
172
|
|
173
173
|
it "should read the attributes from the header chunk correctly" do
|
@@ -184,13 +184,13 @@ describe "When reading an RGB+alpha PNG file (color type 6)" do
|
|
184
184
|
|
185
185
|
it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
|
186
186
|
png = Prawn::Images::PNG.new(@img_data)
|
187
|
-
data = File.
|
187
|
+
data = File.binread(@data_filename)
|
188
188
|
png.img_data.should == data
|
189
189
|
end
|
190
190
|
|
191
191
|
it "should correctly extract the alpha channel data from the image data chunk" do
|
192
192
|
png = Prawn::Images::PNG.new(@img_data)
|
193
|
-
data = File.
|
193
|
+
data = File.binread(@alpha_data_filename)
|
194
194
|
png.alpha_channel.should == data
|
195
195
|
end
|
196
196
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,13 +9,15 @@ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
|
9
9
|
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'vendor','pdf-inspector','lib')
|
10
10
|
require "prawn"
|
11
11
|
|
12
|
+
Prawn.debug = true
|
13
|
+
|
12
14
|
gem 'pdf-reader', ">=0.7.3"
|
13
15
|
require "pdf/reader"
|
14
16
|
require "pdf/inspector"
|
15
17
|
|
16
|
-
def create_pdf
|
17
|
-
@pdf =
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
18
|
+
def create_pdf(klass=Prawn::Document)
|
19
|
+
@pdf = klass.new(:left_margin => 0,
|
20
|
+
:right_margin => 0,
|
21
|
+
:top_margin => 0,
|
22
|
+
:bottom_margin => 0)
|
23
|
+
end
|
data/spec/table_spec.rb
CHANGED
@@ -75,6 +75,29 @@ end
|
|
75
75
|
|
76
76
|
describe "A table's content" do
|
77
77
|
|
78
|
+
it "should not cause an error if rendering the very first row causes a page break" do
|
79
|
+
Prawn::Document.new( :page_layout => :portrait ) do
|
80
|
+
arr = Array(1..5).collect{|i| ["cell #{i}"] }
|
81
|
+
|
82
|
+
move_down( y - (bounds.absolute_bottom + 3) )
|
83
|
+
|
84
|
+
lambda {
|
85
|
+
table( arr,
|
86
|
+
:font_size => 9,
|
87
|
+
:horizontal_padding => 3,
|
88
|
+
:vertical_padding => 3,
|
89
|
+
:border_width => 0.05,
|
90
|
+
:border_style => :none,
|
91
|
+
:row_colors => %w{ffffff eeeeee},
|
92
|
+
:widths => {0 =>110},
|
93
|
+
:position => :left,
|
94
|
+
:headers => ["exploding header"],
|
95
|
+
:align => :left,
|
96
|
+
:align_headers => :center)
|
97
|
+
}.should.not.raise
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
78
101
|
it "should output content cell by cell, row by row" do
|
79
102
|
data = [["foo","bar"],["baz","bang"]]
|
80
103
|
@pdf = Prawn::Document.new
|
@@ -136,4 +159,21 @@ describe "An invalid table" do
|
|
136
159
|
@pdf.table(@bad_data)
|
137
160
|
end
|
138
161
|
end
|
162
|
+
|
163
|
+
it "should raise an EmptyTableError with empty table data" do
|
164
|
+
lambda {
|
165
|
+
data = []
|
166
|
+
@pdf = Prawn::Document.new
|
167
|
+
@pdf.table(data)
|
168
|
+
}.should.raise( Prawn::Errors::EmptyTable )
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should raise an EmptyTableError with nil table data" do
|
172
|
+
lambda {
|
173
|
+
data = nil
|
174
|
+
@pdf = Prawn::Document.new
|
175
|
+
@pdf.table(data)
|
176
|
+
}.should.raise( Prawn::Errors::EmptyTable )
|
177
|
+
end
|
178
|
+
|
139
179
|
end
|
data/spec/text_spec.rb
CHANGED
@@ -112,23 +112,25 @@ describe "when drawing text" do
|
|
112
112
|
it "should raise an exception when a utf-8 incompatible string is rendered" do
|
113
113
|
str = "Blah \xDD"
|
114
114
|
str.force_encoding("ASCII-8BIT")
|
115
|
-
lambda { @pdf.text str }.should.raise(
|
115
|
+
lambda { @pdf.text str }.should.raise(ArgumentError)
|
116
116
|
end
|
117
117
|
it "should not raise an exception when a shift-jis string is rendered" do
|
118
|
+
puts "\nFIXME: SJIS not working on 1.9 right now due to TTFunk issue"
|
119
|
+
return
|
118
120
|
datafile = "#{Prawn::BASEDIR}/data/shift_jis_text.txt"
|
119
121
|
sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets }
|
120
122
|
@pdf.font("#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf")
|
121
|
-
lambda { @pdf.text sjis_str }.should.not.raise(
|
123
|
+
lambda { @pdf.text sjis_str }.should.not.raise(ArgumentError)
|
122
124
|
end
|
123
125
|
else
|
124
126
|
# Handle non utf-8 string encodings in a sane way on non-M17N aware VMs
|
125
127
|
it "should raise an exception when a corrupt utf-8 string is rendered" do
|
126
128
|
str = "Blah \xDD"
|
127
|
-
lambda { @pdf.text str }.should.raise(
|
129
|
+
lambda { @pdf.text str }.should.raise(ArgumentError)
|
128
130
|
end
|
129
131
|
it "should raise an exception when a shift-jis string is rendered" do
|
130
132
|
sjis_str = File.read("#{Prawn::BASEDIR}/data/shift_jis_text.txt")
|
131
|
-
lambda { @pdf.text sjis_str }.should.raise(
|
133
|
+
lambda { @pdf.text sjis_str }.should.raise(ArgumentError)
|
132
134
|
end
|
133
135
|
end
|
134
136
|
|