Skip to content

Commit 05e147e

Browse files
committed
FOP-2469: Apply FOP-2469-2018-07-17.patch to current main branch
1 parent fb908e1 commit 05e147e

31 files changed

+1983
-81
lines changed

fop-core/src/main/java/org/apache/fop/fo/flow/table/EffRow.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class EffRow {
3838
/** Indicates that the row is the last in a table-body */
3939
public static final int LAST_IN_PART = GridUnit.LAST_IN_PART;
4040

41-
private List gridUnits = new java.util.ArrayList();
41+
private List<GridUnit> gridUnits = new java.util.ArrayList<GridUnit>();
4242
private int index;
4343
/** One of HEADER, FOOTER, BODY */
4444
private int bodyType;
@@ -51,12 +51,12 @@ public class EffRow {
5151
* @param bodyType type of body (one of HEADER, FOOTER, BODY as found on TableRowIterator)
5252
* @param gridUnits the grid units this row is made of
5353
*/
54-
public EffRow(int index, int bodyType, List gridUnits) {
54+
public EffRow(int index, int bodyType, List<GridUnit> gridUnits) {
5555
this.index = index;
5656
this.bodyType = bodyType;
5757
this.gridUnits = gridUnits;
5858
// TODO this is ugly, but we may eventually be able to do without that index
59-
for (Object gu : gridUnits) {
59+
for (GridUnit gu : gridUnits) {
6060
if (gu instanceof PrimaryGridUnit) {
6161
((PrimaryGridUnit) gu).setRowIndex(index);
6262
}
@@ -116,7 +116,7 @@ public void setExplicitHeight(MinOptMax mom) {
116116
}
117117

118118
/** @return the list of GridUnits for this EffRow */
119-
public List getGridUnits() {
119+
public List<GridUnit> getGridUnits() {
120120
return gridUnits;
121121
}
122122

@@ -126,7 +126,7 @@ public List getGridUnits() {
126126
* @return the requested grid unit.
127127
*/
128128
public GridUnit getGridUnit(int column) {
129-
return (GridUnit)gridUnits.get(column);
129+
return gridUnits.get(column);
130130
}
131131

132132
/**
@@ -138,7 +138,7 @@ public GridUnit getGridUnit(int column) {
138138
*/
139139
public GridUnit safelyGetGridUnit(int column) {
140140
if (column < gridUnits.size()) {
141-
return (GridUnit)gridUnits.get(column);
141+
return gridUnits.get(column);
142142
} else {
143143
return null;
144144
}
@@ -173,8 +173,7 @@ public Keep getKeepWithPrevious() {
173173
if (row != null) {
174174
keep = Keep.getKeep(row.getKeepWithPrevious());
175175
}
176-
for (Object gridUnit : gridUnits) {
177-
GridUnit gu = (GridUnit) gridUnit;
176+
for (GridUnit gu : gridUnits) {
178177
if (gu.isPrimary()) {
179178
keep = keep.compare(gu.getPrimary().getKeepWithPrevious());
180179
}
@@ -194,8 +193,7 @@ public Keep getKeepWithNext() {
194193
if (row != null) {
195194
keep = Keep.getKeep(row.getKeepWithNext());
196195
}
197-
for (Object gridUnit : gridUnits) {
198-
GridUnit gu = (GridUnit) gridUnit;
196+
for (GridUnit gu : gridUnits) {
199197
if (!gu.isEmpty() && gu.getColSpanIndex() == 0 && gu.isLastGridUnitRowSpan()) {
200198
keep = keep.compare(gu.getPrimary().getKeepWithNext());
201199
}
@@ -231,8 +229,7 @@ public Keep getKeepTogether() {
231229
*/
232230
public int getBreakBefore() {
233231
int breakBefore = Constants.EN_AUTO;
234-
for (Object gridUnit : gridUnits) {
235-
GridUnit gu = (GridUnit) gridUnit;
232+
for (GridUnit gu : gridUnits) {
236233
if (gu.isPrimary()) {
237234
breakBefore = BreakUtil.compareBreakClasses(breakBefore,
238235
gu.getPrimary().getBreakBefore());
@@ -255,8 +252,7 @@ public int getBreakBefore() {
255252
*/
256253
public int getBreakAfter() {
257254
int breakAfter = Constants.EN_AUTO;
258-
for (Object gridUnit : gridUnits) {
259-
GridUnit gu = (GridUnit) gridUnit;
255+
for (GridUnit gu : gridUnits) {
260256
if (!gu.isEmpty() && gu.getColSpanIndex() == 0 && gu.isLastGridUnitRowSpan()) {
261257
breakAfter = BreakUtil.compareBreakClasses(breakAfter,
262258
gu.getPrimary().getBreakAfter());
@@ -267,7 +263,7 @@ public int getBreakAfter() {
267263

268264
/** {@inheritDoc} */
269265
public String toString() {
270-
StringBuffer sb = new StringBuffer("EffRow {");
266+
StringBuilder sb = new StringBuilder("EffRow {");
271267
sb.append(index);
272268
if (getBodyType() == TableRowIterator.BODY) {
273269
sb.append(" in body");

fop-core/src/main/java/org/apache/fop/fo/flow/table/PrimaryGridUnit.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,9 @@ public int getAfterBorderWidth(int which) {
240240
return getAfterBorderWidth(getCell().getNumberRowsSpanned() - 1, which);
241241
}
242242

243-
/** @return the length of the cell content */
243+
/** @return the length of the cell content, auto-layout disallows caching */
244244
public int getContentLength() {
245-
if (contentLength < 0) {
246-
contentLength = ElementListUtils.calcContentLength(elements);
247-
}
245+
contentLength = ElementListUtils.calcContentLength(elements);
248246
return contentLength;
249247
}
250248

fop-core/src/main/java/org/apache/fop/fo/flow/table/Table.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder, Break
7272
private int tableOmitFooterAtBreak;
7373
private int tableOmitHeaderAtBreak;
7474
private WritingModeTraits writingModeTraits;
75+
76+
// Used to determine when a table has a width attribute
77+
// For example <fo:table ...... width = "100%">
78+
private Length width;
79+
7580
// Unused but valid items, commented out for performance:
7681
// private CommonAural commonAural;
7782
// private CommonRelativePosition commonRelativePosition;
@@ -141,6 +146,7 @@ public void bind(PropertyList pList) throws FOPException {
141146
writingModeTraits = new WritingModeTraits(
142147
WritingMode.valueOf(pList.get(PR_WRITING_MODE).getEnum()),
143148
pList.getExplicit(PR_WRITING_MODE) != null);
149+
width = pList.get(PR_WIDTH).getLength();
144150

145151
//Bind extension properties
146152
widowContentLimit = pList.get(PR_X_WIDOW_CONTENT_LIMIT).getLength();
@@ -152,10 +158,10 @@ public void bind(PropertyList pList) throws FOPException {
152158
eventProducer.nonAutoBPDOnTable(this, getLocator());
153159
// Anyway, the bpd of a table is not used by the layout code
154160
}
155-
if (tableLayout == EN_AUTO) {
161+
/*if (tableLayout == EN_AUTO) {
156162
getFOValidationEventProducer().unimplementedFeature(this, getName(),
157163
"table-layout=\"auto\"", getLocator());
158-
}
164+
}*/
159165
if (!isSeparateBorderModel()) {
160166
if (borderCollapse == EN_COLLAPSE_WITH_PRECEDENCE) {
161167
getFOValidationEventProducer().unimplementedFeature(this, getName(),
@@ -400,6 +406,11 @@ public boolean isAutoLayout() {
400406
return (tableLayout == EN_AUTO);
401407
}
402408

409+
/** @return the table width. It is EN_AUTO when the width attribute is not provided in the <fo:table> tag */
410+
public Length getWidth() {
411+
return width;
412+
}
413+
403414
/**
404415
* Returns the list of table-column elements.
405416
*

fop-core/src/main/java/org/apache/fop/fo/flow/table/TableColumn.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,7 @@ public boolean isHeader() {
275275
return isHeader;
276276
}
277277

278+
public final boolean isAutoLayout() {
279+
return getColumnWidth() instanceof TableColLength;
280+
}
278281
}

fop-core/src/main/java/org/apache/fop/layoutmgr/AbstractBaseLayoutManager.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,14 @@ public boolean isFromFootnote() {
298298
public void setFromFootnote(boolean fromFootnote) {
299299
this.fromFootnote = fromFootnote;
300300
}
301+
302+
/** {@inheritDoc} */
303+
public int getMinimumIPD() {
304+
int minimumIPD = -1;
305+
for (LayoutManager childLM : getChildLMs()) {
306+
int curMinIPD = childLM.getMinimumIPD();
307+
minimumIPD = Math.max(minimumIPD, curMinIPD);
308+
}
309+
return minimumIPD;
310+
}
301311
}

fop-core/src/main/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ private void setupAreaDimensions(LayoutContext context) {
338338

339339
referenceIPD = context.getRefIPD();
340340
if (width.getEnum() == EN_AUTO) {
341-
updateContentAreaIPDwithOverconstrainedAdjust();
341+
updateContentAreaIPDwithOverconstrainedAdjust(context);
342342
} else {
343343
int contentWidth = width.getValue(this);
344344
updateContentAreaIPDwithOverconstrainedAdjust(contentWidth);

fop-core/src/main/java/org/apache/fop/layoutmgr/BlockLayoutManager.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,23 @@ protected List<ListElement> getNextChildElements(LayoutManager childLM, LayoutCo
137137
//Handled already by the parent (break collapsing, see above)
138138
}
139139

140+
List<ListElement> childElements;
141+
140142
if (lmStack == null) {
141-
return childLM.getNextKnuthElements(childLC, alignment);
143+
childElements = childLM.getNextKnuthElements(childLC, alignment);
142144
} else {
143145
if (childLM instanceof LineLayoutManager) {
144146
if (!(restartPosition instanceof LeafPosition)) {
145147
restartPosition = null;
146148
}
147-
return ((LineLayoutManager) childLM).getNextKnuthElements(childLC, alignment,
149+
childElements = ((LineLayoutManager) childLM).getNextKnuthElements(childLC, alignment,
148150
(LeafPosition) restartPosition);
149151
} else {
150-
return childLM.getNextKnuthElements(childLC, alignment,
152+
childElements = childLM.getNextKnuthElements(childLC, alignment,
151153
lmStack, restartPosition, restartAtLM);
152154
}
153155
}
156+
return childElements;
154157
}
155158

156159
private void resetSpaces() {

fop-core/src/main/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ public static BlockLevelEventProducer get(EventBroadcaster broadcaster) {
5858
*/
5959
void rowTooTall(Object source, int row, int effCellBPD, int maxCellBPD, Locator loc);
6060

61+
/**
62+
* The minimal width required for the auto-layout of a table's columns is bigger than the available space.
63+
* Alternatively: even using the minimal width required for the auto-layout table, its content overflows the
64+
* available area by (effIPD - maxIPD) millipoints
65+
* @param source the event source
66+
* @param effIPD the effective extent in inline-progression direction of the table contents
67+
* @param maxIPD the maximum extent in inline-progression direction available
68+
* @param loc the location of the error or null
69+
* @event.severity WARN
70+
*/
71+
void columnsInAutoTableTooWide(Object source, int effIPD, int maxIPD, Locator loc);
72+
6173
/**
6274
* Auto-table layout is not supported, yet.
6375
* @param source the event source

fop-core/src/main/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.fop.fo.properties.KeepProperty;
3838
import org.apache.fop.fo.properties.SpaceProperty;
3939
import org.apache.fop.layoutmgr.inline.InlineContainerLayoutManager;
40+
import org.apache.fop.layoutmgr.inline.LineLayoutManager;
4041
import org.apache.fop.layoutmgr.inline.InlineLayoutManager;
4142
import org.apache.fop.traits.MinOptMax;
4243
import org.apache.fop.util.ListUtil;
@@ -197,10 +198,10 @@ protected int neededUnits(int len) {
197198
*
198199
* @return the resulting content area IPD
199200
*/
200-
protected int updateContentAreaIPDwithOverconstrainedAdjust() {
201+
protected int updateContentAreaIPDwithOverconstrainedAdjust(LayoutContext context) {
201202
int ipd = referenceIPD - (startIndent + endIndent);
202-
if (ipd < 0) {
203-
//5.3.4, XSL 1.0, Overconstrained Geometry
203+
if (ipd < 0 && !context.isChildOfAutoLayoutElement()) {
204+
//5.3.4, XSL 1.1, Overconstrained Geometry
204205
log.debug("Adjusting end-indent based on overconstrained geometry rules for " + fobj);
205206
BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get(
206207
getFObj().getUserAgent().getEventBroadcaster());
@@ -223,7 +224,7 @@ protected int updateContentAreaIPDwithOverconstrainedAdjust() {
223224
protected int updateContentAreaIPDwithOverconstrainedAdjust(int contentIPD) {
224225
int ipd = referenceIPD - (contentIPD + (startIndent + endIndent));
225226
if (ipd < 0) {
226-
//5.3.4, XSL 1.0, Overconstrained Geometry
227+
//5.3.4, XSL 1.1, Overconstrained Geometry
227228
log.debug("Adjusting end-indent based on overconstrained geometry rules for " + fobj);
228229
BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get(
229230
getFObj().getUserAgent().getEventBroadcaster());
@@ -247,7 +248,7 @@ public List<ListElement> getNextKnuthElements(LayoutContext context, int alignme
247248
Stack lmStack, Position restartPosition, LayoutManager restartAtLM) {
248249
isRestartAtLM = restartAtLM != null;
249250
referenceIPD = context.getRefIPD();
250-
updateContentAreaIPDwithOverconstrainedAdjust();
251+
updateContentAreaIPDwithOverconstrainedAdjust(context);
251252

252253
boolean isRestart = (lmStack != null);
253254
boolean emptyStack = (!isRestart || lmStack.isEmpty());
@@ -299,6 +300,17 @@ public List<ListElement> getNextKnuthElements(LayoutContext context, int alignme
299300
emptyStack = true;
300301
}
301302

303+
final int ipd = childLC.getRefIPD();
304+
if (getContentAreaIPD() < ipd && context.isChildOfAutoLayoutElement()) {
305+
if (currentChildLM instanceof LineLayoutManager) {
306+
referenceIPD = startIndent + ipd + endIndent;
307+
} else {
308+
referenceIPD = ipd;
309+
}
310+
updateContentAreaIPDwithOverconstrainedAdjust(context);
311+
context.setRefIPD(this.referenceIPD);
312+
}
313+
302314
if (contentList.isEmpty()) {
303315
// propagate keep-with-previous up from the first child
304316
context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
@@ -387,7 +399,7 @@ public List<ListElement> getNextKnuthElements(LayoutContext context, int alignme
387399
* @return a new child layout context
388400
*/
389401
protected LayoutContext makeChildLayoutContext(LayoutContext context) {
390-
LayoutContext childLC = LayoutContext.newInstance();
402+
LayoutContext childLC = LayoutContext.offspringOf(context);
391403
childLC.copyPendingMarksFrom(context);
392404
childLC.setStackLimitBP(context.getStackLimitBP());
393405
childLC.setRefIPD(referenceIPD);

fop-core/src/main/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@ protected KnuthNode getNode(int line) {
14051405
* @return the width/length in millipoints
14061406
*/
14071407
protected int getLineWidth(int line) {
1408-
assert lineWidth >= 0;
1408+
// assert lineWidth >= 0;
14091409
return this.lineWidth;
14101410
}
14111411

0 commit comments

Comments
 (0)