GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Fast, Nimble PDF Writer for Ruby
Homepage: http://prawn.lighthouseapp.com/projects/9398/home
Clone URL: git://github.com/sandal/prawn.git
Updated to use PDF::Inspector
sandal (author)
Sat Aug 23 10:52:19 -0700 2008
commit  2af9a206d4cea716a342dd9be7af442cd4ce5791
tree    67a0911216faf0f223e785cd0ce9bfd537e8808c
parent  30daf7213ce79be15f901e1c820007fbec023db5
...
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
21
22
23
24
 
25
26
 
27
28
29
30
31
32
 
33
34
 
35
36
37
38
39
40
41
42
43
 
44
45
46
...
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
 
 
134
135
136
137
138
139
140
 
 
141
142
143
144
145
146
147
 
 
 
148
149
150
...
152
153
154
155
156
 
 
157
158
159
...
3
4
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
7
8
9
 
10
11
 
12
13
14
15
16
17
 
18
19
 
20
21
 
 
 
 
 
 
 
 
22
23
24
25
...
86
87
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
90
91
 
 
92
93
94
95
96
97
98
 
 
99
100
101
102
103
104
 
 
 
105
106
107
108
109
110
...
112
113
114
 
 
115
116
117
118
119
0
@@ -3,44 +3,23 @@
0
 require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
0
                                
0
 describe "When creating multi-page documents" do
0
-
0
- class PageCounter
0
- attr_accessor :pages
0
-
0
- def initialize
0
- @pages = 0
0
- end
0
-
0
- # Called when page parsing ends
0
- def end_page
0
- @pages += 1
0
- end
0
- end
0
-
0
-
0
+
0
   before(:each) { create_pdf }
0
   
0
   it "should initialize with a single page" do
0
- page_counter = count_pages
0
+ page_counter = PDF::Inspector::Page.analyze(@pdf.render)
0
     
0
- page_counter.pages.should == 1
0
+ page_counter.pages.size.should == 1
0
     @pdf.page_count.should == 1
0
   end
0
   
0
   it "should provide an accurate page_count" do
0
     3.times { @pdf.start_new_page }
0
- page_counter = count_pages
0
+ page_counter = PDF::Inspector::Page.analyze(@pdf.render)
0
     
0
- page_counter.pages.should == 4
0
+ page_counter.pages.size.should == 4
0
     @pdf.page_count.should == 4
0
- end
0
-
0
- def count_pages
0
- output = @pdf.render
0
- obs = PageCounter.new
0
- PDF::Reader.string(output,obs)
0
- return obs
0
- end
0
+ end
0
   
0
 end
0
 
0
@@ -107,44 +86,25 @@ describe "When ending each page" do
0
 
0
 end
0
 
0
-class PageDetails
0
-
0
- def begin_page(params)
0
- @geometry = params[:MediaBox]
0
- end
0
-
0
- def size
0
- @geometry[-2..-1]
0
- end
0
-
0
-end
0
-
0
-def detect_page_details
0
- output = @pdf.render
0
- obs = PageDetails.new
0
- PDF::Reader.string(output,obs)
0
- return obs
0
-end
0
-
0
 describe "When setting page size" do
0
   it "should default to LETTER" do
0
     @pdf = Prawn::Document.new
0
- page = detect_page_details
0
- page.size.should == Prawn::Document::PageGeometry::SIZES["LETTER"]
0
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
0
+ pages.first[:size].should == Prawn::Document::PageGeometry::SIZES["LETTER"]
0
   end
0
   
0
   (Prawn::Document::PageGeometry::SIZES.keys - ["LETTER"]).each do |k|
0
     it "should provide #{k} geometry" do
0
       @pdf = Prawn::Document.new(:page_size => k)
0
- page = detect_page_details
0
- page.size.should == Prawn::Document::PageGeometry::SIZES[k]
0
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
0
+ pages.first[:size].should == Prawn::Document::PageGeometry::SIZES[k]
0
     end
0
   end
0
   
0
   it "should allow custom page size" do
0
- @pdf = Prawn::Document.new(:page_size => [1920, 1080] )
0
- page = detect_page_details
0
- page.size.should == [1920, 1080]
0
+ @pdf = Prawn::Document.new(:page_size => [1920, 1080] )
0
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
0
+ pages.first[:size].should == [1920, 1080]
0
   end
0
 
0
 end
0
@@ -152,8 +112,8 @@ end
0
 describe "When setting page layout" do
0
   it "should reverse coordinates for landscape" do
0
     @pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
0
- page = detect_page_details
0
- page.size.should == Prawn::Document::PageGeometry::SIZES["A4"].reverse
0
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
0
+ pages.first[:size].should == Prawn::Document::PageGeometry::SIZES["A4"].reverse
0
   end
0
 end
0
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
26
27
28
29
 
30
31
32
...
36
37
38
39
 
40
41
42
43
44
45
46
47
48
49
50
51
 
52
53
54
55
56
 
 
57
58
59
...
61
62
63
64
 
65
66
67
...
80
81
82
83
 
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...
104
105
106
107
 
 
108
109
110
111
 
 
 
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
 
134
135
136
...
139
140
141
142
 
143
144
145
146
147
148
 
149
150
151
...
155
156
157
158
 
159
160
161
...
169
170
171
172
 
173
174
175
...
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
 
208
209
210
211
212
213
214
 
215
216
217
218
219
220
221
 
222
223
224
225
226
227
228
 
229
230
231
232
233
 
234
235
236
237
238
239
240
 
241
242
243
...
262
263
264
265
 
266
...
1
2
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
 
5
6
7
...
9
10
11
 
12
13
14
15
...
19
20
21
 
22
23
24
25
26
 
 
 
 
 
 
 
 
27
28
29
30
 
 
31
32
33
34
35
...
37
38
39
 
40
41
42
43
...
56
57
58
 
59
60
61
62
63
64
 
 
 
 
 
 
 
 
 
 
 
65
66
67
...
69
70
71
 
72
73
74
 
 
 
75
76
77
78
79
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
82
83
84
...
87
88
89
 
90
91
92
93
94
95
 
96
97
98
99
...
103
104
105
 
106
107
108
109
...
117
118
119
 
120
121
122
123
...
126
127
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
130
131
132
133
134
 
135
136
137
138
139
140
141
 
142
143
144
145
146
147
148
 
149
150
151
152
153
154
155
 
156
157
158
159
160
 
161
162
163
164
165
166
 
 
167
168
169
170
...
189
190
191
 
192
193
0
@@ -1,24 +1,7 @@
0
 # encoding: utf-8
0
 
0
 require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
0
-
0
-class LineDrawingObserver
0
- attr_accessor :points, :strokes
0
-
0
- def initialize
0
- @points = []
0
- end
0
-
0
- def append_line(*params)
0
- @points << params
0
- end
0
-
0
- def begin_new_subpath(*params)
0
- @points << params
0
- end
0
   
0
-end
0
-
0
 describe "When drawing a line" do
0
    
0
   before(:each) { create_pdf }
0
@@ -26,7 +9,7 @@ describe "When drawing a line" do
0
   it "should draw a line from (100,600) to (100,500)" do
0
     @pdf.line([100,600],[100,500])
0
     
0
- line_drawing = observer(LineDrawingObserver)
0
+ line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
0
     
0
     line_drawing.points.should == [[100,600],[100,500]]
0
   end
0
@@ -36,24 +19,17 @@ describe "When drawing a line" do
0
     @pdf.line(100,600,100,500)
0
     @pdf.line(75,100,50,125)
0
     
0
- line_drawing = observer(LineDrawingObserver)
0
+ line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
0
     
0
     line_drawing.points.should ==
0
       [[100.0, 600.0], [100.0, 500.0], [75.0, 100.0], [50.0, 125.0]]
0
   end
0
-
0
- class LineWidthReader
0
- attr_accessor :width
0
- def set_line_width(params)
0
- @width = params
0
- end
0
- end
0
-
0
+
0
   it "should properly set line width" do
0
      create_pdf
0
      @pdf.line_width = 10
0
- line = observer(LineWidthReader)
0
- line.width.should == 10
0
+ line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
0
+ line.widths.first.should == 10
0
   end
0
   
0
   describe "(Horizontally)" do
0
@@ -61,7 +37,7 @@ describe "When drawing a line" do
0
     before :each do
0
       @pdf = Prawn::Document.new
0
       @pdf.horizontal_line(100,150)
0
- @line = observer(LineDrawingObserver)
0
+ @line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
0
     end
0
    
0
     it "should draw from [x1,pdf.y],[x2,pdf.y]" do
0
@@ -80,23 +56,12 @@ describe "When drawing a polygon" do
0
   it "should draw each line passed to polygon()" do
0
     @pdf.polygon([100,500],[100,400],[200,400])
0
 
0
- line_drawing = observer(LineDrawingObserver)
0
+ line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
0
     line_drawing.points.should == [[100,500],[100,400],[200,400],[100,500]]
0
   end
0
 
0
 end
0
 
0
-class RectangleDrawingObserver
0
-
0
- attr_reader :point, :width, :height
0
-
0
- def append_rectangle(*params)
0
- @point = params[0..1]
0
- @width = params[2]
0
- @height = params[3]
0
- end
0
-end
0
-
0
 describe "When drawing a rectangle" do
0
 
0
   before(:each) { create_pdf }
0
@@ -104,33 +69,16 @@ describe "When drawing a rectangle" do
0
   it "should use a point, width, and height for coords" do
0
     @pdf.rectangle [200,200], 50, 100
0
 
0
- rectangle = observer(RectangleDrawingObserver)
0
+ rectangles = PDF::Inspector::Graphics::Rectangle.
0
+ analyze(@pdf.render).rectangles
0
     # PDF uses bottom left corner
0
- rectangle.point.should == [200,100]
0
- rectangle.width.should == 50
0
- rectangle.height.should == 100
0
+ rectangles[0][:point].should == [200,100]
0
+ rectangles[0][:width].should == 50
0
+ rectangles[0][:height].should == 100
0
 
0
   end
0
 
0
-end
0
-
0
-class CurveObserver
0
-
0
- attr_reader :coords
0
-
0
- def initialize
0
- @coords = []
0
- end
0
-
0
- def begin_new_subpath(*params)
0
- @coords += params
0
- end
0
-
0
- def append_curved_segment(*params)
0
- @coords += params
0
- end
0
-
0
-end
0
+end
0
 
0
 describe "When drawing a curve" do
0
     
0
@@ -139,13 +87,13 @@ describe "When drawing a curve" do
0
   it "should draw a bezier curve from 50,50 to 100,100" do
0
     @pdf.move_to [50,50]
0
     @pdf.curve_to [100,100],:bounds => [[20,90], [90,70]]
0
- curve = observer(CurveObserver)
0
+ curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
0
     curve.coords.should == [50.0, 50.0, 20.0, 90.0, 90.0, 70.0, 100.0, 100.0]
0
   end
0
   
0
   it "should draw a bezier curve from 100,100 to 50,50" do
0
     @pdf.curve [100,100], [50,50], :bounds => [[20,90], [90,75]]
0
- curve = observer(CurveObserver)
0
+ curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
0
     curve.coords.should == [100.0, 100.0, 20.0, 90.0, 90.0, 75.0, 50.0, 50.0]
0
   end
0
   
0
@@ -155,7 +103,7 @@ describe "When drawing an ellipse" do
0
   before(:each) do
0
     create_pdf
0
     @pdf.ellipse_at [100,100], 25, 50
0
- @curve = observer(CurveObserver)
0
+ @curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
0
   end
0
   
0
   it "should move the pointer to the center of the ellipse after drawing" do
0
@@ -169,7 +117,7 @@ describe "When drawing a circle" do
0
     create_pdf
0
     @pdf.circle_at [100,100], :radius => 25
0
     @pdf.ellipse_at [100,100], 25, 25
0
- @curve = observer(CurveObserver)
0
+ @curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
0
   end
0
   
0
   it "should stroke the same path as the equivalent ellipse" do
0
@@ -178,66 +126,45 @@ describe "When drawing a circle" do
0
   end
0
 end
0
 
0
-class ColorObserver
0
- attr_reader :stroke_color, :fill_color, :stroke_color_count,
0
- :fill_color_count
0
-
0
- def initialize
0
- @stroke_color_count = 0
0
- @fill_color_count = 0
0
- end
0
-
0
- def set_rgb_color_for_stroking(*params)
0
- @stroke_color_count += 1
0
- @stroke_color = params
0
- end
0
-
0
- def set_rgb_color_for_nonstroking(*params)
0
- @fill_color_count += 1
0
- @fill_color = params
0
- end
0
-end
0
-
0
 describe "When setting colors" do
0
 
0
   before(:each) { create_pdf }
0
 
0
   it "should set stroke colors" do
0
     @pdf.stroke_color "ffcccc"
0
- colors = observer(ColorObserver)
0
+ colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
0
     # 100% red, 80% green, 80% blue
0
     colors.stroke_color.should == [1.0, 0.8, 0.8]
0
   end
0
 
0
   it "should set fill colors" do
0
     @pdf.fill_color "ccff00"
0
- colors = observer(ColorObserver)
0
+ colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
0
     # 80% red, 100% green, 0% blue
0
     colors.fill_color.should == [0.8,1.0,0]
0
   end
0
   
0
   it "should reset the colors on each new page if they have been defined" do
0
     @pdf.fill_color "ccff00"
0
- colors = observer(ColorObserver)
0
+ colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
0
     
0
     colors.fill_color_count.should == 2
0
     colors.stroke_color_count.should == 1
0
     @pdf.start_new_page
0
     @pdf.stroke_color "ff00cc"
0
     
0
- colors = observer(ColorObserver)
0
+ colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
0
     colors.fill_color_count.should == 3
0
     colors.stroke_color_count.should == 3
0
     
0
     @pdf.start_new_page
0
- colors = observer(ColorObserver)
0
+ colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
0
     colors.fill_color_count.should == 4
0
     colors.stroke_color_count.should == 4
0
     
0
     colors.fill_color.should == [0.8,1.0,0.0]
0
     colors.stroke_color.should == [1.0,0.0,0.8]
0
- end
0
-
0
+ end
0
 
0
 end
0
 
0
@@ -262,4 +189,4 @@ describe "When using painting shortcuts" do
0
     lambda { @pdf.i_have_a_pretty_girlfriend_named_jia }.
0
       should.raise(NoMethodError)
0
   end
0
-end
0
+end
0
\ No newline at end of file
...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
29
30
31
32
33
34
 
 
 
35
36
37
38
39
 
40
41
42
...
2
3
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
6
7
...
12
13
14
 
 
 
15
16
17
18
19
20
21
 
22
23
24
25
0
@@ -2,23 +2,6 @@
0
 
0
 require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
0
 
0
-class ImageObserver
0
-
0
- attr_accessor :page_xobjects
0
-
0
- def initialize
0
- @page_xobjects = []
0
- end
0
-
0
- def resource_xobject(*params)
0
- @page_xobjects.last << params.first
0
- end
0
-
0
- def begin_page(*params)
0
- @page_xobjects << []
0
- end
0
-end
0
-
0
 describe "the image() function" do
0
 
0
   before(:each) do
0
@@ -29,14 +12,14 @@ describe "the image() function" do
0
   it "should only embed an image once, even if it's added multiple times" do
0
     @pdf.image @filename, :at => [100,100]
0
     @pdf.image @filename, :at => [300,300]
0
-
0
- images = observer(ImageObserver)
0
-
0
+
0
+ output = @pdf.render
0
+ images = PDF::Inspector::XObject.analyze(output)
0
     # there should be 2 images in the page resources
0
     images.page_xobjects.first.size.should == 2
0
 
0
     # but only 1 image xobject
0
- @output.scan(/\/Type \/XObject/).size.should == 1
0
+ output.scan(/\/Type \/XObject/).size.should == 1
0
   end
0
 end
0
 
...
21
22
23
24
 
25
26
27
28
29
30
 
31
32
33
34
35
 
36
37
38
39
40
 
41
42
43
...
53
54
55
56
 
57
58
59
60
61
62
 
63
64
65
...
68
69
70
71
 
72
73
74
...
81
82
83
84
 
85
86
87
...
21
22
23
 
24
25
26
27
28
29
 
30
31
32
33
34
 
35
36
37
38
39
 
40
41
42
43
...
53
54
55
 
56
57
58
59
60
61
 
62
63
64
65
...
68
69
70
 
71
72
73
74
...
81
82
83
 
84
85
86
87
0
@@ -21,23 +21,23 @@ describe "PDF Object Serialization" do
0
   
0
   it "should convert a Ruby string to PDF string when inside a content stream" do
0
     s = "I can has a string"
0
- parse_pdf_object(Prawn::PdfObject(s, true)).should == s
0
+ PDF::Inspector.parse(Prawn::PdfObject(s, true)).should == s
0
   end
0
 
0
   it "should convert a Ruby string to a UTF-16 PDF string when outside a content stream" do
0
     s = "I can has a string"
0
     s_utf16 = "\xFE\xFF" + s.unpack("U*").pack("n*")
0
- parse_pdf_object(Prawn::PdfObject(s, false)).should == s_utf16
0
+ PDF::Inspector.parse(Prawn::PdfObject(s, false)).should == s_utf16
0
   end
0
   
0
   it "should escape parens when converting from Ruby string to PDF" do
0
     s = 'I )(can has a string'
0
- parse_pdf_object(Prawn::PdfObject(s, true)).should == s
0
+ PDF::Inspector.parse(Prawn::PdfObject(s, true)).should == s
0
   end
0
   
0
   it "should handle ruby escaped parens when converting to PDF string" do
0
     s = 'I can \\)( has string'
0
- parse_pdf_object(Prawn::PdfObject(s, true)).should == s
0
+ PDF::Inspector.parse(Prawn::PdfObject(s, true)).should == s
0
   end
0
   
0
   it "should convert a Ruby symbol to PDF name" do
0
@@ -53,13 +53,13 @@ describe "PDF Object Serialization" do
0
   
0
   it "should convert a Ruby array to PDF Array when inside a content stream" do
0
     Prawn::PdfObject([1,2,3]).should == "[1 2 3]"
0
- parse_pdf_object(Prawn::PdfObject([[1,2],:foo,"Bar"], true)).should ==
0
+ PDF::Inspector.parse(Prawn::PdfObject([[1,2],:foo,"Bar"], true)).should ==
0
       [[1,2],:foo, "Bar"]
0
   end
0
 
0
   it "should convert a Ruby array to PDF Array when outside a content stream" do
0
     Prawn::PdfObject([1,2,3]).should == "[1 2 3]"
0
- parse_pdf_object(Prawn::PdfObject([[1,2],:foo,"Bar"], false)).should ==
0
+ PDF::Inspector.parse(Prawn::PdfObject([[1,2],:foo,"Bar"], false)).should ==
0
       [[1,2],:foo, "\xFE\xFF\x00B\x00a\x00r"]
0
   end
0
  
0
@@ -68,7 +68,7 @@ describe "PDF Object Serialization" do
0
                               "baz" => [1,2,3],
0
                               :bang => {:a => "what", :b => [:you, :say] }}, true )
0
 
0
- res = parse_pdf_object(dict)
0
+ res = PDF::Inspector.parse(dict)
0
 
0
     res[:foo].should == :bar
0
     res[:baz].should == [1,2,3]
0
@@ -81,7 +81,7 @@ describe "PDF Object Serialization" do
0
                               "baz" => [1,2,3],
0
                               :bang => {:a => "what", :b => [:you, :say] }}, false )
0
 
0
- res = parse_pdf_object(dict)
0
+ res = PDF::Inspector.parse(dict)
0
 
0
     res[:foo].should == :bar
0
     res[:baz].should == [1,2,3]
...
6
7
8
 
9
 
10
11
 
 
12
13
14
...
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
...
6
7
8
9
10
11
12
 
13
14
15
16
17
...
24
25
26
 
 
 
 
 
 
 
 
 
 
 
 
27
28
0
@@ -6,9 +6,12 @@ require "rubygems"
0
 require "test/spec"
0
 require "mocha"
0
 $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
0
+$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'vendor','pdf-inspector','lib')
0
 require "prawn"
0
+
0
 gem 'pdf-reader', ">=0.7.3"
0
-require "pdf/reader"
0
+require "pdf/reader"
0
+require "pdf/inspector"
0
 
0
 module Prawn
0
   class Document
0
@@ -21,16 +24,4 @@ def create_pdf
0
                              :right_margin => 0,
0
                              :top_margin => 0,
0
                              :bottom_margin => 0)
0
-end
0
-
0
-def observer(klass)
0
- @output = @pdf.render
0
- obs = klass.new
0
- PDF::Reader.string(@output,obs)
0
- obs
0
-end
0
-
0
-def parse_pdf_object(obj)
0
- PDF::Reader::Parser.new(
0
- PDF::Reader::Buffer.new(sio = StringIO.new(obj)), nil).parse_token
0
 end
0
\ No newline at end of file
...
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
 
111
112
113
...
116
117
118
119
 
120
121
122
...
125
126
127
128
 
129
130
131
...
73
74
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
77
78
79
80
81
 
82
83
84
85
...
88
89
90
 
91
92
93
94
...
97
98
99
 
100
101
102
103
0
@@ -73,41 +73,13 @@ describe "A table's height" do
0
   
0
 end
0
 
0
-class TableTextObserver
0
- attr_accessor :font_settings, :size, :strings
0
-
0
- def initialize
0
- @font_settings = []
0
- @fonts = {}
0
- @strings = []
0
- end
0
-
0
- def resource_font(*params)
0
- @fonts[params[0]] = params[1].basefont
0
- end
0
-
0
- def set_text_font_and_size(*params)
0
- @font_settings << { :name => @fonts[params[0]], :size => params[1] }
0
- end
0
-
0
- def show_text(*params)
0
- @strings << params[0]
0
- end
0
-
0
- def show_text_with_positioning(*params)
0
- # ignore kerning information
0
- @strings << params[0].reject { |e| Numeric === e }.join
0
- end
0
-end
0
-
0
-
0
 describe "A table's content" do
0
 
0
   it "should output content cell by cell, row by row" do
0
     data = [["foo","bar"],["baz","bang"]]
0
     @pdf = Prawn::Document.new
0
     @pdf.table(data)
0
- output = observer(TableTextObserver)
0
+ output = PDF::Inspector::Text.analyze(@pdf.render)
0
     output.strings.should == data.flatten
0
   end
0
 
0
@@ -116,7 +88,7 @@ describe "A table's content" do
0
     headers = %w[a b]
0
     @pdf = Prawn::Document.new
0
     @pdf.table(data, :headers => headers)
0
- output = observer(TableTextObserver)
0
+ output = PDF::Inspector::Text.analyze(@pdf.render)
0
     output.strings.should == headers + data.flatten
0
   end
0
 
0
@@ -125,7 +97,7 @@ describe "A table's content" do
0
     headers = ["baz","foobar"]
0
     @pdf = Prawn::Document.new
0
     @pdf.table(data, :headers => headers)
0
- output = observer(TableTextObserver)
0
+ output = PDF::Inspector::Text.analyze(@pdf.render)
0
     output.strings.should == headers + data.flatten[0..-3] + headers +
0
       data.flatten[-2..-1]
0
   end
...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
...
82
83
84
85
86
87
88
89
90
 
 
 
 
91
92
93
...
109
110
111
112
 
113
114
115
 
116
117
118
119
120
 
121
122
123
124
125
126
127
 
128
129
130
...
133
134
135
136
 
137
138
139
...
146
147
148
149
 
150
151
152
...
158
159
160
161
 
162
163
164
...
169
170
171
172
 
173
174
175
...
178
179
180
181
 
182
183
184
185
 
 
 
186
187
188
...
194
195
196
197
198
 
 
199
200
201
...
2
3
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
6
7
...
40
41
42
 
 
 
 
 
 
43
44
45
46
47
48
49
...
65
66
67
 
68
69
70
 
71
72
73
74
75
 
76
77
78
79
80
81
82
 
83
84
85
86
...
89
90
91
 
92
93
94
95
...
102
103
104
 
105
106
107
108
...
114
115
116
 
117
118
119
120
...
125
126
127
 
128
129
130
131
...
134
135
136
 
137
138
 
 
 
139
140
141
142
143
144
...
150
151
152
 
 
153
154
155
156
157
0
@@ -2,48 +2,6 @@
0
 
0
 require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
0
 
0
-class TextObserver
0
-
0
- attr_accessor :font_settings, :size, :string
0
-
0
- def initialize
0
- @font_settings = []
0
- @fonts = {}
0
- end
0
-
0
- def resource_font(*params)
0
- @fonts[params[0]] = params[1].basefont
0
- end
0
-
0