rbpdf 1.18.7 → 1.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +12 -0
- data/Gemfile +3 -0
- data/README.md +1 -5
- data/Rakefile +10 -0
- data/lib/rbpdf.rb +715 -222
- data/lib/rbpdf/version.rb +1 -1
- data/rbpdf.gemspec +3 -3
- data/test/err_font1.rb +3 -0
- data/test/err_font2.rb +4 -0
- data/test/rbpdf_bidi_test.rb +85 -14
- data/test/rbpdf_bookmark_test.rb +1 -2
- data/test/rbpdf_cell_test.rb +1 -2
- data/test/rbpdf_content_test.rb +1 -1
- data/test/rbpdf_css_test.rb +1 -1
- data/test/rbpdf_dom_test.rb +1 -1
- data/test/rbpdf_font_func_test.rb +1 -1
- data/test/rbpdf_font_style_test.rb +1 -2
- data/test/rbpdf_font_test.rb +111 -1
- data/test/rbpdf_format_test.rb +1 -2
- data/test/rbpdf_func_test.rb +1 -1
- data/test/rbpdf_html_anchor_test.rb +107 -0
- data/test/rbpdf_html_func_test.rb +1 -1
- data/test/rbpdf_html_test.rb +196 -349
- data/test/rbpdf_htmlcell_test.rb +1 -1
- data/test/rbpdf_image_rmagick_test.rb +1 -2
- data/test/rbpdf_image_test.rb +1 -2
- data/test/rbpdf_test.rb +1 -1
- data/test/rbpdf_transaction_test.rb +1 -1
- data/test/rbpdf_viewerpreferences_test.rb +1 -1
- data/test/rbpdf_write_test.rb +1 -2
- data/test/test_helper.rb +2 -0
- metadata +38 -89
- data/lib/fonts/README.z +0 -2
- data/lib/fonts/arialunicid0_cw.rb +0 -1738
- data/lib/fonts/cid0cs.rb +0 -21
- data/lib/fonts/cid0ct.rb +0 -21
- data/lib/fonts/cid0jp.rb +0 -21
- data/lib/fonts/cid0kr.rb +0 -21
- data/lib/fonts/courier.rb +0 -37
- data/lib/fonts/dejavu-fonts-ttf-2.33/AUTHORS +0 -53
- data/lib/fonts/dejavu-fonts-ttf-2.33/BUGS +0 -3
- data/lib/fonts/dejavu-fonts-ttf-2.33/LICENSE +0 -99
- data/lib/fonts/dejavu-fonts-ttf-2.33/NEWS +0 -1315
- data/lib/fonts/dejavu-fonts-ttf-2.33/README +0 -59
- data/lib/fonts/dejavusans.ctg.z +0 -0
- data/lib/fonts/dejavusans.rb +0 -338
- data/lib/fonts/dejavusans.z +0 -0
- data/lib/fonts/dejavusansb.ctg.z +0 -0
- data/lib/fonts/dejavusansb.rb +0 -330
- data/lib/fonts/dejavusansb.z +0 -0
- data/lib/fonts/dejavusansbi.ctg.z +0 -0
- data/lib/fonts/dejavusansbi.rb +0 -297
- data/lib/fonts/dejavusansbi.z +0 -0
- data/lib/fonts/dejavusansi.ctg.z +0 -0
- data/lib/fonts/dejavusansi.rb +0 -305
- data/lib/fonts/dejavusansi.z +0 -0
- data/lib/fonts/freefont-20080912/AUTHORS +0 -191
- data/lib/fonts/freefont-20080912/COPYING +0 -341
- data/lib/fonts/freefont-20080912/CREDITS +0 -506
- data/lib/fonts/freefont-20080912/ChangeLog +0 -3320
- data/lib/fonts/freefont-20080912/INSTALL +0 -81
- data/lib/fonts/freefont-20080912/README +0 -108
- data/lib/fonts/freemono.ctg.z +0 -0
- data/lib/fonts/freemono.rb +0 -203
- data/lib/fonts/freemono.z +0 -0
- data/lib/fonts/freemonob.ctg.z +0 -0
- data/lib/fonts/freemonob.rb +0 -120
- data/lib/fonts/freemonob.z +0 -0
- data/lib/fonts/freemonobi.ctg.z +0 -0
- data/lib/fonts/freemonobi.rb +0 -84
- data/lib/fonts/freemonobi.z +0 -0
- data/lib/fonts/freemonoi.ctg.z +0 -0
- data/lib/fonts/freemonoi.rb +0 -136
- data/lib/fonts/freemonoi.z +0 -0
- data/lib/fonts/freesans.ctg.z +0 -0
- data/lib/fonts/freesans.rb +0 -196
- data/lib/fonts/freesans.z +0 -0
- data/lib/fonts/freesansb.ctg.z +0 -0
- data/lib/fonts/freesansb.rb +0 -136
- data/lib/fonts/freesansb.z +0 -0
- data/lib/fonts/freesansbi.ctg.z +0 -0
- data/lib/fonts/freesansbi.rb +0 -108
- data/lib/fonts/freesansbi.z +0 -0
- data/lib/fonts/freesansi.ctg.z +0 -0
- data/lib/fonts/freesansi.rb +0 -136
- data/lib/fonts/freesansi.z +0 -0
- data/lib/fonts/freeserif.ctg.z +0 -0
- data/lib/fonts/freeserif.rb +0 -285
- data/lib/fonts/freeserif.z +0 -0
- data/lib/fonts/freeserifb.ctg.z +0 -0
- data/lib/fonts/freeserifb.rb +0 -164
- data/lib/fonts/freeserifb.z +0 -0
- data/lib/fonts/freeserifbi.ctg.z +0 -0
- data/lib/fonts/freeserifbi.rb +0 -130
- data/lib/fonts/freeserifbi.z +0 -0
- data/lib/fonts/freeserifi.ctg.z +0 -0
- data/lib/fonts/freeserifi.rb +0 -151
- data/lib/fonts/freeserifi.z +0 -0
- data/lib/fonts/helvetica.rb +0 -34
- data/lib/fonts/helveticab.rb +0 -34
- data/lib/fonts/helveticabi.rb +0 -34
- data/lib/fonts/helveticai.rb +0 -34
- data/lib/fonts/hysmyeongjostdmedium.rb +0 -31
- data/lib/fonts/kozgopromedium.rb +0 -47
- data/lib/fonts/kozminproregular.rb +0 -46
- data/lib/fonts/msungstdlight.rb +0 -23
- data/lib/fonts/sjis.rb +0 -834
- data/lib/fonts/stsongstdlight.rb +0 -23
- data/lib/fonts/symbol.rb +0 -33
- data/lib/fonts/times.rb +0 -34
- data/lib/fonts/timesb.rb +0 -34
- data/lib/fonts/timesbi.rb +0 -34
- data/lib/fonts/timesi.rb +0 -34
- data/lib/fonts/uni2cid_ac15.rb +0 -23613
- data/lib/fonts/uni2cid_ag15.rb +0 -30222
- data/lib/fonts/uni2cid_aj16.rb +0 -15705
- data/lib/fonts/uni2cid_ak12.rb +0 -17530
- data/lib/fonts/zapfdingbats.rb +0 -33
data/test/rbpdf_html_test.rb
CHANGED
@@ -1,12 +1,50 @@
|
|
1
1
|
# coding: ASCII-8BIT
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
|
-
class
|
4
|
+
class RbpdfHtmlTest < Test::Unit::TestCase
|
5
5
|
class MYPDF < RBPDF
|
6
6
|
def getPageBuffer(page)
|
7
7
|
super
|
8
8
|
end
|
9
9
|
|
10
|
+
# get text count and x_pos from pdf page
|
11
|
+
def get_html_text_position_x(page, regrep_text, x_pos_exp=nil)
|
12
|
+
count_line, count_text, x_pos, y_pos = get_html_text_position(page, regrep_text, x_pos_exp)
|
13
|
+
return count_line, count_text, x_pos
|
14
|
+
end
|
15
|
+
|
16
|
+
# get text count and y_pos from pdf page
|
17
|
+
def get_html_text_position_y(page, regrep_text)
|
18
|
+
count_line, count_text, x_pos, y_pos = get_html_text_position(page, regrep_text)
|
19
|
+
return count_line, count_text, y_pos
|
20
|
+
end
|
21
|
+
|
22
|
+
# get text count and pos from pdf page
|
23
|
+
def get_html_text_position(page, regrep_text, x_pos_exp=nil)
|
24
|
+
content = []
|
25
|
+
contents = getPageBuffer(page)
|
26
|
+
contents.each_line {|line| content.push line.chomp }
|
27
|
+
count_line = count_text = 0
|
28
|
+
x_pos = y_pos = -1
|
29
|
+
content.each do |line|
|
30
|
+
count_line += 1 if line =~ /TJ ET Q$/ # Text Line Count
|
31
|
+
if line =~ regrep_text
|
32
|
+
count_text += 1
|
33
|
+
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
34
|
+
x_pos = $1
|
35
|
+
y_pos = $2 if y_pos == -1 # y first position only
|
36
|
+
|
37
|
+
if x_pos.nil? or y_pos.nil? # Error
|
38
|
+
return count_line, count_text, nil, nil
|
39
|
+
end
|
40
|
+
if !x_pos_exp.nil? and x_pos != x_pos_exp # Error
|
41
|
+
return count_line, count_text, x_pos, y_pos
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
return count_line, count_text, x_pos, y_pos
|
46
|
+
end
|
47
|
+
|
10
48
|
# get text from pdf page
|
11
49
|
def get_html_text(page)
|
12
50
|
content = []
|
@@ -69,47 +107,22 @@ class RbpdfTest < ActiveSupport::TestCase
|
|
69
107
|
pno = pdf.get_page
|
70
108
|
assert_equal pno, 3
|
71
109
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
83
|
-
pos1 = $1
|
84
|
-
assert_not_nil pos1
|
85
|
-
end
|
86
|
-
if line =~ /abcd/
|
87
|
-
count += 1
|
88
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
89
|
-
pos2 = $1
|
90
|
-
assert_not_nil pos2
|
91
|
-
end
|
92
|
-
end
|
93
|
-
assert_equal count_text, 13
|
94
|
-
assert_equal count, 1
|
95
|
-
assert_equal pos1, pos2
|
110
|
+
# Page 1
|
111
|
+
count_line, count_text, xpos1 = pdf.get_html_text_position_x(1, /ABCD/) # Header
|
112
|
+
assert_not_nil xpos1
|
113
|
+
assert_equal 1, count_text
|
114
|
+
assert_equal 13, count_line
|
115
|
+
count_line, count_text, xpos2 = pdf.get_html_text_position_x(1, /abcd/)
|
116
|
+
assert_not_nil xpos2
|
117
|
+
assert_equal 1, count_text
|
118
|
+
assert_equal xpos1, xpos2
|
119
|
+
assert_equal 13, count_line
|
96
120
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
count_text = 0
|
103
|
-
content.each do |line|
|
104
|
-
count_text += 1 if line =~ /TJ ET Q$/
|
105
|
-
if line =~ /\([6-9]\)/
|
106
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
107
|
-
pos2 = $1
|
108
|
-
assert_not_nil pos2
|
109
|
-
assert_equal pos1, pos2
|
110
|
-
end
|
111
|
-
end
|
112
|
-
assert_equal count_text, 7
|
121
|
+
# Page 2
|
122
|
+
count_line, count_text, xpos2 = pdf.get_html_text_position_x(2, /\([6-9]\)/, xpos1)
|
123
|
+
assert_not_nil xpos2
|
124
|
+
assert_equal xpos1, xpos2
|
125
|
+
assert_equal 7, count_line
|
113
126
|
end
|
114
127
|
|
115
128
|
test "write_html Table thead tag test 1" do
|
@@ -125,15 +138,8 @@ class RbpdfTest < ActiveSupport::TestCase
|
|
125
138
|
page = pdf.get_page
|
126
139
|
assert_equal 1, page
|
127
140
|
|
128
|
-
|
129
|
-
|
130
|
-
contents.each_line {|line| content.push line.chomp }
|
131
|
-
|
132
|
-
count = 0
|
133
|
-
content.each do |line|
|
134
|
-
count += 1 if line =~ /ABCD/
|
135
|
-
end
|
136
|
-
assert_equal count, 1
|
141
|
+
count_line, count_text, xpos = pdf.get_html_text_position_x(1, /ABCD/) # Header
|
142
|
+
assert_equal 1, count_text
|
137
143
|
end
|
138
144
|
|
139
145
|
test "write_html Table thead tag test 2" do
|
@@ -151,83 +157,44 @@ class RbpdfTest < ActiveSupport::TestCase
|
|
151
157
|
assert_equal 3, page
|
152
158
|
|
153
159
|
# Page 1
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
count_head += 1
|
164
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
165
|
-
pos1 = $1
|
166
|
-
assert_not_nil pos1
|
167
|
-
end
|
168
|
-
if line =~ /abcd/
|
169
|
-
count += 1
|
170
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
171
|
-
pos2 = $1
|
172
|
-
assert_not_nil pos2
|
173
|
-
end
|
174
|
-
end
|
175
|
-
assert_equal count_text, 13
|
176
|
-
assert_equal count_head, 1
|
177
|
-
assert_equal count, 1
|
178
|
-
assert_equal pos1, pos2
|
160
|
+
count_line, count_text, xpos1 = pdf.get_html_text_position_x(1, /ABCD/) # Header
|
161
|
+
assert_not_nil xpos1
|
162
|
+
assert_equal 1, count_text
|
163
|
+
assert_equal 13, count_line
|
164
|
+
count_line, count_text, xpos2 = pdf.get_html_text_position_x(1, /abcd/)
|
165
|
+
assert_not_nil xpos2
|
166
|
+
assert_equal 1, count_text
|
167
|
+
assert_equal xpos1, xpos2
|
168
|
+
assert_equal 13, count_line
|
179
169
|
|
180
170
|
# Page 2
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
end
|
194
|
-
count += 1 if line =~ /abcd/
|
195
|
-
if line =~ /\([6-9]\)/
|
196
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
197
|
-
pos2 = $1
|
198
|
-
assert_not_nil pos2
|
199
|
-
assert_equal pos1, pos2
|
200
|
-
end
|
201
|
-
end
|
202
|
-
assert_equal count_text, 10
|
203
|
-
assert_equal count_head, 1
|
204
|
-
assert_equal count, 0
|
171
|
+
count_line, count_text, xpos2 = pdf.get_html_text_position_x(2, /ABCD/, xpos1) # Header
|
172
|
+
assert_not_nil xpos2
|
173
|
+
assert_equal 1, count_text
|
174
|
+
assert_equal xpos1, xpos2
|
175
|
+
assert_equal 10, count_line
|
176
|
+
count_line, count_text, xpos2 = pdf.get_html_text_position_x(2, /abcd/)
|
177
|
+
assert_equal 0, count_text
|
178
|
+
assert_equal 10, count_line
|
179
|
+
count_line, count_text, xpos2 = pdf.get_html_text_position_x(2, /\([6-9]\)/, xpos1)
|
180
|
+
assert_not_nil xpos2
|
181
|
+
assert_equal xpos1, xpos2
|
182
|
+
assert_equal 10, count_line
|
205
183
|
|
206
184
|
# Page 3
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
count += 1 if line =~ /abcd/
|
221
|
-
if line =~ /\(11\)/
|
222
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
223
|
-
pos2 = $1
|
224
|
-
assert_not_nil pos2
|
225
|
-
assert_equal pos1, pos2
|
226
|
-
end
|
227
|
-
end
|
228
|
-
assert_equal count_text, 5
|
229
|
-
assert_equal count_head, 1
|
230
|
-
assert_equal count, 0
|
185
|
+
count_line, count_text, xpos2 = pdf.get_html_text_position_x(3, /ABCD/, xpos1) # Header
|
186
|
+
assert_not_nil xpos2
|
187
|
+
assert_equal 1, count_text
|
188
|
+
assert_equal xpos1, xpos2
|
189
|
+
assert_equal 5, count_line
|
190
|
+
count_line, count_text, xpos2 = pdf.get_html_text_position_x(3, /abcd/)
|
191
|
+
assert_equal 0, count_text
|
192
|
+
assert_equal 5, count_line
|
193
|
+
count_line, count_text, xpos2 = pdf.get_html_text_position_x(3, /\(11\)/, xpos1)
|
194
|
+
assert_not_nil xpos2
|
195
|
+
assert_equal 1, count_text
|
196
|
+
assert_equal xpos1, xpos2
|
197
|
+
assert_equal 5, count_line
|
231
198
|
end
|
232
199
|
|
233
200
|
test "write_html_cell Table thead tag test" do
|
@@ -255,83 +222,39 @@ class RbpdfTest < ActiveSupport::TestCase
|
|
255
222
|
assert_equal 1, page
|
256
223
|
|
257
224
|
# Page 1
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
count_head += 1
|
268
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
269
|
-
pos1 = $1
|
270
|
-
assert_not_nil pos1
|
271
|
-
end
|
272
|
-
if line =~ /left/
|
273
|
-
count += 1
|
274
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
275
|
-
pos2 = $1
|
276
|
-
assert_not_nil pos2
|
277
|
-
end
|
278
|
-
end
|
279
|
-
assert_equal count_text, 13
|
280
|
-
assert_equal count_head, 1
|
281
|
-
assert_equal count, 1
|
282
|
-
assert_equal pos1, pos2
|
225
|
+
count_line, count_text, xpos1 = pdf.get_html_text_position_x(1, /Left align/) # Header
|
226
|
+
assert_not_nil xpos1
|
227
|
+
assert_equal 1, count_text
|
228
|
+
assert_equal 13, count_line
|
229
|
+
count_line, count_text, xpos2 = pdf.get_html_text_position_x(1, /left/)
|
230
|
+
assert_not_nil xpos2
|
231
|
+
assert_equal 1, count_text
|
232
|
+
assert_equal 13, count_line
|
233
|
+
assert_equal xpos1, xpos2
|
283
234
|
|
284
235
|
# Page 2
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
assert_not_nil pos2
|
296
|
-
assert_equal pos1, pos2
|
297
|
-
end
|
298
|
-
if line =~ /\(6\)/
|
299
|
-
count += 1
|
300
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
301
|
-
pos2 = $1
|
302
|
-
assert_not_nil pos2
|
303
|
-
assert_equal pos1, pos2
|
304
|
-
end
|
305
|
-
end
|
306
|
-
assert_equal count_text, 10
|
307
|
-
assert_equal count_head, 1
|
308
|
-
assert_equal count, 1
|
236
|
+
count_line, count_text, xpos2 = pdf.get_html_text_position_x(2, /Left align/, xpos1) # Header
|
237
|
+
assert_not_nil xpos2
|
238
|
+
assert_equal 1, count_text
|
239
|
+
assert_equal xpos1, xpos2
|
240
|
+
assert_equal 10, count_line
|
241
|
+
count_line, count_text, xpos2 = pdf.get_html_text_position_x(2, /\(6\)/, xpos1)
|
242
|
+
assert_not_nil xpos2
|
243
|
+
assert_equal 1, count_text
|
244
|
+
assert_equal xpos1, xpos2
|
245
|
+
assert_equal 10, count_line
|
309
246
|
|
310
247
|
# Page 3
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
assert_not_nil pos2
|
322
|
-
assert_equal pos1, pos2
|
323
|
-
end
|
324
|
-
if line =~ /\(11\)/
|
325
|
-
count += 1
|
326
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
327
|
-
pos2 = $1
|
328
|
-
assert_not_nil pos2
|
329
|
-
assert_equal pos1, pos2
|
330
|
-
end
|
331
|
-
end
|
332
|
-
assert_equal count_text, 5
|
333
|
-
assert_equal count_head, 1
|
334
|
-
assert_equal count, 1
|
248
|
+
count_line, count_text, xpos2 = pdf.get_html_text_position_x(3, /Left align/, xpos1) # Header
|
249
|
+
assert_not_nil xpos2
|
250
|
+
assert_equal 1, count_text
|
251
|
+
assert_equal xpos1, xpos2
|
252
|
+
assert_equal 5, count_line
|
253
|
+
count_line, count_text, xpos2 = pdf.get_html_text_position_x(3, /\(11\)/, xpos1)
|
254
|
+
assert_not_nil xpos2
|
255
|
+
assert_equal 1, count_text
|
256
|
+
assert_equal xpos1, xpos2
|
257
|
+
assert_equal 5, count_line
|
335
258
|
end
|
336
259
|
|
337
260
|
test "write_html_cell Table thead tag cellpadding x position test" do
|
@@ -359,57 +282,27 @@ class RbpdfTest < ActiveSupport::TestCase
|
|
359
282
|
assert_equal 1, page
|
360
283
|
|
361
284
|
# Page 1
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
count_head += 1
|
372
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
373
|
-
pos1 = $1
|
374
|
-
assert_not_nil pos1
|
375
|
-
end
|
376
|
-
if line =~ /right/
|
377
|
-
count += 1
|
378
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
379
|
-
pos2 = $1
|
380
|
-
assert_not_nil pos2
|
381
|
-
end
|
382
|
-
end
|
383
|
-
assert_equal count_text, 13
|
384
|
-
assert_equal count_head, 1
|
385
|
-
assert_equal count, 1
|
386
|
-
assert_equal pos1, pos2
|
285
|
+
count_line, count_text, xpos1 = pdf.get_html_text_position_x(1, /Right align/) # Header
|
286
|
+
assert_not_nil xpos1
|
287
|
+
assert_equal 1, count_text
|
288
|
+
assert_equal 13, count_line
|
289
|
+
count_line, count_text, xpos2 = pdf.get_html_text_position_x(1, /right/)
|
290
|
+
assert_not_nil xpos2
|
291
|
+
assert_equal 1, count_text
|
292
|
+
assert_equal xpos1, xpos2
|
293
|
+
assert_equal 13, count_line
|
387
294
|
|
388
295
|
# Page 2
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
assert_not_nil pos2
|
400
|
-
assert_equal pos1, pos2
|
401
|
-
end
|
402
|
-
if line =~ /\(6\)/
|
403
|
-
count += 1
|
404
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
405
|
-
pos2 = $1
|
406
|
-
assert_not_nil pos2
|
407
|
-
assert_equal pos1, pos2
|
408
|
-
end
|
409
|
-
end
|
410
|
-
assert_equal count_text, 10
|
411
|
-
assert_equal count_head, 1
|
412
|
-
assert_equal count, 1
|
296
|
+
count_line, count_text, xpos2 = pdf.get_html_text_position_x(2, /Right align/, xpos1) # Header
|
297
|
+
assert_not_nil xpos2
|
298
|
+
assert_equal 1, count_text
|
299
|
+
assert_equal xpos1, xpos2
|
300
|
+
assert_equal 10, count_line
|
301
|
+
count_line, count_text, xpos2 = pdf.get_html_text_position_x(2, /\(6\)/, xpos1)
|
302
|
+
assert_not_nil xpos2
|
303
|
+
assert_equal 1, count_text
|
304
|
+
assert_equal xpos1, xpos2
|
305
|
+
assert_equal 10, count_line
|
413
306
|
end
|
414
307
|
|
415
308
|
test "write_html_cell Table thead tag cellpadding y position test 1" do
|
@@ -426,57 +319,26 @@ class RbpdfTest < ActiveSupport::TestCase
|
|
426
319
|
pdf.write_html_cell(0, 0, '', '',tablehtml)
|
427
320
|
|
428
321
|
# Page 1
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
439
|
-
pos1 = $2
|
440
|
-
assert_not_nil pos1
|
441
|
-
end
|
442
|
-
if line =~ /AAA/
|
443
|
-
count += 1
|
444
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
445
|
-
pos2 = $2 if pos2 == -1
|
446
|
-
assert_not_nil pos2
|
447
|
-
end
|
448
|
-
end
|
449
|
-
|
450
|
-
assert_equal count_text, 65
|
451
|
-
assert_equal count_head, 1
|
452
|
-
assert_equal count, 20
|
453
|
-
base_pos = pos1.to_i - pos2.to_i
|
322
|
+
count_line, count_text, ypos1 = pdf.get_html_text_position_y(1, /Left align/) # Header
|
323
|
+
assert_not_nil ypos1
|
324
|
+
assert_equal 1, count_text
|
325
|
+
assert_equal 65, count_line
|
326
|
+
count_line, count_text, ypos2 = pdf.get_html_text_position_y(1, /AAA/)
|
327
|
+
assert_not_nil ypos2
|
328
|
+
assert_equal 20, count_text
|
329
|
+
assert_equal 65, count_line
|
330
|
+
base_pos = ypos1.to_i - ypos2.to_i
|
454
331
|
|
455
332
|
# Page 2
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
466
|
-
pos1 = $2
|
467
|
-
assert_not_nil pos1
|
468
|
-
end
|
469
|
-
if line =~ /AAA/
|
470
|
-
count += 1
|
471
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
472
|
-
pos2 = $2 if pos2 == -1
|
473
|
-
assert_not_nil pos2
|
474
|
-
end
|
475
|
-
end
|
476
|
-
assert_equal count_text, 34
|
477
|
-
assert_equal count_head, 1
|
478
|
-
assert_equal count, 10
|
479
|
-
assert_equal base_pos, pos1.to_i - pos2.to_i
|
333
|
+
count_line, count_text, ypos1 = pdf.get_html_text_position_y(2, /Left align/) # Header
|
334
|
+
assert_not_nil ypos2
|
335
|
+
assert_equal 1, count_text
|
336
|
+
assert_equal 34, count_line
|
337
|
+
count_line, count_text, ypos2 = pdf.get_html_text_position_y(2, /AAA/)
|
338
|
+
assert_not_nil ypos2
|
339
|
+
assert_equal 10, count_text
|
340
|
+
assert_equal 34, count_line
|
341
|
+
assert_equal base_pos, ypos1.to_i - ypos2.to_i
|
480
342
|
end
|
481
343
|
|
482
344
|
test "write_html_cell Table thead tag cellpadding y position test 2" do
|
@@ -493,57 +355,26 @@ class RbpdfTest < ActiveSupport::TestCase
|
|
493
355
|
pdf.write_html_cell(0, 0, '', '',tablehtml)
|
494
356
|
|
495
357
|
# Page 1
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
506
|
-
pos1 = $2
|
507
|
-
assert_not_nil pos1
|
508
|
-
end
|
509
|
-
if line =~ /AAA/
|
510
|
-
count += 1
|
511
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
512
|
-
pos2 = $2 if pos2 == -1
|
513
|
-
assert_not_nil pos2
|
514
|
-
end
|
515
|
-
end
|
516
|
-
|
517
|
-
assert_equal count_text, 66
|
518
|
-
assert_equal count_head, 1
|
519
|
-
assert_equal count, 20
|
520
|
-
base_pos = pos1.to_i - pos2.to_i
|
358
|
+
count_line, count_text, ypos1 = pdf.get_html_text_position_y(1, /Left align/) # Header
|
359
|
+
assert_not_nil ypos1
|
360
|
+
assert_equal 1, count_text
|
361
|
+
assert_equal 66, count_line
|
362
|
+
count_line, count_text, ypos2 = pdf.get_html_text_position_y(1, /AAA/)
|
363
|
+
assert_not_nil ypos2
|
364
|
+
assert_equal 20, count_text
|
365
|
+
assert_equal 66, count_line
|
366
|
+
base_pos = ypos1.to_i - ypos2.to_i
|
521
367
|
|
522
368
|
# Page 2
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
533
|
-
pos1 = $2
|
534
|
-
assert_not_nil pos1
|
535
|
-
end
|
536
|
-
if line =~ /AAA/
|
537
|
-
count += 1
|
538
|
-
line =~ /BT ([0-9.]+) ([0-9.]+) Td/
|
539
|
-
pos2 = $2 if pos2 == -1
|
540
|
-
assert_not_nil pos2
|
541
|
-
end
|
542
|
-
end
|
543
|
-
assert_equal count_text, 34
|
544
|
-
assert_equal count_head, 1
|
545
|
-
assert_equal count, 10
|
546
|
-
assert_equal base_pos, pos1.to_i - pos2.to_i
|
369
|
+
count_line, count_text, ypos1 = pdf.get_html_text_position_y(2, /Left align/) # Header
|
370
|
+
assert_not_nil ypos2
|
371
|
+
assert_equal 1, count_text
|
372
|
+
assert_equal 34, count_line
|
373
|
+
count_line, count_text, ypos2 = pdf.get_html_text_position_y(2, /AAA/)
|
374
|
+
assert_not_nil ypos2
|
375
|
+
assert_equal 10, count_text
|
376
|
+
assert_equal 34, count_line
|
377
|
+
assert_equal base_pos, ypos1.to_i - ypos2.to_i
|
547
378
|
end
|
548
379
|
|
549
380
|
test "write_html ASCII text test" do
|
@@ -560,11 +391,11 @@ class RbpdfTest < ActiveSupport::TestCase
|
|
560
391
|
contents = pdf.getPageBuffer(1)
|
561
392
|
contents.each_line {|line| content.push line.chomp }
|
562
393
|
|
563
|
-
|
394
|
+
count_text = 0
|
564
395
|
content.each do |line|
|
565
|
-
|
396
|
+
count_text += 1 unless line.scan(text).empty?
|
566
397
|
end
|
567
|
-
assert_equal
|
398
|
+
assert_equal count_text, 1
|
568
399
|
end
|
569
400
|
|
570
401
|
test "write_html Non ASCII text test" do
|
@@ -584,12 +415,28 @@ class RbpdfTest < ActiveSupport::TestCase
|
|
584
415
|
|
585
416
|
text = 'HTML Example ' + "\x83\x86"
|
586
417
|
text.force_encoding('ASCII-8BIT') if text.respond_to?(:force_encoding)
|
587
|
-
|
418
|
+
count_text = 0
|
588
419
|
content.each do |line|
|
589
420
|
line.force_encoding('ASCII-8BIT') if line.respond_to?(:force_encoding)
|
590
|
-
|
421
|
+
count_text += 1 unless line.scan(text).empty?
|
422
|
+
end
|
423
|
+
assert_equal count_text, 1
|
424
|
+
end
|
425
|
+
|
426
|
+
test "works internal links out of page range" do
|
427
|
+
pdf = RBPDF.new
|
428
|
+
pdf.add_page()
|
429
|
+
|
430
|
+
htmlcontent = '<a href="#100400_somelink">FooLink</a>'
|
431
|
+
pdf.write_html(htmlcontent, true, 0, true, 0)
|
432
|
+
|
433
|
+
assert_nothing_raised do
|
434
|
+
pdf.Close
|
435
|
+
end
|
436
|
+
|
437
|
+
assert_nothing_raised do
|
438
|
+
pdf.Output
|
591
439
|
end
|
592
|
-
assert_equal count, 1
|
593
440
|
end
|
594
441
|
|
595
442
|
test "write_html <b> tag test" do
|