13
13
* limitations under the License.
14
14
*/
15
15
16
- import { $getParent , $toStyle , XFAObject } from "./xfa_object.js" ;
16
+ import { $extra , $ getParent, $toStyle , XFAObject } from "./xfa_object.js" ;
17
17
import { warn } from "../../shared/util.js" ;
18
18
19
19
function measureToString ( m ) {
@@ -56,8 +56,17 @@ const converters = {
56
56
}
57
57
} ,
58
58
dimensions ( node , style ) {
59
- if ( node . w ) {
60
- style . width = measureToString ( node . w ) ;
59
+ const parent = node [ $getParent ] ( ) ;
60
+ const extra = parent [ $extra ] ;
61
+ let width = node . w ;
62
+ if ( extra && extra . columnWidths ) {
63
+ width = extra . columnWidths [ extra . currentColumn ] ;
64
+ extra . currentColumn =
65
+ ( extra . currentColumn + 1 ) % extra . columnWidths . length ;
66
+ }
67
+
68
+ if ( width !== "" ) {
69
+ style . width = measureToString ( width ) ;
61
70
} else {
62
71
style . width = "auto" ;
63
72
if ( node . maxW > 0 ) {
@@ -66,7 +75,7 @@ const converters = {
66
75
style . minWidth = measureToString ( node . minW ) ;
67
76
}
68
77
69
- if ( node . h ) {
78
+ if ( node . h !== "" ) {
70
79
style . height = measureToString ( node . h ) ;
71
80
} else {
72
81
style . height = "auto" ;
@@ -108,6 +117,53 @@ const converters = {
108
117
break ;
109
118
}
110
119
} ,
120
+ hAlign ( node , style ) {
121
+ switch ( node . hAlign ) {
122
+ case "justifyAll" :
123
+ style . textAlign = "justify-all" ;
124
+ break ;
125
+ case "radix" :
126
+ // TODO: implement this correctly !
127
+ style . textAlign = "left" ;
128
+ break ;
129
+ default :
130
+ style . textAlign = node . hAlign ;
131
+ }
132
+ } ,
133
+ borderMarginPadding ( node , style ) {
134
+ // Get border width in order to compute margin and padding.
135
+ const borderWidths = [ 0 , 0 , 0 , 0 ] ;
136
+ const marginWidths = [ 0 , 0 , 0 , 0 ] ;
137
+ const marginNode = node . margin
138
+ ? [
139
+ node . margin . topInset ,
140
+ node . margin . rightInset ,
141
+ node . margin . bottomInset ,
142
+ node . margin . leftInset ,
143
+ ]
144
+ : [ 0 , 0 , 0 , 0 ] ;
145
+ if ( node . border ) {
146
+ Object . assign ( style , node . border [ $toStyle ] ( borderWidths , marginWidths ) ) ;
147
+ }
148
+
149
+ if ( borderWidths . every ( x => x === 0 ) ) {
150
+ // No border: margin & padding are padding
151
+ if ( node . margin ) {
152
+ Object . assign ( style , node . margin [ $toStyle ] ( ) ) ;
153
+ }
154
+ style . padding = style . margin ;
155
+ delete style . margin ;
156
+ } else {
157
+ style . padding =
158
+ measureToString ( marginNode [ 0 ] - borderWidths [ 0 ] - marginWidths [ 0 ] ) +
159
+ " " +
160
+ measureToString ( marginNode [ 1 ] - borderWidths [ 1 ] - marginWidths [ 1 ] ) +
161
+ " " +
162
+ measureToString ( marginNode [ 2 ] - borderWidths [ 2 ] - marginWidths [ 2 ] ) +
163
+ " " +
164
+ measureToString ( marginNode [ 3 ] - borderWidths [ 3 ] - marginWidths [ 3 ] ) ;
165
+ }
166
+ } ,
111
167
} ;
112
168
113
169
function layoutClass ( node ) {
@@ -155,4 +211,26 @@ function toStyle(node, ...names) {
155
211
return style ;
156
212
}
157
213
158
- export { layoutClass , measureToString , toStyle } ;
214
+ function addExtraDivForMargin ( html ) {
215
+ const style = html . attributes . style ;
216
+ if ( style . margin ) {
217
+ const padding = style . margin ;
218
+ delete style . margin ;
219
+ const width = style . width || "auto" ;
220
+ const height = style . height || "auto" ;
221
+
222
+ style . width = "100%" ;
223
+ style . height = "100%" ;
224
+
225
+ return {
226
+ name : "div" ,
227
+ attributes : {
228
+ style : { padding, width, height } ,
229
+ } ,
230
+ children : [ html ] ,
231
+ } ;
232
+ }
233
+ return html ;
234
+ }
235
+
236
+ export { addExtraDivForMargin , layoutClass , measureToString , toStyle } ;
0 commit comments