rbpdf-fruitcake0525 1.19.0

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