rbpdf 1.20.0 → 1.21.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.
Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG +18 -0
  3. data/README.md +11 -1
  4. data/lib/rbpdf/version.rb +2 -2
  5. data/lib/rbpdf.rb +69 -46
  6. data/lib/unicode_data.rb +29 -0
  7. data/rbpdf.gemspec +8 -20
  8. metadata +28 -101
  9. data/test/err_font1.rb +0 -7
  10. data/test/err_font2.rb +0 -8
  11. data/test/input.jpg +0 -0
  12. data/test/json: +0 -0
  13. data/test/logo_rbpdf_8bit .png +0 -0
  14. data/test/logo_rbpdf_8bit+ .png +0 -0
  15. data/test/logo_rbpdf_8bit.gif +0 -0
  16. data/test/logo_rbpdf_8bit.jpg +0 -0
  17. data/test/logo_rbpdf_8bit.png +0 -0
  18. data/test/logo_rbpdf_8bit_alpha.gif +0 -0
  19. data/test/logo_rbpdf_mono_gray.jpg +0 -0
  20. data/test/logo_rbpdf_mono_gray.png +0 -0
  21. data/test/logo_rbpdf_mono_rgb.jpg +0 -0
  22. data/test/logo_rbpdf_mono_rgb.png +0 -0
  23. data/test/output.png +0 -0
  24. data/test/png_test_alpha.png +0 -0
  25. data/test/png_test_msk_alpha.png +0 -0
  26. data/test/png_test_non_alpha.png +0 -0
  27. data/test/rbpdf_bidi_test.rb +0 -453
  28. data/test/rbpdf_bookmark_test.rb +0 -66
  29. data/test/rbpdf_cell_test.rb +0 -231
  30. data/test/rbpdf_content_test.rb +0 -213
  31. data/test/rbpdf_css_test.rb +0 -640
  32. data/test/rbpdf_dom_test.rb +0 -272
  33. data/test/rbpdf_examples_test.rb +0 -83
  34. data/test/rbpdf_font_func_test.rb +0 -45
  35. data/test/rbpdf_font_style_test.rb +0 -37
  36. data/test/rbpdf_font_test.rb +0 -308
  37. data/test/rbpdf_format_test.rb +0 -30
  38. data/test/rbpdf_func_test.rb +0 -139
  39. data/test/rbpdf_html_anchor_test.rb +0 -105
  40. data/test/rbpdf_html_func_test.rb +0 -170
  41. data/test/rbpdf_html_test.rb +0 -658
  42. data/test/rbpdf_htmlcell_test.rb +0 -60
  43. data/test/rbpdf_http_test.rb +0 -76
  44. data/test/rbpdf_image_rmagick_test.rb +0 -170
  45. data/test/rbpdf_image_test.rb +0 -174
  46. data/test/rbpdf_test.rb +0 -375
  47. data/test/rbpdf_transaction_test.rb +0 -203
  48. data/test/rbpdf_viewerpreferences_test.rb +0 -41
  49. data/test/rbpdf_write_test.rb +0 -229
  50. data/test/test.rb +0 -22
  51. data/test/test_helper.rb +0 -9
@@ -1,658 +0,0 @@
1
- # coding: ASCII-8BIT
2
- #
3
- # Copyright (c) 2011-2017 NAITOH Jun
4
- # Released under the MIT license
5
- # http://www.opensource.org/licenses/MIT
6
-
7
- require 'test_helper'
8
-
9
- class RbpdfHtmlTest < Test::Unit::TestCase
10
- class MYPDF < RBPDF
11
- def getPageBuffer(page)
12
- super
13
- end
14
-
15
- # get text count and x_pos from pdf page
16
- def get_html_text_position_x(page, regrep_text, x_pos_exp=nil)
17
- count_line, count_text, x_pos, _y_pos = get_html_text_position(page, regrep_text, x_pos_exp)
18
- return count_line, count_text, x_pos
19
- end
20
-
21
- # get text count and y_pos from pdf page
22
- def get_html_text_position_y(page, regrep_text)
23
- count_line, count_text, _x_pos, y_pos = get_html_text_position(page, regrep_text)
24
- return count_line, count_text, y_pos
25
- end
26
-
27
- # get text count and pos from pdf page
28
- def get_html_text_position(page, regrep_text, x_pos_exp=nil)
29
- content = []
30
- contents = getPageBuffer(page)
31
- contents.each_line {|line| content.push line.chomp }
32
- count_line = count_text = 0
33
- x_pos = y_pos = -1
34
- content.each do |line|
35
- count_line += 1 if line =~ /TJ ET Q$/ # Text Line Count
36
- if line =~ regrep_text
37
- count_text += 1
38
- line =~ /BT ([0-9.]+) ([0-9.]+) Td/
39
- x_pos = $1
40
- y_pos = $2 if y_pos == -1 # y first position only
41
-
42
- if x_pos.nil? or y_pos.nil? # Error
43
- return count_line, count_text, nil, nil
44
- end
45
- if !x_pos_exp.nil? and x_pos != x_pos_exp # Error
46
- return count_line, count_text, x_pos, y_pos
47
- end
48
- end
49
- end
50
- return count_line, count_text, x_pos, y_pos
51
- end
52
-
53
- # get text from pdf page
54
- def get_html_text(page)
55
- content = []
56
- contents = getPageBuffer(page)
57
- contents.each_line {|line| content.push line.chomp }
58
- pdf_text = ''
59
- content.each do |line|
60
- if line =~ /\[\((.*)\)\] TJ ET/
61
- pdf_text << $1
62
- end
63
- end
64
- return pdf_text
65
- end
66
- end
67
-
68
- test "write_html Basic test" do
69
- pdf = RBPDF.new
70
- pdf.add_page()
71
-
72
- htmlcontent = '<h1>HTML Example</h1>'
73
- pdf.write_html(htmlcontent, true, 0, true, 0)
74
-
75
- htmlcontent = 'abcdefghijklmnopgrstuvwxyz01234567890 abcdefghijklmnopgrstuvwxyz01234567890 abcdefghijklmnopgrstuvwxyz01234567890 abcdefghijklmnopgrstuvwxyz01234567890 abcdefghijklmnopgrstuvwxyz01234567890'
76
- pdf.write_html(htmlcontent, true, 0, true, 0)
77
-
78
- htmlcontent = '1<br><br><br><br><br><br><br><br><br><br> 2<br><br><br><br><br><br><br><br><br><br> 3<br><br><br><br><br><br><br><br><br><br> 4<br><br><br><br><br><br><br><br><br><br> 5<br><br><br><br><br><br><br><br><br><br> 6<br><br><br><br><br><br><br><br><br><br> 7<br><br><br><br><br><br><br><br><br><br> 8<br><br><br><br><br><br><br><br><br><br> 9<br><br><br><br><br><br><br><br><br><br> 10<br><br><br><br><br><br><br><br><br><br> 11<br><br><br><br><br><br><br><br><br><br>'
79
- pdf.write_html(htmlcontent, true, 0, true, 0)
80
-
81
- pno = pdf.get_page
82
- assert_equal 3, pno
83
- end
84
-
85
- test "write_html Table test 1" do
86
- pdf = RBPDF.new
87
- pdf.add_page()
88
-
89
- tablehtml = '<table border="1" cellspacing="1" cellpadding="1"><tr><td>a</td><td>b</td></tr><tr><td>c</td><td>d</td></tr></table>'
90
- pdf.write_html(tablehtml, true, 0, true, 0)
91
-
92
- htmlcontent = '1<br><br><br><br><br><br><br><br><br><br> 2<br><br><br><br><br><br><br><br><br><br> 3<br><br><br><br><br><br><br><br><br><br> 4<br><br><br><br><br><br><br><br><br><br> 5<br><br><br><br><br><br><br><br><br><br> 6<br><br><br><br><br><br><br><br><br><br> 7<br><br><br><br><br><br><br><br><br><br> 8<br><br><br><br><br><br><br><br><br><br> 9<br><br><br><br><br><br><br><br><br><br> 10<br><br><br><br><br><br><br><br><br><br> 11<br><br><br><br><br><br><br><br><br><br>'
93
-
94
- tablehtml = '<table border="1" cellspacing="1" cellpadding="1"><tr><td>a</td><td>b</td></tr><tr><td>c</td><td>' + htmlcontent + '</td></tr></table>'
95
- pdf.write_html(tablehtml, true, 0, true, 0)
96
-
97
- pno = pdf.get_page
98
- assert_equal 3, pno
99
- end
100
-
101
- test "write_html Table test 2" do
102
- pdf = MYPDF.new
103
- pdf.add_page()
104
-
105
- htmlcontent = '1<br><br><br><br><br><br><br><br><br><br> 2<br><br><br><br><br><br><br><br><br><br> 3<br><br><br><br><br><br><br><br><br><br> 4<br><br><br><br><br><br><br><br><br><br> 5<br><br><br><br><br><br><br><br><br><br> 6<br><br><br><br><br><br><br><br><br><br> 7<br><br><br><br><br><br><br><br><br><br> 8<br><br><br><br><br><br><br><br><br><br> 9<br><br><br><br><br><br><br><br><br><br> 10<br><br><br><br><br><br><br><br><br><br> 11<br><br><br><br><br><br><br><br><br><br>'
106
-
107
- tablehtml = '<table border="1"><tr><td>ABCD</td><td>EFGH</td><td>IJKL</td></tr>
108
- <tr><td>abcd</td><td>efgh</td><td>ijkl</td></tr>
109
- <tr><td>' + htmlcontent + '</td></tr></table>'
110
- pdf.write_html(tablehtml, true, 0, true, 0)
111
-
112
- pno = pdf.get_page
113
- assert_equal 3, pno
114
-
115
- # Page 1
116
- count_line, count_text, xpos1 = pdf.get_html_text_position_x(1, /ABCD/) # Header
117
- assert_not_nil xpos1
118
- assert_equal 1, count_text
119
- assert_equal 13, count_line
120
- count_line, count_text, xpos2 = pdf.get_html_text_position_x(1, /abcd/)
121
- assert_not_nil xpos2
122
- assert_equal 1, count_text
123
- assert_equal xpos1, xpos2
124
- assert_equal 13, count_line
125
-
126
- # Page 2
127
- count_line, count_text, xpos2 = pdf.get_html_text_position_x(2, /\([6-9]\)/, xpos1)
128
- assert_not_nil xpos2
129
- assert_equal xpos1, xpos2
130
- assert_equal 7, count_line
131
- end
132
-
133
- test "write_html Table thead tag test 1" do
134
- pdf = MYPDF.new
135
- pdf.add_page()
136
-
137
- tablehtml = '<table border="1" cellpadding="1" cellspacing="1">
138
- <thead><tr><td>ABCD</td><td>EFGH</td><td>IJKL</td></tr></thead>
139
- <tr><td>abcd</td><td>efgh</td><td>ijkl</td></tr>
140
- </table>'
141
-
142
- pdf.write_html(tablehtml, true, 0, true, 0)
143
- page = pdf.get_page
144
- assert_equal 1, page
145
-
146
- _count_line, count_text, _xpos = pdf.get_html_text_position_x(1, /ABCD/) # Header
147
- assert_equal 1, count_text
148
- end
149
-
150
- test "write_html Table thead tag test 2" do
151
- pdf = MYPDF.new
152
- pdf.add_page()
153
-
154
- htmlcontent = '1<br><br><br><br><br><br><br><br><br><br> 2<br><br><br><br><br><br><br><br><br><br> 3<br><br><br><br><br><br><br><br><br><br> 4<br><br><br><br><br><br><br><br><br><br> 5<br><br><br><br><br><br><br><br><br><br> 6<br><br><br><br><br><br><br><br><br><br> 7<br><br><br><br><br><br><br><br><br><br> 8<br><br><br><br><br><br><br><br><br><br> 9<br><br><br><br><br><br><br><br><br><br> 10<br><br><br><br><br><br><br><br><br><br> 11<br><br><br><br><br><br><br><br><br><br>'
155
-
156
- tablehtml = '<table><thead><tr><td>ABCD</td><td>EFGH</td><td>IJKL</td></tr></thead>
157
- <tr><td>abcd</td><td>efgh</td><td>ijkl</td></tr>
158
- <tr><td>' + htmlcontent + '</td></tr></table>'
159
-
160
- pdf.write_html(tablehtml, true, 0, true, 0)
161
- page = pdf.get_page
162
- assert_equal 3, page
163
-
164
- # Page 1
165
- count_line, count_text, xpos1 = pdf.get_html_text_position_x(1, /ABCD/) # Header
166
- assert_not_nil xpos1
167
- assert_equal 1, count_text
168
- assert_equal 13, count_line
169
- count_line, count_text, xpos2 = pdf.get_html_text_position_x(1, /abcd/)
170
- assert_not_nil xpos2
171
- assert_equal 1, count_text
172
- assert_equal xpos1, xpos2
173
- assert_equal 13, count_line
174
-
175
- # Page 2
176
- count_line, count_text, xpos2 = pdf.get_html_text_position_x(2, /ABCD/, xpos1) # Header
177
- assert_not_nil xpos2
178
- assert_equal 1, count_text
179
- assert_equal xpos1, xpos2
180
- assert_equal 10, count_line
181
- count_line, count_text, xpos2 = pdf.get_html_text_position_x(2, /abcd/)
182
- assert_equal 0, count_text
183
- assert_equal 10, count_line
184
- count_line, count_text, xpos2 = pdf.get_html_text_position_x(2, /\([6-9]\)/, xpos1)
185
- assert_not_nil xpos2
186
- assert_equal xpos1, xpos2
187
- assert_equal 10, count_line
188
-
189
- # Page 3
190
- count_line, count_text, xpos2 = pdf.get_html_text_position_x(3, /ABCD/, xpos1) # Header
191
- assert_not_nil xpos2
192
- assert_equal 1, count_text
193
- assert_equal xpos1, xpos2
194
- assert_equal 5, count_line
195
- count_line, count_text, xpos2 = pdf.get_html_text_position_x(3, /abcd/)
196
- assert_equal 0, count_text
197
- assert_equal 5, count_line
198
- count_line, count_text, xpos2 = pdf.get_html_text_position_x(3, /\(11\)/, xpos1)
199
- assert_not_nil xpos2
200
- assert_equal 1, count_text
201
- assert_equal xpos1, xpos2
202
- assert_equal 5, count_line
203
- end
204
-
205
- test "write_html_cell Table thead tag test" do
206
- pdf = MYPDF.new
207
- pdf.add_page()
208
-
209
- htmlcontent = '<br>1<br><br><br><br><br><br><br><br><br><br> 2<br><br><br><br><br><br><br><br><br><br> 3<br><br><br><br><br><br><br><br><br><br> 4<br>
210
- <br><br><br><br><br><br><br><br><br> 5<br><br><br><br><br><br><br><br><br><br> 6<br><br><br><br><br><br><br><br><br><br> 7<br><br><br><br><br><br><br>
211
- <br><br><br> 8<br><br><br><br><br><br><br><br><br><br> 9<br><br><br><br><br><br><br><br><br><br> 10<br><br><br><br><br><br><br><br><br><br> 11<br><br>
212
- <br><br><br><br><br><br><br><br>'
213
-
214
- tablehtml ='<table><thead><tr>
215
- <th style="text-align: left">Left align</th>
216
- <th style="text-align: right">Right align</th>
217
- <th style="text-align: center">Center align</th>
218
- </tr> </thead><tbody> <tr>
219
- <td style="text-align: left">left' + htmlcontent + '</td>
220
- <td style="text-align: right">right</td>
221
- <td style="text-align: center">center</td>
222
- </tr> </tbody></table>'
223
-
224
- pdf.write_html_cell(0, 0, '', '',tablehtml)
225
-
226
- page = pdf.get_page
227
- assert_equal 1, page
228
-
229
- # Page 1
230
- count_line, count_text, xpos1 = pdf.get_html_text_position_x(1, /Left align/) # Header
231
- assert_not_nil xpos1
232
- assert_equal 1, count_text
233
- assert_equal 13, count_line
234
- count_line, count_text, xpos2 = pdf.get_html_text_position_x(1, /left/)
235
- assert_not_nil xpos2
236
- assert_equal 1, count_text
237
- assert_equal 13, count_line
238
- assert_equal xpos1, xpos2
239
-
240
- # Page 2
241
- count_line, count_text, xpos2 = pdf.get_html_text_position_x(2, /Left align/, xpos1) # Header
242
- assert_not_nil xpos2
243
- assert_equal 1, count_text
244
- assert_equal xpos1, xpos2
245
- assert_equal 10, count_line
246
- count_line, count_text, xpos2 = pdf.get_html_text_position_x(2, /\(6\)/, xpos1)
247
- assert_not_nil xpos2
248
- assert_equal 1, count_text
249
- assert_equal xpos1, xpos2
250
- assert_equal 10, count_line
251
-
252
- # Page 3
253
- count_line, count_text, xpos2 = pdf.get_html_text_position_x(3, /Left align/, xpos1) # Header
254
- assert_not_nil xpos2
255
- assert_equal 1, count_text
256
- assert_equal xpos1, xpos2
257
- assert_equal 5, count_line
258
- count_line, count_text, xpos2 = pdf.get_html_text_position_x(3, /\(11\)/, xpos1)
259
- assert_not_nil xpos2
260
- assert_equal 1, count_text
261
- assert_equal xpos1, xpos2
262
- assert_equal 5, count_line
263
- end
264
-
265
- test "write_html_cell Table thead tag cellpadding x position test" do
266
- pdf = MYPDF.new
267
- pdf.add_page()
268
-
269
- htmlcontent = '<br>1<br><br><br><br><br><br><br><br><br><br> 2<br><br><br><br><br><br><br><br><br><br> 3<br><br><br><br><br><br><br><br><br><br> 4<br>
270
- <br><br><br><br><br><br><br><br><br> 5<br><br><br><br><br><br><br><br><br><br> 6<br><br><br><br><br><br><br><br><br><br> 7<br><br><br><br><br><br><br>
271
- <br><br><br> 8<br><br><br><br><br><br><br><br><br><br> 9<br><br><br><br><br><br><br><br><br><br> 10<br><br><br><br><br><br><br><br><br><br> 11<br><br>
272
- <br><br><br><br><br><br><br><br>'
273
-
274
- tablehtml ='<table cellpadding="10"><thead><tr>
275
- <th style="text-align: left">Left align</th>
276
- <th style="text-align: right">Center align</th>
277
- <th style="text-align: left">Right align</th>
278
- </tr> </thead><tbody> <tr>
279
- <td style="text-align: left">left</td>
280
- <td style="text-align: right">center</td>
281
- <td style="text-align: left">right' + htmlcontent + '</td>
282
- </tr> </tbody></table>'
283
-
284
- pdf.write_html_cell(0, 0, '', '',tablehtml)
285
-
286
- page = pdf.get_page
287
- assert_equal 1, page
288
-
289
- # Page 1
290
- count_line, count_text, xpos1 = pdf.get_html_text_position_x(1, /Right align/) # Header
291
- assert_not_nil xpos1
292
- assert_equal 1, count_text
293
- assert_equal 13, count_line
294
- count_line, count_text, xpos2 = pdf.get_html_text_position_x(1, /right/)
295
- assert_not_nil xpos2
296
- assert_equal 1, count_text
297
- assert_equal xpos1, xpos2
298
- assert_equal 13, count_line
299
-
300
- # Page 2
301
- count_line, count_text, xpos2 = pdf.get_html_text_position_x(2, /Right align/, xpos1) # Header
302
- assert_not_nil xpos2
303
- assert_equal 1, count_text
304
- assert_equal xpos1, xpos2
305
- assert_equal 10, count_line
306
- count_line, count_text, xpos2 = pdf.get_html_text_position_x(2, /\(6\)/, xpos1)
307
- assert_not_nil xpos2
308
- assert_equal 1, count_text
309
- assert_equal xpos1, xpos2
310
- assert_equal 10, count_line
311
- end
312
-
313
- test "write_html_cell Table thead tag cellpadding y position test 1" do
314
- pdf = MYPDF.new
315
- pdf.add_page()
316
-
317
- table_start='<table cellpadding="10"><thead><tr>
318
- <th style="text-align: left">Left align</th><th style="text-align: center">Center align</th><th style="text-align: right">Right align</th>
319
- </tr></thead><tbody>'
320
- table_col='<tr><td style="text-align: left">AAA</td><td style="text-align: center">BBB</td><td style="text-align: right">CCC</td></tr>'
321
- table_end='</tbody></table>'
322
- tablehtml= table_start + table_col * 30 + table_end
323
-
324
- pdf.write_html_cell(0, 0, '', '',tablehtml)
325
-
326
- # Page 1
327
- count_line, count_text, ypos1 = pdf.get_html_text_position_y(1, /Left align/) # Header
328
- assert_not_nil ypos1
329
- assert_equal 1, count_text
330
- assert_equal 65, count_line
331
- count_line, count_text, ypos2 = pdf.get_html_text_position_y(1, /AAA/)
332
- assert_not_nil ypos2
333
- assert_equal 20, count_text
334
- assert_equal 65, count_line
335
- base_pos = ypos1.to_i - ypos2.to_i
336
-
337
- # Page 2
338
- count_line, count_text, ypos1 = pdf.get_html_text_position_y(2, /Left align/) # Header
339
- assert_not_nil ypos2
340
- assert_equal 1, count_text
341
- assert_equal 34, count_line
342
- count_line, count_text, ypos2 = pdf.get_html_text_position_y(2, /AAA/)
343
- assert_not_nil ypos2
344
- assert_equal 10, count_text
345
- assert_equal 34, count_line
346
- assert_equal base_pos, ypos1.to_i - ypos2.to_i
347
- end
348
-
349
- test "write_html_cell Table thead tag cellpadding y position test 2" do
350
- pdf = MYPDF.new
351
- pdf.add_page()
352
-
353
- table_start='abc<br><table cellpadding="10"><thead><tr>
354
- <th style="text-align: left">Left align</th><th style="text-align: center">Center align</th><th style="text-align: right">Right align</th>
355
- </tr></thead><tbody>'
356
- table_col='<tr><td style="text-align: left">AAA</td><td style="text-align: center">BBB</td><td style="text-align: right">CCC</td></tr>'
357
- table_end='</tbody></table>'
358
- tablehtml= table_start + table_col * 30 + table_end
359
-
360
- pdf.write_html_cell(0, 0, '', '',tablehtml)
361
-
362
- # Page 1
363
- count_line, count_text, ypos1 = pdf.get_html_text_position_y(1, /Left align/) # Header
364
- assert_not_nil ypos1
365
- assert_equal 1, count_text
366
- assert_equal 66, count_line
367
- count_line, count_text, ypos2 = pdf.get_html_text_position_y(1, /AAA/)
368
- assert_not_nil ypos2
369
- assert_equal 20, count_text
370
- assert_equal 66, count_line
371
- base_pos = ypos1.to_i - ypos2.to_i
372
-
373
- # Page 2
374
- count_line, count_text, ypos1 = pdf.get_html_text_position_y(2, /Left align/) # Header
375
- assert_not_nil ypos2
376
- assert_equal 1, count_text
377
- assert_equal 34, count_line
378
- count_line, count_text, ypos2 = pdf.get_html_text_position_y(2, /AAA/)
379
- assert_not_nil ypos2
380
- assert_equal 10, count_text
381
- assert_equal 34, count_line
382
- assert_equal base_pos, ypos1.to_i - ypos2.to_i
383
- end
384
-
385
- test "write_html ASCII text test" do
386
- pdf = MYPDF.new
387
- pdf.add_page()
388
-
389
- text = 'HTML Example'
390
- htmlcontent = '<h1>' + text + '</h1>'
391
- pdf.write_html(htmlcontent, true, 0, true, 0)
392
- page = pdf.get_page
393
- assert_equal 1, page
394
-
395
- content = []
396
- contents = pdf.getPageBuffer(1)
397
- contents.each_line {|line| content.push line.chomp }
398
-
399
- count_text = 0
400
- content.each do |line|
401
- count_text += 1 unless line.scan(text).empty?
402
- end
403
- assert_equal 1, count_text
404
- end
405
-
406
- test "write_html Justify text test" do
407
- pdf = MYPDF.new
408
- pdf.set_font('times', 'BI', 20)
409
- pdf.add_page()
410
-
411
- text = 'hello Ruby (inside hello world) hello Ruby (inside hello world) hello Ruby (inside hello world)'
412
- justify_text = 'hello Ruby \(inside hello world\) hello Ruby \(inside hello world\)'
413
- htmlcontent = '<div style="text-align:justify;">' + text + '</div>'
414
-
415
- pdf.write_html(htmlcontent, true, 0, true, 0)
416
-
417
- page = pdf.get_page
418
- assert_equal 1, page
419
-
420
- content = []
421
- contents = pdf.getPageBuffer(1)
422
- contents.each_line {|line| content.push line.chomp if line.include? ' TJ ET' } # Text Line set
423
-
424
- count_text = 0
425
- content.each do |line|
426
- count_text += 1 unless line.scan(justify_text).empty?
427
- end
428
- assert_equal 1, count_text, "'#{justify_text}' is not include in '#{content.inspect}'"
429
- end
430
-
431
- test "write_html Non ASCII text test" do
432
- pdf = MYPDF.new
433
- pdf.add_page()
434
-
435
- text = 'HTML Example ' + "\xc2\x83\xc2\x86"
436
-
437
- htmlcontent = '<h1>' + text + '</h1>'
438
- pdf.write_html(htmlcontent, true, 0, true, 0)
439
- page = pdf.get_page
440
- assert_equal 1, page
441
-
442
- content = []
443
- contents = pdf.getPageBuffer(1)
444
- contents.each_line {|line| content.push line.chomp }
445
-
446
- text = 'HTML Example ' + "\x83\x86"
447
- text.force_encoding('ASCII-8BIT') if text.respond_to?(:force_encoding)
448
- count_text = 0
449
- content.each do |line|
450
- line.force_encoding('ASCII-8BIT') if line.respond_to?(:force_encoding)
451
- count_text += 1 unless line.scan(text).empty?
452
- end
453
- assert_equal 1, count_text
454
- end
455
-
456
- test "works internal links out of page range" do
457
- pdf = RBPDF.new
458
- pdf.add_page()
459
-
460
- htmlcontent = '<a href="#100400_somelink">FooLink</a>'
461
- pdf.write_html(htmlcontent, true, 0, true, 0)
462
-
463
- assert_nothing_raised do
464
- pdf.Close
465
- end
466
-
467
- assert_nothing_raised do
468
- pdf.Output
469
- end
470
- end
471
-
472
- test "write_html no tag text test" do
473
- pdf = MYPDF.new
474
- pdf.set_print_header(false)
475
- pdf.add_page()
476
-
477
- text = ' abc def '
478
- pdf.write_html(text, true, 0, true, 0)
479
- pdf_text = pdf.get_html_text(1)
480
- assert_equal 'abc def', pdf_text
481
- end
482
-
483
- test "write_html no tag back slash test" do
484
- pdf = MYPDF.new
485
- pdf.set_print_header(false)
486
- pdf.add_page()
487
-
488
- text = " abc \\def "
489
- pdf.write_html(text, true, 0, true, 0) # use escape() method in getCellCode()
490
- pdf_text = pdf.get_html_text(1)
491
- assert_equal "abc \\\\def", pdf_text
492
- end
493
-
494
- test "write_html <b> tag test" do
495
- pdf = MYPDF.new
496
- pdf.set_print_header(false)
497
- pdf.add_page()
498
-
499
- text = ' ' + 'A' * 70
500
- htmlcontent = '<b>' + text + '</b>'
501
-
502
- pdf.write_html(htmlcontent, true, 0, true, 0)
503
- pdf_text = pdf.get_html_text(1)
504
- assert_equal 'A' * 70, pdf_text
505
- end
506
-
507
- test "write_html <i> tag test" do
508
- pdf = MYPDF.new
509
- pdf.set_print_header(false)
510
- pdf.add_page()
511
-
512
- text = ' ' + 'A' * 70
513
- htmlcontent = '<i>' + text + '</i>'
514
-
515
- pdf.write_html(htmlcontent, true, 0, true, 0)
516
- pdf_text = pdf.get_html_text(1)
517
- assert_equal 'A' * 70, pdf_text
518
- end
519
-
520
- test "write_html <u> tag test" do
521
- pdf = MYPDF.new
522
- pdf.set_print_header(false)
523
- pdf.add_page()
524
-
525
- text = ' ' + 'A' * 70
526
- htmlcontent = '<u>' + text + '</u>'
527
-
528
- pdf.write_html(htmlcontent, true, 0, true, 0)
529
- pdf_text = pdf.get_html_text(1)
530
- assert_equal 'A' * 70, pdf_text
531
- end
532
-
533
- test "write_html <pre> tag space 1 test" do
534
- pdf = MYPDF.new
535
- pdf.set_print_header(false)
536
- pdf.add_page()
537
-
538
- text = ' ' + 'A' * 70
539
- htmlcontent = '<pre>' + text + '</pre>'
540
-
541
- pdf.write_html(htmlcontent, true, 0, true, 0)
542
- pdf_text = pdf.get_html_text(1)
543
- assert_equal "\xa0" + 'A' * 70, pdf_text
544
- end
545
-
546
- test "write_html <pre> tag space 2 test" do
547
- pdf = MYPDF.new
548
- pdf.set_print_header(false)
549
- pdf.add_page()
550
-
551
- text = ' ' + 'A' * 70
552
- htmlcontent = '<pre>' + text + '</pre>'
553
-
554
- pdf.write_html(htmlcontent, true, 0, true, 0)
555
- pdf_text = pdf.get_html_text(1)
556
- assert_equal "\xa0" * 2 + 'A' * 70, pdf_text
557
- end
558
-
559
- test "write_html <table> tag text test" do
560
- pdf = MYPDF.new
561
- pdf.set_print_header(false)
562
- pdf.add_page()
563
-
564
- text = "abc"
565
- htmlcontent = '<table border="1"><tr><td>' + text + '</td></tr></table>'
566
-
567
- pdf.write_html(htmlcontent, true, 0, true, 0)
568
- pdf_text = pdf.get_html_text(1)
569
- assert_equal 'abc', pdf_text
570
- end
571
-
572
- test "write_html <table> tag back slash test" do
573
- pdf = MYPDF.new
574
- pdf.set_print_header(false)
575
- pdf.add_page()
576
-
577
- text = "a\\bc"
578
- htmlcontent = '<table border="1"><tr><td>' + text + '</td></tr></table>'
579
-
580
- pdf.write_html(htmlcontent, true, 0, true, 0) # use escape() method in getCellCode()
581
- pdf_text = pdf.get_html_text(1)
582
- assert_equal 'a\\\\bc', pdf_text
583
- end
584
-
585
- test "write_html Character Entities test" do
586
- pdf = MYPDF.new
587
- pdf.set_print_header(false)
588
-
589
- character_entities = {
590
- '&lt;' => '<',
591
- '&gt;' => '>',
592
- '&amp;' => '&',
593
- '&quot;' => '"',
594
- '&nbsp;' => "\xa0",
595
- '&cent;' => "\xa2",
596
- '&pound;' => "\xa3",
597
- '&yen;' => "\xa5",
598
- '&copy;' => "\xa9",
599
- '&reg;' => "\xae",
600
- '&euro;' => "\x80",
601
- }
602
- character_entities.each {|ce, c|
603
- pdf.add_page()
604
- page = pdf.get_page
605
- pdf.write_html(ce, true, 0, true, 0)
606
- pdf_text = pdf.get_html_text(page)
607
- assert_equal '[' + ce + ']:' + c, '[' + ce + ']:' + pdf_text
608
- }
609
- end
610
-
611
- test "write_html Character Entities test pre mode" do
612
- pdf = MYPDF.new
613
- pdf.set_print_header(false)
614
-
615
- character_entities = {
616
- '&lt;' => '<',
617
- '&gt;' => '>',
618
- '&amp;' => '&',
619
- '&quot;' => '"',
620
- '&nbsp;' => "\xa0",
621
- '&cent;' => "\xa2",
622
- '&pound;' => "\xa3",
623
- '&yen;' => "\xa5",
624
- '&copy;' => "\xa9",
625
- '&reg;' => "\xae",
626
- '&euro;' => "\x80",
627
- }
628
- character_entities.each {|ce, c|
629
- pdf.add_page()
630
- page = pdf.get_page
631
- pdf.write_html('<pre>' + ce + '</pre>', true, 0, true, 0)
632
- pdf_text = pdf.get_html_text(page)
633
- assert_equal '[' + ce + ']:' + c, '[' + ce + ']:' + pdf_text
634
- }
635
- end
636
-
637
- test "unhtmlentities test" do
638
- pdf = RBPDF.new
639
- character_entities = {
640
- '&lt;' => '<',
641
- '&gt;' => '>',
642
- '&amp;' => '&',
643
- '&quot;' => '"',
644
- '&nbsp;' => "\xc2\xa0",
645
- '&cent;' => "\xc2\xa2",
646
- '&pound;' => "\xc2\xa3",
647
- '&yen;' => "\xc2\xa5",
648
- '&copy;' => "\xc2\xa9",
649
- '&reg;' => "\xc2\xae",
650
- '&euro;' => "\xe2\x82\xac",
651
- }
652
- character_entities.each {|ce, c|
653
- text = pdf.unhtmlentities(ce)
654
- text.force_encoding('ASCII-8BIT') if text.respond_to?(:force_encoding)
655
- assert_equal '[' + ce + ']:' + c, '[' + ce + ']:' + text
656
- }
657
- end
658
- end