@@ -106,6 +106,17 @@ function getRoot(node) {
106
106
return parent ;
107
107
}
108
108
109
+ function valueToHtml ( value ) {
110
+ return HTMLResult . success ( {
111
+ name : "span" ,
112
+ attributes : {
113
+ class : [ "xfaRich" ] ,
114
+ style : Object . create ( null ) ,
115
+ } ,
116
+ value,
117
+ } ) ;
118
+ }
119
+
109
120
function getTransformedBBox ( node ) {
110
121
// Take into account rotation and anchor the get the
111
122
// real bounding box.
@@ -615,7 +626,7 @@ class BooleanElement extends Option01 {
615
626
}
616
627
617
628
[ $toHTML ] ( availableSpace ) {
618
- return HTMLResult . success ( this [ $content ] === 1 ) ;
629
+ return valueToHtml ( this [ $content ] === 1 ) ;
619
630
}
620
631
}
621
632
@@ -1257,11 +1268,12 @@ class DateElement extends ContentObject {
1257
1268
}
1258
1269
1259
1270
[ $finalize ] ( ) {
1260
- this [ $content ] = new Date ( this [ $content ] . trim ( ) ) ;
1271
+ const date = this [ $content ] . trim ( ) ;
1272
+ this [ $content ] = date ? new Date ( date ) : null ;
1261
1273
}
1262
1274
1263
1275
[ $toHTML ] ( availableSpace ) {
1264
- return HTMLResult . success ( this [ $content ] . toString ( ) ) ;
1276
+ return valueToHtml ( this [ $content ] ? this [ $content ] . toString ( ) : "" ) ;
1265
1277
}
1266
1278
}
1267
1279
@@ -1275,11 +1287,12 @@ class DateTime extends ContentObject {
1275
1287
}
1276
1288
1277
1289
[ $finalize ] ( ) {
1278
- this [ $content ] = new Date ( this [ $content ] . trim ( ) ) ;
1290
+ const date = this [ $content ] . trim ( ) ;
1291
+ this [ $content ] = date ? new Date ( date ) : null ;
1279
1292
}
1280
1293
1281
1294
[ $toHTML ] ( availableSpace ) {
1282
- return HTMLResult . success ( this [ $content ] . toString ( ) ) ;
1295
+ return valueToHtml ( this [ $content ] ? this [ $content ] . toString ( ) : "" ) ;
1283
1296
}
1284
1297
}
1285
1298
@@ -1351,7 +1364,7 @@ class Decimal extends ContentObject {
1351
1364
}
1352
1365
1353
1366
[ $toHTML ] ( availableSpace ) {
1354
- return HTMLResult . success (
1367
+ return valueToHtml (
1355
1368
this [ $content ] !== null ? this [ $content ] . toString ( ) : ""
1356
1369
) ;
1357
1370
}
@@ -2365,12 +2378,12 @@ class Field extends XFAObject {
2365
2378
if ( this . ui . imageEdit ) {
2366
2379
ui . children . push ( this . value [ $toHTML ] ( ) . html ) ;
2367
2380
} else if ( ! this . ui . button ) {
2368
- const value = this . value [ $toHTML ] ( ) . html ;
2381
+ const value = this . value [ $toHTML ] ( ) . html . value ;
2369
2382
if ( value ) {
2370
2383
if ( ui . children [ 0 ] . name === "textarea" ) {
2371
- ui . children [ 0 ] . attributes . textContent = value . value ;
2384
+ ui . children [ 0 ] . attributes . textContent = value ;
2372
2385
} else {
2373
- ui . children [ 0 ] . attributes . value = value . value ;
2386
+ ui . children [ 0 ] . attributes . value = value ;
2374
2387
}
2375
2388
}
2376
2389
}
@@ -2522,7 +2535,7 @@ class Float extends ContentObject {
2522
2535
}
2523
2536
2524
2537
[ $toHTML ] ( availableSpace ) {
2525
- return HTMLResult . success (
2538
+ return valueToHtml (
2526
2539
this [ $content ] !== null ? this [ $content ] . toString ( ) : ""
2527
2540
) ;
2528
2541
}
@@ -2812,7 +2825,7 @@ class Integer extends ContentObject {
2812
2825
}
2813
2826
2814
2827
[ $toHTML ] ( availableSpace ) {
2815
- return HTMLResult . success (
2828
+ return valueToHtml (
2816
2829
this [ $content ] !== null ? this [ $content ] . toString ( ) : ""
2817
2830
) ;
2818
2831
}
@@ -4642,14 +4655,7 @@ class Text extends ContentObject {
4642
4655
if ( typeof this [ $content ] === "string" ) {
4643
4656
// \u2028 is a line separator.
4644
4657
// \u2029 is a paragraph separator.
4645
- const html = {
4646
- name : "span" ,
4647
- attributes : {
4648
- class : [ "xfaRich" ] ,
4649
- style : { } ,
4650
- } ,
4651
- value : this [ $content ] ,
4652
- } ;
4658
+ const html = valueToHtml ( this [ $content ] ) . html ;
4653
4659
4654
4660
if ( this [ $content ] . includes ( "\u2029" ) ) {
4655
4661
// We've plain text containing a paragraph separator
@@ -4782,12 +4788,13 @@ class Time extends StringObject {
4782
4788
}
4783
4789
4784
4790
[ $finalize ] ( ) {
4785
- // TODO
4786
- this [ $content ] = new Date ( this [ $content ] ) ;
4791
+ // TODO: need to handle the string as a time and not as a date.
4792
+ const date = this [ $content ] . trim ( ) ;
4793
+ this [ $content ] = date ? new Date ( date ) : null ;
4787
4794
}
4788
4795
4789
4796
[ $toHTML ] ( availableSpace ) {
4790
- return HTMLResult . success ( this [ $content ] . toString ( ) ) ;
4797
+ return valueToHtml ( this [ $content ] ? this [ $content ] . toString ( ) : "" ) ;
4791
4798
}
4792
4799
}
4793
4800
0 commit comments