1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
|
/*
* Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* $Id$ */
package org.apache.fop.fo.flow;
import java.util.BitSet;
import java.util.List;
import org.xml.sax.Locator;
import org.apache.fop.apps.FOPException;
import org.apache.fop.datatypes.ValidationPercentBaseContext;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fo.StaticPropertyList;
import org.apache.fop.fo.ValidationException;
import org.apache.fop.fo.properties.CommonAccessibility;
import org.apache.fop.fo.properties.CommonAural;
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
import org.apache.fop.fo.properties.CommonMarginBlock;
import org.apache.fop.fo.properties.CommonRelativePosition;
import org.apache.fop.fo.properties.KeepProperty;
import org.apache.fop.fo.properties.LengthPairProperty;
import org.apache.fop.fo.properties.LengthRangeProperty;
/**
* Class modelling the fo:table object.
*/
public class Table extends TableFObj {
// The value of properties relevant for fo:table.
private CommonAccessibility commonAccessibility;
private CommonAural commonAural;
private CommonBorderPaddingBackground commonBorderPaddingBackground;
private CommonMarginBlock commonMarginBlock;
private CommonRelativePosition commonRelativePosition;
private LengthRangeProperty blockProgressionDimension;
private int borderCollapse;
private LengthPairProperty borderSeparation;
private int breakAfter;
private int breakBefore;
private String id;
private LengthRangeProperty inlineProgressionDimension;
private int intrusionDisplace;
//private Length height;
private KeepProperty keepTogether;
private KeepProperty keepWithNext;
private KeepProperty keepWithPrevious;
private int tableLayout;
private int tableOmitFooterAtBreak;
private int tableOmitHeaderAtBreak;
//private Length width;
private int writingMode;
// End of property values
private static final int MINCOLWIDTH = 10000; // 10pt
/** collection of columns in this table */
protected List columns = null;
private BitSet usedColumnIndices = new BitSet();
private int columnIndex = 1;
private TableBody tableHeader = null;
private TableBody tableFooter = null;
/** used for validation */
private boolean tableColumnFound = false;
private boolean tableHeaderFound = false;
private boolean tableFooterFound = false;
private boolean tableBodyFound = false;
/**
* Default table-column used when no columns are specified. It is used
* to handle inheritance (especially visibility) and defaults properly. */
private TableColumn defaultColumn;
/**
* @param parent FONode that is the parent of this object
*/
public Table(FONode parent) {
super(parent);
}
/**
* @see org.apache.fop.fo.FObj#bind(PropertyList)
*/
public void bind(PropertyList pList) throws FOPException {
commonAccessibility = pList.getAccessibilityProps();
commonAural = pList.getAuralProps();
commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps();
commonMarginBlock = pList.getMarginBlockProps();
commonRelativePosition = pList.getRelativePositionProps();
blockProgressionDimension = pList.get(PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange();
borderCollapse = pList.get(PR_BORDER_COLLAPSE).getEnum();
borderSeparation = pList.get(PR_BORDER_SEPARATION).getLengthPair();
breakAfter = pList.get(PR_BREAK_AFTER).getEnum();
breakBefore = pList.get(PR_BREAK_BEFORE).getEnum();
id = pList.get(PR_ID).getString();
inlineProgressionDimension = pList.get(PR_INLINE_PROGRESSION_DIMENSION).getLengthRange();
intrusionDisplace = pList.get(PR_INTRUSION_DISPLACE).getEnum();
//height = pList.get(PR_HEIGHT).getLength();
keepTogether = pList.get(PR_KEEP_TOGETHER).getKeep();
keepWithNext = pList.get(PR_KEEP_WITH_NEXT).getKeep();
keepWithPrevious = pList.get(PR_KEEP_WITH_PREVIOUS).getKeep();
tableLayout = pList.get(PR_TABLE_LAYOUT).getEnum();
tableOmitFooterAtBreak = pList.get(PR_TABLE_OMIT_FOOTER_AT_BREAK).getEnum();
tableOmitHeaderAtBreak = pList.get(PR_TABLE_OMIT_HEADER_AT_BREAK).getEnum();
//width = pList.get(PR_WIDTH).getLength();
writingMode = pList.get(PR_WRITING_MODE).getEnum();
super.bind(pList);
//Create default column in case no table-columns will be defined.
defaultColumn = new TableColumn(this, true);
PropertyList colPList = new StaticPropertyList(defaultColumn, pList);
colPList.setWritingMode();
defaultColumn.bind(colPList);
if (borderCollapse != EN_SEPARATE) {
attributeWarning("The collapsing border model on an fo:table "
+ "is currently not supported by FOP");
}
if (tableLayout == EN_AUTO) {
attributeWarning("table-layout=\"auto\" is currently not supported by FOP");
}
if (!isSeparateBorderModel() && getCommonBorderPaddingBackground().hasPadding(
ValidationPercentBaseContext.getPseudoContextForValidationPurposes())) {
//See "17.6.2 The collapsing border model" in CSS2
attributeWarning("In collapsing border model a table does not have padding"
+ " (see http://www.w3.org/TR/REC-CSS2/tables.html#collapsing-borders)"
+ ", but a non-zero value for padding was found. The padding will be ignored.");
}
}
/**
* @see org.apache.fop.fo.FONode#startOfNode
*/
protected void startOfNode() throws FOPException {
checkId(id);
getFOEventHandler().startTable(this);
}
/**
* @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
* XSL Content Model: (marker*,table-column*,table-header?,table-footer?,table-body+)
*/
protected void validateChildNode(Locator loc, String nsURI, String localName)
throws ValidationException {
if (FO_URI.equals(nsURI)) {
if (localName.equals("marker")) {
if (tableColumnFound || tableHeaderFound || tableFooterFound
|| tableBodyFound) {
nodesOutOfOrderError(loc, "fo:marker",
"(table-column*,table-header?,table-footer?,table-body+)");
}
} else if (localName.equals("table-column")) {
tableColumnFound = true;
if (tableHeaderFound || tableFooterFound || tableBodyFound) {
nodesOutOfOrderError(loc, "fo:table-column",
"(table-header?,table-footer?,table-body+)");
}
} else if (localName.equals("table-header")) {
if (tableHeaderFound) {
tooManyNodesError(loc, "table-header");
} else {
tableHeaderFound = true;
if (tableFooterFound || tableBodyFound) {
nodesOutOfOrderError(loc, "fo:table-header",
"(table-footer?,table-body+)");
}
}
} else if (localName.equals("table-footer")) {
if (tableFooterFound) {
tooManyNodesError(loc, "table-footer");
} else {
tableFooterFound = true;
if (tableBodyFound) {
nodesOutOfOrderError(loc, "fo:table-footer",
"(table-body+)");
}
}
} else if (localName.equals("table-body")) {
tableBodyFound = true;
} else {
invalidChildError(loc, nsURI, localName);
}
} else {
invalidChildError(loc, nsURI, localName);
}
}
/**
* @see org.apache.fop.fo.FONode#endOfNode
*/
protected void endOfNode() throws FOPException {
if (!tableBodyFound) {
missingChildElementError(
"(marker*,table-column*,table-header?,table-footer?,table-body+)");
}
//release reference
usedColumnIndices = null;
getFOEventHandler().endTable(this);
}
/**
* @see org.apache.fop.fo.FONode#addChildNode(FONode)
*/
protected void addChildNode(FONode child) throws FOPException {
if ("fo:table-column".equals(child.getName())) {
addColumnNode((TableColumn) child);
} else if ("fo:table-footer".equals(child.getName())) {
tableFooter = (TableBody)child;
} else if ("fo:table-header".equals(child.getName())) {
tableHeader = (TableBody)child;
} else {
// add bodies
super.addChildNode(child);
}
}
/**
* Adds a column to the columns List, and updates the columnIndex
* used for determining initial values for column-number
*
* @param col the column to add
* @throws FOPException
*/
private void addColumnNode(TableColumn col) throws FOPException {
int colNumber = col.getColumnNumber();
int colRepeat = col.getNumberColumnsRepeated();
if (columns == null) {
columns = new java.util.ArrayList();
}
if (columns.size() < colNumber) {
//add nulls for non-occupied indices between
//the last column up to and including the current one
while (columns.size() < colNumber) {
columns.add(null);
}
}
//replace the null-value with the actual column
columns.set(colNumber - 1, col);
if (colRepeat > 1) {
//in case column is repeated:
//for the time being, add the same column
//(colRepeat - 1) times to the columns list
//TODO: need to force the column-number
//TODO: need to make sure START/END BorderInfo
// are completely independent instances (clones?)
// = necessary for border-collapse="collapse"
// if collapsing is handled in FOTree
for (int i = colRepeat - 1; --i >= 0;) {
columns.add(col);
}
}
//flag column indices used by this column
for (int i = colNumber - 1; i < colNumber - 1 + colRepeat; i++) {
usedColumnIndices.set(i);
}
//set index for the next column to use
while (usedColumnIndices.get(columnIndex - 1)) {
columnIndex++;
}
}
/** @return true of table-layout="auto" */
public boolean isAutoLayout() {
return (tableLayout != EN_FIXED);
}
/** @return the default table column */
public TableColumn getDefaultColumn() {
return this.defaultColumn;
}
/** @return the list of table-column elements. */
public List getColumns() {
return columns;
}
/**
* @param index index of the table-body element.
* @return the requested table-body element
*/
public TableBody getBody(int index) {
return (TableBody)childNodes.get(index);
}
/** @return the body for the table-header. */
public TableBody getTableHeader() {
return tableHeader;
}
/** @return the body for the table-footer. */
public TableBody getTableFooter() {
return tableFooter;
}
/** @return true if the table-header should be omitted at breaks */
public boolean omitHeaderAtBreak() {
return (this.tableOmitHeaderAtBreak == EN_TRUE);
}
/** @return true if the table-footer should be omitted at breaks */
public boolean omitFooterAtBreak() {
return (this.tableOmitFooterAtBreak == EN_TRUE);
}
/**
* @return the "inline-progression-dimension" property.
*/
public LengthRangeProperty getInlineProgressionDimension() {
return inlineProgressionDimension;
}
/**
* @return the "block-progression-dimension" property.
*/
public LengthRangeProperty getBlockProgressionDimension() {
return blockProgressionDimension;
}
/**
* @return the Common Margin Properties-Block.
*/
public CommonMarginBlock getCommonMarginBlock() {
return commonMarginBlock;
}
/**
* @return the Common Border, Padding, and Background Properties.
*/
public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
return commonBorderPaddingBackground;
}
/** @return the "break-after" property. */
public int getBreakAfter() {
return breakAfter;
}
/** @return the "break-before" property. */
public int getBreakBefore() {
return breakBefore;
}
/** @return the "keep-with-next" property. */
public KeepProperty getKeepWithNext() {
return keepWithNext;
}
/** @return the "keep-with-previous" property. */
public KeepProperty getKeepWithPrevious() {
return keepWithPrevious;
}
/** @return the "keep-together" property. */
public KeepProperty getKeepTogether() {
return keepTogether;
}
/**
* Convenience method to check if a keep-together constraint is specified.
* @return true if keep-together is active.
*/
public boolean mustKeepTogether() {
return !getKeepTogether().getWithinPage().isAuto()
|| !getKeepTogether().getWithinColumn().isAuto();
}
/** @return the "border-collapse" property. */
public int getBorderCollapse() {
return borderCollapse;
}
/** @return true if the separate border model is active */
public boolean isSeparateBorderModel() {
return (getBorderCollapse() == EN_SEPARATE);
}
/** @return the "border-separation" property. */
public LengthPairProperty getBorderSeparation() {
return borderSeparation;
}
/**
* @return the "id" property.
*/
public String getId() {
return id;
}
/** @see org.apache.fop.fo.FONode#getLocalName() */
public String getLocalName() {
return "table";
}
/**
* @see org.apache.fop.fo.FObj#getNameId()
*/
public int getNameId() {
return FO_TABLE;
}
/**
* Returns the current column index of the Table
*
* @return the next column number to use
*/
public int getCurrentColumnIndex() {
return columnIndex;
}
/**
* Sets the current column index of the given Table
* (used by TableColumn.bind() in case the column-number
* was explicitly specified)
*
* @param newIndex the new value for column index
*/
public void setCurrentColumnIndex(int newIndex) {
columnIndex = newIndex;
}
/**
* Checks if a certain column-number is already occupied
*
* @param colNr the column-number to check
* @return true if column-number is already in use
*/
protected boolean isColumnNumberUsed(int colNr) {
return usedColumnIndices.get(colNr - 1);
}
}
|