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.
- checksums.yaml +5 -5
- data/CHANGELOG +18 -0
- data/README.md +11 -1
- data/lib/rbpdf/version.rb +2 -2
- data/lib/rbpdf.rb +69 -46
- data/lib/unicode_data.rb +29 -0
- data/rbpdf.gemspec +8 -20
- metadata +28 -101
- data/test/err_font1.rb +0 -7
- data/test/err_font2.rb +0 -8
- data/test/input.jpg +0 -0
- data/test/json: +0 -0
- data/test/logo_rbpdf_8bit .png +0 -0
- data/test/logo_rbpdf_8bit+ .png +0 -0
- data/test/logo_rbpdf_8bit.gif +0 -0
- data/test/logo_rbpdf_8bit.jpg +0 -0
- data/test/logo_rbpdf_8bit.png +0 -0
- data/test/logo_rbpdf_8bit_alpha.gif +0 -0
- data/test/logo_rbpdf_mono_gray.jpg +0 -0
- data/test/logo_rbpdf_mono_gray.png +0 -0
- data/test/logo_rbpdf_mono_rgb.jpg +0 -0
- data/test/logo_rbpdf_mono_rgb.png +0 -0
- data/test/output.png +0 -0
- data/test/png_test_alpha.png +0 -0
- data/test/png_test_msk_alpha.png +0 -0
- data/test/png_test_non_alpha.png +0 -0
- data/test/rbpdf_bidi_test.rb +0 -453
- data/test/rbpdf_bookmark_test.rb +0 -66
- data/test/rbpdf_cell_test.rb +0 -231
- data/test/rbpdf_content_test.rb +0 -213
- data/test/rbpdf_css_test.rb +0 -640
- data/test/rbpdf_dom_test.rb +0 -272
- data/test/rbpdf_examples_test.rb +0 -83
- data/test/rbpdf_font_func_test.rb +0 -45
- data/test/rbpdf_font_style_test.rb +0 -37
- data/test/rbpdf_font_test.rb +0 -308
- data/test/rbpdf_format_test.rb +0 -30
- data/test/rbpdf_func_test.rb +0 -139
- data/test/rbpdf_html_anchor_test.rb +0 -105
- data/test/rbpdf_html_func_test.rb +0 -170
- data/test/rbpdf_html_test.rb +0 -658
- data/test/rbpdf_htmlcell_test.rb +0 -60
- data/test/rbpdf_http_test.rb +0 -76
- data/test/rbpdf_image_rmagick_test.rb +0 -170
- data/test/rbpdf_image_test.rb +0 -174
- data/test/rbpdf_test.rb +0 -375
- data/test/rbpdf_transaction_test.rb +0 -203
- data/test/rbpdf_viewerpreferences_test.rb +0 -41
- data/test/rbpdf_write_test.rb +0 -229
- data/test/test.rb +0 -22
- data/test/test_helper.rb +0 -9
data/test/rbpdf_font_test.rb
DELETED
@@ -1,308 +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 RbpdfFontTest < Test::Unit::TestCase
|
8
|
-
class MYPDF < RBPDF
|
9
|
-
def putfonts()
|
10
|
-
super
|
11
|
-
end
|
12
|
-
|
13
|
-
def getFontBuffer(font)
|
14
|
-
super
|
15
|
-
end
|
16
|
-
|
17
|
-
def getFontsList()
|
18
|
-
super
|
19
|
-
end
|
20
|
-
|
21
|
-
def fontlist()
|
22
|
-
@fontlist
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
test "Font subsetting enable/disable test" do
|
27
|
-
pdf = MYPDF.new
|
28
|
-
subsetting = pdf.get_font_subsetting
|
29
|
-
assert_equal true, subsetting
|
30
|
-
|
31
|
-
pdf.set_font_subsetting(false)
|
32
|
-
subsetting = pdf.get_font_subsetting
|
33
|
-
assert_equal false, subsetting
|
34
|
-
|
35
|
-
pdf.set_font_subsetting(true)
|
36
|
-
subsetting = pdf.get_font_subsetting
|
37
|
-
assert_equal true, subsetting
|
38
|
-
end
|
39
|
-
|
40
|
-
test "Font getFontsList" do
|
41
|
-
pdf = MYPDF.new
|
42
|
-
pdf.getFontsList()
|
43
|
-
fonts = pdf.fontlist()
|
44
|
-
assert fonts.include?('kozminproregular')
|
45
|
-
end
|
46
|
-
|
47
|
-
test "core Font test" do
|
48
|
-
pdf = MYPDF.new
|
49
|
-
|
50
|
-
pdf.set_font('helvetica', '', 18)
|
51
|
-
pdf.set_font('helvetica', 'B', 18)
|
52
|
-
pdf.set_font('helvetica', 'I', 18)
|
53
|
-
pdf.set_font('helvetica', 'BI', 18)
|
54
|
-
|
55
|
-
font = pdf.getFontBuffer('helvetica')
|
56
|
-
assert_equal 'Helvetica', font['name']
|
57
|
-
assert_equal 556, font['dw']
|
58
|
-
font = pdf.getFontBuffer('helveticaB')
|
59
|
-
assert_equal 'Helvetica-Bold', font['name']
|
60
|
-
assert_equal 556, font['dw']
|
61
|
-
font = pdf.getFontBuffer('helveticaI')
|
62
|
-
assert_equal 'Helvetica-Oblique', font['name']
|
63
|
-
assert_equal 556, font['dw']
|
64
|
-
font = pdf.getFontBuffer('helveticaBI')
|
65
|
-
assert_equal 'Helvetica-BoldOblique', font['name']
|
66
|
-
assert_equal 556, font['dw']
|
67
|
-
|
68
|
-
pdf.set_font('times', '', 18)
|
69
|
-
pdf.set_font('times', 'B', 18)
|
70
|
-
pdf.set_font('times', 'I', 18)
|
71
|
-
pdf.set_font('times', 'BI', 18)
|
72
|
-
|
73
|
-
font = pdf.getFontBuffer('times')
|
74
|
-
assert_equal 'Times-Roman', font['name']
|
75
|
-
font = pdf.getFontBuffer('timesB')
|
76
|
-
assert_equal 'Times-Bold', font['name']
|
77
|
-
font = pdf.getFontBuffer('timesI')
|
78
|
-
assert_equal 'Times-Italic', font['name']
|
79
|
-
font = pdf.getFontBuffer('timesBI')
|
80
|
-
assert_equal 'Times-BoldItalic', font['name']
|
81
|
-
|
82
|
-
pdf.set_font('courier', '', 18)
|
83
|
-
pdf.set_font('courier', 'B', 18)
|
84
|
-
pdf.set_font('courier', 'I', 18)
|
85
|
-
pdf.set_font('courier', 'BI', 18)
|
86
|
-
|
87
|
-
font = pdf.getFontBuffer('courier')
|
88
|
-
assert_equal 'Courier', font['name']
|
89
|
-
font = pdf.getFontBuffer('courierB')
|
90
|
-
assert_equal 'Courier-Bold', font['name']
|
91
|
-
font = pdf.getFontBuffer('courierI')
|
92
|
-
assert_equal 'Courier-Oblique', font['name']
|
93
|
-
font = pdf.getFontBuffer('courierBI')
|
94
|
-
assert_equal 'Courier-BoldOblique', font['name']
|
95
|
-
|
96
|
-
pdf.set_font('symbol', '', 18)
|
97
|
-
font = pdf.getFontBuffer('symbol')
|
98
|
-
assert_equal 'Symbol', font['name']
|
99
|
-
|
100
|
-
pdf.set_font('zapfdingbats', '', 18)
|
101
|
-
font = pdf.getFontBuffer('zapfdingbats')
|
102
|
-
assert_equal 'ZapfDingbats', font['name']
|
103
|
-
|
104
|
-
pdf.putfonts()
|
105
|
-
end
|
106
|
-
|
107
|
-
test "TrueTypeUnicode Subset Font test" do
|
108
|
-
pdf = MYPDF.new
|
109
|
-
pdf.set_font_subsetting(true)
|
110
|
-
|
111
|
-
pdf.set_font('freesans', '', 18)
|
112
|
-
pdf.set_font('freesans', 'B', 18)
|
113
|
-
pdf.set_font('freesans', 'I', 18)
|
114
|
-
pdf.set_font('freesans', 'BI', 18)
|
115
|
-
|
116
|
-
pdf.set_font('freeserif', '', 18)
|
117
|
-
pdf.set_font('freeserif', 'B', 18)
|
118
|
-
pdf.set_font('freeserif', 'I', 18)
|
119
|
-
pdf.set_font('freeserif', 'BI', 18)
|
120
|
-
|
121
|
-
pdf.set_font('freemono', '', 18)
|
122
|
-
pdf.set_font('freemono', 'B', 18)
|
123
|
-
pdf.set_font('freemono', 'I', 18)
|
124
|
-
pdf.set_font('freemono', 'BI', 18)
|
125
|
-
|
126
|
-
pdf.set_font('dejavusans', '', 18)
|
127
|
-
pdf.set_font('dejavusans', 'B', 18)
|
128
|
-
pdf.set_font('dejavusans', 'I', 18)
|
129
|
-
pdf.set_font('dejavusans', 'BI', 18)
|
130
|
-
|
131
|
-
pdf.set_font('dejavusanscondensed', '', 18)
|
132
|
-
pdf.set_font('dejavusanscondensed', 'B', 18)
|
133
|
-
pdf.set_font('dejavusanscondensed', 'I', 18)
|
134
|
-
pdf.set_font('dejavusanscondensed', 'BI', 18)
|
135
|
-
|
136
|
-
pdf.set_font('dejavusansmono', '', 18)
|
137
|
-
pdf.set_font('dejavusansmono', 'B', 18)
|
138
|
-
pdf.set_font('dejavusansmono', 'I', 18)
|
139
|
-
pdf.set_font('dejavusansmono', 'BI', 18)
|
140
|
-
|
141
|
-
pdf.set_font('dejavuserif', '', 18)
|
142
|
-
pdf.set_font('dejavuserif', 'B', 18)
|
143
|
-
pdf.set_font('dejavuserif', 'I', 18)
|
144
|
-
pdf.set_font('dejavuserif', 'BI', 18)
|
145
|
-
|
146
|
-
pdf.set_font('dejavuserifcondensed', '', 18)
|
147
|
-
pdf.set_font('dejavuserifcondensed', 'B', 18)
|
148
|
-
pdf.set_font('dejavuserifcondensed', 'I', 18)
|
149
|
-
pdf.set_font('dejavuserifcondensed', 'BI', 18)
|
150
|
-
|
151
|
-
pdf.set_font('dejavusansextralight', '', 18)
|
152
|
-
|
153
|
-
pdf.putfonts()
|
154
|
-
end
|
155
|
-
|
156
|
-
test "TrueTypeUnicode Font test" do
|
157
|
-
pdf = MYPDF.new
|
158
|
-
pdf.set_font_subsetting(false)
|
159
|
-
|
160
|
-
pdf.set_font('freesans', '', 18)
|
161
|
-
pdf.set_font('freesans', 'B', 18)
|
162
|
-
pdf.set_font('freesans', 'I', 18)
|
163
|
-
pdf.set_font('freesans', 'BI', 18)
|
164
|
-
|
165
|
-
pdf.set_font('freeserif', '', 18)
|
166
|
-
pdf.set_font('freeserif', 'B', 18)
|
167
|
-
pdf.set_font('freeserif', 'I', 18)
|
168
|
-
pdf.set_font('freeserif', 'BI', 18)
|
169
|
-
|
170
|
-
pdf.set_font('freemono', '', 18)
|
171
|
-
pdf.set_font('freemono', 'B', 18)
|
172
|
-
pdf.set_font('freemono', 'I', 18)
|
173
|
-
pdf.set_font('freemono', 'BI', 18)
|
174
|
-
|
175
|
-
pdf.set_font('dejavusans', '', 18)
|
176
|
-
pdf.set_font('dejavusans', 'B', 18)
|
177
|
-
pdf.set_font('dejavusans', 'I', 18)
|
178
|
-
pdf.set_font('dejavusans', 'BI', 18)
|
179
|
-
|
180
|
-
pdf.set_font('dejavusanscondensed', '', 18)
|
181
|
-
pdf.set_font('dejavusanscondensed', 'B', 18)
|
182
|
-
pdf.set_font('dejavusanscondensed', 'I', 18)
|
183
|
-
pdf.set_font('dejavusanscondensed', 'BI', 18)
|
184
|
-
|
185
|
-
pdf.set_font('dejavusansmono', '', 18)
|
186
|
-
pdf.set_font('dejavusansmono', 'B', 18)
|
187
|
-
pdf.set_font('dejavusansmono', 'I', 18)
|
188
|
-
pdf.set_font('dejavusansmono', 'BI', 18)
|
189
|
-
|
190
|
-
pdf.set_font('dejavuserif', '', 18)
|
191
|
-
pdf.set_font('dejavuserif', 'B', 18)
|
192
|
-
pdf.set_font('dejavuserif', 'I', 18)
|
193
|
-
pdf.set_font('dejavuserif', 'BI', 18)
|
194
|
-
|
195
|
-
pdf.set_font('dejavuserifcondensed', '', 18)
|
196
|
-
pdf.set_font('dejavuserifcondensed', 'B', 18)
|
197
|
-
pdf.set_font('dejavuserifcondensed', 'I', 18)
|
198
|
-
pdf.set_font('dejavuserifcondensed', 'BI', 18)
|
199
|
-
|
200
|
-
pdf.set_font('dejavusansextralight', '', 18)
|
201
|
-
|
202
|
-
pdf.putfonts()
|
203
|
-
end
|
204
|
-
|
205
|
-
test "cidfont0 Font test" do
|
206
|
-
pdf = MYPDF.new
|
207
|
-
|
208
|
-
pdf.set_font('cid0cs', '', 18)
|
209
|
-
pdf.set_font('cid0cs', 'B', 18)
|
210
|
-
pdf.set_font('cid0cs', 'I', 18)
|
211
|
-
pdf.set_font('cid0cs', 'BI', 18)
|
212
|
-
|
213
|
-
pdf.set_font('cid0ct', '', 18)
|
214
|
-
pdf.set_font('cid0ct', 'B', 18)
|
215
|
-
pdf.set_font('cid0ct', 'I', 18)
|
216
|
-
pdf.set_font('cid0ct', 'BI', 18)
|
217
|
-
|
218
|
-
pdf.set_font('cid0jp', '', 18)
|
219
|
-
pdf.set_font('cid0jp', 'B', 18)
|
220
|
-
pdf.set_font('cid0jp', 'I', 18)
|
221
|
-
pdf.set_font('cid0jp', 'BI', 18)
|
222
|
-
|
223
|
-
pdf.set_font('cid0kr', '', 18)
|
224
|
-
pdf.set_font('cid0kr', 'B', 18)
|
225
|
-
pdf.set_font('cid0kr', 'I', 18)
|
226
|
-
pdf.set_font('cid0kr', 'BI', 18)
|
227
|
-
|
228
|
-
pdf.set_font('kozgopromedium', '', 18)
|
229
|
-
pdf.set_font('kozgopromedium', 'B', 18)
|
230
|
-
pdf.set_font('kozgopromedium', 'I', 18)
|
231
|
-
pdf.set_font('kozgopromedium', 'BI', 18)
|
232
|
-
|
233
|
-
font = pdf.getFontBuffer('kozgopromedium')
|
234
|
-
assert_equal 99, font['desc']['StemV']
|
235
|
-
assert_equal 0, font['desc']['ItalicAngle']
|
236
|
-
assert_equal 'KozGoPro-Medium-Acro', font['name']
|
237
|
-
|
238
|
-
font = pdf.getFontBuffer('kozgopromediumB')
|
239
|
-
assert_equal 99 * 2, font['desc']['StemV']
|
240
|
-
assert_equal 0, font['desc']['ItalicAngle']
|
241
|
-
assert_equal 'KozGoPro-Medium-Acro,Bold', font['name']
|
242
|
-
|
243
|
-
font = pdf.getFontBuffer('kozgopromediumI')
|
244
|
-
assert_equal 99, font['desc']['StemV']
|
245
|
-
assert_equal(-11, font['desc']['ItalicAngle'])
|
246
|
-
assert_equal 'KozGoPro-Medium-Acro,Italic', font['name']
|
247
|
-
|
248
|
-
font = pdf.getFontBuffer('kozgopromediumBI')
|
249
|
-
assert_equal 99 * 2, font['desc']['StemV']
|
250
|
-
assert_equal(-11, font['desc']['ItalicAngle'])
|
251
|
-
assert_equal 'KozGoPro-Medium-Acro,BoldItalic', font['name']
|
252
|
-
|
253
|
-
pdf.set_font('kozminproregular', '', 18)
|
254
|
-
pdf.set_font('kozminproregular', 'B', 18)
|
255
|
-
pdf.set_font('kozminproregular', 'I', 18)
|
256
|
-
pdf.set_font('kozminproregular', 'BI', 18)
|
257
|
-
|
258
|
-
pdf.set_font('msungstdlight', '', 18)
|
259
|
-
pdf.set_font('msungstdlight', 'B', 18)
|
260
|
-
pdf.set_font('msungstdlight', 'I', 18)
|
261
|
-
pdf.set_font('msungstdlight', 'BI', 18)
|
262
|
-
|
263
|
-
pdf.set_font('stsongstdlight', '', 18)
|
264
|
-
pdf.set_font('stsongstdlight', 'B', 18)
|
265
|
-
pdf.set_font('stsongstdlight', 'I', 18)
|
266
|
-
pdf.set_font('stsongstdlight', 'BI', 18)
|
267
|
-
|
268
|
-
pdf.set_font('hysmyeongjostdmedium', '', 18)
|
269
|
-
pdf.set_font('hysmyeongjostdmedium', 'B', 18)
|
270
|
-
pdf.set_font('hysmyeongjostdmedium', 'I', 18)
|
271
|
-
pdf.set_font('hysmyeongjostdmedium', 'BI', 18)
|
272
|
-
|
273
|
-
pdf.putfonts()
|
274
|
-
end
|
275
|
-
|
276
|
-
test "Set Font fontname test" do
|
277
|
-
pdf = MYPDF.new
|
278
|
-
pdf.set_font('helvetica', '', 18, pdf.send(:getfontpath, 'helvetica.rb'))
|
279
|
-
pdf.set_font('helvetica', 'B', 18, pdf.send(:getfontpath, 'helveticab.rb'))
|
280
|
-
pdf.set_font('helvetica', 'I', 18, pdf.send(:getfontpath, 'helveticai.rb'))
|
281
|
-
pdf.set_font('helvetica', 'BI', 18, pdf.send(:getfontpath, 'helveticabi.rb'))
|
282
|
-
pdf.putfonts()
|
283
|
-
end
|
284
|
-
|
285
|
-
test "Font Error test" do
|
286
|
-
pdf = RBPDF.new
|
287
|
-
RBPDF.k_path_fonts = File.join File.dirname(__FILE__)
|
288
|
-
|
289
|
-
err = assert_raises(RBPDFError) {
|
290
|
-
pdf.set_font('err_font', '', 18)
|
291
|
-
}
|
292
|
-
assert_equal 'RBPDF error: Could not include font definition file: err_font', err.message
|
293
|
-
|
294
|
-
err = assert_raises(RBPDFError) {
|
295
|
-
pdf.set_font('err_font1', '', 18)
|
296
|
-
}
|
297
|
-
assert_match(/RBPDF error: The font definition file has a bad format: .*err_font1.rb/, err.message)
|
298
|
-
|
299
|
-
err = assert_raises(RBPDFError) {
|
300
|
-
pdf.set_font('err_font2', '', 18)
|
301
|
-
}
|
302
|
-
assert_equal 'RBPDF error: Unknow font type: Type0', err.message
|
303
|
-
|
304
|
-
# Font path reset test
|
305
|
-
pdf = RBPDF.new
|
306
|
-
pdf.set_font('helvetica', '', 18)
|
307
|
-
end
|
308
|
-
end
|
data/test/rbpdf_format_test.rb
DELETED
@@ -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
|
data/test/rbpdf_func_test.rb
DELETED
@@ -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
|