prawn 0.1.2 → 0.2.0
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/README +16 -2
- data/Rakefile +3 -3
- data/data/images/arrow.png +0 -0
- data/data/images/arrow2.png +0 -0
- data/data/images/barcode_issue.png +0 -0
- data/data/images/ruport_type0.png +0 -0
- data/examples/cell.rb +14 -3
- data/examples/chinese_text_wrapping.rb +17 -0
- data/examples/family_based_styling.rb +21 -0
- data/examples/fancy_table.rb +4 -4
- data/examples/flowing_text_with_header_and_footer.rb +72 -0
- data/examples/font_size.rb +2 -2
- data/examples/lazy_bounding_boxes.rb +19 -0
- data/examples/table.rb +13 -11
- data/examples/text_flow.rb +1 -1
- data/lib/prawn.rb +44 -15
- data/lib/prawn/compatibility.rb +20 -7
- data/lib/prawn/document.rb +72 -122
- data/lib/prawn/document/bounding_box.rb +124 -24
- data/lib/prawn/document/internals.rb +107 -0
- data/lib/prawn/document/table.rb +99 -70
- data/lib/prawn/document/text.rb +92 -314
- data/lib/prawn/errors.rb +13 -2
- data/lib/prawn/font.rb +312 -1
- data/lib/prawn/font/cmap.rb +1 -1
- data/lib/prawn/font/metrics.rb +52 -49
- data/lib/prawn/font/wrapping.rb +14 -12
- data/lib/prawn/graphics.rb +23 -74
- data/lib/prawn/graphics/cell.rb +30 -25
- data/lib/prawn/graphics/color.rb +132 -0
- data/lib/prawn/images.rb +37 -16
- data/lib/prawn/images/png.rb +29 -24
- data/lib/prawn/pdf_object.rb +3 -1
- data/spec/bounding_box_spec.rb +12 -3
- data/spec/document_spec.rb +40 -72
- data/spec/font_spec.rb +97 -0
- data/spec/graphics_spec.rb +46 -99
- data/spec/images_spec.rb +4 -21
- data/spec/pdf_object_spec.rb +8 -8
- data/spec/png_spec.rb +47 -12
- data/spec/spec_helper.rb +5 -24
- data/spec/table_spec.rb +53 -59
- data/spec/text_spec.rb +28 -93
- data/vendor/pdf-inspector/README +18 -0
- data/vendor/pdf-inspector/lib/pdf/inspector.rb +25 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +80 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/page.rb +16 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/text.rb +31 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/xobject.rb +19 -0
- metadata +63 -38
- data/examples/on_page_start.rb +0 -17
- data/examples/table_bench.rb +0 -92
- data/spec/box_calculation_spec.rb +0 -17
data/spec/graphics_spec.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
-
|
5
|
-
class LineDrawingObserver
|
6
|
-
attr_accessor :points, :strokes
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@points = []
|
10
|
-
end
|
11
|
-
|
12
|
-
def append_line(*params)
|
13
|
-
@points << params
|
14
|
-
end
|
15
|
-
|
16
|
-
def begin_new_subpath(*params)
|
17
|
-
@points << params
|
18
|
-
end
|
19
4
|
|
20
|
-
end
|
21
|
-
|
22
5
|
describe "When drawing a line" do
|
23
6
|
|
24
7
|
before(:each) { create_pdf }
|
@@ -26,35 +9,48 @@ describe "When drawing a line" do
|
|
26
9
|
it "should draw a line from (100,600) to (100,500)" do
|
27
10
|
@pdf.line([100,600],[100,500])
|
28
11
|
|
29
|
-
line_drawing =
|
12
|
+
line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
30
13
|
|
31
14
|
line_drawing.points.should == [[100,600],[100,500]]
|
32
15
|
end
|
33
16
|
|
34
|
-
it "should draw two lines (100,600) to (100,500)
|
17
|
+
it "should draw two lines at (100,600) to (100,500) " +
|
35
18
|
"and (75,100) to (50,125)" do
|
36
19
|
@pdf.line(100,600,100,500)
|
37
20
|
@pdf.line(75,100,50,125)
|
38
21
|
|
39
|
-
line_drawing =
|
22
|
+
line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
40
23
|
|
41
24
|
line_drawing.points.should ==
|
42
25
|
[[100.0, 600.0], [100.0, 500.0], [75.0, 100.0], [50.0, 125.0]]
|
43
26
|
end
|
27
|
+
|
28
|
+
it "should properly set line width via line_width=" do
|
29
|
+
@pdf.line_width = 10
|
30
|
+
line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
31
|
+
line.widths.first.should == 10
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should properly set line width via line_width(width)" do
|
35
|
+
@pdf.line_width(10)
|
36
|
+
line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
37
|
+
line.widths.first.should == 10
|
38
|
+
end
|
44
39
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
@
|
40
|
+
describe "(Horizontally)" do
|
41
|
+
|
42
|
+
before :each do
|
43
|
+
@pdf = Prawn::Document.new
|
44
|
+
@pdf.horizontal_line(100,150)
|
45
|
+
@line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
49
46
|
end
|
47
|
+
|
48
|
+
it "should draw from [x1,pdf.y],[x2,pdf.y]" do
|
49
|
+
@line.points.should == [[100.0 + @pdf.bounds.absolute_left, @pdf.y],
|
50
|
+
[150.0 + @pdf.bounds.absolute_left, @pdf.y]]
|
51
|
+
end
|
52
|
+
|
50
53
|
end
|
51
|
-
|
52
|
-
it "should properly set line width" do
|
53
|
-
create_pdf
|
54
|
-
@pdf.line_width = 10
|
55
|
-
line = observer(LineWidthReader)
|
56
|
-
line.width.should == 10
|
57
|
-
end
|
58
54
|
|
59
55
|
end
|
60
56
|
|
@@ -65,23 +61,12 @@ describe "When drawing a polygon" do
|
|
65
61
|
it "should draw each line passed to polygon()" do
|
66
62
|
@pdf.polygon([100,500],[100,400],[200,400])
|
67
63
|
|
68
|
-
line_drawing =
|
64
|
+
line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
69
65
|
line_drawing.points.should == [[100,500],[100,400],[200,400],[100,500]]
|
70
66
|
end
|
71
67
|
|
72
68
|
end
|
73
69
|
|
74
|
-
class RectangleDrawingObserver
|
75
|
-
|
76
|
-
attr_reader :point, :width, :height
|
77
|
-
|
78
|
-
def append_rectangle(*params)
|
79
|
-
@point = params[0..1]
|
80
|
-
@width = params[2]
|
81
|
-
@height = params[3]
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
70
|
describe "When drawing a rectangle" do
|
86
71
|
|
87
72
|
before(:each) { create_pdf }
|
@@ -89,33 +74,16 @@ describe "When drawing a rectangle" do
|
|
89
74
|
it "should use a point, width, and height for coords" do
|
90
75
|
@pdf.rectangle [200,200], 50, 100
|
91
76
|
|
92
|
-
|
77
|
+
rectangles = PDF::Inspector::Graphics::Rectangle.
|
78
|
+
analyze(@pdf.render).rectangles
|
93
79
|
# PDF uses bottom left corner
|
94
|
-
|
95
|
-
|
96
|
-
|
80
|
+
rectangles[0][:point].should == [200,100]
|
81
|
+
rectangles[0][:width].should == 50
|
82
|
+
rectangles[0][:height].should == 100
|
97
83
|
|
98
84
|
end
|
99
85
|
|
100
|
-
end
|
101
|
-
|
102
|
-
class CurveObserver
|
103
|
-
|
104
|
-
attr_reader :coords
|
105
|
-
|
106
|
-
def initialize
|
107
|
-
@coords = []
|
108
|
-
end
|
109
|
-
|
110
|
-
def begin_new_subpath(*params)
|
111
|
-
@coords += params
|
112
|
-
end
|
113
|
-
|
114
|
-
def append_curved_segment(*params)
|
115
|
-
@coords += params
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
86
|
+
end
|
119
87
|
|
120
88
|
describe "When drawing a curve" do
|
121
89
|
|
@@ -124,13 +92,13 @@ describe "When drawing a curve" do
|
|
124
92
|
it "should draw a bezier curve from 50,50 to 100,100" do
|
125
93
|
@pdf.move_to [50,50]
|
126
94
|
@pdf.curve_to [100,100],:bounds => [[20,90], [90,70]]
|
127
|
-
curve =
|
95
|
+
curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
128
96
|
curve.coords.should == [50.0, 50.0, 20.0, 90.0, 90.0, 70.0, 100.0, 100.0]
|
129
97
|
end
|
130
98
|
|
131
99
|
it "should draw a bezier curve from 100,100 to 50,50" do
|
132
100
|
@pdf.curve [100,100], [50,50], :bounds => [[20,90], [90,75]]
|
133
|
-
curve =
|
101
|
+
curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
134
102
|
curve.coords.should == [100.0, 100.0, 20.0, 90.0, 90.0, 75.0, 50.0, 50.0]
|
135
103
|
end
|
136
104
|
|
@@ -140,21 +108,21 @@ describe "When drawing an ellipse" do
|
|
140
108
|
before(:each) do
|
141
109
|
create_pdf
|
142
110
|
@pdf.ellipse_at [100,100], 25, 50
|
143
|
-
@curve =
|
111
|
+
@curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
144
112
|
end
|
145
113
|
|
146
114
|
it "should move the pointer to the center of the ellipse after drawing" do
|
147
115
|
@curve.coords[-2..-1].should == [100,100]
|
148
116
|
end
|
149
117
|
|
150
|
-
end
|
118
|
+
end
|
151
119
|
|
152
120
|
describe "When drawing a circle" do
|
153
121
|
before(:each) do
|
154
122
|
create_pdf
|
155
123
|
@pdf.circle_at [100,100], :radius => 25
|
156
124
|
@pdf.ellipse_at [100,100], 25, 25
|
157
|
-
@curve =
|
125
|
+
@curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
158
126
|
end
|
159
127
|
|
160
128
|
it "should stroke the same path as the equivalent ellipse" do
|
@@ -163,66 +131,45 @@ describe "When drawing a circle" do
|
|
163
131
|
end
|
164
132
|
end
|
165
133
|
|
166
|
-
class ColorObserver
|
167
|
-
attr_reader :stroke_color, :fill_color, :stroke_color_count,
|
168
|
-
:fill_color_count
|
169
|
-
|
170
|
-
def initialize
|
171
|
-
@stroke_color_count = 0
|
172
|
-
@fill_color_count = 0
|
173
|
-
end
|
174
|
-
|
175
|
-
def set_rgb_color_for_stroking(*params)
|
176
|
-
@stroke_color_count += 1
|
177
|
-
@stroke_color = params
|
178
|
-
end
|
179
|
-
|
180
|
-
def set_rgb_color_for_nonstroking(*params)
|
181
|
-
@fill_color_count += 1
|
182
|
-
@fill_color = params
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
134
|
describe "When setting colors" do
|
187
135
|
|
188
136
|
before(:each) { create_pdf }
|
189
137
|
|
190
138
|
it "should set stroke colors" do
|
191
139
|
@pdf.stroke_color "ffcccc"
|
192
|
-
colors =
|
140
|
+
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
193
141
|
# 100% red, 80% green, 80% blue
|
194
142
|
colors.stroke_color.should == [1.0, 0.8, 0.8]
|
195
143
|
end
|
196
144
|
|
197
145
|
it "should set fill colors" do
|
198
146
|
@pdf.fill_color "ccff00"
|
199
|
-
colors =
|
147
|
+
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
200
148
|
# 80% red, 100% green, 0% blue
|
201
149
|
colors.fill_color.should == [0.8,1.0,0]
|
202
150
|
end
|
203
151
|
|
204
152
|
it "should reset the colors on each new page if they have been defined" do
|
205
153
|
@pdf.fill_color "ccff00"
|
206
|
-
colors =
|
154
|
+
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
207
155
|
|
208
156
|
colors.fill_color_count.should == 2
|
209
157
|
colors.stroke_color_count.should == 1
|
210
158
|
@pdf.start_new_page
|
211
159
|
@pdf.stroke_color "ff00cc"
|
212
160
|
|
213
|
-
colors =
|
161
|
+
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
214
162
|
colors.fill_color_count.should == 3
|
215
163
|
colors.stroke_color_count.should == 3
|
216
164
|
|
217
165
|
@pdf.start_new_page
|
218
|
-
colors =
|
166
|
+
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
219
167
|
colors.fill_color_count.should == 4
|
220
168
|
colors.stroke_color_count.should == 4
|
221
169
|
|
222
170
|
colors.fill_color.should == [0.8,1.0,0.0]
|
223
171
|
colors.stroke_color.should == [1.0,0.0,0.8]
|
224
|
-
end
|
225
|
-
|
172
|
+
end
|
226
173
|
|
227
174
|
end
|
228
175
|
|
@@ -247,4 +194,4 @@ describe "When using painting shortcuts" do
|
|
247
194
|
lambda { @pdf.i_have_a_pretty_girlfriend_named_jia }.
|
248
195
|
should.raise(NoMethodError)
|
249
196
|
end
|
250
|
-
end
|
197
|
+
end
|
data/spec/images_spec.rb
CHANGED
@@ -2,23 +2,6 @@
|
|
2
2
|
|
3
3
|
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
4
|
|
5
|
-
class ImageObserver
|
6
|
-
|
7
|
-
attr_accessor :page_xobjects
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@page_xobjects = []
|
11
|
-
end
|
12
|
-
|
13
|
-
def resource_xobject(*params)
|
14
|
-
@page_xobjects.last << params.first
|
15
|
-
end
|
16
|
-
|
17
|
-
def begin_page(*params)
|
18
|
-
@page_xobjects << []
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
5
|
describe "the image() function" do
|
23
6
|
|
24
7
|
before(:each) do
|
@@ -29,14 +12,14 @@ describe "the image() function" do
|
|
29
12
|
it "should only embed an image once, even if it's added multiple times" do
|
30
13
|
@pdf.image @filename, :at => [100,100]
|
31
14
|
@pdf.image @filename, :at => [300,300]
|
32
|
-
|
33
|
-
|
34
|
-
|
15
|
+
|
16
|
+
output = @pdf.render
|
17
|
+
images = PDF::Inspector::XObject.analyze(output)
|
35
18
|
# there should be 2 images in the page resources
|
36
19
|
images.page_xobjects.first.size.should == 2
|
37
20
|
|
38
21
|
# but only 1 image xobject
|
39
|
-
|
22
|
+
output.scan(/\/Type \/XObject/).size.should == 1
|
40
23
|
end
|
41
24
|
end
|
42
25
|
|
data/spec/pdf_object_spec.rb
CHANGED
@@ -21,23 +21,23 @@ describe "PDF Object Serialization" do
|
|
21
21
|
|
22
22
|
it "should convert a Ruby string to PDF string when inside a content stream" do
|
23
23
|
s = "I can has a string"
|
24
|
-
|
24
|
+
PDF::Inspector.parse(Prawn::PdfObject(s, true)).should == s
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should convert a Ruby string to a UTF-16 PDF string when outside a content stream" do
|
28
28
|
s = "I can has a string"
|
29
29
|
s_utf16 = "\xFE\xFF" + s.unpack("U*").pack("n*")
|
30
|
-
|
30
|
+
PDF::Inspector.parse(Prawn::PdfObject(s, false)).should == s_utf16
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should escape parens when converting from Ruby string to PDF" do
|
34
34
|
s = 'I )(can has a string'
|
35
|
-
|
35
|
+
PDF::Inspector.parse(Prawn::PdfObject(s, true)).should == s
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should handle ruby escaped parens when converting to PDF string" do
|
39
39
|
s = 'I can \\)( has string'
|
40
|
-
|
40
|
+
PDF::Inspector.parse(Prawn::PdfObject(s, true)).should == s
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should convert a Ruby symbol to PDF name" do
|
@@ -53,13 +53,13 @@ describe "PDF Object Serialization" do
|
|
53
53
|
|
54
54
|
it "should convert a Ruby array to PDF Array when inside a content stream" do
|
55
55
|
Prawn::PdfObject([1,2,3]).should == "[1 2 3]"
|
56
|
-
|
56
|
+
PDF::Inspector.parse(Prawn::PdfObject([[1,2],:foo,"Bar"], true)).should ==
|
57
57
|
[[1,2],:foo, "Bar"]
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should convert a Ruby array to PDF Array when outside a content stream" do
|
61
61
|
Prawn::PdfObject([1,2,3]).should == "[1 2 3]"
|
62
|
-
|
62
|
+
PDF::Inspector.parse(Prawn::PdfObject([[1,2],:foo,"Bar"], false)).should ==
|
63
63
|
[[1,2],:foo, "\xFE\xFF\x00B\x00a\x00r"]
|
64
64
|
end
|
65
65
|
|
@@ -68,7 +68,7 @@ describe "PDF Object Serialization" do
|
|
68
68
|
"baz" => [1,2,3],
|
69
69
|
:bang => {:a => "what", :b => [:you, :say] }}, true )
|
70
70
|
|
71
|
-
res =
|
71
|
+
res = PDF::Inspector.parse(dict)
|
72
72
|
|
73
73
|
res[:foo].should == :bar
|
74
74
|
res[:baz].should == [1,2,3]
|
@@ -81,7 +81,7 @@ describe "PDF Object Serialization" do
|
|
81
81
|
"baz" => [1,2,3],
|
82
82
|
:bang => {:a => "what", :b => [:you, :say] }}, false )
|
83
83
|
|
84
|
-
res =
|
84
|
+
res = PDF::Inspector.parse(dict)
|
85
85
|
|
86
86
|
res[:foo].should == :bar
|
87
87
|
res[:baz].should == [1,2,3]
|
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.read_binary(@filename)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should read the attributes from the header chunk correctly" do
|
@@ -31,17 +31,34 @@ 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.read_binary(@data_filename)
|
35
35
|
png.img_data.should == data
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
describe "When reading a greyscale PNG file with transparency (color type 0)" do
|
40
|
+
|
41
|
+
before(:each) do
|
42
|
+
@filename = "#{Prawn::BASEDIR}/data/images/ruport_type0.png"
|
43
|
+
@img_data = File.read_binary(@filename)
|
44
|
+
end
|
45
|
+
|
46
|
+
# In a greyscale type 0 PNG image, the tRNS chunk should contain a single value
|
47
|
+
# that indicates the color that should be interpreted as transparent.
|
48
|
+
#
|
49
|
+
# http://www.w3.org/TR/PNG/#11tRNS
|
50
|
+
it "should read the tRNS chunk correctly" do
|
51
|
+
png = Prawn::Images::PNG.new(@img_data)
|
52
|
+
png.transparency[:grayscale].should == 255
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
39
56
|
describe "When reading an RGB PNG file (color type 2)" do
|
40
57
|
|
41
58
|
before(:each) do
|
42
59
|
@filename = "#{Prawn::BASEDIR}/data/images/ruport.png"
|
43
60
|
@data_filename = "#{Prawn::BASEDIR}/data/images/ruport_data.dat"
|
44
|
-
@img_data = File.
|
61
|
+
@img_data = File.read_binary(@filename)
|
45
62
|
end
|
46
63
|
|
47
64
|
it "should read the attributes from the header chunk correctly" do
|
@@ -58,11 +75,29 @@ describe "When reading an RGB PNG file (color type 2)" do
|
|
58
75
|
|
59
76
|
it "should read the image data chunk correctly" do
|
60
77
|
png = Prawn::Images::PNG.new(@img_data)
|
61
|
-
data = File.
|
78
|
+
data = File.read_binary(@data_filename)
|
62
79
|
png.img_data.should == data
|
63
80
|
end
|
64
81
|
end
|
65
82
|
|
83
|
+
describe "When reading an RGB PNG file with transparency (color type 2)" do
|
84
|
+
|
85
|
+
before(:each) do
|
86
|
+
@filename = "#{Prawn::BASEDIR}/data/images/arrow2.png"
|
87
|
+
@img_data = File.read_binary(@filename)
|
88
|
+
end
|
89
|
+
|
90
|
+
# In a RGB type 2 PNG image, the tRNS chunk should contain a single RGB value
|
91
|
+
# that indicates the color that should be interpreted as transparent. In this
|
92
|
+
# case it's green.
|
93
|
+
#
|
94
|
+
# http://www.w3.org/TR/PNG/#11tRNS
|
95
|
+
it "should read the tRNS chunk correctly" do
|
96
|
+
png = Prawn::Images::PNG.new(@img_data)
|
97
|
+
png.transparency[:rgb].should == [0, 255, 0]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
66
101
|
# TODO: describe "When reading an indexed color PNG file wiih transparency (color type 3)"
|
67
102
|
|
68
103
|
describe "When reading an indexed color PNG file (color type 3)" do
|
@@ -70,7 +105,7 @@ describe "When reading an indexed color PNG file (color type 3)" do
|
|
70
105
|
before(:each) do
|
71
106
|
@filename = "#{Prawn::BASEDIR}/data/images/rails.png"
|
72
107
|
@data_filename = "#{Prawn::BASEDIR}/data/images/rails.dat"
|
73
|
-
@img_data = File.
|
108
|
+
@img_data = File.read_binary(@filename)
|
74
109
|
end
|
75
110
|
|
76
111
|
it "should read the attributes from the header chunk correctly" do
|
@@ -87,7 +122,7 @@ describe "When reading an indexed color PNG file (color type 3)" do
|
|
87
122
|
|
88
123
|
it "should read the image data chunk correctly" do
|
89
124
|
png = Prawn::Images::PNG.new(@img_data)
|
90
|
-
data = File.
|
125
|
+
data = File.read_binary(@data_filename)
|
91
126
|
png.img_data.should == data
|
92
127
|
end
|
93
128
|
end
|
@@ -98,7 +133,7 @@ describe "When reading a greyscale+alpha PNG file (color type 4)" do
|
|
98
133
|
@filename = "#{Prawn::BASEDIR}/data/images/page_white_text.png"
|
99
134
|
@data_filename = "#{Prawn::BASEDIR}/data/images/page_white_text.dat"
|
100
135
|
@alpha_data_filename = "#{Prawn::BASEDIR}/data/images/page_white_text.alpha"
|
101
|
-
@img_data = File.
|
136
|
+
@img_data = File.read_binary(@filename)
|
102
137
|
end
|
103
138
|
|
104
139
|
it "should read the attributes from the header chunk correctly" do
|
@@ -115,13 +150,13 @@ describe "When reading a greyscale+alpha PNG file (color type 4)" do
|
|
115
150
|
|
116
151
|
it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
|
117
152
|
png = Prawn::Images::PNG.new(@img_data)
|
118
|
-
data = File.
|
153
|
+
data = File.read_binary(@data_filename)
|
119
154
|
png.img_data.should == data
|
120
155
|
end
|
121
156
|
|
122
157
|
it "should correctly extract the alpha channel data from the image data chunk" do
|
123
158
|
png = Prawn::Images::PNG.new(@img_data)
|
124
|
-
data = File.
|
159
|
+
data = File.read_binary(@alpha_data_filename)
|
125
160
|
png.alpha_channel.should == data
|
126
161
|
end
|
127
162
|
end
|
@@ -132,7 +167,7 @@ describe "When reading an RGB+alpha PNG file (color type 6)" do
|
|
132
167
|
@filename = "#{Prawn::BASEDIR}/data/images/dice.png"
|
133
168
|
@data_filename = "#{Prawn::BASEDIR}/data/images/dice.dat"
|
134
169
|
@alpha_data_filename = "#{Prawn::BASEDIR}/data/images/dice.alpha"
|
135
|
-
@img_data = File.
|
170
|
+
@img_data = File.read_binary(@filename)
|
136
171
|
end
|
137
172
|
|
138
173
|
it "should read the attributes from the header chunk correctly" do
|
@@ -149,13 +184,13 @@ describe "When reading an RGB+alpha PNG file (color type 6)" do
|
|
149
184
|
|
150
185
|
it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
|
151
186
|
png = Prawn::Images::PNG.new(@img_data)
|
152
|
-
data = File.
|
187
|
+
data = File.read_binary(@data_filename)
|
153
188
|
png.img_data.should == data
|
154
189
|
end
|
155
190
|
|
156
191
|
it "should correctly extract the alpha channel data from the image data chunk" do
|
157
192
|
png = Prawn::Images::PNG.new(@img_data)
|
158
|
-
data = File.
|
193
|
+
data = File.read_binary(@alpha_data_filename)
|
159
194
|
png.alpha_channel.should == data
|
160
195
|
end
|
161
196
|
end
|