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
|
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.table;
import org.apache.fop.apps.FOPException;
import org.apache.fop.datatypes.Numeric;
import org.apache.fop.datatypes.ValidationPercentBaseContext;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fo.expr.PropertyException;
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
import org.apache.fop.fo.properties.EnumNumber;
import org.apache.fop.fo.properties.EnumProperty;
import org.apache.fop.fo.properties.NumberProperty;
import org.apache.fop.fo.properties.Property;
import org.apache.fop.fo.properties.PropertyMaker;
import org.apache.fop.layoutmgr.table.CollapsingBorderModel;
/**
* Common base class for table-related FOs
*/
public abstract class TableFObj extends FObj {
private Numeric borderAfterPrecedence;
private Numeric borderBeforePrecedence;
private Numeric borderEndPrecedence;
private Numeric borderStartPrecedence;
ConditionalBorder borderBefore;
ConditionalBorder borderAfter;
BorderSpecification borderStart;
BorderSpecification borderEnd;
CollapsingBorderModel collapsingBorderModel;
/**
* Main constructor
*
* @param parent the parent node
*/
public TableFObj(FONode parent) {
super(parent);
}
/** {@inheritDoc} */
public void bind(PropertyList pList) throws FOPException {
super.bind(pList);
borderAfterPrecedence = pList.get(PR_BORDER_AFTER_PRECEDENCE).getNumeric();
borderBeforePrecedence = pList.get(PR_BORDER_BEFORE_PRECEDENCE).getNumeric();
borderEndPrecedence = pList.get(PR_BORDER_END_PRECEDENCE).getNumeric();
borderStartPrecedence = pList.get(PR_BORDER_START_PRECEDENCE).getNumeric();
if (getNameId() != FO_TABLE //Separate check for fo:table in Table.java
&& getNameId() != FO_TABLE_CELL
&& getCommonBorderPaddingBackground().hasPadding(
ValidationPercentBaseContext.getPseudoContext())) {
TableEventProducer eventProducer = TableEventProducer.Provider.get(
getUserAgent().getEventBroadcaster());
eventProducer.paddingNotApplicable(this, getName(), getLocator());
}
}
/**
*
* @param side the side for which to return the border precedence
* @return the "border-precedence" value for the given side
*/
public Numeric getBorderPrecedence(int side) {
switch (side) {
case CommonBorderPaddingBackground.BEFORE:
return borderBeforePrecedence;
case CommonBorderPaddingBackground.AFTER:
return borderAfterPrecedence;
case CommonBorderPaddingBackground.START:
return borderStartPrecedence;
case CommonBorderPaddingBackground.END:
return borderEndPrecedence;
default:
return null;
}
}
/**
* Convenience method to returns a reference
* to the base Table instance
*
* @return the base table instance
*
*/
public Table getTable() {
// Will be overridden in Table; for any other Table-node, recursive call to
// parent.getTable()
return ((TableFObj) parent).getTable();
}
/**
* @return the Common Border, Padding, and Background Properties.
*/
public abstract CommonBorderPaddingBackground getCommonBorderPaddingBackground();
/**
* PropertyMaker subclass for the column-number property
*
*/
public static class ColumnNumberPropertyMaker extends PropertyMaker {
/**
* Constructor
* @param propId the id of the property for which the maker should
* be created
*/
public ColumnNumberPropertyMaker(int propId) {
super(propId);
}
/** {@inheritDoc} */
public Property make(PropertyList propertyList)
throws PropertyException {
FObj fo = propertyList.getFObj();
return NumberProperty.getInstance(((ColumnNumberManagerHolder) fo.getParent())
.getColumnNumberManager().getCurrentColumnNumber());
}
/**
* Check the value of the column-number property.
* Return the parent's column index (initial value) in case
* of a negative or zero value
*
* @see org.apache.fop.fo.properties.PropertyMaker#make(PropertyList, String, FObj)
*/
public Property make(PropertyList propertyList, String value, FObj fo)
throws PropertyException {
Property p = super.make(propertyList, value, fo);
ColumnNumberManagerHolder parent
= (ColumnNumberManagerHolder) propertyList.getParentFObj();
ColumnNumberManager columnIndexManager = parent.getColumnNumberManager();
int columnIndex = p.getNumeric().getValue();
int colSpan = propertyList.get(Constants.PR_NUMBER_COLUMNS_SPANNED)
.getNumeric().getValue();
int lastIndex = columnIndex - 1 + colSpan;
for (int i = columnIndex; i <= lastIndex; ++i) {
if (columnIndexManager.isColumnNumberUsed(i)) {
/* if column-number is already in use by another
* cell/column => error!
*/
TableEventProducer eventProducer = TableEventProducer.Provider.get(
fo.getUserAgent().getEventBroadcaster());
eventProducer.cellOverlap(this, propertyList.getFObj().getName(),
i, fo.getLocator());
}
}
return p;
}
/**
* If the value is not positive, return a property whose value is the next column number
*
* {@inheritDoc}
*/
public Property convertProperty(Property p,
PropertyList propertyList, FObj fo)
throws PropertyException {
if (p instanceof EnumProperty) {
return EnumNumber.getInstance(p);
}
Number val = p.getNumber();
if (val != null) {
int i = Math.round(val.floatValue());
if (i <= 0) {
ColumnNumberManagerHolder parent =
(ColumnNumberManagerHolder) propertyList.getParentFObj();
ColumnNumberManager columnIndexManager = parent.getColumnNumberManager();
i = columnIndexManager.getCurrentColumnNumber();
TableEventProducer eventProducer =
TableEventProducer.Provider.get(fo.getUserAgent().getEventBroadcaster());
eventProducer.forceNextColumnNumber(this, propertyList.getFObj().getName(),
val, i, fo.getLocator());
}
return NumberProperty.getInstance(i);
}
return convertPropertyDatatype(p, propertyList, fo);
}
}
/** {@inheritDoc} */
public void startOfNode() throws FOPException {
super.startOfNode();
Table table = getTable();
if (!inMarker() && !table.isSeparateBorderModel()) {
collapsingBorderModel = CollapsingBorderModel.getBorderModelFor(table
.getBorderCollapse());
setCollapsedBorders();
}
}
/*
* TODO made public so that RetrieveMarker can access it.
*/
/** {@inheritDoc} */
public void endOfNode() throws FOPException {
super.endOfNode();
}
/**
* Prepares the borders of this element if the collapsing-border model is in use.
* Conflict resolution with parent elements is done where applicable.
*/
protected void setCollapsedBorders() {
createBorder(CommonBorderPaddingBackground.START);
createBorder(CommonBorderPaddingBackground.END);
createBorder(CommonBorderPaddingBackground.BEFORE);
createBorder(CommonBorderPaddingBackground.AFTER);
}
/**
* Creates a BorderSpecification from the border set on the given side. If no border
* is set, a BorderSpecification with border-style none is created.
*
* @param side one of CommonBorderPaddingBackground.BEFORE|AFTER|START|END
*/
private void createBorder(int side) {
BorderSpecification borderSpec = new BorderSpecification(
getCommonBorderPaddingBackground().getBorderInfo(side), getNameId());
switch (side) {
case CommonBorderPaddingBackground.BEFORE:
borderBefore = new ConditionalBorder(borderSpec, collapsingBorderModel);
break;
case CommonBorderPaddingBackground.AFTER:
borderAfter = new ConditionalBorder(borderSpec, collapsingBorderModel);
break;
case CommonBorderPaddingBackground.START:
borderStart = borderSpec;
break;
case CommonBorderPaddingBackground.END:
borderEnd = borderSpec;
break;
default: assert false;
}
}
}
|