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,640 +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 RbpdfCssTest < Test::Unit::TestCase
8
- class MYPDF < RBPDF
9
- def extractCSSproperties(cssdata)
10
- super
11
- end
12
- def isValidCSSSelectorForTag(dom, key, selector)
13
- super
14
- end
15
- def getTagStyleFromCSS(dom, key, css)
16
- super
17
- end
18
- def getHtmlDomArray(html)
19
- super
20
- end
21
- end
22
-
23
- test "CSS Basic" do
24
- pdf = MYPDF.new
25
-
26
- # empty
27
- css = pdf.extractCSSproperties('')
28
- assert_equal({}, css)
29
- # empty blocks
30
- css = pdf.extractCSSproperties('h1 {}')
31
- assert_equal({}, css)
32
- # comment
33
- css = pdf.extractCSSproperties('/* comment */')
34
- assert_equal({}, css)
35
-
36
- css = pdf.extractCSSproperties('h1 { color: navy; font-family: times; }')
37
- assert_equal({"0001 h1"=>"color:navy;font-family:times;"}, css)
38
-
39
- css = pdf.extractCSSproperties('h1 { color: navy; font-family: times; } p.first { color: #003300; font-family: helvetica; font-size: 12pt; }')
40
- assert_equal({"0001 h1"=>"color:navy;font-family:times;", "0021 p.first"=>"color:#003300;font-family:helvetica;font-size:12pt;"}, css)
41
-
42
- css = pdf.extractCSSproperties('h1,h2,h3{background-color:#e0e0e0}')
43
- assert_equal({"0001 h1"=>"background-color:#e0e0e0", "0001 h2"=>"background-color:#e0e0e0", "0001 h3"=>"background-color:#e0e0e0"}, css)
44
-
45
- css = pdf.extractCSSproperties('p.second { color: rgb(00,63,127); font-family: times; font-size: 12pt; text-align: justify; }')
46
- assert_equal({"0011 p.second"=>"color:rgb(00,63,127);font-family:times;font-size:12pt;text-align:justify;"}, css)
47
-
48
- css = pdf.extractCSSproperties('p#second { color: rgb(00,63,127); font-family: times; font-size: 12pt; text-align: justify; }')
49
- assert_equal({"0101 p#second"=>"color:rgb(00,63,127);font-family:times;font-size:12pt;text-align:justify;"}, css)
50
-
51
- css = pdf.extractCSSproperties('p.first { color: rgb(00,63,127); } p.second { font-family: times; }')
52
- assert_equal({"0021 p.first"=>"color:rgb(00,63,127);", "0011 p.second"=>"font-family:times;"}, css)
53
-
54
- css = pdf.extractCSSproperties('p#first { color: rgb(00,63,127); } p#second { color: rgb(00,63,127); }')
55
- assert_equal({"0111 p#first"=>"color:rgb(00,63,127);", "0101 p#second"=>"color:rgb(00,63,127);"}, css)
56
-
57
- # media
58
- css = pdf.extractCSSproperties('@media print { body { font: 10pt serif } }')
59
- assert_equal({"0001 body"=>"font:10pt serif"}, css)
60
- css = pdf.extractCSSproperties('@media screen { body { font: 12pt sans-serif } }')
61
- assert_equal({}, css)
62
- css = pdf.extractCSSproperties('@media all { body { line-height: 1.2 } }')
63
- assert_equal({"0001 body"=>"line-height:1.2"}, css)
64
-
65
- css = pdf.extractCSSproperties('@media print {
66
- #top-menu, #header, #main-menu, #sidebar, #footer, .contextual, .other-formats { display:none; }
67
- #main { background: #fff; }
68
- #content { width: 99%; margin: 0; padding: 0; border: 0; background: #fff; overflow: visible !important;}
69
- #wiki_add_attachment { display:none; }
70
- .hide-when-print { display: none; }
71
- .autoscroll {overflow-x: visible;}
72
- table.list {margin-top:0.5em;}
73
- table.list th, table.list td {border: 1px solid #aaa;}
74
- } @media all { body { line-height: 1.2 } }')
75
- assert_equal({"0100 #top-menu"=>"display:none;",
76
- "0100 #header"=>"display:none;",
77
- "0100 #main-menu"=>"display:none;",
78
- "0100 #sidebar"=>"display:none;",
79
- "0100 #footer"=>"display:none;",
80
- "0010 .contextual"=>"display:none;",
81
- "0010 .other-formats"=>"display:none;",
82
- "0100 #main"=>"background:#fff;",
83
- "0100 #content"=>"width:99%;margin:0;padding:0;border:0;background:#fff;overflow:visible !important;",
84
- "0100 #wiki_add_attachment"=>"display:none;",
85
- "0010 .hide-when-print"=>"display:none;",
86
- "0010 .autoscroll"=>"overflow-x:visible;",
87
- "0011 table.list"=>"margin-top:0.5em;",
88
- "0012 table.list th"=>"border:1px solid #aaa;",
89
- "0012 table.list td"=>"border:1px solid #aaa;",
90
- "0001 body"=>"line-height:1.2"}, css)
91
- end
92
-
93
- test "CSS Selector Valid test" do
94
- pdf = MYPDF.new
95
-
96
- # Simple CSS
97
- dom = pdf.getHtmlDomArray('<p>abc</p>')
98
- assert_equal 4, dom.length
99
- valid = pdf.isValidCSSSelectorForTag(dom, 1, ' p') # dom, key, css selector
100
- assert_equal true, valid
101
-
102
- dom = pdf.getHtmlDomArray('<h1>abc</h1>')
103
- assert_equal 4, dom.length
104
- valid = pdf.isValidCSSSelectorForTag(dom, 1, ' h1') # dom, key, css selector
105
- assert_equal true, valid
106
-
107
- dom = pdf.getHtmlDomArray('<p class="first">abc</p>')
108
- assert_equal 4, dom.length
109
- valid = pdf.isValidCSSSelectorForTag(dom, 1, ' p.first') # dom, key, css selector
110
- assert_equal true, valid
111
-
112
- dom = pdf.getHtmlDomArray('<p class="first">abc<span>def</span></p>')
113
- assert_equal 7, dom.length
114
- valid = pdf.isValidCSSSelectorForTag(dom, 3, ' p.first span') # dom, key, css selector
115
- assert_equal true, valid
116
-
117
- dom = pdf.getHtmlDomArray('<p id="second">abc</p>')
118
- assert_equal 4, dom.length
119
- valid = pdf.isValidCSSSelectorForTag(dom, 1, ' p#second') # dom, key, css selector
120
- assert_equal true, valid
121
-
122
- dom = pdf.getHtmlDomArray('<p id="second">abc<span>def</span></p>')
123
- assert_equal 7, dom.length
124
- valid = pdf.isValidCSSSelectorForTag(dom, 3, ' p#second > span') # dom, key, css selector
125
- assert_equal true, valid
126
- end
127
-
128
- test "CSS Tag Sytle test 1" do
129
- pdf = MYPDF.new
130
-
131
- # Simple CSS
132
- dom = pdf.getHtmlDomArray('<h1>abc</h1>')
133
- assert_equal 4, dom.length
134
-
135
- tag = pdf.getTagStyleFromCSS(dom, 1, {'0001 h1'=>'color:navy;font-family:times;'}) # dom, key, css selector
136
- assert_equal ';color:navy;font-family:times;', tag
137
-
138
- tag = pdf.getTagStyleFromCSS(dom, 1, {'0001h1'=>'color:navy;font-family:times;'}) # dom, key, css selector
139
- assert_equal '', tag
140
-
141
- tag = pdf.getTagStyleFromCSS(dom, 1, {'0001 h2'=>'color:navy;font-family:times;'}) # dom, key, css selector
142
- assert_equal '', tag
143
- end
144
-
145
- test "CSS Tag Sytle test 2" do
146
- pdf = MYPDF.new
147
-
148
- dom = pdf.getHtmlDomArray('<p class="first">abc</p>')
149
- assert_equal 4, dom.length
150
-
151
- tag = pdf.getTagStyleFromCSS(dom, 1, {'0021 p.first'=>'color:rgb(00,63,127);'})
152
- assert_equal ';color:rgb(00,63,127);', tag
153
-
154
- dom = pdf.getHtmlDomArray('<p id="second">abc</p>')
155
- assert_equal 4, dom.length
156
-
157
- tag = pdf.getTagStyleFromCSS(dom, 1, {'0101 p#second'=>'color:rgb(00,63,127);font-family:times;font-size:12pt;text-align:justify;'})
158
- assert_equal ';color:rgb(00,63,127);font-family:times;font-size:12pt;text-align:justify;', tag
159
- end
160
-
161
- test "CSS Dom test" do
162
- pdf = MYPDF.new
163
-
164
- html = '<style> table, td { border: 2px #ff0000 solid; } </style>
165
- <h2>HTML TABLE:</h2>
166
- <table> <tr> <th>abc</th> </tr>
167
- <tr> <td>def</td> </tr> </table>'
168
- dom = pdf.getHtmlDomArray(html)
169
- ## remove style tag block (by getHtmlDomArray()) ##
170
- ## added marker tag (by getHtmlDomArray()) ##
171
- # '<h2>HTML TABLE:</h2>
172
- # <table><tr><th>abc<marker style="font-size:0"/></th></tr>
173
- # <tr><td>def<marker style="font-size:0"/></td></tr></table>'
174
- assert_equal 18, dom.length
175
-
176
- assert_equal 0, dom[0]['parent'] # Root
177
- assert_equal false, dom[0]['tag']
178
- assert_equal({}, dom[0]['attribute'])
179
-
180
- # <h2>
181
- assert_equal 0, dom[1]['elkey']
182
- assert_equal 0, dom[1]['parent'] # parent -> parent tag key
183
- assert_equal true, dom[1]['tag']
184
- assert_equal true, dom[1]['opening']
185
- assert_equal 'h2', dom[1]['value']
186
-
187
- # <table>
188
- assert_equal 3, dom[4]['elkey']
189
- assert_equal 'table', dom[4]['value']
190
- assert_equal({'border'=>'2px #ff0000 solid', 'style'=>';border:2px #ff0000 solid;'}, dom[4]['attribute'])
191
- assert_equal '2px #ff0000 solid', dom[4]['style']['border']
192
- assert_equal '2px #ff0000 solid', dom[4]['attribute']['border']
193
- end
194
-
195
- test "CSS Dom table thead test" do
196
- pdf = MYPDF.new
197
-
198
- html = '<style> table, td { border: 2px #ff0000 solid; } </style>
199
- <h2>HTML TABLE THEAD:</h2>
200
- <table><thead>
201
- <tr> <th>abc</th> </tr>
202
- </thead>
203
- <tbody>
204
- <tr> <td>def</td> </tr>
205
- <tr> <td>ghi</td> </tr>
206
- </tbody></table>'
207
-
208
- dom = pdf.getHtmlDomArray(html)
209
- ## remove style tag block (by getHtmlDomArray()) ##
210
- ## remove thead/tbody tag block (by getHtmlDomArray()) ##
211
- ## added marker tag (by getHtmlDomArray()) ##
212
- # '<h2>HTML TABLE:</h2>
213
- # <table><tr><th>abc<marker style="font-size:0"/></th></tr>
214
- # <tr><td>def<marker style="font-size:0"/></td></tr></table>'
215
- assert_equal 24, dom.length
216
-
217
- assert_equal 0, dom[0]['parent'] # Root
218
- assert_equal false, dom[0]['tag']
219
- assert_equal({}, dom[0]['attribute'])
220
-
221
- # <h2>
222
- assert_equal 0, dom[1]['elkey']
223
- assert_equal 0, dom[1]['parent'] # parent -> parent tag key
224
- assert_equal true, dom[1]['tag']
225
- assert_equal true, dom[1]['opening']
226
- assert_equal 'h2', dom[1]['value']
227
-
228
- # <table>
229
- assert_equal 3, dom[4]['elkey']
230
- assert_equal 'table', dom[4]['value']
231
- assert_equal({'border'=>'2px #ff0000 solid', 'style'=>';border:2px #ff0000 solid;'}, dom[4]['attribute'])
232
- assert_equal '2px #ff0000 solid', dom[4]['style']['border']
233
- assert_equal '2px #ff0000 solid', dom[4]['attribute']['border']
234
- assert_equal '<style>table {;border:2px #ff0000 solid;}</style><table tablehead="1"><tr><th>abc<marker style="font-size:0"/></th></tr></table>', dom[4]['thead']
235
- end
236
-
237
- test "CSS Dom line-height test normal" do
238
- pdf = MYPDF.new
239
-
240
- html = '<style> h2 { line-height: normal; } </style>
241
- <h2>HTML TEST</h2>'
242
- dom = pdf.getHtmlDomArray(html)
243
- ## remove style tag block (by getHtmlDomArray()) ##
244
- # '<h2>HTML TEST</h2>'
245
- assert_equal 4, dom.length
246
-
247
- # <h2>
248
- assert_equal 0, dom[1]['elkey']
249
- assert_equal 0, dom[1]['parent'] # parent -> parent tag key
250
- assert_equal true, dom[1]['tag']
251
- assert_equal true, dom[1]['opening']
252
- assert_equal 'h2', dom[1]['value']
253
- assert_equal 1.25, dom[1]['line-height']
254
- end
255
-
256
- test "CSS Dom line-height test numeric" do
257
- pdf = MYPDF.new
258
-
259
- html = '<style> h2 { line-height: 1.4; } </style>
260
- <h2>HTML TEST</h2>'
261
- dom = pdf.getHtmlDomArray(html)
262
- ## remove style tag block (by getHtmlDomArray()) ##
263
- # '<h2>HTML TEST</h2>'
264
- assert_equal dom.length, 4
265
-
266
- # <h2>
267
- assert_equal 0, dom[1]['elkey']
268
- assert_equal 0, dom[1]['parent'] # parent -> parent tag key
269
- assert_equal true, dom[1]['tag']
270
- assert_equal true, dom[1]['opening']
271
- assert_equal 'h2', dom[1]['value']
272
- assert_equal 1.4, dom[1]['line-height']
273
- end
274
-
275
- test "CSS Dom line-height test percentage" do
276
- pdf = MYPDF.new
277
-
278
- html = '<style> h2 { line-height: 10%; } </style>
279
- <h2>HTML TEST</h2>'
280
- dom = pdf.getHtmlDomArray(html)
281
- ## remove style tag block (by getHtmlDomArray()) ##
282
- # '<h2>HTML TEST</h2>'
283
- assert_equal dom.length, 4
284
-
285
- # <h2>
286
- assert_equal 0, dom[1]['parent'] # parent -> parent tag key
287
- assert_equal 0, dom[1]['elkey']
288
- assert_equal true, dom[1]['tag']
289
- assert_equal true, dom[1]['opening']
290
- assert_equal 'h2', dom[1]['value']
291
- assert_equal 0.1, dom[1]['line-height']
292
- end
293
-
294
- test "CSS Dom class test" do
295
- pdf = MYPDF.new
296
-
297
- html = '<style>p.first { color: #003300; font-family: helvetica; font-size: 12pt; }
298
- p.first span { color: #006600; font-style: italic; }</style>
299
- <p class="first">Example <span>Fusce</span></p>'
300
- dom = pdf.getHtmlDomArray(html)
301
- ## remove style tag block (by getHtmlDomArray()) ##
302
- # '<p class="first">Example <span>Fusce</span></p>'
303
- assert_equal dom.length, 7
304
-
305
- # <p class="first">
306
- assert_equal 0, dom[1]['elkey']
307
- assert_equal 0, dom[1]['parent'] # parent -> parent tag key
308
- assert_equal true, dom[1]['tag']
309
- assert_equal true, dom[1]['opening']
310
- assert_equal 'p', dom[1]['value']
311
- assert_equal 'first', dom[1]['attribute']['class']
312
- assert_equal '#003300', dom[1]['style']['color']
313
- assert_equal 'helvetica', dom[1]['style']['font-family']
314
- assert_equal '12pt', dom[1]['style']['font-size']
315
-
316
- # Example
317
- assert_equal 1, dom[2]['elkey']
318
- assert_equal 1, dom[2]['parent']
319
- assert_equal false, dom[2]['tag']
320
- assert_equal 'Example ', dom[2]['value']
321
-
322
- # <span>
323
- assert_equal 2, dom[3]['elkey']
324
- assert_equal 1, dom[3]['parent']
325
- assert_equal true, dom[3]['tag']
326
- assert_equal true, dom[3]['opening']
327
- assert_equal 'span', dom[3]['value']
328
- assert_equal '#006600', dom[3]['style']['color']
329
- assert_equal 'italic', dom[3]['style']['font-style']
330
- end
331
-
332
- test "CSS Dom height width test" do
333
- pdf = MYPDF.new
334
-
335
- html = '<style> p.first { height: 60%; }
336
- p.second { width: 70%; }</style>
337
- <p class="first">ABC</p><p class="second">DEF</p>'
338
- dom = pdf.getHtmlDomArray(html)
339
- assert_equal 7, dom.length
340
-
341
- # <p class="first">
342
- assert_equal 0, dom[1]['elkey']
343
- assert_equal 0, dom[1]['parent'] # parent -> parent tag key
344
- assert_equal true, dom[1]['tag']
345
- assert_equal true, dom[1]['opening']
346
- assert_equal 'p', dom[1]['value']
347
- assert_not_nil dom[1]['style']
348
- assert_equal '60%', dom[1]['style']['height']
349
- assert_equal '60%', dom[1]['height']
350
-
351
- # ABC
352
- assert_equal 1, dom[2]['elkey']
353
- assert_equal 1, dom[2]['parent']
354
- assert_equal false, dom[2]['tag']
355
- assert_equal 'ABC', dom[2]['value']
356
-
357
- # <p class="second">
358
- assert_equal 3, dom[4]['elkey']
359
- assert_equal 0, dom[4]['parent'] # parent -> parent tag key
360
- assert_equal true, dom[4]['tag']
361
- assert_equal true, dom[4]['opening']
362
- assert_equal 'p', dom[4]['value']
363
- assert_not_nil dom[4]['style']
364
- assert_equal '70%', dom[4]['style']['width']
365
- assert_equal '70%', dom[4]['width']
366
- end
367
-
368
- test "CSS Dom font-weight test" do
369
- pdf = MYPDF.new
370
-
371
- html = '<style> p.first { font-weight: bold; }</style>
372
- <p class="first">ABC</p><p class="second">DEF</p>'
373
- dom = pdf.getHtmlDomArray(html)
374
- assert_equal 7, dom.length
375
-
376
- # <p class="first">
377
- assert_equal 0, dom[1]['elkey']
378
- assert_equal 0, dom[1]['parent'] # parent -> parent tag key
379
- assert_equal true, dom[1]['tag']
380
- assert_equal true, dom[1]['opening']
381
- assert_equal 'p', dom[1]['value']
382
- assert_not_nil dom[1]['style']
383
- assert_equal 'bold', dom[1]['style']['font-weight']
384
- assert_equal 'B', dom[1]['fontstyle']
385
-
386
- # ABC
387
- assert_equal 1, dom[2]['elkey']
388
- assert_equal 1, dom[2]['parent']
389
- assert_equal false, dom[2]['tag']
390
- assert_equal 'ABC', dom[2]['value']
391
- end
392
-
393
- test "CSS Dom id test" do
394
- pdf = MYPDF.new
395
-
396
- html = '<style> p#second > span { background-color: #FFFFAA; }</style>
397
- <p id="second">Example <span>Fusce</span></p>'
398
- dom = pdf.getHtmlDomArray(html)
399
- ## remove style tag block (by getHtmlDomArray()) ##
400
- # '<p id="second">Example <span>Fusce</span></p>'
401
- assert_equal 7, dom.length
402
-
403
- # <p id="second">
404
- assert_equal 0, dom[1]['elkey']
405
- assert_equal 0, dom[1]['parent'] # parent -> parent tag key
406
- assert_equal true, dom[1]['tag']
407
- assert_equal true, dom[1]['opening']
408
- assert_equal 'p', dom[1]['value']
409
- assert_equal 'second', dom[1]['attribute']['id']
410
-
411
- # Example
412
- assert_equal 1, dom[2]['elkey']
413
- assert_equal 1, dom[2]['parent']
414
- assert_equal false, dom[2]['tag']
415
- assert_equal 'Example ', dom[2]['value']
416
-
417
- # <span>
418
- assert_equal 2, dom[3]['elkey']
419
- assert_equal 1, dom[3]['parent']
420
- assert_equal true, dom[3]['tag']
421
- assert_equal true, dom[3]['opening']
422
- assert_equal 'span', dom[3]['value']
423
- assert_equal '#FFFFAA', dom[3]['style']['background-color']
424
- end
425
-
426
- test "CSS Dom text-decoration test" do
427
- pdf = MYPDF.new
428
-
429
- html = '<style> p.first { text-decoration: none;}
430
- p.second {text-decoration: underline;}
431
- p.third {text-decoration: overline;}
432
- p.fourth {text-decoration: line-through;}
433
- p.fifth {text-decoration: underline overline line-through;}</style>
434
- <p class="first">ABC</p><p class="second">DEF</p><p class="third">GHI</p><p class="fourth">JKL</p><p class="fifth">MNO</p>'
435
- dom = pdf.getHtmlDomArray(html)
436
- assert_equal 16, dom.length
437
-
438
- # <p class="first">
439
- assert_equal 0, dom[1]['elkey']
440
- assert_equal 0, dom[1]['parent'] # parent -> parent tag key
441
- assert_equal true, dom[1]['tag']
442
- assert_equal true, dom[1]['opening']
443
- assert_equal 'p', dom[1]['value']
444
- assert_not_nil dom[1]['style']
445
- assert_equal 'none', dom[1]['style']['text-decoration']
446
- assert_equal '', dom[1]['fontstyle']
447
-
448
- # ABC
449
- assert_equal 1, dom[2]['elkey']
450
- assert_equal 1, dom[2]['parent']
451
- assert_equal false, dom[2]['tag']
452
- assert_equal 'ABC', dom[2]['value']
453
-
454
- # <p class="second">
455
- assert_equal 3, dom[4]['elkey']
456
- assert_equal 0, dom[4]['parent'] # parent -> parent tag key
457
- assert_equal true, dom[4]['tag']
458
- assert_equal true, dom[4]['opening']
459
- assert_equal 'p', dom[4]['value']
460
- assert_not_nil dom[1]['style']
461
- assert_equal 'underline', dom[4]['style']['text-decoration']
462
- assert_equal 'U', dom[4]['fontstyle']
463
-
464
- # <p class="third">
465
- assert_equal 6, dom[7]['elkey']
466
- assert_equal 0, dom[7]['parent'] # parent -> parent tag key
467
- assert_equal true, dom[7]['tag']
468
- assert_equal true, dom[7]['opening']
469
- assert_equal 'p', dom[7]['value']
470
- assert_not_nil dom[7]['style']
471
- assert_equal 'overline', dom[7]['style']['text-decoration']
472
- assert_equal 'O', dom[7]['fontstyle']
473
-
474
- # <p class="fourth">
475
- assert_equal 9, dom[10]['elkey']
476
- assert_equal 0, dom[10]['parent'] # parent -> parent tag key
477
- assert_equal true, dom[10]['tag']
478
- assert_equal true, dom[10]['opening']
479
- assert_equal 'p', dom[10]['value']
480
- assert_not_nil dom[10]['style']
481
- assert_equal 'line-through', dom[10]['style']['text-decoration']
482
- assert_equal 'D', dom[10]['fontstyle']
483
-
484
- # <p class="fifth">
485
- assert_equal 12, dom[13]['elkey']
486
- assert_equal 0, dom[13]['parent'] # parent -> parent tag key
487
- assert_equal true, dom[13]['tag']
488
- assert_equal true, dom[13]['opening']
489
- assert_equal 'p', dom[13]['value']
490
- assert_not_nil dom[13]['style']
491
- assert_equal 'underline overline line-through', dom[13]['style']['text-decoration']
492
- assert_equal 'UOD', dom[13]['fontstyle']
493
- end
494
-
495
- test "CSS Dom text-indent test" do
496
- pdf = MYPDF.new
497
-
498
- html = '<style> p.first { text-indent: 10px; }
499
- p.second { text-indent: 5em; }
500
- p.third { text-indent: 5ex; }
501
- p.fourth { text-indent: 50%; }</style>
502
- <p class="first">ABC</p><p class="second">DEF</p><p class="third">GHI</p><p class="fourth">JKL</p>'
503
- dom = pdf.getHtmlDomArray(html)
504
- assert_equal 13, dom.length
505
-
506
- # <p class="first">
507
- assert_equal 0, dom[1]['elkey']
508
- assert_equal 0, dom[1]['parent'] # parent -> parent tag key
509
- assert_equal true, dom[1]['tag']
510
- assert_equal true, dom[1]['opening']
511
- assert_equal 'p', dom[1]['value']
512
- assert_not_nil dom[1]['style']
513
- assert_equal '10px', dom[1]['style']['text-indent']
514
- assert_in_delta 3.53, dom[1]['text-indent'], 0.01
515
-
516
- # ABC
517
- assert_equal 1, dom[2]['elkey']
518
- assert_equal 1, dom[2]['parent']
519
- assert_equal false, dom[2]['tag']
520
- assert_equal 'ABC', dom[2]['value']
521
-
522
- # <p class="second">
523
- assert_equal 3, dom[4]['elkey']
524
- assert_equal 0, dom[4]['parent'] # parent -> parent tag key
525
- assert_equal true, dom[4]['tag']
526
- assert_equal true, dom[4]['opening']
527
- assert_equal 'p', dom[4]['value']
528
- assert_not_nil dom[4]['style']
529
- assert_equal '5em', dom[4]['style']['text-indent']
530
- assert_equal 5.0, dom[4]['text-indent']
531
-
532
- # <p class="third">
533
- assert_equal 6, dom[7]['elkey']
534
- assert_equal 0, dom[7]['parent'] # parent -> parent tag key
535
- assert_equal true, dom[7]['tag']
536
- assert_equal true, dom[7]['opening']
537
- assert_equal 'p', dom[7]['value']
538
- assert_not_nil dom[7]['style']
539
- assert_equal '5ex', dom[7]['style']['text-indent']
540
- assert_equal 2.5, dom[7]['text-indent']
541
-
542
- # <p class="fourth">
543
- assert_equal 9, dom[10]['elkey']
544
- assert_equal 0, dom[10]['parent'] # parent -> parent tag key
545
- assert_equal true, dom[10]['tag']
546
- assert_equal true, dom[10]['opening']
547
- assert_equal 'p', dom[10]['value']
548
- assert_not_nil dom[10]['style']
549
- assert_equal '50%', dom[10]['style']['text-indent']
550
- assert_equal 0.5, dom[10]['text-indent']
551
- end
552
-
553
- test "CSS Dom list-style-type test" do
554
- pdf = MYPDF.new
555
-
556
- html = '<style> p.first { list-style-type: none; }
557
- p.second { list-style-type: disc; }
558
- p.third { list-style-type: circle; }
559
- p.fourth { list-style-type: square; }</style>
560
- <p class="first">ABC</p><p class="second">DEF</p><p class="third">GHI</p><p class="fourth">JKL</p>'
561
- dom = pdf.getHtmlDomArray(html)
562
- assert_equal 13, dom.length
563
-
564
- # <p class="first">
565
- assert_equal 0, dom[1]['elkey']
566
- assert_equal 0, dom[1]['parent'] # parent -> parent tag key
567
- assert_equal true, dom[1]['tag']
568
- assert_equal true, dom[1]['opening']
569
- assert_equal 'p', dom[1]['value']
570
- assert_not_nil dom[1]['style']
571
- assert_equal 'none', dom[1]['style']['list-style-type']
572
- assert_equal 'none', dom[1]['listtype']
573
-
574
- # ABC
575
- assert_equal 1, dom[2]['elkey']
576
- assert_equal 1, dom[2]['parent']
577
- assert_equal false, dom[2]['tag']
578
- assert_equal 'ABC', dom[2]['value']
579
-
580
- # <p class="second">
581
- assert_equal 3, dom[4]['elkey']
582
- assert_equal 0, dom[4]['parent'] # parent -> parent tag key
583
- assert_equal true, dom[4]['tag']
584
- assert_equal true, dom[4]['opening']
585
- assert_equal 'p', dom[4]['value']
586
- assert_not_nil dom[4]['style']
587
- assert_equal 'disc', dom[4]['style']['list-style-type']
588
- assert_equal 'disc', dom[4]['listtype']
589
-
590
- # <p class="third">
591
- assert_equal 6, dom[7]['elkey']
592
- assert_equal 0, dom[7]['parent'] # parent -> parent tag key
593
- assert_equal true, dom[7]['tag']
594
- assert_equal true, dom[7]['opening']
595
- assert_equal 'p', dom[7]['value']
596
- assert_not_nil dom[7]['style']
597
- assert_equal 'circle', dom[7]['style']['list-style-type']
598
- assert_equal 'circle', dom[7]['listtype']
599
- end
600
-
601
- test "CSS Dom page-break test" do
602
- pdf = MYPDF.new
603
-
604
- html = '<style> p.first { page-break-before: left; page-break-after: always; }
605
- p.second { page-break-inside:avoid; }</style>
606
- <p class="first">ABC</p><p class="second">DEF</p>'
607
- dom = pdf.getHtmlDomArray(html)
608
- assert_equal 7, dom.length
609
-
610
- # <p class="first">
611
- assert_equal 0, dom[1]['elkey']
612
- assert_equal 0, dom[1]['parent'] # parent -> parent tag key
613
- assert_equal true, dom[1]['tag']
614
- assert_equal true, dom[1]['opening']
615
- assert_equal 'p', dom[1]['value']
616
- assert_not_nil dom[1]['style']
617
- assert_equal 'left', dom[1]['style']['page-break-before']
618
- assert_equal 'always', dom[1]['style']['page-break-after']
619
- assert_not_nil dom[1]['attribute']
620
- assert_equal 'left', dom[1]['attribute']['pagebreak']
621
- assert_equal 'true', dom[1]['attribute']['pagebreakafter']
622
-
623
- # ABC
624
- assert_equal 1, dom[2]['elkey']
625
- assert_equal 1, dom[2]['parent']
626
- assert_equal false, dom[2]['tag']
627
- assert_equal 'ABC', dom[2]['value']
628
-
629
- # <p class="second">
630
- assert_equal 3, dom[4]['elkey']
631
- assert_equal 0, dom[4]['parent'] # parent -> parent tag key
632
- assert_equal true, dom[4]['tag']
633
- assert_equal true, dom[4]['opening']
634
- assert_equal 'p', dom[4]['value']
635
- assert_not_nil dom[1]['style']
636
- assert_equal 'avoid', dom[4]['style']['page-break-inside']
637
- assert_not_nil dom[4]['attribute']
638
- assert_equal 'true', dom[4]['attribute']['nobr']
639
- end
640
- end