Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions fop-core/src/main/java/org/apache/fop/fo/flow/table/EffRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class EffRow {
/** Indicates that the row is the last in a table-body */
public static final int LAST_IN_PART = GridUnit.LAST_IN_PART;

private List gridUnits = new java.util.ArrayList();
private List<GridUnit> gridUnits = new java.util.ArrayList<GridUnit>();
private int index;
/** One of HEADER, FOOTER, BODY */
private int bodyType;
Expand All @@ -51,12 +51,12 @@ public class EffRow {
* @param bodyType type of body (one of HEADER, FOOTER, BODY as found on TableRowIterator)
* @param gridUnits the grid units this row is made of
*/
public EffRow(int index, int bodyType, List gridUnits) {
public EffRow(int index, int bodyType, List<GridUnit> gridUnits) {
this.index = index;
this.bodyType = bodyType;
this.gridUnits = gridUnits;
// TODO this is ugly, but we may eventually be able to do without that index
for (Object gu : gridUnits) {
for (GridUnit gu : gridUnits) {
if (gu instanceof PrimaryGridUnit) {
((PrimaryGridUnit) gu).setRowIndex(index);
}
Expand Down Expand Up @@ -116,7 +116,7 @@ public void setExplicitHeight(MinOptMax mom) {
}

/** @return the list of GridUnits for this EffRow */
public List getGridUnits() {
public List<GridUnit> getGridUnits() {
return gridUnits;
}

Expand All @@ -126,7 +126,7 @@ public List getGridUnits() {
* @return the requested grid unit.
*/
public GridUnit getGridUnit(int column) {
return (GridUnit)gridUnits.get(column);
return gridUnits.get(column);
}

/**
Expand All @@ -138,7 +138,7 @@ public GridUnit getGridUnit(int column) {
*/
public GridUnit safelyGetGridUnit(int column) {
if (column < gridUnits.size()) {
return (GridUnit)gridUnits.get(column);
return gridUnits.get(column);
} else {
return null;
}
Expand Down Expand Up @@ -173,8 +173,7 @@ public Keep getKeepWithPrevious() {
if (row != null) {
keep = Keep.getKeep(row.getKeepWithPrevious());
}
for (Object gridUnit : gridUnits) {
GridUnit gu = (GridUnit) gridUnit;
for (GridUnit gu : gridUnits) {
if (gu.isPrimary()) {
keep = keep.compare(gu.getPrimary().getKeepWithPrevious());
}
Expand All @@ -194,8 +193,7 @@ public Keep getKeepWithNext() {
if (row != null) {
keep = Keep.getKeep(row.getKeepWithNext());
}
for (Object gridUnit : gridUnits) {
GridUnit gu = (GridUnit) gridUnit;
for (GridUnit gu : gridUnits) {
if (!gu.isEmpty() && gu.getColSpanIndex() == 0 && gu.isLastGridUnitRowSpan()) {
keep = keep.compare(gu.getPrimary().getKeepWithNext());
}
Expand Down Expand Up @@ -231,8 +229,7 @@ public Keep getKeepTogether() {
*/
public int getBreakBefore() {
int breakBefore = Constants.EN_AUTO;
for (Object gridUnit : gridUnits) {
GridUnit gu = (GridUnit) gridUnit;
for (GridUnit gu : gridUnits) {
if (gu.isPrimary()) {
breakBefore = BreakUtil.compareBreakClasses(breakBefore,
gu.getPrimary().getBreakBefore());
Expand All @@ -255,8 +252,7 @@ public int getBreakBefore() {
*/
public int getBreakAfter() {
int breakAfter = Constants.EN_AUTO;
for (Object gridUnit : gridUnits) {
GridUnit gu = (GridUnit) gridUnit;
for (GridUnit gu : gridUnits) {
if (!gu.isEmpty() && gu.getColSpanIndex() == 0 && gu.isLastGridUnitRowSpan()) {
breakAfter = BreakUtil.compareBreakClasses(breakAfter,
gu.getPrimary().getBreakAfter());
Expand All @@ -267,7 +263,7 @@ public int getBreakAfter() {

/** {@inheritDoc} */
public String toString() {
StringBuffer sb = new StringBuffer("EffRow {");
StringBuilder sb = new StringBuilder("EffRow {");
sb.append(index);
if (getBodyType() == TableRowIterator.BODY) {
sb.append(" in body");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,9 @@ public int getAfterBorderWidth(int which) {
return getAfterBorderWidth(getCell().getNumberRowsSpanned() - 1, which);
}

/** @return the length of the cell content */
/** @return the length of the cell content, auto-layout disallows caching */
public int getContentLength() {
if (contentLength < 0) {
contentLength = ElementListUtils.calcContentLength(elements);
}
contentLength = ElementListUtils.calcContentLength(elements);
return contentLength;
}

Expand Down
15 changes: 13 additions & 2 deletions fop-core/src/main/java/org/apache/fop/fo/flow/table/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder, Break
private int tableOmitFooterAtBreak;
private int tableOmitHeaderAtBreak;
private WritingModeTraits writingModeTraits;

// Used to determine when a table has a width attribute
// For example <fo:table ...... width = "100%">
private Length width;

// Unused but valid items, commented out for performance:
// private CommonAural commonAural;
// private CommonRelativePosition commonRelativePosition;
Expand Down Expand Up @@ -141,6 +146,7 @@ public void bind(PropertyList pList) throws FOPException {
writingModeTraits = new WritingModeTraits(
WritingMode.valueOf(pList.get(PR_WRITING_MODE).getEnum()),
pList.getExplicit(PR_WRITING_MODE) != null);
width = pList.get(PR_WIDTH).getLength();

//Bind extension properties
widowContentLimit = pList.get(PR_X_WIDOW_CONTENT_LIMIT).getLength();
Expand All @@ -152,10 +158,10 @@ public void bind(PropertyList pList) throws FOPException {
eventProducer.nonAutoBPDOnTable(this, getLocator());
// Anyway, the bpd of a table is not used by the layout code
}
if (tableLayout == EN_AUTO) {
/*if (tableLayout == EN_AUTO) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete the commented-out code.

getFOValidationEventProducer().unimplementedFeature(this, getName(),
"table-layout=\"auto\"", getLocator());
}
}*/
if (!isSeparateBorderModel()) {
if (borderCollapse == EN_COLLAPSE_WITH_PRECEDENCE) {
getFOValidationEventProducer().unimplementedFeature(this, getName(),
Expand Down Expand Up @@ -400,6 +406,11 @@ public boolean isAutoLayout() {
return (tableLayout == EN_AUTO);
}

/** @return the table width. It is EN_AUTO when the width attribute is not provided in the <fo:table> tag */
public Length getWidth() {
return width;
}

/**
* Returns the list of table-column elements.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,7 @@ public boolean isHeader() {
return isHeader;
}

public final boolean isAutoLayout() {
return getColumnWidth() instanceof TableColLength;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,14 @@ public boolean isFromFootnote() {
public void setFromFootnote(boolean fromFootnote) {
this.fromFootnote = fromFootnote;
}

/** {@inheritDoc} */
public int getMinimumIPD() {
int minimumIPD = -1;
for (LayoutManager childLM : getChildLMs()) {
int curMinIPD = childLM.getMinimumIPD();
minimumIPD = Math.max(minimumIPD, curMinIPD);
}
return minimumIPD;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private void setupAreaDimensions(LayoutContext context) {

referenceIPD = context.getRefIPD();
if (width.getEnum() == EN_AUTO) {
updateContentAreaIPDwithOverconstrainedAdjust();
updateContentAreaIPDwithOverconstrainedAdjust(context);
} else {
int contentWidth = width.getValue(this);
updateContentAreaIPDwithOverconstrainedAdjust(contentWidth);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,23 @@ protected List<ListElement> getNextChildElements(LayoutManager childLM, LayoutCo
//Handled already by the parent (break collapsing, see above)
}

List<ListElement> childElements;

if (lmStack == null) {
return childLM.getNextKnuthElements(childLC, alignment);
childElements = childLM.getNextKnuthElements(childLC, alignment);
} else {
if (childLM instanceof LineLayoutManager) {
if (!(restartPosition instanceof LeafPosition)) {
restartPosition = null;
}
return ((LineLayoutManager) childLM).getNextKnuthElements(childLC, alignment,
childElements = ((LineLayoutManager) childLM).getNextKnuthElements(childLC, alignment,
(LeafPosition) restartPosition);
} else {
return childLM.getNextKnuthElements(childLC, alignment,
childElements = childLM.getNextKnuthElements(childLC, alignment,
lmStack, restartPosition, restartAtLM);
}
}
return childElements;
}

private void resetSpaces() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ public static BlockLevelEventProducer get(EventBroadcaster broadcaster) {
*/
void rowTooTall(Object source, int row, int effCellBPD, int maxCellBPD, Locator loc);

/**
* The minimal width required for the auto-layout of a table's columns is bigger than the available space.
* Alternatively: even using the minimal width required for the auto-layout table, its content overflows the
* available area by (effIPD - maxIPD) millipoints
* @param source the event source
* @param effIPD the effective extent in inline-progression direction of the table contents
* @param maxIPD the maximum extent in inline-progression direction available
* @param loc the location of the error or null
* @event.severity WARN
*/
void columnsInAutoTableTooWide(Object source, int effIPD, int maxIPD, Locator loc);

/**
* Auto-table layout is not supported, yet.
* @param source the event source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.fop.fo.properties.KeepProperty;
import org.apache.fop.fo.properties.SpaceProperty;
import org.apache.fop.layoutmgr.inline.InlineContainerLayoutManager;
import org.apache.fop.layoutmgr.inline.LineLayoutManager;
import org.apache.fop.layoutmgr.inline.InlineLayoutManager;
import org.apache.fop.traits.MinOptMax;
import org.apache.fop.util.ListUtil;
Expand Down Expand Up @@ -197,10 +198,10 @@ protected int neededUnits(int len) {
*
* @return the resulting content area IPD
*/
protected int updateContentAreaIPDwithOverconstrainedAdjust() {
protected int updateContentAreaIPDwithOverconstrainedAdjust(LayoutContext context) {
int ipd = referenceIPD - (startIndent + endIndent);
if (ipd < 0) {
//5.3.4, XSL 1.0, Overconstrained Geometry
if (ipd < 0 && !context.isChildOfAutoLayoutElement()) {
//5.3.4, XSL 1.1, Overconstrained Geometry
log.debug("Adjusting end-indent based on overconstrained geometry rules for " + fobj);
BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get(
getFObj().getUserAgent().getEventBroadcaster());
Expand All @@ -223,7 +224,7 @@ protected int updateContentAreaIPDwithOverconstrainedAdjust() {
protected int updateContentAreaIPDwithOverconstrainedAdjust(int contentIPD) {
int ipd = referenceIPD - (contentIPD + (startIndent + endIndent));
if (ipd < 0) {
//5.3.4, XSL 1.0, Overconstrained Geometry
//5.3.4, XSL 1.1, Overconstrained Geometry
log.debug("Adjusting end-indent based on overconstrained geometry rules for " + fobj);
BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get(
getFObj().getUserAgent().getEventBroadcaster());
Expand All @@ -247,7 +248,7 @@ public List<ListElement> getNextKnuthElements(LayoutContext context, int alignme
Stack lmStack, Position restartPosition, LayoutManager restartAtLM) {
isRestartAtLM = restartAtLM != null;
referenceIPD = context.getRefIPD();
updateContentAreaIPDwithOverconstrainedAdjust();
updateContentAreaIPDwithOverconstrainedAdjust(context);

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

final int ipd = childLC.getRefIPD();
if (getContentAreaIPD() < ipd && context.isChildOfAutoLayoutElement()) {
if (currentChildLM instanceof LineLayoutManager) {
referenceIPD = startIndent + ipd + endIndent;
} else {
referenceIPD = ipd;
}
updateContentAreaIPDwithOverconstrainedAdjust(context);
context.setRefIPD(this.referenceIPD);
}

if (contentList.isEmpty()) {
// propagate keep-with-previous up from the first child
context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
Expand Down Expand Up @@ -387,7 +399,7 @@ public List<ListElement> getNextKnuthElements(LayoutContext context, int alignme
* @return a new child layout context
*/
protected LayoutContext makeChildLayoutContext(LayoutContext context) {
LayoutContext childLC = LayoutContext.newInstance();
LayoutContext childLC = LayoutContext.offspringOf(context);
childLC.copyPendingMarksFrom(context);
childLC.setStackLimitBP(context.getStackLimitBP());
childLC.setRefIPD(referenceIPD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,7 @@ protected KnuthNode getNode(int line) {
* @return the width/length in millipoints
*/
protected int getLineWidth(int line) {
assert lineWidth >= 0;
// assert lineWidth >= 0;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What could be the reason for commenting out this assertion?

return this.lineWidth;
}

Expand Down
Loading