Skip to content

Commit

Permalink
#379 Revert "Overcoming Table Cell and Line Splitting Challenges (#358)"
Browse files Browse the repository at this point in the history
This reverts commit aec1510.

* That commit caused issue #379, and I could not find a solution for it.
* Just in case, here is PR for reproducing issue #379: #380
  • Loading branch information
asolntsev committed Sep 20, 2024
1 parent dea0e49 commit 1fb9b48
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ public void calcCollapsedBorder(CssContext c) {
_collapsedPaintingBorder = new BorderPropertySet(top, right, bottom, left);

// Give the extra pixel to top and left.
top.setWidth((top.width() + 1) / 2);
right.setWidth(right.width() / 2);
bottom.setWidth(bottom.width() / 2);
left.setWidth((left.width() + 1) / 2);
top.setWidth((top.width()+1)/2);
right.setWidth(right.width()/2);
bottom.setWidth(bottom.width()/2);
left.setWidth((left.width()+1)/2);

_collapsedLayoutBorder = new BorderPropertySet(top, right, bottom, left);

Expand Down Expand Up @@ -146,14 +146,14 @@ public void layout(LayoutContext c) {
public TableBox getTable() {
// cell -> row -> section -> table
if (_table == null) {
_table = (TableBox) getParent().getParent().getParent();
_table = (TableBox)getParent().getParent().getParent();
}
return _table;
}

protected TableSectionBox getSection() {
if (_section == null) {
_section = (TableSectionBox) getParent().getParent();
_section = (TableSectionBox)getParent().getParent();
}
return _section;
}
Expand All @@ -166,10 +166,10 @@ public Length getOuterStyleWidth(CssContext c) {

int bordersAndPadding = 0;
BorderPropertySet border = getBorder(c);
bordersAndPadding += (int) border.left() + (int) border.right();
bordersAndPadding += (int)border.left() + (int)border.right();

RectPropertySet padding = getPadding(c);
bordersAndPadding += (int) padding.left() + (int) padding.right();
bordersAndPadding += (int)padding.left() + (int)padding.right();

result.setValue(result.value() + bordersAndPadding);

Expand All @@ -178,7 +178,7 @@ public Length getOuterStyleWidth(CssContext c) {

public Length getOuterStyleOrColWidth(CssContext c) {
Length result = getOuterStyleWidth(c);
if (getStyle().getColSpan() > 1 || !result.isVariable()) {
if (getStyle().getColSpan() > 1 || ! result.isVariable()) {
return result;
}
TableColumn col = getTable().colElement(getCol());
Expand All @@ -197,7 +197,7 @@ public void setLayoutWidth(LayoutContext c, int width) {

@Override
public boolean isAutoHeight() {
return getStyle().isAutoHeight() || !getStyle().hasAbsoluteUnit(CSSName.HEIGHT);
return getStyle().isAutoHeight() || ! getStyle().hasAbsoluteUnit(CSSName.HEIGHT);
}

@Override
Expand All @@ -207,7 +207,7 @@ public int calcBaseline(LayoutContext c) {
return result;
} else {
Rectangle contentArea = getContentAreaEdge(getAbsX(), getAbsY(), c);
return (int) contentArea.getY();
return (int)contentArea.getY();
}
}

Expand All @@ -228,7 +228,7 @@ public void moveContent(final int deltaY) {
}

public boolean isPageBreaksChange(LayoutContext c, int posDeltaY) {
if (!c.isPageBreaksAllowed()) {
if (! c.isPageBreaksAllowed()) {
return false;
}

Expand Down Expand Up @@ -298,23 +298,23 @@ bounds, getTable().getColumnBounds(c, getCol()),
imageContainer.y += tableStyle.getBorderVSpacing(c);
imageContainer.height -= tableStyle.getBorderVSpacing(c);
imageContainer.x += tableStyle.getBorderHSpacing(c);
imageContainer.width -= 2 * tableStyle.getBorderHSpacing(c);
imageContainer.width -= 2*tableStyle.getBorderHSpacing(c);

c.getOutputDevice().paintBackground(c, sectionStyle, bounds, imageContainer, sectionStyle.getBorder(c));

CalculatedStyle rowStyle = row.getStyle();

imageContainer = row.getPaintingBorderEdge(c);
imageContainer.x += tableStyle.getBorderHSpacing(c);
imageContainer.width -= 2 * tableStyle.getBorderHSpacing(c);
imageContainer.width -= 2*tableStyle.getBorderHSpacing(c);

c.getOutputDevice().paintBackground(c, rowStyle, bounds, imageContainer, rowStyle.getBorder(c));
c.getOutputDevice().paintBackground(c, getStyle(), bounds, getPaintingBorderEdge(c), border);
}

@Override
public void paintBorder(RenderingContext c) {
if (isPaintBackgroundsAndBorders() && !hasCollapsedPaintingBorder()) {
if (isPaintBackgroundsAndBorders() && ! hasCollapsedPaintingBorder()) {
// Collapsed table borders are painted separately
if (c.isPrint() && getTable().getStyle().isPaginateTable() && getStyle().isVisible()) {
Rectangle bounds = getContentLimitedBorderEdge(c);
Expand All @@ -340,7 +340,7 @@ private Rectangle getContentLimitedBorderEdge(RenderingContext c) {
return result;
}

ContentLimitContainer contentLimitContainer = ((TableRowBox) getParent()).getContentLimitContainer();
ContentLimitContainer contentLimitContainer = ((TableRowBox)getParent()).getContentLimitContainer();
ContentLimit limit = contentLimitContainer != null ? contentLimitContainer.getContentLimit(c.getPageNo()) : null;

if (limit == null) {
Expand All @@ -355,14 +355,14 @@ private Rectangle getContentLimitedBorderEdge(RenderingContext c) {
if (c.getPageNo() == contentLimitContainer.getInitialPageNo()) {
top = result.y;
} else {
top = limit.getTop() - ((TableRowBox) getParent()).getExtraSpaceTop();
top = limit.getTop() - ((TableRowBox)getParent()).getExtraSpaceTop() ;
}

int bottom;
if (c.getPageNo() == contentLimitContainer.getLastPageNo()) {
bottom = result.y + result.height;
} else {
bottom = limit.getBottom() + ((TableRowBox) getParent()).getExtraSpaceBottom();
bottom = limit.getBottom() + ((TableRowBox)getParent()).getExtraSpaceBottom();
}

result.y = top;
Expand All @@ -379,8 +379,8 @@ public Rectangle getChildrenClipEdge(RenderingContext c) {
if (bounds != null) {
BorderPropertySet border = getBorder(c);
RectPropertySet padding = getPadding(c);
bounds.y += (int) border.top() + (int) padding.top();
bounds.height -= (int) border.height() + (int) padding.height();
bounds.y += (int)border.top() + (int)padding.top();
bounds.height -= (int)border.height() + (int)padding.height();
return bounds;
}
}
Expand Down Expand Up @@ -423,7 +423,7 @@ protected boolean isSkipWhenCollapsingMargins() {
// is used when two elements of the same type disagree.
public static CollapsedBorderValue compareBorders(
CollapsedBorderValue border1, CollapsedBorderValue border2, boolean returnNullOnEqual) {
// Sanity check the values passed in. If either is null, return the other.
// Sanity check the values passed in. If either is null, return the other.
if (!border2.defined()) {
return border1;
}
Expand Down Expand Up @@ -519,9 +519,6 @@ private CollapsedBorderValue collapsedLeftBorder(CssContext c) {

// (6) The previous column's right border.
if (getCol() > 0) {
if (getStyle().getRowSpan() > 1) {
return result;
}
colElt = getTable().colElement(getCol() - 1);
if (colElt != null) {
result = compareBorders(
Expand Down Expand Up @@ -559,9 +556,6 @@ private CollapsedBorderValue collapsedRightBorder(CssContext c) {

// (2) The next cell's left border.
if (!inLastColumn) {
if (getStyle().getRowSpan() > 1) {
return result;
}
TableCellBox nextCell = tableElt.cellRight(this);
if (nextCell != null) {
result = compareBorders(result,
Expand Down Expand Up @@ -652,7 +646,7 @@ private CollapsedBorderValue collapsedTopBorder(CssContext c) {

if (prevRow != null) {
result = compareBorders(result,
CollapsedBorderValue.borderBottom(prevRow.getStyle().getBorder(c), BROW));
CollapsedBorderValue.borderBottom(prevRow.getStyle().getBorder(c), BROW));
if (result.hidden()) {
return result;
}
Expand All @@ -664,7 +658,7 @@ private CollapsedBorderValue collapsedTopBorder(CssContext c) {
if (getRow() == 0) {
// (5) Our row group's top border.
result = compareBorders(result,
CollapsedBorderValue.borderTop(currSection.getStyle().getBorder(c), BROWGROUP));
CollapsedBorderValue.borderTop(currSection.getStyle().getBorder(c), BROWGROUP));
if (result.hidden()) {
return result;
}
Expand All @@ -673,7 +667,7 @@ private CollapsedBorderValue collapsedTopBorder(CssContext c) {
currSection = getTable().sectionAbove(currSection, false);
if (currSection != null) {
result = compareBorders(result,
CollapsedBorderValue.borderBottom(currSection.getStyle().getBorder(c), BROWGROUP));
CollapsedBorderValue.borderBottom(currSection.getStyle().getBorder(c), BROWGROUP));
if (result.hidden()) {
return result;
}
Expand Down Expand Up @@ -728,7 +722,7 @@ private CollapsedBorderValue collapsedBottomBorder(CssContext c) {
// (4) The next row's top border.
if (nextCell != null) {
result = compareBorders(result,
CollapsedBorderValue.borderTop(nextCell.getParent().getStyle().getBorder(c), BROW));
CollapsedBorderValue.borderTop(nextCell.getParent().getStyle().getBorder(c), BROW));
if (result.hidden()) {
return result;
}
Expand All @@ -739,7 +733,7 @@ private CollapsedBorderValue collapsedBottomBorder(CssContext c) {
if (getRow() + getStyle().getRowSpan() >= currSection.numRows()) {
// (5) Our row group's bottom border.
result = compareBorders(result,
CollapsedBorderValue.borderBottom(currSection.getStyle().getBorder(c), BROWGROUP));
CollapsedBorderValue.borderBottom(currSection.getStyle().getBorder(c), BROWGROUP));
if (result.hidden()) {
return result;
}
Expand All @@ -748,7 +742,7 @@ private CollapsedBorderValue collapsedBottomBorder(CssContext c) {
currSection = getTable().sectionBelow(currSection, false);
if (currSection != null) {
result = compareBorders(result,
CollapsedBorderValue.borderTop(currSection.getStyle().getBorder(c), BROWGROUP));
CollapsedBorderValue.borderTop(currSection.getStyle().getBorder(c), BROWGROUP));
if (result.hidden()) {
return result;
}
Expand All @@ -760,15 +754,15 @@ private CollapsedBorderValue collapsedBottomBorder(CssContext c) {
TableColumn colElt = getTable().colElement(getCol());
if (colElt != null) {
result = compareBorders(result,
CollapsedBorderValue.borderBottom(colElt.getStyle().getBorder(c), BCOL));
CollapsedBorderValue.borderBottom(colElt.getStyle().getBorder(c), BCOL));
if (result.hidden()) {
return result;
}
}

// (9) The table's bottom border.
result = compareBorders(result,
CollapsedBorderValue.borderBottom(getTable().getStyle().getBorder(c), BTABLE));
CollapsedBorderValue.borderBottom(getTable().getStyle().getBorder(c), BTABLE));
if (result.hidden()) {
return result;
}
Expand Down Expand Up @@ -844,7 +838,7 @@ public void addCollapsedBorders(Set<CollapsedBorderValue> all, List<CollapsedBor
}

// Treat height as if it specifies border height (i.e.
// box-sizing: border-box in CSS3). There doesn't seem to be any
// box-sizing: border-box in CSS3). There doesn't seem to be any
// justification in the spec for this, but everybody does it
// (in standards mode) so I guess we will too
@Override
Expand All @@ -856,10 +850,10 @@ protected int getCSSHeight(CssContext c) {
CSSName.HEIGHT, getContainingBlock().getContentWidth(), c);

BorderPropertySet border = getBorder(c);
result -= (int) border.top() + (int) border.bottom();
result -= (int)border.top() + (int)border.bottom();

RectPropertySet padding = getPadding(c);
result -= (int) padding.top() + (int) padding.bottom();
result -= (int)padding.top() + (int)padding.bottom();

return result >= 0 ? result : -1;
}
Expand All @@ -876,24 +870,11 @@ public boolean isNeedsClipOnPaint(RenderingContext c) {
if (result) {
return result;
}
ContentLimitContainer contentLimitContainer = ((TableRowBox) getParent()).getContentLimitContainer();
ContentLimitContainer contentLimitContainer = ((TableRowBox)getParent()).getContentLimitContainer();
if (contentLimitContainer == null) {
return false;
return false;
}
return c.isPrint() && getTable().getStyle().isPaginateTable() &&
contentLimitContainer.isContainsMultiplePages();
}

private int fixedHeight;
public void setFixedHeight(int fixedHeight) {
this.fixedHeight = fixedHeight;
}

@Override
public void setHeight(int height) {
if (height != 0 && fixedHeight > 0) {
height = fixedHeight;
}
super.setHeight(height);
}
}
Loading

0 comments on commit 1fb9b48

Please sign in to comment.