rbpdf 1.20.0 → 1.20.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +4 -0
  3. data/lib/rbpdf/version.rb +1 -1
  4. data/rbpdf.gemspec +1 -2
  5. metadata +4 -90
  6. data/test/err_font1.rb +0 -7
  7. data/test/err_font2.rb +0 -8
  8. data/test/input.jpg +0 -0
  9. data/test/json: +0 -0
  10. data/test/logo_rbpdf_8bit .png +0 -0
  11. data/test/logo_rbpdf_8bit+ .png +0 -0
  12. data/test/logo_rbpdf_8bit.gif +0 -0
  13. data/test/logo_rbpdf_8bit.jpg +0 -0
  14. data/test/logo_rbpdf_8bit.png +0 -0
  15. data/test/logo_rbpdf_8bit_alpha.gif +0 -0
  16. data/test/logo_rbpdf_mono_gray.jpg +0 -0
  17. data/test/logo_rbpdf_mono_gray.png +0 -0
  18. data/test/logo_rbpdf_mono_rgb.jpg +0 -0
  19. data/test/logo_rbpdf_mono_rgb.png +0 -0
  20. data/test/output.png +0 -0
  21. data/test/png_test_alpha.png +0 -0
  22. data/test/png_test_msk_alpha.png +0 -0
  23. data/test/png_test_non_alpha.png +0 -0
  24. data/test/rbpdf_bidi_test.rb +0 -453
  25. data/test/rbpdf_bookmark_test.rb +0 -66
  26. data/test/rbpdf_cell_test.rb +0 -231
  27. data/test/rbpdf_content_test.rb +0 -213
  28. data/test/rbpdf_css_test.rb +0 -640
  29. data/test/rbpdf_dom_test.rb +0 -272
  30. data/test/rbpdf_examples_test.rb +0 -83
  31. data/test/rbpdf_font_func_test.rb +0 -45
  32. data/test/rbpdf_font_style_test.rb +0 -37
  33. data/test/rbpdf_font_test.rb +0 -308
  34. data/test/rbpdf_format_test.rb +0 -30
  35. data/test/rbpdf_func_test.rb +0 -139
  36. data/test/rbpdf_html_anchor_test.rb +0 -105
  37. data/test/rbpdf_html_func_test.rb +0 -170
  38. data/test/rbpdf_html_test.rb +0 -658
  39. data/test/rbpdf_htmlcell_test.rb +0 -60
  40. data/test/rbpdf_http_test.rb +0 -76
  41. data/test/rbpdf_image_rmagick_test.rb +0 -170
  42. data/test/rbpdf_image_test.rb +0 -174
  43. data/test/rbpdf_test.rb +0 -375
  44. data/test/rbpdf_transaction_test.rb +0 -203
  45. data/test/rbpdf_viewerpreferences_test.rb +0 -41
  46. data/test/rbpdf_write_test.rb +0 -229
  47. data/test/test.rb +0 -22
  48. data/test/test_helper.rb +0 -9
@@ -1,30 +0,0 @@
1
- # Copyright (c) 2011-2017 NAITOH Jun
2
- # Released under the MIT license
3
- # http://www.opensource.org/licenses/MIT
4
-
5
- require 'test_helper'
6
-
7
- class RbpdfFormatTest < Test::Unit::TestCase
8
- test "set_page_orientation" do
9
- pdf = RBPDF.new
10
-
11
- pagedim = pdf.set_page_orientation('')
12
- assert_equal 'P', pagedim['or']
13
- assert_equal true, pagedim['pb']
14
- assert_equal nil, pagedim['olm']
15
- assert_equal nil, pagedim['orm']
16
- assert_in_delta 20, pagedim['bm'], 0.1
17
-
18
- pagedim = pdf.set_page_orientation('P')
19
- assert_equal 'P', pagedim['or']
20
-
21
- pagedim = pdf.set_page_orientation('L', false)
22
- assert_equal 'L', pagedim['or']
23
- assert_equal false, pagedim['pb']
24
-
25
- pagedim = pdf.set_page_orientation('P', true, 5)
26
- assert_equal 'P', pagedim['or']
27
- assert_equal true, pagedim['pb']
28
- assert_equal 5, pagedim['bm']
29
- end
30
- end
@@ -1,139 +0,0 @@
1
- # Copyright (c) 2011-2017 NAITOH Jun
2
- # Released under the MIT license
3
- # http://www.opensource.org/licenses/MIT
4
-
5
- require 'test_helper'
6
-
7
- class RbpdfTest < Test::Unit::TestCase
8
- class MYPDF < RBPDF
9
- def getSpaceString
10
- super
11
- end
12
- end
13
-
14
- test "get_html_unit_to_units test" do
15
- pdf = RBPDF.new
16
- unit = pdf.get_html_unit_to_units("100", 1)
17
- assert_in_delta 35.27, unit, 0.01
18
-
19
- unit = pdf.get_html_unit_to_units("100px", 1, 'px', false)
20
- assert_in_delta 35.27, unit, 0.01
21
-
22
- unit = pdf.get_html_unit_to_units(100, 1, 'pt', false)
23
- assert_in_delta 35.27, unit, 0.01
24
-
25
- unit = pdf.get_html_unit_to_units(100.0, 1, 'pt', false)
26
- assert_in_delta 35.27, unit, 0.01
27
-
28
- unit = pdf.get_html_unit_to_units("100.0", 1, 'pt', false)
29
- assert_in_delta 35.27, unit, 0.01
30
-
31
- unit = pdf.get_html_unit_to_units("200", 1, '%', false)
32
- assert_equal 2.0, unit
33
-
34
- unit = pdf.get_html_unit_to_units("400%", 1, '%', false)
35
- assert_equal 4.0, unit
36
-
37
- unit = pdf.get_html_unit_to_units("10", 1, '%', false)
38
- assert_equal 0.1, unit
39
-
40
- unit = pdf.get_html_unit_to_units("10mm", 1, '%', false)
41
- assert_in_delta 10, unit, 0.01
42
-
43
- unit = pdf.get_html_unit_to_units("10", 1, 'mm', false)
44
- assert_in_delta 10, unit, 0.01
45
-
46
- unit = pdf.get_html_unit_to_units(10, 1, 'mm', false)
47
- assert_in_delta 10, unit, 0.01
48
-
49
- unit = pdf.get_html_unit_to_units("1", 1, 'cm', false)
50
- assert_in_delta 10, unit, 0.01
51
-
52
- unit = pdf.get_html_unit_to_units(10, 1, 'em', false)
53
- assert_equal 10, unit
54
-
55
- unit = pdf.get_html_unit_to_units(10, 2, 'em', false)
56
- assert_equal 20, unit
57
- end
58
-
59
- test "getSpaceString test" do
60
- pdf = MYPDF.new
61
- spacestr = pdf.getSpaceString()
62
- assert_equal 32.chr, spacestr
63
-
64
- pdf.set_font('freesans', '', 18)
65
- spacestr = pdf.getSpaceString()
66
- assert_equal 0.chr + 32.chr, spacestr
67
- end
68
-
69
- test "revstrpos test" do
70
- pdf = RBPDF.new
71
- pos = pdf.revstrpos('abcd efgh ', 'cd')
72
- assert_equal 2, pos
73
-
74
- pos = pdf.revstrpos('abcd efgh ', 'cd ')
75
- assert_equal 2, pos
76
-
77
- pos = pdf.revstrpos('abcd efgh abcd efg', 'cd')
78
- assert_equal 12, pos
79
-
80
- pos = pdf.revstrpos('abcd efgh abcd efg', 'zy')
81
- assert_equal nil, pos
82
- end
83
-
84
- test "revstrpos offset test 1" do
85
- pdf = RBPDF.new
86
-
87
- pos = pdf.revstrpos('abcd efgh ', 'cd', 3) # 'abc'
88
- assert_equal pos, nil
89
-
90
- pos = pdf.revstrpos('abcd efgh ', 'cd', 4) # 'abcd'
91
- assert_equal pos, 2
92
-
93
- pos = pdf.revstrpos('abcd efgh abcd efg', 'cd', 3) # 'abc'
94
- assert_equal pos, nil
95
-
96
- pos = pdf.revstrpos('abcd efgh abcd efg', 'cd', 4) # 'abcd'
97
- assert_equal pos, 2
98
-
99
- pos = pdf.revstrpos('abcd efgh abcd efg', 'cd', 13) # 'abcd efgh abc'
100
- assert_equal pos, 2
101
-
102
- pos = pdf.revstrpos('abcd efgh abcd efg', 'cd', 14) # 'abcd efgh abcd'
103
- assert_equal pos, 12
104
- end
105
-
106
- test "revstrpos offset test 2" do
107
- pdf = RBPDF.new
108
-
109
- pos = pdf.revstrpos('abcd efgh ', 'cd', -6) # 'abcd'
110
- assert_equal pos, 2
111
-
112
- pos = pdf.revstrpos('abcd efgh ', 'cd', -7) # 'abc'
113
- assert_equal pos, nil
114
-
115
- pos = pdf.revstrpos('abcd efgh abcd efg', 'cd', -4) # 'abcd efgh abcd'
116
- assert_equal pos, 12
117
-
118
- pos = pdf.revstrpos('abcd efgh abcd efg', 'cd', -5) # 'abcd efgh abc'
119
- assert_equal pos, 2
120
- end
121
-
122
- test "set_line_style Basic test" do
123
- pdf = RBPDF.new
124
-
125
- pdf.set_line_style({'width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => [0, 0, 0]})
126
- pdf.set_line_style({'width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => [255, 0, 0]})
127
- pdf.set_line_style({'width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '1,2,3,4', 'phase' => 0, 'color' => [255, 0, 0]})
128
- pdf.set_line_style({'width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 'a', 'phase' => 0, 'color' => [255, 0, 0]}) # Invalid
129
- end
130
-
131
- test "get_string_width encoding test" do
132
- return unless 'test'.respond_to?(:force_encoding)
133
-
134
- pdf = RBPDF.new
135
- str = 'test'.force_encoding('UTF-8')
136
- pdf.get_string_width(str)
137
- assert_equal 'UTF-8', str.encoding.to_s
138
- end
139
- end
@@ -1,105 +0,0 @@
1
- # Copyright (c) 2011-2017 NAITOH Jun
2
- # Released under the MIT license
3
- # http://www.opensource.org/licenses/MIT
4
-
5
- require 'test_helper'
6
-
7
- class RbpdfTest < Test::Unit::TestCase
8
- test "anchor with text inside" do
9
- pdf = RBPDF.new
10
- pdf.add_page()
11
-
12
- htmlcontent = '<a name="foo">HTML Example</a>'
13
- pdf.write_html(htmlcontent, true, 0, true, 0)
14
-
15
- position = pdf.get_html_anchor_position('foo')
16
- assert_equal [1, 10.001249999999999], position
17
- end
18
-
19
- test "anchor with id" do
20
- pdf = RBPDF.new
21
- pdf.add_page()
22
-
23
- htmlcontent = '<a id="foo">HTML Example</a>'
24
- pdf.write_html(htmlcontent, true, 0, true, 0)
25
-
26
- position = pdf.get_html_anchor_position('foo')
27
- assert_equal [1, 10.001249999999999], position
28
- end
29
-
30
- test "empty anchor" do
31
- pdf = RBPDF.new
32
- pdf.add_page()
33
-
34
- htmlcontent = '<a id="foo"></a>'
35
- pdf.write_html(htmlcontent, true, 0, true, 0)
36
-
37
- position = pdf.get_html_anchor_position('foo')
38
- assert_equal [1, 10.001249999999999], position
39
- end
40
-
41
-
42
- test "anchor with overtical offset" do
43
- pdf = RBPDF.new
44
- pdf.add_page()
45
-
46
- htmlcontent = '<br><br><br><br><br><br><br><br><br><br><a id="foo"></a>'
47
- pdf.write_html(htmlcontent, true, 0, true, 0)
48
-
49
- position = pdf.get_html_anchor_position('foo')
50
- assert_equal [1, 57.626249999999985], position
51
- end
52
-
53
-
54
- test "on the second page" do
55
- pdf = RBPDF.new
56
- pdf.add_page()
57
- 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>'
58
- pdf.write_html(htmlcontent, true, 0, true, 0)
59
-
60
- htmlcontent = '<a id="foo"></a>'
61
- pdf.write_html(htmlcontent, true, 0, true, 0)
62
-
63
- position = pdf.get_html_anchor_position('foo')
64
- assert_equal [3, 68.20958333333331], position
65
- end
66
-
67
-
68
- test "maps when anchor after link" do
69
- pdf = RBPDF.new
70
- pdf.add_page()
71
-
72
- htmlcontent = '<a href="#foo">FooLink</a>'
73
- pdf.write_html(htmlcontent, true, 0, true, 0)
74
-
75
- 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>'
76
- pdf.write_html(htmlcontent, true, 0, true, 0)
77
-
78
- htmlcontent = '<a id="foo"></a>'
79
- pdf.write_html(htmlcontent, true, 0, true, 0)
80
-
81
- pdf.send(:mapLinksToHtmlAnchors)
82
- link_position = pdf.instance_variable_get(:@links)[1]
83
- assert_equal [3, 73.50124999999998], link_position
84
- end
85
-
86
- test "maps when anchor before link" do
87
- pdf = RBPDF.new
88
- pdf.add_page()
89
-
90
- htmlcontent = '<a id="foo"></a>'
91
- pdf.write_html(htmlcontent, true, 0, true, 0)
92
-
93
- 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>'
94
- pdf.write_html(htmlcontent, true, 0, true, 0)
95
-
96
- htmlcontent = '<a href="#foo">FooLink</a>'
97
- pdf.write_html(htmlcontent, true, 0, true, 0)
98
-
99
- pdf.send(:mapLinksToHtmlAnchors)
100
-
101
- link_position = pdf.instance_variable_get(:@links)[1]
102
- assert_equal [1, 10.001249999999999], link_position
103
- end
104
-
105
- end
@@ -1,170 +0,0 @@
1
- # Copyright (c) 2011-2017 NAITOH Jun
2
- # Released under the MIT license
3
- # http://www.opensource.org/licenses/MIT
4
-
5
- require 'test_helper'
6
-
7
- class RbpdfTest < Test::Unit::TestCase
8
- class MYPDF < RBPDF
9
- def addHTMLVertSpace(hbz, hb, cell, firstorlast)
10
- super
11
- end
12
- def sanitize_html(html)
13
- super
14
- end
15
- end
16
-
17
- test "html func addHTMLVertSpace empty lines test" do
18
- pdf = MYPDF.new
19
- pdf.add_page()
20
-
21
- # same line, start position
22
- x1 = pdf.get_x
23
- pdf.set_x(x1 + 10)
24
- y1 = pdf.get_y
25
- pdf.addHTMLVertSpace(1, 0, false, true)
26
- x2 = pdf.get_x
27
- y2 = pdf.get_y
28
- assert_equal x1, x2
29
- assert_equal y1, y2
30
-
31
- # same line, @c_margin position
32
- margins = pdf.get_margins
33
-
34
- x1 = pdf.get_x
35
- y1 = pdf.get_y
36
- pdf.addHTMLVertSpace(1, 0, true, true)
37
- x2 = pdf.get_x
38
- y2 = pdf.get_y
39
- assert_equal x1 + margins['cell'], x2
40
- assert_equal y1, y2
41
- end
42
-
43
- test "html func addHTMLVertSpace add line test" do
44
- pdf = MYPDF.new
45
- pdf.add_page()
46
-
47
- # next line, start position
48
- x1 = pdf.get_x
49
- pdf.set_x(x1 + 10)
50
- y1 = pdf.get_y
51
- pdf.addHTMLVertSpace(5, 0, false, false)
52
- x2 = pdf.get_x
53
- y2 = pdf.get_y
54
- assert_equal x1, x2
55
- assert_equal y1 + 5, y2
56
-
57
- # next line, @c_margin position
58
- margins = pdf.get_margins
59
-
60
- x1 = pdf.get_x
61
- y1 = pdf.get_y
62
- pdf.addHTMLVertSpace(5, 0, true, false)
63
- x2 = pdf.get_x
64
- y2 = pdf.get_y
65
- assert_equal x1 + margins['cell'], x2
66
- assert_equal y1 + 5, y2
67
- end
68
-
69
- test "html func addHTMLVertSpace height of the break test 1" do
70
- pdf = MYPDF.new
71
- pdf.add_page()
72
-
73
- margins = pdf.get_margins
74
- x1 = pdf.get_x
75
- y1 = pdf.get_y
76
- pdf.addHTMLVertSpace(0, 5, true, false) # height of the break : 5
77
- x2 = pdf.get_x
78
- y2 = pdf.get_y
79
- assert_equal x1 + margins['cell'], x2
80
- assert_equal y1 + 5, y2
81
-
82
- pdf.addHTMLVertSpace(0, 5, true, false) # height of the break : 5
83
- x3 = pdf.get_x
84
- y3 = pdf.get_y
85
- assert_equal x2, x3
86
- assert_equal y2, y3
87
-
88
- pdf.addHTMLVertSpace(0, 5 + 2, true, false) # height of the break : 7
89
- x4 = pdf.get_x
90
- y4 = pdf.get_y
91
- assert_equal x3, x4
92
- assert_equal y3 + 2, y4
93
-
94
- pdf.addHTMLVertSpace(0, 5, true, false) # height of the break : 7
95
- x5 = pdf.get_x
96
- y5 = pdf.get_y
97
- assert_equal x4, x5
98
- assert_equal y4, y5
99
-
100
- pdf.addHTMLVertSpace(0, 5 + 2 + 1, true, false) # height of the break : 8
101
- x6 = pdf.get_x
102
- y6 = pdf.get_y
103
- assert_equal x5, x6
104
- assert_equal y5 + 1, y6
105
-
106
- pdf.addHTMLVertSpace(0, 10, true, true) # height of the break : 0 (reset)
107
- x7 = pdf.get_x
108
- y7 = pdf.get_y
109
- assert_equal x6, x7
110
- assert_equal y6, y7
111
-
112
- pdf.addHTMLVertSpace(0, 2, true, false) # height of the break : 2
113
- x8 = pdf.get_x
114
- y8 = pdf.get_y
115
- assert_equal x7, x8
116
- assert_equal y7 + 2, y8
117
- end
118
-
119
- test "html func addHTMLVertSpace height of the break test 2" do
120
- pdf = MYPDF.new
121
- pdf.add_page()
122
-
123
- x1 = pdf.get_x
124
- y1 = pdf.get_y
125
- pdf.addHTMLVertSpace(10, 5, false, false) # height of the break : 5
126
- x2 = pdf.get_x
127
- y2 = pdf.get_y
128
- assert_equal x1, x2
129
- assert_equal y1 + 10 + 5, y2
130
-
131
- pdf.addHTMLVertSpace(10, 5, false, false) # height of the break : 5
132
- x3 = pdf.get_x
133
- y3 = pdf.get_y
134
- assert_equal x2, x3
135
- assert_equal y2 + 10, y3
136
-
137
- pdf.addHTMLVertSpace(10, 5 + 2, false, false) # height of the break : 7
138
- x4 = pdf.get_x
139
- y4 = pdf.get_y
140
- assert_equal x3, x4
141
- assert_equal y3 + 10 + 2, y4
142
- end
143
-
144
- test "html func sanitize test 1" do
145
- pdf = MYPDF.new
146
- pdf.add_page()
147
- html = '<table border="1"><thead><tr><td>ABCD</td><td>EFGH</td><td>IJKL</td></tr></thead><tr><td>abcd</td><td>efgh</td><td>ijkl</td></tr><tr><td>' + 'ABC' + '</td></tr></table>'
148
- html = pdf.sanitize_html(html).gsub(/[\r\n]/,'')
149
-
150
- assert_equal %{<table border="1"><thead><tr><td>ABCD</td><td>EFGH</td><td>IJKL</td></tr></thead><tr><td>abcd</td><td>efgh</td><td>ijkl</td></tr><tr><td>ABC</td></tr></table>}, html
151
- end
152
-
153
- test "html func sanitize test 2" do
154
- pdf = MYPDF.new
155
- pdf.add_page()
156
-
157
- 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>'
158
- html = '<table cellpadding="1"><thead><tr><td>ABCD</td><td>EFGH</td><td>IJKL</td></tr></thead><tr><td>abcd</td><td>efgh</td><td>ijkl</td></tr><tr><td>' + htmlcontent + '</td></tr></table>'
159
- html = pdf.sanitize_html(html).gsub(/[\r\n]/,'')
160
- assert_equal %{<table cellpadding="1"><thead><tr><td>ABCD</td><td>EFGH</td><td>IJKL</td></tr></thead><tr><td>abcd</td><td>efgh</td><td>ijkl</td></tr><tr><td>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></td></tr></table>}, html
161
- end
162
-
163
- test "html func sanitize open angled bracket '<' test" do
164
- pdf = MYPDF.new
165
- pdf.add_page()
166
- html = "<p>AAA '<'-BBB << <<< '</' '<//' '<///' <</ <<// CCC.</p>"
167
- html = pdf.sanitize_html(html).gsub(/[\r\n]/,'')
168
- assert_equal %{<p>AAA '&lt;'-BBB &lt;&lt; &lt;&lt;&lt; '&lt;/' '&lt;//' '&lt;///' &lt;&lt;/ &lt;&lt;// CCC.</p>}, html
169
- end
170
- end
@@ -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