rbpdf 1.18.7 → 1.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +12 -0
  3. data/Gemfile +3 -0
  4. data/README.md +1 -5
  5. data/Rakefile +10 -0
  6. data/lib/rbpdf.rb +715 -222
  7. data/lib/rbpdf/version.rb +1 -1
  8. data/rbpdf.gemspec +3 -3
  9. data/test/err_font1.rb +3 -0
  10. data/test/err_font2.rb +4 -0
  11. data/test/rbpdf_bidi_test.rb +85 -14
  12. data/test/rbpdf_bookmark_test.rb +1 -2
  13. data/test/rbpdf_cell_test.rb +1 -2
  14. data/test/rbpdf_content_test.rb +1 -1
  15. data/test/rbpdf_css_test.rb +1 -1
  16. data/test/rbpdf_dom_test.rb +1 -1
  17. data/test/rbpdf_font_func_test.rb +1 -1
  18. data/test/rbpdf_font_style_test.rb +1 -2
  19. data/test/rbpdf_font_test.rb +111 -1
  20. data/test/rbpdf_format_test.rb +1 -2
  21. data/test/rbpdf_func_test.rb +1 -1
  22. data/test/rbpdf_html_anchor_test.rb +107 -0
  23. data/test/rbpdf_html_func_test.rb +1 -1
  24. data/test/rbpdf_html_test.rb +196 -349
  25. data/test/rbpdf_htmlcell_test.rb +1 -1
  26. data/test/rbpdf_image_rmagick_test.rb +1 -2
  27. data/test/rbpdf_image_test.rb +1 -2
  28. data/test/rbpdf_test.rb +1 -1
  29. data/test/rbpdf_transaction_test.rb +1 -1
  30. data/test/rbpdf_viewerpreferences_test.rb +1 -1
  31. data/test/rbpdf_write_test.rb +1 -2
  32. data/test/test_helper.rb +2 -0
  33. metadata +38 -89
  34. data/lib/fonts/README.z +0 -2
  35. data/lib/fonts/arialunicid0_cw.rb +0 -1738
  36. data/lib/fonts/cid0cs.rb +0 -21
  37. data/lib/fonts/cid0ct.rb +0 -21
  38. data/lib/fonts/cid0jp.rb +0 -21
  39. data/lib/fonts/cid0kr.rb +0 -21
  40. data/lib/fonts/courier.rb +0 -37
  41. data/lib/fonts/dejavu-fonts-ttf-2.33/AUTHORS +0 -53
  42. data/lib/fonts/dejavu-fonts-ttf-2.33/BUGS +0 -3
  43. data/lib/fonts/dejavu-fonts-ttf-2.33/LICENSE +0 -99
  44. data/lib/fonts/dejavu-fonts-ttf-2.33/NEWS +0 -1315
  45. data/lib/fonts/dejavu-fonts-ttf-2.33/README +0 -59
  46. data/lib/fonts/dejavusans.ctg.z +0 -0
  47. data/lib/fonts/dejavusans.rb +0 -338
  48. data/lib/fonts/dejavusans.z +0 -0
  49. data/lib/fonts/dejavusansb.ctg.z +0 -0
  50. data/lib/fonts/dejavusansb.rb +0 -330
  51. data/lib/fonts/dejavusansb.z +0 -0
  52. data/lib/fonts/dejavusansbi.ctg.z +0 -0
  53. data/lib/fonts/dejavusansbi.rb +0 -297
  54. data/lib/fonts/dejavusansbi.z +0 -0
  55. data/lib/fonts/dejavusansi.ctg.z +0 -0
  56. data/lib/fonts/dejavusansi.rb +0 -305
  57. data/lib/fonts/dejavusansi.z +0 -0
  58. data/lib/fonts/freefont-20080912/AUTHORS +0 -191
  59. data/lib/fonts/freefont-20080912/COPYING +0 -341
  60. data/lib/fonts/freefont-20080912/CREDITS +0 -506
  61. data/lib/fonts/freefont-20080912/ChangeLog +0 -3320
  62. data/lib/fonts/freefont-20080912/INSTALL +0 -81
  63. data/lib/fonts/freefont-20080912/README +0 -108
  64. data/lib/fonts/freemono.ctg.z +0 -0
  65. data/lib/fonts/freemono.rb +0 -203
  66. data/lib/fonts/freemono.z +0 -0
  67. data/lib/fonts/freemonob.ctg.z +0 -0
  68. data/lib/fonts/freemonob.rb +0 -120
  69. data/lib/fonts/freemonob.z +0 -0
  70. data/lib/fonts/freemonobi.ctg.z +0 -0
  71. data/lib/fonts/freemonobi.rb +0 -84
  72. data/lib/fonts/freemonobi.z +0 -0
  73. data/lib/fonts/freemonoi.ctg.z +0 -0
  74. data/lib/fonts/freemonoi.rb +0 -136
  75. data/lib/fonts/freemonoi.z +0 -0
  76. data/lib/fonts/freesans.ctg.z +0 -0
  77. data/lib/fonts/freesans.rb +0 -196
  78. data/lib/fonts/freesans.z +0 -0
  79. data/lib/fonts/freesansb.ctg.z +0 -0
  80. data/lib/fonts/freesansb.rb +0 -136
  81. data/lib/fonts/freesansb.z +0 -0
  82. data/lib/fonts/freesansbi.ctg.z +0 -0
  83. data/lib/fonts/freesansbi.rb +0 -108
  84. data/lib/fonts/freesansbi.z +0 -0
  85. data/lib/fonts/freesansi.ctg.z +0 -0
  86. data/lib/fonts/freesansi.rb +0 -136
  87. data/lib/fonts/freesansi.z +0 -0
  88. data/lib/fonts/freeserif.ctg.z +0 -0
  89. data/lib/fonts/freeserif.rb +0 -285
  90. data/lib/fonts/freeserif.z +0 -0
  91. data/lib/fonts/freeserifb.ctg.z +0 -0
  92. data/lib/fonts/freeserifb.rb +0 -164
  93. data/lib/fonts/freeserifb.z +0 -0
  94. data/lib/fonts/freeserifbi.ctg.z +0 -0
  95. data/lib/fonts/freeserifbi.rb +0 -130
  96. data/lib/fonts/freeserifbi.z +0 -0
  97. data/lib/fonts/freeserifi.ctg.z +0 -0
  98. data/lib/fonts/freeserifi.rb +0 -151
  99. data/lib/fonts/freeserifi.z +0 -0
  100. data/lib/fonts/helvetica.rb +0 -34
  101. data/lib/fonts/helveticab.rb +0 -34
  102. data/lib/fonts/helveticabi.rb +0 -34
  103. data/lib/fonts/helveticai.rb +0 -34
  104. data/lib/fonts/hysmyeongjostdmedium.rb +0 -31
  105. data/lib/fonts/kozgopromedium.rb +0 -47
  106. data/lib/fonts/kozminproregular.rb +0 -46
  107. data/lib/fonts/msungstdlight.rb +0 -23
  108. data/lib/fonts/sjis.rb +0 -834
  109. data/lib/fonts/stsongstdlight.rb +0 -23
  110. data/lib/fonts/symbol.rb +0 -33
  111. data/lib/fonts/times.rb +0 -34
  112. data/lib/fonts/timesb.rb +0 -34
  113. data/lib/fonts/timesbi.rb +0 -34
  114. data/lib/fonts/timesi.rb +0 -34
  115. data/lib/fonts/uni2cid_ac15.rb +0 -23613
  116. data/lib/fonts/uni2cid_ag15.rb +0 -30222
  117. data/lib/fonts/uni2cid_aj16.rb +0 -15705
  118. data/lib/fonts/uni2cid_ak12.rb +0 -17530
  119. data/lib/fonts/zapfdingbats.rb +0 -33
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class RbpdfTest < ActiveSupport::TestCase
3
+ class RbpdfTest < Test::Unit::TestCase
4
4
  class MYPDF < RBPDF
5
5
  def addHTMLVertSpace(hbz, hb, cell, firstorlast)
6
6
  super
@@ -1,12 +1,50 @@
1
1
  # coding: ASCII-8BIT
2
2
  require 'test_helper'
3
3
 
4
- class RbpdfTest < ActiveSupport::TestCase
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
- content = []
73
- contents = pdf.getPageBuffer(1)
74
- contents.each_line {|line| content.push line.chomp }
75
- count = 0
76
- count_text = 0
77
- pos1 = -1
78
- pos2 = -2
79
- content.each do |line|
80
- count_text += 1 if line =~ /TJ ET Q$/
81
- if line =~ /ABCD/
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
- content = []
98
- contents = pdf.getPageBuffer(2)
99
- contents.each_line {|line| content.push line.chomp }
100
- count_head = 0
101
- count = 0
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
- content = []
129
- contents = pdf.getPageBuffer(page)
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
- content = []
155
- contents = pdf.getPageBuffer(1)
156
- contents.each_line {|line| content.push line.chomp }
157
- count_text = count_head = count = 0
158
- pos1 = -1
159
- pos2 = -2
160
- content.each do |line|
161
- count_text += 1 if line =~ /TJ ET Q$/
162
- if line =~ /ABCD/
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
- content = []
182
- contents = pdf.getPageBuffer(2)
183
- contents.each_line {|line| content.push line.chomp }
184
- count_text = count_head = count = 0
185
- content.each do |line|
186
- count_text += 1 if line =~ /TJ ET Q$/
187
- if line =~ /ABCD/
188
- count_head += 1
189
- line =~ /BT ([0-9.]+) ([0-9.]+) Td/
190
- pos2 = $1
191
- assert_not_nil pos2
192
- assert_equal pos1, pos2
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
- content = []
208
- contents = pdf.getPageBuffer(3)
209
- contents.each_line {|line| content.push line.chomp }
210
- count_text = count_head = count = 0
211
- content.each do |line|
212
- count_text += 1 if line =~ /TJ ET Q$/
213
- if line =~ /ABCD/
214
- count_head += 1
215
- line =~ /BT ([0-9.]+) ([0-9.]+) Td/
216
- pos2 = $1
217
- assert_not_nil pos2
218
- assert_equal pos1, pos2
219
- end
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
- content = []
259
- contents = pdf.getPageBuffer(1)
260
- contents.each_line {|line| content.push line.chomp }
261
- count_text = count_head = count = 0
262
- pos1 = -1
263
- pos2 = -2
264
- content.each do |line|
265
- count_text += 1 if line =~ /TJ ET Q$/
266
- if line =~ /Left align/
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
- content = []
286
- contents = pdf.getPageBuffer(2)
287
- contents.each_line {|line| content.push line.chomp }
288
- count_text = count_head = count = 0
289
- content.each do |line|
290
- count_text += 1 if line =~ /TJ ET Q$/
291
- if line =~ /Left align/
292
- count_head += 1
293
- line =~ /BT ([0-9.]+) ([0-9.]+) Td/
294
- pos2 = $1
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
- content = []
312
- contents = pdf.getPageBuffer(3)
313
- contents.each_line {|line| content.push line.chomp }
314
- count_text = count_head = count = 0
315
- content.each do |line|
316
- count_text += 1 if line =~ /TJ ET Q$/
317
- if line =~ /Left align/
318
- count_head += 1
319
- line =~ /BT ([0-9.]+) ([0-9.]+) Td/
320
- pos2 = $1
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
- content = []
363
- contents = pdf.getPageBuffer(1)
364
- contents.each_line {|line| content.push line.chomp }
365
- count_text = count_head = count = 0
366
- pos1 = -1
367
- pos2 = -2
368
- content.each do |line|
369
- count_text += 1 if line =~ /TJ ET Q$/
370
- if line =~ /Right align/
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
- content = []
390
- contents = pdf.getPageBuffer(2)
391
- contents.each_line {|line| content.push line.chomp }
392
- count_text = count_head = count = 0
393
- content.each do |line|
394
- count_text += 1 if line =~ /TJ ET Q$/
395
- if line =~ /Right align/
396
- count_head += 1
397
- line =~ /BT ([0-9.]+) ([0-9.]+) Td/
398
- pos2 = $1
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
- content = []
430
- contents = pdf.getPageBuffer(1)
431
- contents.each_line {|line| content.push line.chomp }
432
- count_text = count_head = count = 0
433
- pos1 = pos2 = -1
434
- content.each do |line|
435
- count_text += 1 if line =~ /TJ ET Q$/
436
- if line =~ /Left align/
437
- count_head += 1
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
- content = []
457
- contents = pdf.getPageBuffer(2)
458
- contents.each_line {|line| content.push line.chomp }
459
- count_text = count_head = count = 0
460
- pos1 = pos2 = -1
461
- content.each do |line|
462
- count_text += 1 if line =~ /TJ ET Q$/
463
- if line =~ /Left align/
464
- count_head += 1
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
- content = []
497
- contents = pdf.getPageBuffer(1)
498
- contents.each_line {|line| content.push line.chomp }
499
- count_text = count_head = count = 0
500
- pos1 = pos2 = -1
501
- content.each do |line|
502
- count_text += 1 if line =~ /TJ ET Q$/
503
- if line =~ /Left align/
504
- count_head += 1
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
- content = []
524
- contents = pdf.getPageBuffer(2)
525
- contents.each_line {|line| content.push line.chomp }
526
- count_text = count_head = count = 0
527
- pos1 = pos2 = -1
528
- content.each do |line|
529
- count_text += 1 if line =~ /TJ ET Q$/
530
- if line =~ /Left align/
531
- count_head += 1
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
- count = 0
394
+ count_text = 0
564
395
  content.each do |line|
565
- count += 1 unless line.scan(text).empty?
396
+ count_text += 1 unless line.scan(text).empty?
566
397
  end
567
- assert_equal count, 1
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
- count = 0
418
+ count_text = 0
588
419
  content.each do |line|
589
420
  line.force_encoding('ASCII-8BIT') if line.respond_to?(:force_encoding)
590
- count += 1 unless line.scan(text).empty?
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