rfpdf 1.17.1

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 (107) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +18 -0
  3. data/Gemfile +4 -0
  4. data/Rakefile +2 -0
  5. data/lib/core/rmagick.rb +85 -0
  6. data/lib/fonts/README.z +2 -0
  7. data/lib/fonts/arialunicid0_cw.rb +1738 -0
  8. data/lib/fonts/cid0cs.rb +21 -0
  9. data/lib/fonts/cid0ct.rb +21 -0
  10. data/lib/fonts/cid0jp.rb +21 -0
  11. data/lib/fonts/cid0kr.rb +21 -0
  12. data/lib/fonts/courier.rb +37 -0
  13. data/lib/fonts/dejavu-fonts-ttf-2.33/AUTHORS +53 -0
  14. data/lib/fonts/dejavu-fonts-ttf-2.33/BUGS +3 -0
  15. data/lib/fonts/dejavu-fonts-ttf-2.33/LICENSE +99 -0
  16. data/lib/fonts/dejavu-fonts-ttf-2.33/NEWS +1315 -0
  17. data/lib/fonts/dejavu-fonts-ttf-2.33/README +59 -0
  18. data/lib/fonts/dejavusans.ctg.z +0 -0
  19. data/lib/fonts/dejavusans.rb +338 -0
  20. data/lib/fonts/dejavusans.z +0 -0
  21. data/lib/fonts/dejavusansb.ctg.z +0 -0
  22. data/lib/fonts/dejavusansb.rb +330 -0
  23. data/lib/fonts/dejavusansb.z +0 -0
  24. data/lib/fonts/dejavusansbi.ctg.z +0 -0
  25. data/lib/fonts/dejavusansbi.rb +297 -0
  26. data/lib/fonts/dejavusansbi.z +0 -0
  27. data/lib/fonts/dejavusansi.ctg.z +0 -0
  28. data/lib/fonts/dejavusansi.rb +305 -0
  29. data/lib/fonts/dejavusansi.z +0 -0
  30. data/lib/fonts/freefont-20080912/AUTHORS +191 -0
  31. data/lib/fonts/freefont-20080912/COPYING +341 -0
  32. data/lib/fonts/freefont-20080912/CREDITS +506 -0
  33. data/lib/fonts/freefont-20080912/ChangeLog +3320 -0
  34. data/lib/fonts/freefont-20080912/INSTALL +81 -0
  35. data/lib/fonts/freefont-20080912/README +108 -0
  36. data/lib/fonts/freemono.ctg.z +0 -0
  37. data/lib/fonts/freemono.rb +203 -0
  38. data/lib/fonts/freemono.z +0 -0
  39. data/lib/fonts/freemonob.ctg.z +0 -0
  40. data/lib/fonts/freemonob.rb +120 -0
  41. data/lib/fonts/freemonob.z +0 -0
  42. data/lib/fonts/freemonobi.ctg.z +0 -0
  43. data/lib/fonts/freemonobi.rb +84 -0
  44. data/lib/fonts/freemonobi.z +0 -0
  45. data/lib/fonts/freemonoi.ctg.z +0 -0
  46. data/lib/fonts/freemonoi.rb +136 -0
  47. data/lib/fonts/freemonoi.z +0 -0
  48. data/lib/fonts/freesans.ctg.z +0 -0
  49. data/lib/fonts/freesans.rb +196 -0
  50. data/lib/fonts/freesans.z +0 -0
  51. data/lib/fonts/freesansb.ctg.z +0 -0
  52. data/lib/fonts/freesansb.rb +136 -0
  53. data/lib/fonts/freesansb.z +0 -0
  54. data/lib/fonts/freesansbi.ctg.z +0 -0
  55. data/lib/fonts/freesansbi.rb +108 -0
  56. data/lib/fonts/freesansbi.z +0 -0
  57. data/lib/fonts/freesansi.ctg.z +0 -0
  58. data/lib/fonts/freesansi.rb +136 -0
  59. data/lib/fonts/freesansi.z +0 -0
  60. data/lib/fonts/helvetica.rb +34 -0
  61. data/lib/fonts/helveticab.rb +34 -0
  62. data/lib/fonts/helveticabi.rb +34 -0
  63. data/lib/fonts/helveticai.rb +34 -0
  64. data/lib/fonts/hysmyeongjostdmedium.rb +31 -0
  65. data/lib/fonts/kozgopromedium.rb +47 -0
  66. data/lib/fonts/kozminproregular.rb +46 -0
  67. data/lib/fonts/msungstdlight.rb +23 -0
  68. data/lib/fonts/sjis.rb +834 -0
  69. data/lib/fonts/stsongstdlight.rb +23 -0
  70. data/lib/fonts/symbol.rb +33 -0
  71. data/lib/fonts/times.rb +34 -0
  72. data/lib/fonts/timesb.rb +34 -0
  73. data/lib/fonts/timesbi.rb +34 -0
  74. data/lib/fonts/timesi.rb +34 -0
  75. data/lib/fonts/uni2cid_ac15.rb +23613 -0
  76. data/lib/fonts/uni2cid_ag15.rb +30222 -0
  77. data/lib/fonts/uni2cid_aj16.rb +15705 -0
  78. data/lib/fonts/uni2cid_ak12.rb +17530 -0
  79. data/lib/fonts/zapfdingbats.rb +33 -0
  80. data/lib/htmlcolors.rb +209 -0
  81. data/lib/rfpdf/version.rb +3 -0
  82. data/lib/rfpdf.rb +16 -0
  83. data/lib/tcpdf.rb +14186 -0
  84. data/lib/unicode_data.rb +18317 -0
  85. data/logo_example.png +0 -0
  86. data/rfpdf.gemspec +35 -0
  87. data/test/tcpdf_bidi_test.rb +65 -0
  88. data/test/tcpdf_bookmark_test.rb +57 -0
  89. data/test/tcpdf_cell_test.rb +54 -0
  90. data/test/tcpdf_content_test.rb +117 -0
  91. data/test/tcpdf_css_test.rb +318 -0
  92. data/test/tcpdf_dom_test.rb +113 -0
  93. data/test/tcpdf_font_func_test.rb +27 -0
  94. data/test/tcpdf_font_style_test.rb +34 -0
  95. data/test/tcpdf_font_test.rb +176 -0
  96. data/test/tcpdf_format_test.rb +27 -0
  97. data/test/tcpdf_func_test.rb +126 -0
  98. data/test/tcpdf_html_test.rb +164 -0
  99. data/test/tcpdf_image_test.rb +54 -0
  100. data/test/tcpdf_test.rb +245 -0
  101. data/test/tcpdf_transaction_test.rb +199 -0
  102. data/test/tcpdf_viewerpreferences_test.rb +37 -0
  103. data/test/tcpdf_write_test.rb +173 -0
  104. data/test/test_helper.rb +1 -0
  105. data/test_unicode.rfpdf +115 -0
  106. data/utf8test.txt +135 -0
  107. metadata +202 -0
@@ -0,0 +1,113 @@
1
+ require 'test_helper'
2
+
3
+ class TcpdfTest < ActiveSupport::TestCase
4
+ class MYPDF < TCPDF
5
+ def getHtmlDomArray(html)
6
+ super
7
+ end
8
+ end
9
+
10
+ test "Dom Basic" do
11
+ pdf = MYPDF.new
12
+
13
+ # Simple Text
14
+ dom = pdf.getHtmlDomArray('abc')
15
+ assert_equal 0, dom[0]['parent'] # Root
16
+ assert_equal false, dom[0]['tag']
17
+ assert_equal({'tag'=>false, 'value'=>'abc', 'elkey'=>0, 'parent'=>0, 'block'=>false}, dom[1])
18
+
19
+ # Simple Tag
20
+ dom = pdf.getHtmlDomArray('<b>abc</b>')
21
+ assert_equal dom.length, 4
22
+
23
+ assert_equal 0, dom[0]['parent'] # Root
24
+ assert_equal false, dom[0]['tag']
25
+ assert_equal({}, dom[0]['attribute'])
26
+
27
+ assert_equal dom[1]['parent'], 0 # parent -> parent tag key
28
+ assert_equal dom[1]['elkey'], 0
29
+ assert_equal dom[1]['tag'], true
30
+ assert_equal dom[1]['opening'], true
31
+ assert_equal dom[1]['value'], 'b'
32
+ assert_equal dom[1]['attribute'], {}
33
+
34
+ assert_equal({'tag' => false, 'value'=>'abc', 'elkey'=>1, 'parent'=>1, 'block'=>false}, dom[2]) # parent -> open tag key
35
+
36
+ assert_equal dom[3]['parent'], 1 # parent -> open tag key
37
+ assert_equal dom[3]['elkey'], 2
38
+ assert_equal dom[3]['tag'], true
39
+ assert_equal dom[3]['opening'], false
40
+ assert_equal dom[3]['value'], 'b'
41
+
42
+ # Error Tag (doble colse tag)
43
+ dom = pdf.getHtmlDomArray('</ul></div>')
44
+ assert_equal dom.length, 3
45
+
46
+ assert_equal 0, dom[0]['parent'] # Root
47
+ assert_equal false, dom[0]['tag']
48
+ assert_equal({}, dom[0]['attribute'])
49
+
50
+ assert_equal dom[1]['parent'], 0 # parent -> Root key
51
+ assert_equal dom[1]['elkey'], 0
52
+ assert_equal dom[1]['tag'], true
53
+ assert_equal dom[1]['opening'], false
54
+ assert_equal dom[1]['value'], 'ul'
55
+
56
+ assert_equal dom[2]['parent'], 0 # parent -> Root key
57
+ assert_equal dom[2]['elkey'], 1
58
+ assert_equal dom[2]['tag'], true
59
+ assert_equal dom[2]['opening'], false
60
+ assert_equal dom[2]['value'], 'div'
61
+
62
+ # Attribute
63
+ dom = pdf.getHtmlDomArray('<p style="text-align:justify">abc</p>')
64
+ assert_equal dom.length, 4
65
+
66
+ assert_equal 0, dom[0]['parent'] # Root
67
+ assert_equal false, dom[0]['tag']
68
+ assert_equal({}, dom[0]['attribute'])
69
+
70
+ assert_equal dom[1]['parent'], 0 # parent -> parent tag key
71
+ assert_equal dom[1]['elkey'], 0
72
+ assert_equal dom[1]['tag'], true
73
+ assert_equal dom[1]['opening'], true
74
+ assert_equal dom[1]['value'], 'p'
75
+ assert_equal dom[1]['attribute'], {'style'=>'text-align: justify;'}
76
+ assert_equal dom[1]['attribute']['style'], 'text-align: justify;'
77
+ assert_equal dom[1]['align'], 'J'
78
+
79
+ # Table border
80
+ dom = pdf.getHtmlDomArray('<table border="1"><tr><td>abc</td></tr></table>')
81
+ ## added marker tag (by getHtmlDomArray()) ##
82
+ # '<table border="1"><tr><td>abc<marker style="font-size:0"/></td></tr></table>'
83
+ assert_equal dom.length, 9
84
+
85
+ assert_equal dom[1]['parent'], 0 # parent -> parent tag key
86
+ assert_equal dom[1]['elkey'], 0
87
+ assert_equal dom[1]['tag'], true
88
+ assert_equal dom[1]['opening'], true
89
+ assert_equal dom[1]['value'], 'table'
90
+ assert_equal dom[1]['attribute']['border'], '1'
91
+
92
+ ## marker tag (by getHtmlDomArray())
93
+ assert_equal dom[5]['parent'], 3 # parent -> parent tag key
94
+ assert_equal dom[5]['elkey'], 4
95
+ assert_equal dom[5]['tag'], true
96
+ assert_equal dom[5]['opening'], true
97
+ assert_equal dom[5]['value'], 'marker'
98
+ assert_equal dom[5]['attribute']['style'], 'font-size:0'
99
+
100
+ # Table td Width
101
+ dom = pdf.getHtmlDomArray('<table><tr><td width="10">abc</td></tr></table>')
102
+ ## added marker tag (by getHtmlDomArray()) ##
103
+ # '<table><tr><td width="10">abc<marker style="font-size:0"/></td></tr></table>'
104
+ assert_equal dom.length, 9
105
+
106
+ assert_equal dom[3]['parent'], 2 # parent -> parent tag key
107
+ assert_equal dom[3]['elkey'], 2
108
+ assert_equal dom[3]['tag'], true
109
+ assert_equal dom[3]['opening'], true
110
+ assert_equal dom[3]['value'], 'td'
111
+ assert_equal dom[3]['width'], '10'
112
+ end
113
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ class TcpdfFontFuncTest < ActiveSupport::TestCase
4
+ test "Font get_font_descent function test 1" do
5
+ pdf = TCPDF.new
6
+ fontdescent = pdf.get_font_descent('times', '', 18)
7
+ assert_in_delta 0.95, fontdescent, 0.01
8
+ end
9
+
10
+ test "Font get_font_descent function test 2" do
11
+ pdf = TCPDF.new
12
+ fontdescent = pdf.get_font_descent('freesans', '', 18)
13
+ assert_in_delta 1.91, fontdescent, 0.01
14
+ end
15
+
16
+ test "Font get_font_ascent function test 1" do
17
+ pdf = TCPDF.new
18
+ fontascent = pdf.get_font_ascent('times', '', 18)
19
+ assert_in_delta 5.39, fontascent, 0.01
20
+ end
21
+
22
+ test "Font get_font_ascent function test 2" do
23
+ pdf = TCPDF.new
24
+ fontascent = pdf.get_font_ascent('freesans', '', 18)
25
+ assert_in_delta 6.35, fontascent, 0.01
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ class TcpdfFontStyleTest < ActiveSupport::TestCase
4
+
5
+ class MYPDF < TCPDF
6
+ def dounderline(x, y, txt)
7
+ super
8
+ end
9
+ def dolinethrough(x, y, txt)
10
+ super
11
+ end
12
+ def dooverline(x, y, txt)
13
+ super
14
+ end
15
+ end
16
+
17
+ test "Font dounderline function test 1" do
18
+ pdf = MYPDF.new
19
+ line = pdf.dounderline(10, 10, "test")
20
+ assert_equal line, '28.35 812.94 19.34 -0.60 re f'
21
+ end
22
+
23
+ test "Font dolinethrough function test 1" do
24
+ pdf = MYPDF.new
25
+ line = pdf.dolinethrough(10, 10, "test")
26
+ assert_equal line, '28.35 816.94 19.34 -0.60 re f'
27
+ end
28
+
29
+ test "Font dooverline function test 1" do
30
+ pdf = MYPDF.new
31
+ line = pdf.dooverline(10, 10, "test")
32
+ assert_equal line, '28.35 824.34 19.34 -0.60 re f'
33
+ end
34
+ end
@@ -0,0 +1,176 @@
1
+ require 'test_helper'
2
+
3
+ class TcpdfFontTest < ActiveSupport::TestCase
4
+ class MYPDF < TCPDF
5
+ def putfonts()
6
+ super
7
+ end
8
+
9
+ def getFontBuffer(font)
10
+ super
11
+ end
12
+
13
+ def getFontsList()
14
+ super
15
+ end
16
+
17
+ def fontlist()
18
+ @fontlist
19
+ end
20
+ end
21
+
22
+ test "Font getFontsList" do
23
+ pdf = MYPDF.new
24
+ pdf.getFontsList()
25
+ fonts = pdf.fontlist()
26
+ assert fonts.include?('kozminproregular')
27
+ end
28
+
29
+ test "core Font test" do
30
+ pdf = MYPDF.new
31
+
32
+ pdf.set_font('helvetica', '', 18)
33
+ pdf.set_font('helvetica', 'B', 18)
34
+ pdf.set_font('helvetica', 'I', 18)
35
+ pdf.set_font('helvetica', 'BI', 18)
36
+
37
+ font = pdf.getFontBuffer('helvetica')
38
+ assert_equal font['name'], 'Helvetica'
39
+ assert_equal font['dw'], 556
40
+ font = pdf.getFontBuffer('helveticaB')
41
+ assert_equal font['name'], 'Helvetica-Bold'
42
+ assert_equal font['dw'], 556
43
+ font = pdf.getFontBuffer('helveticaI')
44
+ assert_equal font['name'], 'Helvetica-Oblique'
45
+ assert_equal font['dw'], 556
46
+ font = pdf.getFontBuffer('helveticaBI')
47
+ assert_equal font['name'], 'Helvetica-BoldOblique'
48
+ assert_equal font['dw'], 556
49
+
50
+ pdf.set_font('times', '', 18)
51
+ pdf.set_font('times', 'B', 18)
52
+ pdf.set_font('times', 'I', 18)
53
+ pdf.set_font('times', 'BI', 18)
54
+
55
+ font = pdf.getFontBuffer('times')
56
+ assert_equal font['name'], 'Times-Roman'
57
+ font = pdf.getFontBuffer('timesB')
58
+ assert_equal font['name'], 'Times-Bold'
59
+ font = pdf.getFontBuffer('timesI')
60
+ assert_equal font['name'], 'Times-Italic'
61
+ font = pdf.getFontBuffer('timesBI')
62
+ assert_equal font['name'], 'Times-BoldItalic'
63
+
64
+ pdf.set_font('courier', '', 18)
65
+ pdf.set_font('courier', 'B', 18)
66
+ pdf.set_font('courier', 'I', 18)
67
+ pdf.set_font('courier', 'BI', 18)
68
+
69
+ font = pdf.getFontBuffer('courier')
70
+ assert_equal font['name'], 'Courier'
71
+ font = pdf.getFontBuffer('courierB')
72
+ assert_equal font['name'], 'Courier-Bold'
73
+ font = pdf.getFontBuffer('courierI')
74
+ assert_equal font['name'], 'Courier-Oblique'
75
+ font = pdf.getFontBuffer('courierBI')
76
+ assert_equal font['name'], 'Courier-BoldOblique'
77
+
78
+ pdf.set_font('symbol', '', 18)
79
+ font = pdf.getFontBuffer('symbol')
80
+ assert_equal font['name'], 'Symbol'
81
+
82
+ pdf.set_font('zapfdingbats', '', 18)
83
+ font = pdf.getFontBuffer('zapfdingbats')
84
+ assert_equal font['name'], 'ZapfDingbats'
85
+
86
+ pdf.putfonts()
87
+ end
88
+
89
+ test "TrueTypeUnicode Font test" do
90
+ pdf = MYPDF.new
91
+
92
+ pdf.set_font('freesans', '', 18)
93
+ pdf.set_font('freesans', 'B', 18)
94
+ pdf.set_font('freesans', 'I', 18)
95
+ pdf.set_font('freesans', 'BI', 18)
96
+
97
+ pdf.set_font('freemono', '', 18)
98
+ pdf.set_font('freemono', 'B', 18)
99
+ pdf.set_font('freemono', 'I', 18)
100
+ pdf.set_font('freemono', 'BI', 18)
101
+
102
+ pdf.set_font('dejavusans', '', 18)
103
+ pdf.set_font('dejavusans', 'B', 18)
104
+ pdf.set_font('dejavusans', 'I', 18)
105
+ pdf.set_font('dejavusans', 'BI', 18)
106
+
107
+ pdf.putfonts()
108
+ end
109
+
110
+ test "cidfont0 Font test" do
111
+ pdf = MYPDF.new
112
+
113
+ pdf.set_font('cid0cs', '', 18)
114
+ pdf.set_font('cid0cs', 'B', 18)
115
+ pdf.set_font('cid0cs', 'I', 18)
116
+ pdf.set_font('cid0cs', 'BI', 18)
117
+
118
+ pdf.set_font('cid0ct', '', 18)
119
+ pdf.set_font('cid0ct', 'B', 18)
120
+ pdf.set_font('cid0ct', 'I', 18)
121
+ pdf.set_font('cid0ct', 'BI', 18)
122
+
123
+ pdf.set_font('cid0jp', '', 18)
124
+ pdf.set_font('cid0jp', 'B', 18)
125
+ pdf.set_font('cid0jp', 'I', 18)
126
+ pdf.set_font('cid0jp', 'BI', 18)
127
+
128
+ pdf.set_font('cid0kr', '', 18)
129
+ pdf.set_font('cid0kr', 'B', 18)
130
+ pdf.set_font('cid0kr', 'I', 18)
131
+ pdf.set_font('cid0kr', 'BI', 18)
132
+
133
+ pdf.set_font('kozgopromedium', '', 18)
134
+ pdf.set_font('kozgopromedium', 'B', 18)
135
+ pdf.set_font('kozgopromedium', 'I', 18)
136
+ pdf.set_font('kozgopromedium', 'BI', 18)
137
+
138
+ font = pdf.getFontBuffer('kozgopromedium')
139
+ assert_equal font['desc']['StemV'], 99
140
+ assert_equal font['desc']['ItalicAngle'], 0
141
+
142
+ font = pdf.getFontBuffer('kozgopromediumB')
143
+ assert_equal font['desc']['StemV'], 99 * 2
144
+ assert_equal font['desc']['ItalicAngle'], 0
145
+
146
+ font = pdf.getFontBuffer('kozgopromediumI')
147
+ assert_equal font['desc']['StemV'], 99
148
+ assert_equal font['desc']['ItalicAngle'], -11
149
+
150
+ font = pdf.getFontBuffer('kozgopromediumBI')
151
+ assert_equal font['desc']['StemV'], 99 * 2
152
+ assert_equal font['desc']['ItalicAngle'], -11
153
+
154
+ pdf.set_font('kozminproregular', '', 18)
155
+ pdf.set_font('kozminproregular', 'B', 18)
156
+ pdf.set_font('kozminproregular', 'I', 18)
157
+ pdf.set_font('kozminproregular', 'BI', 18)
158
+
159
+ pdf.set_font('msungstdlight', '', 18)
160
+ pdf.set_font('msungstdlight', 'B', 18)
161
+ pdf.set_font('msungstdlight', 'I', 18)
162
+ pdf.set_font('msungstdlight', 'BI', 18)
163
+
164
+ pdf.set_font('stsongstdlight', '', 18)
165
+ pdf.set_font('stsongstdlight', 'B', 18)
166
+ pdf.set_font('stsongstdlight', 'I', 18)
167
+ pdf.set_font('stsongstdlight', 'BI', 18)
168
+
169
+ pdf.set_font('hysmyeongjostdmedium', '', 18)
170
+ pdf.set_font('hysmyeongjostdmedium', 'B', 18)
171
+ pdf.set_font('hysmyeongjostdmedium', 'I', 18)
172
+ pdf.set_font('hysmyeongjostdmedium', 'BI', 18)
173
+
174
+ pdf.putfonts()
175
+ end
176
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ class TcpdfFormatTest < ActiveSupport::TestCase
4
+
5
+ test "set_page_orientation" do
6
+ pdf = TCPDF.new
7
+
8
+ pagedim = pdf.set_page_orientation('')
9
+ assert_equal pagedim['or'], 'P'
10
+ assert_equal pagedim['pb'], true
11
+ assert_equal pagedim['olm'], nil
12
+ assert_equal pagedim['orm'], nil
13
+ assert_in_delta pagedim['bm'], 20, 0.1
14
+
15
+ pagedim = pdf.set_page_orientation('P')
16
+ assert_equal pagedim['or'], 'P'
17
+
18
+ pagedim = pdf.set_page_orientation('L', false)
19
+ assert_equal pagedim['or'], 'L'
20
+ assert_equal pagedim['pb'], false
21
+
22
+ pagedim = pdf.set_page_orientation('P', true, 5)
23
+ assert_equal pagedim['or'], 'P'
24
+ assert_equal pagedim['pb'], true
25
+ assert_equal pagedim['bm'], 5
26
+ end
27
+ end
@@ -0,0 +1,126 @@
1
+ require 'test_helper'
2
+
3
+ class TcpdfTest < ActiveSupport::TestCase
4
+ class MYPDF < TCPDF
5
+ def getSpaceString
6
+ super
7
+ end
8
+ end
9
+
10
+ test "get_html_unit_to_units test" do
11
+ pdf = TCPDF.new
12
+ unit = pdf.get_html_unit_to_units("100", 1)
13
+ assert_in_delta unit, 35.27, 0.01
14
+
15
+ unit = pdf.get_html_unit_to_units("100px", 1, 'px', false)
16
+ assert_in_delta unit, 35.27, 0.01
17
+
18
+ unit = pdf.get_html_unit_to_units(100, 1, 'pt', false)
19
+ assert_in_delta unit, 35.27, 0.01
20
+
21
+ unit = pdf.get_html_unit_to_units(100.0, 1, 'pt', false)
22
+ assert_in_delta unit, 35.27, 0.01
23
+
24
+ unit = pdf.get_html_unit_to_units("100.0", 1, 'pt', false)
25
+ assert_in_delta unit, 35.27, 0.01
26
+
27
+ unit = pdf.get_html_unit_to_units("200", 1, '%', false)
28
+ assert_equal unit, 2.0
29
+
30
+ unit = pdf.get_html_unit_to_units("400%", 1, '%', false)
31
+ assert_equal unit, 4.0
32
+
33
+ unit = pdf.get_html_unit_to_units("10", 1, '%', false)
34
+ assert_equal unit, 0.1
35
+
36
+ unit = pdf.get_html_unit_to_units("10mm", 1, '%', false)
37
+ assert_in_delta unit, 10, 0.01
38
+
39
+ unit = pdf.get_html_unit_to_units("10", 1, 'mm', false)
40
+ assert_in_delta unit, 10, 0.01
41
+
42
+ unit = pdf.get_html_unit_to_units(10, 1, 'mm', false)
43
+ assert_in_delta unit, 10, 0.01
44
+
45
+ unit = pdf.get_html_unit_to_units("1", 1, 'cm', false)
46
+ assert_in_delta unit, 10, 0.01
47
+
48
+ unit = pdf.get_html_unit_to_units(10, 1, 'em', false)
49
+ assert_equal unit, 10
50
+
51
+ unit = pdf.get_html_unit_to_units(10, 2, 'em', false)
52
+ assert_equal unit, 20
53
+ end
54
+
55
+ test "getSpaceString test" do
56
+ pdf = MYPDF.new
57
+ spacestr = pdf.getSpaceString()
58
+ assert_equal spacestr, 32.chr
59
+
60
+ pdf.set_font('freesans', '', 18)
61
+ spacestr = pdf.getSpaceString()
62
+ assert_equal spacestr, 0.chr + 32.chr
63
+ end
64
+
65
+ test "revstrpos test" do
66
+ pdf = TCPDF.new
67
+ pos = pdf.revstrpos('abcd efgh ', 'cd')
68
+ assert_equal pos, 2
69
+
70
+ pos = pdf.revstrpos('abcd efgh ', 'cd ')
71
+ assert_equal pos, 2
72
+
73
+ pos = pdf.revstrpos('abcd efgh abcd efg', 'cd')
74
+ assert_equal pos, 12
75
+
76
+ pos = pdf.revstrpos('abcd efgh abcd efg', 'zy')
77
+ assert_equal pos, nil
78
+ end
79
+
80
+ test "revstrpos offset test 1" do
81
+ pdf = TCPDF.new
82
+
83
+ pos = pdf.revstrpos('abcd efgh ', 'cd', 3) # 'abc'
84
+ assert_equal pos, nil
85
+
86
+ pos = pdf.revstrpos('abcd efgh ', 'cd', 4) # 'abcd'
87
+ assert_equal pos, 2
88
+
89
+ pos = pdf.revstrpos('abcd efgh abcd efg', 'cd', 3) # 'abc'
90
+ assert_equal pos, nil
91
+
92
+ pos = pdf.revstrpos('abcd efgh abcd efg', 'cd', 4) # 'abcd'
93
+ assert_equal pos, 2
94
+
95
+ pos = pdf.revstrpos('abcd efgh abcd efg', 'cd', 13) # 'abcd efgh abc'
96
+ assert_equal pos, 2
97
+
98
+ pos = pdf.revstrpos('abcd efgh abcd efg', 'cd', 14) # 'abcd efgh abcd'
99
+ assert_equal pos, 12
100
+ end
101
+
102
+ test "revstrpos offset test 2" do
103
+ pdf = TCPDF.new
104
+
105
+ pos = pdf.revstrpos('abcd efgh ', 'cd', -6) # 'abcd'
106
+ assert_equal pos, 2
107
+
108
+ pos = pdf.revstrpos('abcd efgh ', 'cd', -7) # 'abc'
109
+ assert_equal pos, nil
110
+
111
+ pos = pdf.revstrpos('abcd efgh abcd efg', 'cd', -4) # 'abcd efgh abcd'
112
+ assert_equal pos, 12
113
+
114
+ pos = pdf.revstrpos('abcd efgh abcd efg', 'cd', -5) # 'abcd efgh abc'
115
+ assert_equal pos, 2
116
+ end
117
+
118
+ test "set_line_style Basic test" do
119
+ pdf = TCPDF.new
120
+
121
+ pdf.set_line_style({'width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => [0, 0, 0]})
122
+ pdf.set_line_style({'width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => [255, 0, 0]})
123
+ pdf.set_line_style({'width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '1,2,3,4', 'phase' => 0, 'color' => [255, 0, 0]})
124
+ pdf.set_line_style({'width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 'a', 'phase' => 0, 'color' => [255, 0, 0]}) # Invalid
125
+ end
126
+ end
@@ -0,0 +1,164 @@
1
+ require 'test_helper'
2
+
3
+ class TcpdfTest < ActiveSupport::TestCase
4
+ class MYPDF < TCPDF
5
+ def getPageBuffer(page)
6
+ super
7
+ end
8
+ end
9
+
10
+ test "write_html Basic test" do
11
+ pdf = TCPDF.new
12
+ pdf.add_page()
13
+
14
+
15
+ htmlcontent = '<h1>HTML Example</h1>'
16
+ pdf.write_html(htmlcontent, true, 0, true, 0)
17
+
18
+ htmlcontent = 'abcdefghijklmnopgrstuvwxyz01234567890 abcdefghijklmnopgrstuvwxyz01234567890 abcdefghijklmnopgrstuvwxyz01234567890 abcdefghijklmnopgrstuvwxyz01234567890 abcdefghijklmnopgrstuvwxyz01234567890'
19
+ pdf.write_html(htmlcontent, true, 0, true, 0)
20
+
21
+ 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>'
22
+ pdf.write_html(htmlcontent, true, 0, true, 0)
23
+
24
+ pno = pdf.get_page
25
+ assert_equal pno, 3
26
+ end
27
+
28
+ test "write_html Table test" do
29
+ pdf = TCPDF.new
30
+ pdf.add_page()
31
+
32
+ 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>'
33
+ pdf.write_html(tablehtml, true, 0, true, 0)
34
+
35
+ 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>'
36
+
37
+ 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>'
38
+ pdf.write_html(tablehtml, true, 0, true, 0)
39
+
40
+ pno = pdf.get_page
41
+ assert_equal pno, 3
42
+ end
43
+
44
+ test "write_html Table thead tag test 1" do
45
+ pdf = MYPDF.new
46
+ pdf.add_page()
47
+
48
+ tablehtml = '<table border="1" cellpadding="1" cellspacing="1">
49
+ <thead><tr><td>ABCD</td><td>EFGH</td><td>IJKL</td></tr></thead>
50
+ <tr><td>abcd</td><td>efgh</td><td>ijkl</td></tr>
51
+ </table>'
52
+
53
+ pdf.write_html(tablehtml, true, 0, true, 0)
54
+ page = pdf.get_page
55
+ assert_equal 1, page
56
+
57
+ content = []
58
+ contents = pdf.getPageBuffer(page)
59
+ contents.each_line {|line| content.push line.chomp }
60
+
61
+ count = 0
62
+ content.each do |line|
63
+ count += 1 if line =~ /ABCD/
64
+ end
65
+ assert_equal count, 1
66
+ end
67
+
68
+ test "write_html Table thead tag test 2" do
69
+ pdf = MYPDF.new
70
+ pdf.add_page()
71
+
72
+ 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>'
73
+
74
+ tablehtml = '<table border="1" cellpadding="1" cellspacing="1"><thead><tr><td>ABCD</td><td>EFGH</td><td>IJKL</td></tr></thead>
75
+ <tr><td>abcd</td><td>efgh</td><td>ijkl</td></tr>
76
+ <tr><td>' + htmlcontent + '</td></tr></table>'
77
+
78
+ pdf.write_html(tablehtml, true, 0, true, 0)
79
+ page = pdf.get_page
80
+ assert_equal 3, page
81
+
82
+ content = []
83
+ contents = pdf.getPageBuffer(1)
84
+ contents.each_line {|line| content.push line.chomp }
85
+ count_head = 0
86
+ count = 0
87
+ content.each do |line|
88
+ count_head += 1 if line =~ /ABCD/
89
+ count += 1 if line =~ /abcd/
90
+ end
91
+ assert_equal count_head, 1
92
+ assert_equal count, 1
93
+
94
+ content = []
95
+ contents = pdf.getPageBuffer(2)
96
+ contents.each_line {|line| content.push line.chomp }
97
+ count_head = 0
98
+ count = 0
99
+ content.each do |line|
100
+ count_head += 1 if line =~ /ABCD/
101
+ count += 1 if line =~ /abcd/
102
+ end
103
+ assert_equal count_head, 1
104
+ assert_equal count, 0
105
+
106
+ content = []
107
+ contents = pdf.getPageBuffer(3)
108
+ contents.each_line {|line| content.push line.chomp }
109
+ count_head = 0
110
+ count = 0
111
+ content.each do |line|
112
+ count_head += 1 if line =~ /ABCD/
113
+ count += 1 if line =~ /abcd/
114
+ end
115
+ assert_equal count_head, 1
116
+ assert_equal count, 0
117
+ end
118
+
119
+ test "write_html ASCII text test" do
120
+ pdf = MYPDF.new
121
+ pdf.add_page()
122
+
123
+ text = 'HTML Example'
124
+ htmlcontent = '<h1>' + text + '</h1>'
125
+ pdf.write_html(htmlcontent, true, 0, true, 0)
126
+ page = pdf.get_page
127
+ assert_equal 1, page
128
+
129
+ content = []
130
+ contents = pdf.getPageBuffer(1)
131
+ contents.each_line {|line| content.push line.chomp }
132
+
133
+ count = 0
134
+ content.each do |line|
135
+ count += 1 unless line.scan(text).empty?
136
+ end
137
+ assert_equal count, 1
138
+ end
139
+
140
+ test "write_html Non ASCII text test" do
141
+ pdf = MYPDF.new
142
+ pdf.add_page()
143
+
144
+ text = 'HTML Example ' + "\xc2\x83\xc2\x86"
145
+
146
+ htmlcontent = '<h1>' + text + '</h1>'
147
+ pdf.write_html(htmlcontent, true, 0, true, 0)
148
+ page = pdf.get_page
149
+ assert_equal 1, page
150
+
151
+ content = []
152
+ contents = pdf.getPageBuffer(1)
153
+ contents.each_line {|line| content.push line.chomp }
154
+
155
+ text = 'HTML Example ' + "\x83\x86"
156
+ text.force_encoding('ASCII-8BIT') if text.respond_to?(:force_encoding)
157
+ count = 0
158
+ content.each do |line|
159
+ line.force_encoding('ASCII-8BIT') if line.respond_to?(:force_encoding)
160
+ count += 1 unless line.scan(text).empty?
161
+ end
162
+ assert_equal count, 1
163
+ end
164
+ end