| 1 |
lars |
1 |
/box-table-apply-colspans { % => MaxWC MinWC WidthFun Context Widths This
|
|
|
2 |
dup box-table-get-colspans { % => MaxWC MinWC WidthFun Context Widths This Colspan
|
|
|
3 |
dup cellspan-get-row
|
|
|
4 |
1 index cellspan-get-column
|
|
|
5 |
3 index box-table-get-cell % => MaxWC MinWC WidthFun Context Widths This Colspan Cell
|
|
|
6 |
|
|
|
7 |
% apply colspans to the corresponsing colspanned-cell dimension
|
|
|
8 |
4 index 1 index
|
|
|
9 |
7 index call-method % => MaxWC MinWC WidthFun Context Widths This Colspan Cell CellWidth
|
|
|
10 |
|
|
|
11 |
% Apply cell constraint width, if any AND if table width is constrained
|
|
|
12 |
% if table width is not constrained, we should not do this, as current value
|
|
|
13 |
% of $table->get_width is maximal width (parent width), not the actual
|
|
|
14 |
% width of the table
|
|
|
15 |
1 index get-width-constraint
|
|
|
16 |
dup /type get /none ne { % => MaxWC MinWC WidthFun Context Widths This Colspan Cell CellWidth WC
|
|
|
17 |
4 index /get-width call-method
|
|
|
18 |
2 index
|
|
|
19 |
2 index
|
|
|
20 |
dup /apply get exec % => MaxWC MinWC WidthFun Context Widths This Colspan Cell CellWidth WC CellWidth'
|
|
|
21 |
exch pop
|
|
|
22 |
exch pop
|
|
|
23 |
} { pop } ifelse % => MaxWC MinWC WidthFun Context Widths This Colspan Cell CellWidth'
|
|
|
24 |
|
|
|
25 |
% now select the pre-calculated widths of columns covered by this cell
|
|
|
26 |
% select the list of resizable columns covered by this cell
|
|
|
27 |
[] [] % => MaxWC MinWC WidthFun Context Widths This Colspan Cell CellWidth' SpannedWidth SpannedRezisable
|
|
|
28 |
|
|
|
29 |
4 index cellspan-get-column
|
|
|
30 |
1
|
|
|
31 |
6 index cellspan-get-column
|
|
|
32 |
7 index cellspan-get-size add
|
|
|
33 |
1 sub { % => MaxWC MinWC WidthFun Context Widths This Colspan Cell CellWidth'
|
|
|
34 |
% SpannedWidth SpannedRezisable I
|
|
|
35 |
7 index 1 index get % => MaxWC MinWC WidthFun Context Widths This Colspan Cell CellWidth'
|
|
|
36 |
% SpannedWidth SpannedRezisable I Widths[i]
|
|
|
37 |
4 3 roll array-prepend
|
|
|
38 |
3 1 roll % => MaxWC MinWC WidthFun Context Widths This Colspan Cell CellWidth'
|
|
|
39 |
% SpannedWidth' SpannedRezisable I
|
|
|
40 |
11 index 1 index get % => MaxWC MinWC WidthFun Context Widths This Colspan Cell CellWidth'
|
|
|
41 |
% SpannedWidth' SpannedRezisable I MaxWC[i]
|
|
|
42 |
11 index 2 index get % => MaxWC MinWC WidthFun Context Widths This Colspan Cell CellWidth'
|
|
|
43 |
% SpannedWidth' SpannedRezisable I MaxWC[i] MinWC[i]
|
|
|
44 |
ne % => MaxWC MinWC WidthFun Context Widths This Colspan Cell CellWidth'
|
|
|
45 |
% SpannedWidth' SpannedRezisable I MaxWC[i]<>MinWC[i]
|
|
|
46 |
exch pop
|
|
|
47 |
exch array-prepend % => MaxWC MinWC WidthFun Context Widths This Colspan Cell CellWidth'
|
|
|
48 |
% SpannedWidth' SpannedRezisable'
|
|
|
49 |
} for % => MaxWC MinWC WidthFun Context Widths This Colspan Cell CellWidth'
|
|
|
50 |
% SpannedWidth' SpannedRezisable'
|
|
|
51 |
|
|
|
52 |
% Sometimes we may encounter the colspan over the empty columns (I mean ALL columns are empty); in this case
|
|
|
53 |
% we need to make these columns reizable in order to fit colspanned cell contents
|
|
|
54 |
|
|
|
55 |
1 index sum 0 eq { % => MaxWC MinWC WidthFun Context Widths This Colspan Cell CellWidth'
|
|
|
56 |
% SpannedWidth' SpannedRezisable'
|
|
|
57 |
|
|
|
58 |
% SpannedWidth' SpannedRezisable' I
|
|
|
59 |
2 index 1 index rounding-epsilon put
|
|
|
60 |
1 index 1 index true put
|
|
|
61 |
pop
|
|
|
62 |
} for
|
|
|
63 |
} if % => MaxWC MinWC WidthFun Context Widths This Colspan Cell CellWidth'
|
|
|
64 |
% SpannedWidth' SpannedRezisable'
|
|
|
65 |
|
|
|
66 |
% The same problem may arise when all colspanned columns are not resizable; in this case we'll force all
|
|
|
67 |
% of them to be resized
|
|
|
68 |
{ or } false 2 index reduce % => MaxWC MinWC WidthFun Context Widths This Colspan Cell CellWidth'
|
|
|
69 |
% SpannedWidth' SpannedRezisable' AnyResizable
|
|
|
70 |
not {
|
|
|
71 |
|
|
|
72 |
% SpannedWidth' SpannedRezisable' I
|
|
|
73 |
1 index 1 index true put
|
|
|
74 |
pop
|
|
|
75 |
} for
|
|
|
76 |
} if % => MaxWC MinWC WidthFun Context Widths This Colspan Cell CellWidth'
|
|
|
77 |
% SpannedWidth' SpannedRezisable'
|
|
|
78 |
|
|
|
79 |
% Expand resizable columns
|
|
|
80 |
expand-to-with-flags % => MaxWC MinWC WidthFun Context Widths This Colspan Cell SpannedWidths'
|
|
|
81 |
|
|
|
82 |
% Store modified widths
|
|
|
83 |
4 index
|
|
|
84 |
3 index cellspan-get-column
|
|
|
85 |
2 index
|
|
|
86 |
putinterval % => MaxWC MinWC WidthFun Context Widths This Colspan Cell SpannedWidths'
|
|
|
87 |
|
|
|
88 |
pop pop pop
|
|
|
89 |
} forall % => MaxWC MinWC WidthFun Context Widths' This
|
|
|
90 |
|
|
|
91 |
pop
|
|
|
92 |
exch pop
|
|
|
93 |
exch pop
|
|
|
94 |
exch pop
|
|
|
95 |
exch pop
|
|
|
96 |
} def % => Widths
|
|
|
97 |
|
|
|
98 |
/box-table-columns-fit { % => Context Width Table
|
|
|
99 |
2 index
|
|
|
100 |
1 index
|
|
|
101 |
box-table-get-table-columns-min-widths % => Context Width Table MinW
|
|
|
102 |
|
|
|
103 |
3 index
|
|
|
104 |
2 index
|
|
|
105 |
box-table-get-table-columns-max-widths % => Context Width Table MinW MaxW
|
|
|
106 |
|
|
|
107 |
% Store number of columns
|
|
|
108 |
|
|
|
109 |
dup length % => Context Width Table MinW MaxW Columns
|
|
|
110 |
|
|
|
111 |
% Apply column width constraints
|
|
|
112 |
|
|
|
113 |
[] [] % => Context Width Table MinW MaxW Columns MinWC MaxWC
|
|
|
114 |
|
|
|
115 |
dup 7 index
|
|
|
116 |
box-table-get-cwc % => Context Width Table MinW MaxW Columns MinWC MaxWC I CWC
|
|
|
117 |
|
|
|
118 |
% Do not allow constrained max width be less than min width
|
|
|
119 |
% Do not allow constrained min width be less than min width
|
|
|
120 |
|
|
|
121 |
7 index /get-width call-method % => Context Width Table MinW MaxW Columns MinWC MaxWC I CWC ThisWidth
|
|
|
122 |
8 index /cellpadding get-css-value 2 mul
|
|
|
123 |
9 index /cellspacing get-css-value add
|
|
|
124 |
% => Context Width Table MinW MaxW Columns MinWC MaxWC I CWC ThisWidth Extra
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
8 index 4 index get % => Context Width Table MinW MaxW Columns MinWC MaxWC I CWC ThisWidth Extra MinW[i]
|
|
|
128 |
1 index sub
|
|
|
129 |
2 index 1 index 5 index
|
|
|
130 |
dup /apply get exec % => Context Width Table MinW MaxW Columns MinWC MaxWC I CWC ThisWidth Extra MinW[i] MinW[i]'
|
|
|
131 |
2 index add
|
|
|
132 |
max % => Context Width Table MinW MaxW Columns MinWC MaxWC I CWC ThisWidth Extra MinW[i]''
|
|
|
133 |
7 6 roll array-prepend
|
|
|
134 |
6 1 roll % => Context Width Table MinW MaxW Columns MinWC' MaxWC I CWC ThisWidth Extra
|
|
|
135 |
|
|
|
136 |
8 index 4 index get % => Context Width Table MinW MaxW Columns MinWC MaxWC I CWC ThisWidth Extra MinW[i]
|
|
|
137 |
1 index sub
|
|
|
138 |
2 index 1 index 5 index
|
|
|
139 |
dup /apply get exec % => Context Width Table MinW MaxW Columns MinWC MaxWC I CWC ThisWidth Extra MinW[i] MaxW[i]'
|
|
|
140 |
2 index add
|
|
|
141 |
max % => Context Width Table MinW MaxW Columns MinWC MaxWC I CWC ThisWidth Extra MaxW[i]''
|
|
|
142 |
6 5 roll array-prepend
|
|
|
143 |
5 1 roll % => Context Width Table MinW MaxW Columns MinWC MaxWC' I CWC ThisWidth Extra
|
|
|
144 |
|
|
|
145 |
pop pop pop pop % => Context Width Table MinW MaxW Columns MinWC MaxWC
|
|
|
146 |
} for
|
|
|
147 |
|
|
|
148 |
1 index 5 index 8 index 8 index
|
|
|
149 |
box-table-normalize-min-widths % => Context Width Table MinW MaxW Columns MinWC MaxWC MinWC'
|
|
|
150 |
3 2 roll pop exch % => Context Width Table MinW MaxW Columns MinWC' MaxWC
|
|
|
151 |
|
|
|
152 |
dup
|
|
|
153 |
2 index
|
|
|
154 |
/get-min-width
|
|
|
155 |
10 index
|
|
|
156 |
5 index
|
|
|
157 |
10 index
|
|
|
158 |
box-table-apply-colspans % => Context Width Table MinW MaxW Columns MinWC MaxWC MinWC'
|
|
|
159 |
3 2 roll pop exch % => Context Width Table MinW MaxW Columns MinWC' MaxWC
|
|
|
160 |
|
|
|
161 |
% We need to normalize widths for the case of colspans width is too much; for example:
|
|
|
162 |
% <table><tr><td width="100">
|
|
|
163 |
% <table><tr><td width="150">TEXT<td>TEXT<tr><td colspan="2" width="200">
|
|
|
164 |
% in this case table SHOULD NOT be expanded over the 100px!
|
|
|
165 |
|
|
|
166 |
1 index
|
|
|
167 |
5 index
|
|
|
168 |
8 index
|
|
|
169 |
8 index
|
|
|
170 |
box-table-normalize-min-widths % => Context Width Table MinW MaxW Columns MinWC' MaxWC MinWC'
|
|
|
171 |
3 2 roll pop exch
|
|
|
172 |
|
|
|
173 |
dup
|
|
|
174 |
2 index
|
|
|
175 |
/get-max-width
|
|
|
176 |
10 index
|
|
|
177 |
4 index
|
|
|
178 |
10 index
|
|
|
179 |
box-table-apply-colspans % => Context Width Table MinW MaxW Columns MinWC MaxWC MaxWC'
|
|
|
180 |
exch pop % => Context Width Table MinW MaxW Columns MinWC' MaxWC
|
|
|
181 |
|
|
|
182 |
% Calculate actual widths
|
|
|
183 |
% Calculate widths for all constrained columns
|
|
|
184 |
|
|
|
185 |
[]
|
|
|
186 |
|
|
|
187 |
dup 8 index
|
|
|
188 |
box-table-is-constrained-column {
|
|
|
189 |
3 index exch get
|
|
|
190 |
exch array-prepend % => Context Width Table MinW MaxW Columns MinWC' MaxWC Widths'
|
|
|
191 |
} { % => Context Width Table MinW MaxW Columns MinWC' MaxWC Widths I
|
|
|
192 |
pop 0 exch array-prepend % => Context Width Table MinW MaxW Columns MinWC' MaxWC Widths'
|
|
|
193 |
} ifelse
|
|
|
194 |
} for % => Context Width Table MinW MaxW Columns MinWC' MaxWC Widths'
|
|
|
195 |
|
|
|
196 |
% Quick fix for overconstrained tables: if table have width attribute AND its value is less than sum
|
|
|
197 |
% of constrained columns widths plus minimal widths of uncostrained columns, then we'll expand the width of table
|
|
|
198 |
% to fit all columns
|
|
|
199 |
% 1. calculate sum of constrained column widths
|
|
|
200 |
% 2. calculate sum of unconstrained column minimal widths
|
|
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
dup 10 index box-table-is-constrained-column {
|
|
|
205 |
3 index 1 index get % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths SumCW SumUCW I W
|
|
|
206 |
4 3 roll add 3 1 roll % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths SumCW' SumUCW I
|
|
|
207 |
} {
|
|
|
208 |
5 index 1 index get % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths SumCW SumUCW I CW
|
|
|
209 |
3 2 roll add exch % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths SumCW SumUCW' I
|
|
|
210 |
} ifelse
|
|
|
211 |
pop
|
|
|
212 |
} for % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths SumCW SumUCW
|
|
|
213 |
|
|
|
214 |
% 3. compare these widths with the table width and choose the maximal value
|
|
|
215 |
|
|
|
216 |
add
|
|
|
217 |
8 index max % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths Width'
|
|
|
218 |
9 8 roll pop 8 1 roll % => Context Width' Table MinW MaxW Columns MinWC MaxWC Widths
|
|
|
219 |
|
|
|
220 |
% Second pass - disctribute the rest of the width
|
|
|
221 |
|
|
|
222 |
% Explanation of the stuff below (I've really had problems with this small piece of code, especially
|
|
|
223 |
% when I was trying to fix "bugs" inside it)
|
|
|
224 |
%
|
|
|
225 |
% First of all, no column can be narrower than it minimal width (determined by its content)
|
|
|
226 |
% Note that constrained columns have their widths distributed above, so we can exclude them for now
|
|
|
227 |
% (just throw them out and imagine that table does not contain any width-constrained cols)
|
|
|
228 |
%
|
|
|
229 |
% Second, the relative widths of columns will have _appoximately_ the same ratio as
|
|
|
230 |
% their maximal content widths. (In exception of cases where the first rule will take place -
|
|
|
231 |
% say for the table containing two columns with the VERY long text in the first and one or two words
|
|
|
232 |
% in the second)
|
|
|
233 |
%
|
|
|
234 |
% In general, this approach can be inoptimal in case of _very_ different font sizes
|
|
|
235 |
% inside the cells, of, say big images; nevertheless, it will give a good approximate
|
|
|
236 |
% AND still fast enough (unlike fully correct methods involving evaluation of the content height of the cell)
|
|
|
237 |
%
|
|
|
238 |
% Thus, we do the following:
|
|
|
239 |
% - calculate the ratio of current column MAXIMAL ($current_max) width to the sum of MAXIMAL widths of all columns left
|
|
|
240 |
% (inluding current) second rule applied. Note that we need remember about column spans and select
|
|
|
241 |
% maxw or maxwc in order.
|
|
|
242 |
% - then check if the rest of width will be too small for other columns to fit and decrease current columns
|
|
|
243 |
% width (see MIN function call)
|
|
|
244 |
% - then check again if our width will be too small for current column to fit (and expand if nesessary) -
|
|
|
245 |
% MAX function call
|
|
|
246 |
% => Context Width Table MinW MaxW Columns MinWC MaxWC Widths
|
|
|
247 |
|
|
|
248 |
|
|
|
249 |
dup 8 index
|
|
|
250 |
box-table-is-constrained-column not {
|
|
|
251 |
|
|
|
252 |
% Get undistributed width (total table width - width of constrained columns)
|
|
|
253 |
|
|
|
254 |
8 index 2 index sum sub % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths I Rest
|
|
|
255 |
|
|
|
256 |
% get max width of column being processed
|
|
|
257 |
% If width is equal to zero, use max constrained width, as this column could be covered by colspan;
|
|
|
258 |
% If not, we lose nothing, because all constrained columns are already processed earlier, and no more
|
|
|
259 |
% columns except these two types can have different constrained and raw widths
|
|
|
260 |
|
|
|
261 |
6 index 2 index get
|
|
|
262 |
4 index 3 index get max % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths I Rest CurrentMax
|
|
|
263 |
|
|
|
264 |
% Get sum of maximal constrained widths of unplaced columns
|
|
|
265 |
|
|
|
266 |
% SumMaxCW SumMinCW
|
|
|
267 |
|
|
|
268 |
|
|
|
269 |
% SumMaxCW SumMinCW J
|
|
|
270 |
6 index 1 index get 0 eq {
|
|
|
271 |
10 index 1 index get
|
|
|
272 |
8 index 2 index get
|
|
|
273 |
max % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths I Rest CurrentMax
|
|
|
274 |
% SumMaxCW SumMinCW J DSumMaxCW
|
|
|
275 |
4 3 roll add 3 1 roll % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths I Rest CurrentMax
|
|
|
276 |
% SumMaxCW' SumMinCW J
|
|
|
277 |
|
|
|
278 |
11 index 1 index get
|
|
|
279 |
9 index 2 index get
|
|
|
280 |
max % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths I Rest CurrentMax
|
|
|
281 |
% SumMaxCW SumMinCW J DSumMinCW
|
|
|
282 |
3 2 roll add exch % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths I Rest CurrentMax
|
|
|
283 |
% SumMaxCW SumMinCW' J
|
|
|
284 |
} if % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths I Rest CurrentMax
|
|
|
285 |
% SumMaxCW SumMinCW J
|
|
|
286 |
pop
|
|
|
287 |
} for % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths I Rest CurrentMax
|
|
|
288 |
% SumMaxCW SumMinCW
|
|
|
289 |
|
|
|
290 |
% If some unplaced columns have maximal (constrained width) greater zero
|
|
|
291 |
1 index 0 gt { % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths I Rest CurrentMax
|
|
|
292 |
% SumMaxCW SumMinCW
|
|
|
293 |
10 index 5 index get
|
|
|
294 |
8 index 6 index get max % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths I Rest CurrentMax
|
|
|
295 |
% SumMaxCW SumMinCW max($minwc[$i],$minw[$i]))
|
|
|
296 |
1 index sub
|
|
|
297 |
4 index add % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths I Rest CurrentMax
|
|
|
298 |
% SumMaxCW SumMinCW ($rest-$sum_min_cw+max($minwc[$i],$minw[$i]))
|
|
|
299 |
3 index
|
|
|
300 |
5 index mul
|
|
|
301 |
3 index div
|
|
|
302 |
|
|
|
303 |
min % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths I Rest CurrentMax
|
|
|
304 |
% SumMaxCW SumMinCW CurrentMax'
|
|
|
305 |
exch pop
|
|
|
306 |
exch pop
|
|
|
307 |
exch pop
|
|
|
308 |
exch pop % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths I CurrentMax'
|
|
|
309 |
} {
|
|
|
310 |
pop pop exch pop
|
|
|
311 |
} ifelse % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths I CurrentMax
|
|
|
312 |
|
|
|
313 |
% Check for minimal width (either unconstrained or constrained) of current column
|
|
|
314 |
|
|
|
315 |
7 index 2 index get 0 eq { % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths I CurrentMax
|
|
|
316 |
4 index 2 index get
|
|
|
317 |
} {
|
|
|
318 |
7 index 2 index get
|
|
|
319 |
} ifelse
|
|
|
320 |
max % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths I CurrentMax'
|
|
|
321 |
|
|
|
322 |
% Store calculated width
|
|
|
323 |
|
|
|
324 |
2 index exch
|
|
|
325 |
2 index exch
|
|
|
326 |
put % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths' I
|
|
|
327 |
|
|
|
328 |
} if % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths I CurrentMax
|
|
|
329 |
|
|
|
330 |
pop
|
|
|
331 |
} for % => Context Width' Table MinW MaxW Columns MinWC MaxWC Widths
|
|
|
332 |
|
|
|
333 |
% Process the case of a lone empty table cell (used, for example, for its background color)
|
|
|
334 |
% as we're using floating point numbers, we cannot use equals sign
|
|
|
335 |
|
|
|
336 |
dup sum rounding-epsilon lt {
|
|
|
337 |
|
|
|
338 |
1 index exch % => Context Width' Table MinW MaxW Columns MinWC MaxWC I Widths
|
|
|
339 |
rounding-epsilon
|
|
|
340 |
put % => Context Width' Table MinW MaxW Columns MinWC MaxWC Widths
|
|
|
341 |
} for
|
|
|
342 |
} if % => Context Width' Table MinW MaxW Columns MinWC MaxWC Widths
|
|
|
343 |
|
|
|
344 |
% now - the last attempt; if total width is less than box width, then we have a situation when either
|
|
|
345 |
% all columns AND table are width constrained or the HTML similer to the following:
|
|
|
346 |
%
|
|
|
347 |
% <table cellpadding="0" width="100%" bgcolor="green"><tbody><tr>
|
|
|
348 |
% <td colspan="2" bgcolor="yellow"></td>
|
|
|
349 |
% <td style="width: 100px;" bgcolor="cyan">TEXT
|
|
|
350 |
%
|
|
|
351 |
% e.g. empty column (with zero width) and fixed-width column.
|
|
|
352 |
|
|
|
353 |
dup sum 8 index lt { % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths
|
|
|
354 |
% Let's make zero-width columns
|
|
|
355 |
% non-zero width (so that they columb expanded) and re-try expanding columns
|
|
|
356 |
|
|
|
357 |
|
|
|
358 |
1 index 1 index get 0 eq {
|
|
|
359 |
1 index 1 index rounding-epsilon put
|
|
|
360 |
} if
|
|
|
361 |
pop
|
|
|
362 |
} for % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths
|
|
|
363 |
|
|
|
364 |
7 index
|
|
|
365 |
1 index
|
|
|
366 |
8 index box-table-get-non-constrained-width-flags
|
|
|
367 |
expand-to-with-flags % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths Widths'
|
|
|
368 |
exch pop
|
|
|
369 |
} if % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths
|
|
|
370 |
|
|
|
371 |
% in case of overconstrained table (e.g. two columns with 20% widths), expand them
|
|
|
372 |
7 index
|
|
|
373 |
1 index expand-to
|
|
|
374 |
exch pop % => Context Width Table MinW MaxW Columns MinWC MaxWC Widths'
|
|
|
375 |
|
|
|
376 |
exch pop
|
|
|
377 |
exch pop
|
|
|
378 |
exch pop
|
|
|
379 |
exch pop
|
|
|
380 |
exch pop
|
|
|
381 |
exch pop
|
|
|
382 |
exch pop
|
|
|
383 |
exch pop
|
|
|
384 |
} def
|
|
|
385 |
|
|
|
386 |
/box-table-column-widths { % => Context Table
|
|
|
387 |
1 index
|
|
|
388 |
1 index /get-width call-method
|
|
|
389 |
2 index box-table-columns-fit % => Context Table Widths
|
|
|
390 |
exch pop
|
|
|
391 |
exch pop
|
|
|
392 |
} def
|
|
|
393 |
|
|
|
394 |
/box-table-count-cols {
|
|
|
395 |
get-content 0 get
|
|
|
396 |
get-content length
|
|
|
397 |
} def
|
|
|
398 |
|
|
|
399 |
/box-table-count-rows {
|
|
|
400 |
get-content length
|
|
|
401 |
} def
|
|
|
402 |
|
|
|
403 |
/box-table-create { % =>
|
|
|
404 |
box-container-create % => Box
|
|
|
405 |
dup box-table-setup-methods
|
|
|
406 |
dup /box-table add-type
|
|
|
407 |
|
|
|
408 |
% List of column width constraints
|
|
|
409 |
dup [] box-table-put-cwc-list
|
|
|
410 |
dup [] box-table-put-rhc-list
|
|
|
411 |
|
|
|
412 |
} def
|
|
|
413 |
|
|
|
414 |
/box-table-fit-rowspans { % => Heights Table
|
|
|
415 |
% Scan all cells spanning several rows
|
|
|
416 |
dup box-table-get-rowspans % => Heights Table Rowspans
|
|
|
417 |
{ % => Heights Table Rowspan
|
|
|
418 |
dup cellspan-get-row
|
|
|
419 |
1 index cellspan-get-column % => Heights Table Rowspan RsRow RsCol
|
|
|
420 |
3 index box-table-get-cell % => Heights Table Rowspan Cell
|
|
|
421 |
|
|
|
422 |
% now check if cell height is less than sum of spanned rows heights
|
|
|
423 |
3 index
|
|
|
424 |
2 index cellspan-get-row
|
|
|
425 |
3 index cellspan-get-size
|
|
|
426 |
getinterval % => Heights Table Rowspan Cell RowHeights
|
|
|
427 |
sum % => Heights Table Rowspan Cell RowHeightsSum
|
|
|
428 |
|
|
|
429 |
dup 2 index get-full-height gt {
|
|
|
430 |
% Vertical-align current cell
|
|
|
431 |
% calculate (approximate) row baseline
|
|
|
432 |
3 index get-content % => Heights Table Rowspan Cell RowHeightsSum Rows
|
|
|
433 |
3 index cellspan-get-row get % => Heights Table Rowspan Cell RowHeightsSum Row
|
|
|
434 |
box-table-row-get-baseline % => Heights Table Rowspan Cell RowHeightsSum RowBaseline
|
|
|
435 |
|
|
|
436 |
|
|
|
437 |
% apply vertical-align
|
|
|
438 |
1 index 3 index % => Heights Tablw Rowspan Cell RowHeightsSum Baseline RowHeightsSum Cell
|
|
|
439 |
box-table-cell-apply-vertical-align
|
|
|
440 |
% => Heights Tablw Rowspan Cell RowHeightsSum
|
|
|
441 |
|
|
|
442 |
% Make cell fill all available vertical space
|
|
|
443 |
dup 2 index put-full-height % => Heights Tablw Rowspan Cell RowHeightsSum
|
|
|
444 |
} if % => Heights Table Rowspan Cell RowHeightsSum
|
|
|
445 |
pop pop pop
|
|
|
446 |
} forall % => Heights Table
|
|
|
447 |
|
|
|
448 |
pop pop
|
|
|
449 |
} def
|
|
|
450 |
|
|
|
451 |
/box-table-get-cell { % => Y X Table
|
|
|
452 |
dup get-content
|
|
|
453 |
3 index get % => Y X Table Row
|
|
|
454 |
get-content
|
|
|
455 |
2 index get % => Y X Table Cell
|
|
|
456 |
exch pop
|
|
|
457 |
exch pop
|
|
|
458 |
exch pop
|
|
|
459 |
} def
|
|
|
460 |
|
|
|
461 |
/box-table-get-colspans { % => Table
|
|
|
462 |
[]
|
|
|
463 |
|
|
|
464 |
2 index get-content % => Table RS I Rows
|
|
|
465 |
{ % => Table RS I Row
|
|
|
466 |
1 index exch
|
|
|
467 |
box-table-row-get-colspans % => Table RS I RowColSpans
|
|
|
468 |
3 2 roll exch % => Table I RS RowColSpans
|
|
|
469 |
array-merge % => Table I RS'
|
|
|
470 |
exch % => Table RS' I
|
|
|
471 |
|
|
|
472 |
1 add
|
|
|
473 |
} forall
|
|
|
474 |
pop
|
|
|
475 |
|
|
|
476 |
exch pop
|
|
|
477 |
} def
|
|
|
478 |
|
|
|
479 |
/box-table-get-cwc { % => Index Table
|
|
|
480 |
/CWC get exch get
|
|
|
481 |
} def
|
|
|
482 |
|
|
|
483 |
% Note that if table have no width constraint AND some columns are percentage constrained,
|
|
|
484 |
% then the width of the table can be determined based on the minimal column width;
|
|
|
485 |
% e.g. if some column have minimal width of 10px and 10% width constraint,
|
|
|
486 |
% then table will have minimal width of 100px. If there's several percentage-constrained columns,
|
|
|
487 |
% then we choose from the generated values the maximal one
|
|
|
488 |
%
|
|
|
489 |
% Of course, all of the above can be applied ONLY to table without width constraint;
|
|
|
490 |
% of theres any w.c. applied to the table, it will have greater than column constraints
|
|
|
491 |
%
|
|
|
492 |
% We must take constrained table width into account; if there's a width constraint,
|
|
|
493 |
% then we must choose the maximal value between the constrained width and sum of minimal
|
|
|
494 |
% columns widths - so, expanding the constrained width in case it is not enough to fit
|
|
|
495 |
% the table contents
|
|
|
496 |
%
|
|
|
497 |
% @param $context referene to a flow context object
|
|
|
498 |
% @return minimal box width (including the padding/margin/border width! NOT content width)
|
|
|
499 |
%
|
|
|
500 |
/box-table-get-min-width { % => Context Table
|
|
|
501 |
1 index 1 index
|
|
|
502 |
box-table-get-table-columns-min-widths
|
|
|
503 |
% => Context Table Widths
|
|
|
504 |
dup sum % => Context Table Widths Width
|
|
|
505 |
dup % => Context Table Widths Width BaseWidth
|
|
|
506 |
|
|
|
507 |
3 index get-width-constraint
|
|
|
508 |
/type get /none ne { % => Context Table Widths Width BaseWidth
|
|
|
509 |
% Check if constrained table width should be expanded to fit the table contents
|
|
|
510 |
|
|
|
511 |
1 index % => Context Table Widths Width BaseWidth Width
|
|
|
512 |
5 index
|
|
|
513 |
5 index get-parent
|
|
|
514 |
box-container-get-available-width
|
|
|
515 |
% => Context Table Widths Width BaseWidth Width AvailWidth
|
|
|
516 |
|
|
|
517 |
6 index get-width-constraint
|
|
|
518 |
dup /apply get exec % => Context Table Widths Width BaseWidth Width CWidth
|
|
|
519 |
max % => Context Table Widths Width BaseWidth Width'
|
|
|
520 |
|
|
|
521 |
3 2 roll pop exch % => Context Table Widths Width' BaseWidth
|
|
|
522 |
} { % => Context Table Widths Width BaseWidth
|
|
|
523 |
% Now check if there's any percentage column width constraints (note that
|
|
|
524 |
% if we've get here, than the table width is not constrained). Calculate
|
|
|
525 |
% the table width basing on these values and select the maximal value
|
|
|
526 |
|
|
|
527 |
|
|
|
528 |
3 index { % => Context Table Widths Width BaseWidth I Widths[i]
|
|
|
529 |
1 index
|
|
|
530 |
6 index box-table-get-cwc % => Context Table Widths Width BaseWidth I Widths[i] CWC
|
|
|
531 |
|
|
|
532 |
3 index exch % => Context Table Widths Width BaseWidth I Widths[i] BaseWidth CWC
|
|
|
533 |
2 index exch % => Context Table Widths Width BaseWidth I Widths[i] BaseWidth Width[i] CWC
|
|
|
534 |
dup /apply-inverse get exec % => Context Table Widths Width BaseWidth I Widths[i] ICW
|
|
|
535 |
|
|
|
536 |
7 index
|
|
|
537 |
7 index get-parent
|
|
|
538 |
box-container-get-available-width
|
|
|
539 |
% => Context Table Widths Width BaseWidth I Widths[i] ICW AW
|
|
|
540 |
7 index get-hor-extra sub % => Context Table Widths Width BaseWidth I Widths[i] ICW AW-HE
|
|
|
541 |
min % => Context Table Widths Width BaseWidth I Widths[i] min(ICW,AW-HE)
|
|
|
542 |
|
|
|
543 |
4 index max % => Context Table Widths Width BaseWidth I Widths[i] W
|
|
|
544 |
5 4 roll pop 4 1 roll % => Context Table Widths Width' BaseWidth I Widths[i]
|
|
|
545 |
|
|
|
546 |
pop 1 add
|
|
|
547 |
} forall % => Context Table Widths Width BaseWidth I
|
|
|
548 |
pop
|
|
|
549 |
} ifelse
|
|
|
550 |
|
|
|
551 |
pop % => Context Table Widths Width
|
|
|
552 |
2 index get-hor-extra add % => Context Table Widths Width'
|
|
|
553 |
exch pop
|
|
|
554 |
exch pop
|
|
|
555 |
exch pop
|
|
|
556 |
} def
|
|
|
557 |
|
|
|
558 |
/box-table-get-max-width { % => Context Table
|
|
|
559 |
dup get-width-constraint
|
|
|
560 |
/type get /none ne { % => Context Table
|
|
|
561 |
% Check if constrained table width should be expanded to fit the table contents
|
|
|
562 |
1 index
|
|
|
563 |
1 index
|
|
|
564 |
box-container-get-available-width
|
|
|
565 |
% => COntext Table AvailableWidth
|
|
|
566 |
|
|
|
567 |
2 index get-width-constraint % => Context Table AvailableWidth 0 WC
|
|
|
568 |
dup /apply get exec % => Context Table WC
|
|
|
569 |
} { % => Context Table
|
|
|
570 |
2 copy
|
|
|
571 |
box-table-get-table-columns-max-widths
|
|
|
572 |
% => Context Table CMaxW
|
|
|
573 |
2 index
|
|
|
574 |
2 index
|
|
|
575 |
box-table-get-table-columns-min-widths
|
|
|
576 |
% => Context Table CMaxWs CMinWs
|
|
|
577 |
1 index
|
|
|
578 |
1 index
|
|
|
579 |
/get-max-width % => Context Table CMaxWs CMinWs CMaxWs CMinWs /get-max-width
|
|
|
580 |
6 index % => Context Table CMaxWs CMinWs CMaxWs CMinWs /get-max-width Context
|
|
|
581 |
3 index % => Context Table CMaxWs CMinWs CMaxWs CMinWs /get-max-width Context CMaxWs
|
|
|
582 |
7 index
|
|
|
583 |
box-table-apply-colspans % => Context Table CMaxWs CMinWs CMaxWs'
|
|
|
584 |
exch pop exch pop % => Context Table Widths
|
|
|
585 |
|
|
|
586 |
dup sum dup % => COntext Table Widths W BaseW
|
|
|
587 |
|
|
|
588 |
% Now check if there's any percentage column width constraints (note that
|
|
|
589 |
% if we've get here, than the table width is not constrained). Calculate
|
|
|
590 |
% the table width basing on these values and select the maximal value
|
|
|
591 |
|
|
|
592 |
|
|
|
593 |
3 index { % => Context Table Widths Width BaseWidth I Widths[i]
|
|
|
594 |
1 index
|
|
|
595 |
6 index box-table-get-cwc % => Context Table Widths Width BaseWidth I Widths[i] CWC
|
|
|
596 |
|
|
|
597 |
3 index exch % => Context Table Widths Width BaseWidth I Widths[i] BaseWidth CWC
|
|
|
598 |
2 index exch % => Context Table Widths Width BaseWidth I Widths[i] BaseWidth Width[i] CWC
|
|
|
599 |
dup /apply-inverse get exec % => Context Table Widths Width BaseWidth I Widths[i] ICW
|
|
|
600 |
|
|
|
601 |
7 index
|
|
|
602 |
7 index get-parent
|
|
|
603 |
box-container-get-available-width
|
|
|
604 |
% => Context Table Widths Width BaseWidth I Widths[i] ICW AW
|
|
|
605 |
7 index get-hor-extra sub % => Context Table Widths Width BaseWidth I Widths[i] ICW AW-HE
|
|
|
606 |
min % => Context Table Widths Width BaseWidth I Widths[i] min(ICW,AW-HE)
|
|
|
607 |
|
|
|
608 |
4 index max % => Context Table Widths Width BaseWidth I Widths[i] W
|
|
|
609 |
5 4 roll pop 4 1 roll % => Context Table Widths Width' BaseWidth I Widths[i]
|
|
|
610 |
|
|
|
611 |
pop 1 add
|
|
|
612 |
} forall % => Context Table Widths Width BaseWidth I
|
|
|
613 |
pop pop exch pop % => Context Table Width
|
|
|
614 |
} ifelse
|
|
|
615 |
|
|
|
616 |
1 index get-hor-extra add % => Context Table Width'
|
|
|
617 |
exch pop
|
|
|
618 |
exch pop
|
|
|
619 |
} def
|
|
|
620 |
|
|
|
621 |
% Get a list of boolean values indicating if table rows are NOT constant constrained
|
|
|
622 |
%
|
|
|
623 |
% @return array containing 'true' value at index I if I-th row is height-constrained
|
|
|
624 |
% and 'false' otherwise
|
|
|
625 |
%
|
|
|
626 |
/box-table-get-non-constant-constrained-height-flags {
|
|
|
627 |
[] % => Table Flags
|
|
|
628 |
|
|
|
629 |
box-table-count-rows
|
|
|
630 |
1 sub { % => Table Flags I
|
|
|
631 |
2 index box-table-get-rhc % => Table Flags RHC
|
|
|
632 |
hc-is-constant not % => Table Flags Flag
|
|
|
633 |
exch array-prepend % => Table Flags'
|
|
|
634 |
} for % => Table Flags
|
|
|
635 |
|
|
|
636 |
exch pop % => Flags
|
|
|
637 |
} def
|
|
|
638 |
|
|
|
639 |
% Get a list of boolean values indicating if table rows are height constrained
|
|
|
640 |
%
|
|
|
641 |
% @return array containing 'true' value at index I if I-th row is not height-constrained
|
|
|
642 |
% and 'false' otherwise
|
|
|
643 |
%
|
|
|
644 |
/box-table-get-non-constrained-flags { % => Table
|
|
|
645 |
[] % => Table Flags
|
|
|
646 |
|
|
|
647 |
box-table-count-rows
|
|
|
648 |
1 sub { % => Table Flags I
|
|
|
649 |
2 index box-table-get-rhc % => Table Flags RHC
|
|
|
650 |
hc-is-null % => Table Flags Flag
|
|
|
651 |
exch array-prepend % => Table Flags'
|
|
|
652 |
} for % => Table Flags
|
|
|
653 |
|
|
|
654 |
exch pop % => Flags
|
|
|
655 |
} def
|
|
|
656 |
|
|
|
657 |
% Get a list of boolean values indicating if table columns are height constrained
|
|
|
658 |
%
|
|
|
659 |
% @return array containing 'true' value at index I if I-th columns is not width-constrained
|
|
|
660 |
% and 'false' otherwise
|
|
|
661 |
%
|
|
|
662 |
/box-table-get-non-constrained-width-flags {
|
|
|
663 |
[] % => Table Flags
|
|
|
664 |
|
|
|
665 |
box-table-count-cols
|
|
|
666 |
1 sub { % => Table Flags I
|
|
|
667 |
2 index box-table-get-cwc % => Table Flags CWC
|
|
|
668 |
/type get /none eq
|
|
|
669 |
exch array-prepend % => Table Flags'
|
|
|
670 |
} for % => Table Flags
|
|
|
671 |
|
|
|
672 |
exch pop % => Flags
|
|
|
673 |
} def
|
|
|
674 |
|
|
|
675 |
% Get a list of boolean values indicating if table rows are height constrained using percentage values
|
|
|
676 |
%
|
|
|
677 |
% @return array containing 'true' value at index I if I-th row is not height-constrained
|
|
|
678 |
% and 'false' otherwise
|
|
|
679 |
%
|
|
|
680 |
/box-table-get-non-percentage-constrained-height-flags {
|
|
|
681 |
[] % => Table Flags
|
|
|
682 |
|
|
|
683 |
box-table-count-rows
|
|
|
684 |
1 sub { % => Table Flags I
|
|
|
685 |
2 index box-table-get-rhc % => Table Flags RHC
|
|
|
686 |
hc-is-percentage not % => Table Flags Flag
|
|
|
687 |
exch array-prepend % => Table Flags'
|
|
|
688 |
} for % => Table Flags
|
|
|
689 |
|
|
|
690 |
exch pop % => Flags
|
|
|
691 |
} def
|
|
|
692 |
|
|
|
693 |
/box-table-get-rhc { % => Index Table
|
|
|
694 |
/RHC get exch get
|
|
|
695 |
} def
|
|
|
696 |
|
|
|
697 |
/box-table-get-rowspans { % => Table
|
|
|
698 |
[]
|
|
|
699 |
|
|
|
700 |
2 index get-content % => Table RS I Rows
|
|
|
701 |
{ % => Table RS I Row
|
|
|
702 |
1 index exch
|
|
|
703 |
box-table-row-get-rowspans % => Table RS I RowColSpans
|
|
|
704 |
3 2 roll exch % => Table I RS RowColSpans
|
|
|
705 |
array-merge % => Table I RS'
|
|
|
706 |
exch % => Table RS' I
|
|
|
707 |
|
|
|
708 |
1 add
|
|
|
709 |
} forall % => Table RS I
|
|
|
710 |
pop
|
|
|
711 |
|
|
|
712 |
exch pop
|
|
|
713 |
} def
|
|
|
714 |
|
|
|
715 |
/box-table-get-table-columns-min-widths { % => Context Table
|
|
|
716 |
[] % => Context Table Widths
|
|
|
717 |
1 index get-content 0 get get-content { % => Context Table Widths Cell
|
|
|
718 |
pop 0 exch array-append
|
|
|
719 |
} forall % => Context Table Widths
|
|
|
720 |
|
|
|
721 |
1 index get-content { % => Context Table Widths Row
|
|
|
722 |
3 index exch
|
|
|
723 |
box-table-row-get-table-columns-min-widths
|
|
|
724 |
{ max } zip-with % => Context Table Widths'
|
|
|
725 |
} forall % => Context Table Widths
|
|
|
726 |
|
|
|
727 |
exch pop
|
|
|
728 |
exch pop
|
|
|
729 |
} def
|
|
|
730 |
|
|
|
731 |
/box-table-get-table-columns-max-widths { % => Context Table
|
|
|
732 |
[] % => Context Table Widths
|
|
|
733 |
1 index get-content 0 get get-content { % => Context Table Widths Cell
|
|
|
734 |
pop 0 exch array-append
|
|
|
735 |
} forall % => Context Table Widths
|
|
|
736 |
|
|
|
737 |
1 index get-content { % => Context Table Widths Row
|
|
|
738 |
3 index exch
|
|
|
739 |
box-table-row-get-table-columns-max-widths
|
|
|
740 |
{ max } zip-with % => Context Table Widths'
|
|
|
741 |
} forall % => Context Table Widths
|
|
|
742 |
|
|
|
743 |
% Use column width constraints - column should not be wider its constrained width
|
|
|
744 |
|
|
|
745 |
dup 3 index box-table-get-cwc % => Context Table Widths I CWC
|
|
|
746 |
|
|
|
747 |
% Newertheless, percentage constraints should not be applied IF table
|
|
|
748 |
% does not have constrained width
|
|
|
749 |
|
|
|
750 |
dup /type get
|
|
|
751 |
/fraction eq not { % => Context Table Widths I CWC
|
|
|
752 |
3 index /get-width call-method
|
|
|
753 |
3 index 3 index get
|
|
|
754 |
2 index dup /apply get exec % => Context Table Widths I CWC W
|
|
|
755 |
3 index exch
|
|
|
756 |
3 index exch put % => Context Table Widths I CWC
|
|
|
757 |
} if
|
|
|
758 |
pop
|
|
|
759 |
pop
|
|
|
760 |
} for
|
|
|
761 |
|
|
|
762 |
exch pop
|
|
|
763 |
exch pop
|
|
|
764 |
} def
|
|
|
765 |
|
|
|
766 |
/box-table-get-width { % => Table
|
|
|
767 |
dup get-parent
|
|
|
768 |
/box-table-cell is-a not % => Table C1
|
|
|
769 |
1 index get-parent
|
|
|
770 |
get-width-constraint /type get
|
|
|
771 |
/none eq not % => Table C1 C2
|
|
|
772 |
2 index get-width-constraint
|
|
|
773 |
/type get /fraction eq not % => Table C1 C2 C3
|
|
|
774 |
or or {
|
|
|
775 |
dup get-parent /Position get /width get
|
|
|
776 |
1 index /Position get /width get
|
|
|
777 |
2 index get-width-constraint
|
|
|
778 |
wc-apply % => Table W
|
|
|
779 |
} {
|
|
|
780 |
dup /Position get /width get
|
|
|
781 |
} ifelse
|
|
|
782 |
|
|
|
783 |
exch pop
|
|
|
784 |
} def
|
|
|
785 |
|
|
|
786 |
/box-table-have-colspan { % => Y X Table
|
|
|
787 |
3 copy box-table-get-cell % => Y X Table Cell
|
|
|
788 |
box-table-cell-get-colspan
|
|
|
789 |
|
|
|
790 |
exch pop
|
|
|
791 |
exch pop
|
|
|
792 |
exch pop
|
|
|
793 |
} def
|
|
|
794 |
|
|
|
795 |
/box-table-have-rowspan { % => Y X Table
|
|
|
796 |
dup get-content % => Y X Table Rows
|
|
|
797 |
3 index get % => Y X Table Row
|
|
|
798 |
2 index get % => Y X Table Cell
|
|
|
799 |
box-table-cell-get-rowspan
|
|
|
800 |
|
|
|
801 |
exch pop
|
|
|
802 |
exch pop
|
|
|
803 |
exch pop
|
|
|
804 |
} def
|
|
|
805 |
|
|
|
806 |
/box-table-is-constrained-column { % => Index Table
|
|
|
807 |
2 copy box-table-get-cwc
|
|
|
808 |
/type get /none ne
|
|
|
809 |
|
|
|
810 |
exch pop
|
|
|
811 |
exch pop
|
|
|
812 |
} def
|
|
|
813 |
|
|
|
814 |
% Tries to change minimal constrained width so that columns will fit into the given
|
|
|
815 |
% table width
|
|
|
816 |
%
|
|
|
817 |
% Note that every width constraint have its own priority; first, the unconstrained columns are collapsed,
|
|
|
818 |
% then - percentage constrained and after all - columns having fixed width
|
|
|
819 |
%
|
|
|
820 |
% @param $width table width
|
|
|
821 |
% @param $minw array of unconstrained minimal widths
|
|
|
822 |
% @param $minwc array of constrained minimal widths
|
|
|
823 |
% @return list of normalized minimal constrained widths
|
|
|
824 |
%
|
|
|
825 |
/box-table-normalize-min-widths { % => MinWC MinW Width Table
|
|
|
826 |
% Check if sum of constrained widths is too big
|
|
|
827 |
% Note that we compare sum of constrained width with the MAXIMAL value of table width and
|
|
|
828 |
% sum of uncostrained minimal width; it will prevent from unneeded collapsing of table cells
|
|
|
829 |
% if table content will expand its width anyway
|
|
|
830 |
|
|
|
831 |
2 index sum
|
|
|
832 |
2 index max % => MinWC MinW Width Table TWidth
|
|
|
833 |
|
|
|
834 |
% compare with sum of minimal constrained widths
|
|
|
835 |
|
|
|
836 |
4 index sum 1 index gt {
|
|
|
837 |
4 index sum 1 index sub % => MinWC MinW Width Table TWidth Delta
|
|
|
838 |
|
|
|
839 |
% Calculate the amount of difference between minimal and constrained minimal width for each columns
|
|
|
840 |
5 index
|
|
|
841 |
5 index
|
|
|
842 |
{ sub } zip-with % => MinWC MinW Width Table TWidth Delta Diff
|
|
|
843 |
|
|
|
844 |
% If no difference is found, we can collapse no columns
|
|
|
845 |
% otherwise scale some columns...
|
|
|
846 |
|
|
|
847 |
dup sum % => MinWC MinW Width Table TWidth Delta Diff CWDelta
|
|
|
848 |
|
|
|
849 |
dup 0 gt { % => MinWC MinW Width Table TWidth Delta Diff CWDelta
|
|
|
850 |
|
|
|
851 |
2 index 1 index get neg % => MinWC MinW Width Table TWidth Delta Diff CWDelta I -diff[i]
|
|
|
852 |
2 index div % => MinWC MinW Width Table TWidth Delta Diff CWDelta I -diff[i]/cwdelta
|
|
|
853 |
4 index mul % => MinWC MinW Width Table TWidth Delta Diff CWDelta I -diff[i]/cwdelta*delta
|
|
|
854 |
9 index 2 index get add % => MinWC MinW Width Table TWidth Delta Diff CWDelta I MinWC[i]'
|
|
|
855 |
9 index exch
|
|
|
856 |
2 index exch put % => MinWC MinW Width Table TWidth Delta Diff CWDelta I
|
|
|
857 |
pop % => MinWC MinW Width Table TWidth Delta Diff CWDelta
|
|
|
858 |
} for
|
|
|
859 |
} if % => MinWC MinW Width Table TWidth Delta Diff CWDelta
|
|
|
860 |
pop pop pop
|
|
|
861 |
} if % => MinWC MinW Width Table TWidth
|
|
|
862 |
pop pop pop pop % => MinWC
|
|
|
863 |
} def
|
|
|
864 |
|
|
|
865 |
/box-table-put-cwc-list { % => Box List
|
|
|
866 |
/CWC exch put
|
|
|
867 |
} def
|
|
|
868 |
|
|
|
869 |
/box-table-put-rhc-list { % => Box List
|
|
|
870 |
/RHC exch put
|
|
|
871 |
|
|
|
872 |
} def
|
|
|
873 |
|
|
|
874 |
/box-table-reflow { % => Context Parent This
|
|
|
875 |
dup /float get-css-value /none eq {
|
|
|
876 |
3 copy
|
|
|
877 |
box-table-reflow-static-normal
|
|
|
878 |
} {
|
|
|
879 |
3 copy
|
|
|
880 |
box-container-reflow-static-float
|
|
|
881 |
} ifelse
|
|
|
882 |
|
|
|
883 |
pop pop pop
|
|
|
884 |
} def
|
|
|
885 |
|
|
|
886 |
/box-table-reflow-content { % => Context This
|
|
|
887 |
% Reset current Y value
|
|
|
888 |
|
|
|
889 |
dup get-top
|
|
|
890 |
1 index put-current-y
|
|
|
891 |
|
|
|
892 |
% Determine the base table width
|
|
|
893 |
% if width constraint exists, the actual table width will not be changed anyway
|
|
|
894 |
|
|
|
895 |
dup /get-width call-method
|
|
|
896 |
2 index 2 index /get-max-width call-method
|
|
|
897 |
min
|
|
|
898 |
1 index put-width
|
|
|
899 |
|
|
|
900 |
% calculate width of table columns
|
|
|
901 |
|
|
|
902 |
2 copy box-table-column-widths % => Context This ColWidths
|
|
|
903 |
|
|
|
904 |
% Collapse table to minimum width (if width is not constrained
|
|
|
905 |
|
|
|
906 |
dup sum 2 index put-width % => Context This ColWidths
|
|
|
907 |
|
|
|
908 |
% Flow cells horizontally in each table row
|
|
|
909 |
|
|
|
910 |
|
|
|
911 |
3 index box-table-count-rows
|
|
|
912 |
1 sub { % => Context This ColWidths I
|
|
|
913 |
|
|
|
914 |
% Row flow started
|
|
|
915 |
% Reset current X coordinate to the far left of the table
|
|
|
916 |
|
|
|
917 |
2 index get-left
|
|
|
918 |
3 index put-current-x
|
|
|
919 |
|
|
|
920 |
% Flow each cell in the row
|
|
|
921 |
|
|
|
922 |
|
|
|
923 |
|
|
|
924 |
5 index box-table-count-cols
|
|
|
925 |
1 sub { % => Context This ColWidths I Span J
|
|
|
926 |
% Skip cells covered by colspans (fake cells, anyway)
|
|
|
927 |
1 index 0 eq { % => Context This ColWidths I Span J
|
|
|
928 |
% Flow current cell
|
|
|
929 |
% Any colspans here?
|
|
|
930 |
2 index 1 index 6 index
|
|
|
931 |
box-table-have-colspan % => COntext This ColWidths I Span J Span'
|
|
|
932 |
3 2 roll pop exch % => COntext This ColWidths I Span' J
|
|
|
933 |
|
|
|
934 |
% Get sum of width for the current cell (or several cells in colspan)
|
|
|
935 |
% In most cases, $span == 1 here (just a single cell)
|
|
|
936 |
|
|
|
937 |
3 index 1 index 3 index
|
|
|
938 |
getinterval sum % => COntext This ColWidths I Span' J CW
|
|
|
939 |
|
|
|
940 |
% store calculated width of the current cell
|
|
|
941 |
|
|
|
942 |
3 index 2 index % => Context This ColWidths I Span J CW I(Row) J(Col)
|
|
|
943 |
7 index
|
|
|
944 |
box-table-get-cell % => COntext This ColWidths I Span J CW Cell
|
|
|
945 |
|
|
|
946 |
1 index 1 index
|
|
|
947 |
put-full-width % => COntext This ColWidths I Span J CW Cell
|
|
|
948 |
|
|
|
949 |
1 index 1 index get-hor-extra sub
|
|
|
950 |
wc-create-constant
|
|
|
951 |
1 index put-width-constraint % => COntext This ColWidths I Span' J CW Cell
|
|
|
952 |
|
|
|
953 |
% Flow cell
|
|
|
954 |
|
|
|
955 |
7 index 7 index 2 index
|
|
|
956 |
/reflow call-method % => COntext This ColWidths I Span' J CW Cell
|
|
|
957 |
|
|
|
958 |
6 index get-current-x
|
|
|
959 |
2 index add
|
|
|
960 |
7 index put-current-x % => COntext This ColWidths I Span' J CW Cell
|
|
|
961 |
|
|
|
962 |
pop pop
|
|
|
963 |
} if % => Context This ColWidths I SPan J
|
|
|
964 |
pop % => Context This ColWidths I SPan
|
|
|
965 |
|
|
|
966 |
% Current cell have been processed or skipped
|
|
|
967 |
1 sub 0 max
|
|
|
968 |
} for % => Context This ColWidths I SPan
|
|
|
969 |
|
|
|
970 |
pop % => Context This ColWidths I
|
|
|
971 |
|
|
|
972 |
% row height calculation offset current Y coordinate by the row height calculated
|
|
|
973 |
2 index get-content
|
|
|
974 |
1 index get % => Context This ColWidth I Row
|
|
|
975 |
box-table-row-height % => Context This ColWidth I RH
|
|
|
976 |
3 index get-current-y
|
|
|
977 |
exch sub
|
|
|
978 |
3 index put-current-y % => Context This ColWidth I
|
|
|
979 |
|
|
|
980 |
pop
|
|
|
981 |
} for % => Context This ColWidths
|
|
|
982 |
|
|
|
983 |
pop % => Context This
|
|
|
984 |
|
|
|
985 |
% Calculate (and possibly adjust height of table rows)
|
|
|
986 |
0.1 1 index box-table-row-heights % => Context This RowHeights
|
|
|
987 |
|
|
|
988 |
% adjust row heights to fit cells spanning several rows
|
|
|
989 |
1 index box-table-get-rowspans { % => Context This RowHeights Rowspan
|
|
|
990 |
% Get height of the cell
|
|
|
991 |
dup cellspan-get-row
|
|
|
992 |
1 index cellspan-get-column
|
|
|
993 |
4 index
|
|
|
994 |
box-table-get-cell
|
|
|
995 |
get-full-height % => Context This RowHeights Rowspan CellHeight
|
|
|
996 |
|
|
|
997 |
% Get calculated height of the spanned-over rows
|
|
|
998 |
2 index
|
|
|
999 |
2 index cellspan-get-row
|
|
|
1000 |
3 index cellspan-get-size
|
|
|
1001 |
getinterval % => Context This RowHeights Rowspan CellHeight CellRowHeights
|
|
|
1002 |
|
|
|
1003 |
% Get list of non-constrained columns
|
|
|
1004 |
4 index box-table-get-non-constrained-flags
|
|
|
1005 |
3 index cellspan-get-row
|
|
|
1006 |
4 index cellspan-get-size
|
|
|
1007 |
getinterval % => Context This RowHeights Rowspan CellHeight CellRowHeights Flags
|
|
|
1008 |
|
|
|
1009 |
% Expand row heights (only for non-constrained columns)
|
|
|
1010 |
3 copy
|
|
|
1011 |
expand-to-with-flags % => Context This RowHeights Rowspan CellHeight CellRowHeights Flags NewHeights
|
|
|
1012 |
exch pop % => Context This RowHeights Rowspan CellHeight CellRowHeights NewHeights
|
|
|
1013 |
|
|
|
1014 |
% Check if rows could not be expanded
|
|
|
1015 |
|
|
|
1016 |
dup sum 3 index rounding-epsilon sub lt { % => Context This RowHeights Rowspan CellHeight CellRowHeights NewHeights
|
|
|
1017 |
pop
|
|
|
1018 |
|
|
|
1019 |
% Get list of non-constant-constrained columns
|
|
|
1020 |
|
|
|
1021 |
4 index box-table-get-non-constant-constrained-flags
|
|
|
1022 |
3 index cellspan-get-row
|
|
|
1023 |
4 index cellspan-get-size
|
|
|
1024 |
getinterval % => Context This RowHeights Rowspan CellHeight CellRowHeights Flags
|
|
|
1025 |
|
|
|
1026 |
3 copy
|
|
|
1027 |
expand-to-with-flags % => Context This RowHeights Rowspan CellHeight CellRowHeights Flags NewHeights
|
|
|
1028 |
exch pop % => Context This RowHeights Rowspan CellHeight CellRowHeights NewHeights
|
|
|
1029 |
} if % => Context This RowHeights Rowspan CellHeight CellRowHeights NewHeights
|
|
|
1030 |
|
|
|
1031 |
% Update the rows heights
|
|
|
1032 |
4 index
|
|
|
1033 |
4 index cellspan-get-row
|
|
|
1034 |
2 index
|
|
|
1035 |
putinterval % => Context This RowHeights Rowspan CellHeight CellRowHeights NewHeights
|
|
|
1036 |
|
|
|
1037 |
pop pop pop pop
|
|
|
1038 |
} forall % => Context This RowHeights
|
|
|
1039 |
|
|
|
1040 |
% Now expand rows to full table height
|
|
|
1041 |
dup sum
|
|
|
1042 |
2 index get-height
|
|
|
1043 |
max % => Context This RowHeights TableHeight
|
|
|
1044 |
|
|
|
1045 |
% Get list of non-constrained coluns
|
|
|
1046 |
2 index box-table-get-non-constrained-flags
|
|
|
1047 |
1 index exch
|
|
|
1048 |
3 index exch
|
|
|
1049 |
expand-to-with-flags % => Context This RowHeights TableHeight RowHeights'
|
|
|
1050 |
3 2 roll pop exch % => Context This RowHeights' TableHeight
|
|
|
1051 |
|
|
|
1052 |
% Check if rows could not be expanded
|
|
|
1053 |
1 index sum
|
|
|
1054 |
1 index rounding-epsilon sub % => Context This RowHeights' TableHeight
|
|
|
1055 |
lt {
|
|
|
1056 |
% Get list of non-constant-constrained columns
|
|
|
1057 |
2 index box-table-get-non-constant-constrained-flags
|
|
|
1058 |
% use non-constant-constrained rows
|
|
|
1059 |
2 index exch
|
|
|
1060 |
expand-to-with-flags % => Context This RowHeights' TableHeight
|
|
|
1061 |
} if % => Context This RowHeights' TableHeight
|
|
|
1062 |
pop
|
|
|
1063 |
|
|
|
1064 |
% Now we calculated row heights, time to actually resize them
|
|
|
1065 |
dup 2 index box-table-resize-rows % => Context This RowHeights
|
|
|
1066 |
|
|
|
1067 |
% Update size of cells spanning several rows
|
|
|
1068 |
dup 2 index
|
|
|
1069 |
box-table-fit-rowspans % => Context This Rowheights
|
|
|
1070 |
|
|
|
1071 |
pop pop pop
|
|
|
1072 |
} def
|
|
|
1073 |
|
|
|
1074 |
/box-table-reflow-static-normal { % => Context Parent This
|
|
|
1075 |
% Calculate margin values if they have been set as a percentage
|
|
|
1076 |
1 index 1 index
|
|
|
1077 |
box-generic-calc-percentage-margins
|
|
|
1078 |
|
|
|
1079 |
% Calculate width value if it had been set as a percentage
|
|
|
1080 |
3 copy
|
|
|
1081 |
box-generic-calc-percentage-width
|
|
|
1082 |
|
|
|
1083 |
% As table width can be deterimined by its contents, we may calculate auto values
|
|
|
1084 |
% only AFTER the contents have been reflown; thus, we'll offset the table
|
|
|
1085 |
% as a whole by a value of left margin AFTER the content reflow
|
|
|
1086 |
|
|
|
1087 |
% Do margin collapsing
|
|
|
1088 |
|
|
|
1089 |
3 copy box-generic-collapse-margin % => Context Parent This Y
|
|
|
1090 |
|
|
|
1091 |
% At this moment we have top parent/child collapsed margin at the top of context object
|
|
|
1092 |
% margin stack
|
|
|
1093 |
|
|
|
1094 |
3 index exch 2 index box-generic-apply-clear
|
|
|
1095 |
|
|
|
1096 |
% Store calculated Y coordinate as current Y in the parent box
|
|
|
1097 |
|
|
|
1098 |
2 index put-current-y % => Context Parent This
|
|
|
1099 |
|
|
|
1100 |
% Terminate current parent line-box
|
|
|
1101 |
|
|
|
1102 |
2 index 2 index
|
|
|
1103 |
box-container-close-line
|
|
|
1104 |
|
|
|
1105 |
% And add current box to the parent's line-box (alone)
|
|
|
1106 |
|
|
|
1107 |
dup 2 index
|
|
|
1108 |
box-container-append-line % => Context Parent This
|
|
|
1109 |
|
|
|
1110 |
% Determine upper-left _content_ corner position of current box
|
|
|
1111 |
% Also see note above regarding margins
|
|
|
1112 |
|
|
|
1113 |
1 index get-current-x
|
|
|
1114 |
1 index get-border-left-width add
|
|
|
1115 |
1 index get-padding-left add
|
|
|
1116 |
1 index put-left % => Context Pareht This
|
|
|
1117 |
|
|
|
1118 |
% Note that top margin already used above during maring collapsing
|
|
|
1119 |
|
|
|
1120 |
1 index get-current-y
|
|
|
1121 |
1 index get-border-top-width sub
|
|
|
1122 |
1 index get-padding-top sub
|
|
|
1123 |
1 index put-top % => Context Parent This
|
|
|
1124 |
|
|
|
1125 |
% By default, child block box will fill all available parent width;
|
|
|
1126 |
% note that actual width will be smaller because of non-zero padding, border and margins
|
|
|
1127 |
|
|
|
1128 |
2 index
|
|
|
1129 |
2 index box-container-get-available-width
|
|
|
1130 |
1 index put-full-width % => Context Parent This
|
|
|
1131 |
|
|
|
1132 |
% reflow contents
|
|
|
1133 |
|
|
|
1134 |
2 index 1 index
|
|
|
1135 |
box-table-reflow-content % => Context Parent This
|
|
|
1136 |
|
|
|
1137 |
% Update the collapsed margin value with current box bottom margin
|
|
|
1138 |
|
|
|
1139 |
2 index context-pop-collapsed-margin
|
|
|
1140 |
2 index context-pop-collapsed-margin
|
|
|
1141 |
dup get-margin-bottom
|
|
|
1142 |
3 index context-push-collapsed-margin
|
|
|
1143 |
|
|
|
1144 |
% Calculate margins and/or width is 'auto' values have been specified
|
|
|
1145 |
|
|
|
1146 |
2 copy box-generic-calc-auto-width-margins
|
|
|
1147 |
|
|
|
1148 |
/offset call-method
|
|
|
1149 |
|
|
|
1150 |
% Extend parent's height to fit current box
|
|
|
1151 |
dup get-bottom-margin
|
|
|
1152 |
2 index box-generic-extend-height
|
|
|
1153 |
|
|
|
1154 |
% terminate parent's line box
|
|
|
1155 |
|
|
|
1156 |
2 index
|
|
|
1157 |
2 index box-container-close-line % => Context Parent This
|
|
|
1158 |
|
|
|
1159 |
pop pop pop
|
|
|
1160 |
} def
|
|
|
1161 |
|
|
|
1162 |
/box-table-resize-rows { % => Heights Table
|
|
|
1163 |
dup get-top % => Heights Table RowTop
|
|
|
1164 |
|
|
|
1165 |
2 index get-content { % => Heights Table RowTop I Row
|
|
|
1166 |
4 index 2 index get % => Heights Table RowTop I Row H[I]
|
|
|
1167 |
3 index % => Heights Table RowTop I Row H[I] RowTop
|
|
|
1168 |
1 index % => Heights Table RowTop I Row H[I] RowTop H[I]
|
|
|
1169 |
3 index % => Heights Table RowTop I Row H[i] RowTop H[I] Row
|
|
|
1170 |
box-table-row-resize % => Heights Table RowTop I Row H[i]
|
|
|
1171 |
|
|
|
1172 |
exch pop % => Heights Table RowTop I H[i]
|
|
|
1173 |
3 2 roll exch sub exch % => Heights Table RowTop' I
|
|
|
1174 |
|
|
|
1175 |
1 add % => Heights Table RowTop I+1
|
|
|
1176 |
} forall % => Heights Table RowTop I
|
|
|
1177 |
pop pop
|
|
|
1178 |
|
|
|
1179 |
1 index sum
|
|
|
1180 |
1 index put-height
|
|
|
1181 |
|
|
|
1182 |
pop pop % =>
|
|
|
1183 |
} def
|
|
|
1184 |
|
|
|
1185 |
% Calculate set of row heights
|
|
|
1186 |
%
|
|
|
1187 |
% @param $minheight the minimal allowed height of the row; as we'll need to expand rows later
|
|
|
1188 |
% and rows containing totally empty cells will have zero height
|
|
|
1189 |
% @return array of row heights in media points
|
|
|
1190 |
%
|
|
|
1191 |
/box-table-row-heights { % => Minheight Box
|
|
|
1192 |
[] [] 0 % => Minheight Box Heights CHeights I
|
|
|
1193 |
3 index get-content { % => Minheight Box Heights CHeights I Row
|
|
|
1194 |
box-table-row-height % => Minheight Box Heights CHeights I RowHeight
|
|
|
1195 |
5 index max % => Minheight Box Heights CHeights I RowHeight'
|
|
|
1196 |
|
|
|
1197 |
dup % => Minheight Box Heights CHeights I RowHeight RowHeight
|
|
|
1198 |
5 4 roll % => Minheight Box CHeights I RowHeight RowHeight Heights
|
|
|
1199 |
array-prepend % => Minheight Box CHeights I RowHeight Heights'
|
|
|
1200 |
4 1 roll % => Minheight Box Heights' CHeights I RowHeight
|
|
|
1201 |
|
|
|
1202 |
1 index 5 index
|
|
|
1203 |
box-table-get-rhc % => Minheight Box Heights' CHeights I RowHeight RHC
|
|
|
1204 |
|
|
|
1205 |
5 index get-content
|
|
|
1206 |
3 index get exch % => Minheight Box Heights' CHeights I RowHeight RHC Cell
|
|
|
1207 |
2 index exch
|
|
|
1208 |
hc-apply % => Minheight Box Heights' CHeights I RowHeight RowHeightC
|
|
|
1209 |
|
|
|
1210 |
4 3 roll % => Minheight Box Heights' I RowHeight RowHeightC CHeights
|
|
|
1211 |
array-prepend % => Minheight Box Heights' I RowHeight CHeights'
|
|
|
1212 |
3 1 roll % => Minheight Box Heights' CHeights' I RowHeight
|
|
|
1213 |
|
|
|
1214 |
pop 1 add % => Minheight Box Heights' CHeights' I+1
|
|
|
1215 |
} forall pop % => Minheight Box Heights' CHeights'
|
|
|
1216 |
|
|
|
1217 |
% Now adjust percentage-constrained rows;
|
|
|
1218 |
2 index box-table-get-non-percentage-constrained-height-flags
|
|
|
1219 |
% => Minheight Box Heights CHeights Flags
|
|
|
1220 |
|
|
|
1221 |
3 index get-height % => Minheight Box Heights CHeights Flags H CH
|
|
|
1222 |
|
|
|
1223 |
|
|
|
1224 |
|
|
|
1225 |
3 index { % => Minheight Box Heights CHeights Flags H CH I Flag
|
|
|
1226 |
{ % => Minheight Box Heights CHeights Flags H CH I
|
|
|
1227 |
4 index 1 index get % => Minheight Box Heights CHeights Flags H CH I CH[i]
|
|
|
1228 |
4 3 roll exch sub % => Minheight Box Heights CHeights Flags CH I H'
|
|
|
1229 |
3 1 roll % => Minheight Box Heights CHeights Flags H' CH I
|
|
|
1230 |
} { % => Minheight Box Heights CHeights Flags H CH I
|
|
|
1231 |
4 index 1 index get % => Minheight Box Heights CHeights Flags H CH I CH[i]
|
|
|
1232 |
3 2 roll add % => Minheight Box Heights CHeights Flags H I CH'
|
|
|
1233 |
exch % => Minheight Box Heights CHeights Flags H CH' I
|
|
|
1234 |
} ifelse
|
|
|
1235 |
1 add
|
|
|
1236 |
} forall pop % => Minheight Box Heights CHeights Flags H CH'
|
|
|
1237 |
|
|
|
1238 |
dup 0 gt {
|
|
|
1239 |
div % => Minheight Box Heights CHeights Flags Scale
|
|
|
1240 |
|
|
|
1241 |
2 index % => Minheight Box Heights CHeights Flags Scale I Flags
|
|
|
1242 |
{ % => Minheight Box Heights CHeights Flags Scale I Flag
|
|
|
1243 |
{ % => Minheight Box Heights CHeights Flags Scale I
|
|
|
1244 |
3 index 1 index get % => Minheight Box Heights CHeights Flags Scale I CH[i]
|
|
|
1245 |
2 index mul % => Minheight Box Heights CHeights Flags Scale I CH[i]'
|
|
|
1246 |
4 index exch % => Minheight Box Heights CHeights Flags Scale I CH CH[i]'
|
|
|
1247 |
2 index exch % => Minheight Box Heights CHeights Flags Scale I CH I CH[i]'
|
|
|
1248 |
put % => Minheight Box Heights CHeights Flags Scale I
|
|
|
1249 |
} if
|
|
|
1250 |
1 add % => Minheight Box Heights CHeights Flags Scale I+1
|
|
|
1251 |
} forall
|
|
|
1252 |
|
|
|
1253 |
pop pop pop
|
|
|
1254 |
} {
|
|
|
1255 |
pop pop pop
|
|
|
1256 |
} ifelse % => Minheight Box Heights CHeights
|
|
|
1257 |
|
|
|
1258 |
{ max } zip-with % => Minheight Box Heights'
|
|
|
1259 |
|
|
|
1260 |
exch pop
|
|
|
1261 |
exch pop
|
|
|
1262 |
} def
|
|
|
1263 |
|
|
|
1264 |
/box-table-setup-methods { % => Box
|
|
|
1265 |
dup get-box-dict /Methods get
|
|
|
1266 |
dup /reflow {box-table-reflow} put
|
|
|
1267 |
dup /get-min-width {box-table-get-min-width} put
|
|
|
1268 |
dup /get-max-width {box-table-get-max-width} put
|
|
|
1269 |
dup /get-width {box-table-get-width} put
|
|
|
1270 |
dup /reflow-content {box-table-reflow-content} put
|
|
|
1271 |
pop pop
|
|
|
1272 |
} def % =>
|