Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add visibility:-fs-table-paginate-repeated-visible for paginated tables. #32

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public class IdentValue implements FSDerivedValue {
public final static IdentValue FONT_WEIGHT_900 = addValue("900");
public final static IdentValue FS_CONTENT_PLACEHOLDER = addValue("-fs-content-placeholder");
public final static IdentValue FS_INITIAL_VALUE = addValue("-fs-initial-value");
public final static IdentValue FS_TABLE_PAGINATE_REPEATED_VISIBLE = addValue("-fs-table-paginate-repeated-visible");
public final static IdentValue GEORGIAN = addValue("georgian");
public final static IdentValue GROOVE = addValue("groove");
public final static IdentValue HEBREW = addValue("hebrew");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1515,10 +1515,11 @@ protected BitSet getAllowed() {
}

public static class Visibility extends SingleIdent {
// visible | hidden | collapse | inherit
// visible | hidden | collapse | inherit | -fs-table-paginate-repeated-visible
private static final BitSet ALLOWED = setFor(
new IdentValue[] {
IdentValue.VISIBLE, IdentValue.HIDDEN, IdentValue.COLLAPSE });
IdentValue.VISIBLE, IdentValue.HIDDEN, IdentValue.COLLAPSE,
IdentValue.FS_TABLE_PAGINATE_REPEATED_VISIBLE });

protected BitSet getAllowed() {
return ALLOWED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@
import com.openhtmltopdf.css.style.derived.NumberValue;
import com.openhtmltopdf.css.style.derived.RectPropertySet;
import com.openhtmltopdf.css.value.FontSpecification;
import com.openhtmltopdf.newtable.TableBox;
import com.openhtmltopdf.render.Box;
import com.openhtmltopdf.render.FSFont;
import com.openhtmltopdf.render.FSFontMetrics;
import com.openhtmltopdf.render.RenderingContext;
import com.openhtmltopdf.util.XRLog;
import com.openhtmltopdf.util.XRRuntimeException;

Expand Down Expand Up @@ -1026,8 +1029,42 @@ public boolean isListItem() {
return isIdent(CSSName.DISPLAY, IdentValue.LIST_ITEM);
}

public boolean isVisible() {
return isIdent(CSSName.VISIBILITY, IdentValue.VISIBLE);
/**
* Determine if the element is visible. This is normaly the case
* if visibility == visible. Only when visibilty is
* -fs-table-paginate-repeated-visible and we are in a repeated table header
* the element will also be visible. This allows to only show an element in the table header
* after a page break.
* @param renderingContext null or the current renderingContext. If null,
* then the -fs-table-paginate-repeated-visible logic
* will not work.
* @param thisElement the element for which the visibility should be determined. Only required if
* -fs-table-paginate-repeated-visible is specified.
* @return true if the element is visible
*/
public boolean isVisible(RenderingContext renderingContext, Box thisElement) {
IdentValue val = getIdent(CSSName.VISIBILITY);
if (val == IdentValue.VISIBLE)
return true;
if (renderingContext != null) {
if (val == IdentValue.FS_TABLE_PAGINATE_REPEATED_VISIBLE) {
/*
* We need to find the parent TableBox which has a
* ContentLimitContainer and can be repeated.
*/
Box parentElement = thisElement.getParent();
while (parentElement != null
&& !(parentElement.getStyle().isTable()
&& ((TableBox) parentElement).hasContentLimitContainer()))
parentElement = parentElement.getDocumentParent();

if (parentElement != null) {
TableBox tableBox = (TableBox) parentElement;
return !tableBox.isTableRenderedOnFirstPage(renderingContext);
}
}
}
return false;
}

public boolean isForcePageBreakBefore() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public void analyzePageBreaks(LayoutContext c, ContentLimitContainer container)
public void paintBackground(RenderingContext c) {
if (_contentLimitContainer == null) {
super.paintBackground(c);
} else if (getStyle().isVisible()) {
} else if (getStyle().isVisible(c, this)) {
c.getOutputDevice().paintBackground(
c, getStyle(), getContentLimitedBorderEdge(c), getPaintingBorderEdge(c),
getStyle().getBorder(c));
Expand All @@ -408,7 +408,7 @@ c, getStyle(), getContentLimitedBorderEdge(c), getPaintingBorderEdge(c),
public void paintBorder(RenderingContext c) {
if (_contentLimitContainer == null) {
super.paintBorder(c);
} else if (getStyle().isVisible()) {
} else if (getStyle().isVisible(c, this)) {
c.getOutputDevice().paintBorder(c, getStyle(), getContentLimitedBorderEdge(c), getBorderSides());
}
}
Expand Down Expand Up @@ -866,6 +866,13 @@ public boolean hasContentLimitContainer() {
return _contentLimitContainer != null;
}

/**
* @return true if the table is rendered on its first page. false if the table is rendered after a page break
*/
public boolean isTableRenderedOnFirstPage(RenderingContext context){
return hasContentLimitContainer() && _contentLimitContainer.getInitialPageNo() == context.getPageNo();
}

public int getExtraSpaceTop() {
return _extraSpaceTop;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private boolean isPaintBackgroundsAndBorders() {
}

public void paintBackground(RenderingContext c) {
if (isPaintBackgroundsAndBorders() && getStyle().isVisible()) {
if (isPaintBackgroundsAndBorders() && getStyle().isVisible(c, this)) {
Rectangle bounds;
if (c.isPrint() && getTable().getStyle().isPaginateTable()) {
bounds = getContentLimitedBorderEdge(c);
Expand Down Expand Up @@ -315,7 +315,7 @@ bounds, getTable().getColumnBounds(c, getCol()),
public void paintBorder(RenderingContext c) {
if (isPaintBackgroundsAndBorders() && ! hasCollapsedPaintingBorder()) {
// Collapsed table borders are painted separately
if (c.isPrint() && getTable().getStyle().isPaginateTable() && getStyle().isVisible()) {
if (c.isPrint() && getTable().getStyle().isPaginateTable() && getStyle().isVisible(c, this)) {
Rectangle bounds = getContentLimitedBorderEdge(c);
if (bounds != null) {
c.getOutputDevice().paintBorder(c, getStyle(), bounds, getBorderSides());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void paintCollapsedBorder(
}

public void paintBorder(RenderingContext c, Box box) {
if (! box.getStyle().isVisible()) {
if (! box.getStyle().isVisible(c, box)) {
return;
}

Expand Down Expand Up @@ -200,7 +200,7 @@ public void paintBackground(
}

public void paintBackground(RenderingContext c, Box box) {
if (! box.getStyle().isVisible()) {
if (! box.getStyle().isVisible(c, box)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public String dump(LayoutContext c, String indent, int which) {
}

public void paintListMarker(RenderingContext c) {
if (! getStyle().isVisible()) {
if (! getStyle().isVisible(c, this)) {
return;
}

Expand All @@ -281,7 +281,7 @@ public Rectangle getPaintingClipEdge(CssContext cssCtx) {
}

public void paintInline(RenderingContext c) {
if (! getStyle().isVisible()) {
if (! getStyle().isVisible(c, this)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ public Box find(CssContext cssCtx, int absX, int absY, boolean findAnonymous) {
}

Rectangle edge = getContentAreaEdge(getAbsX(), getAbsY(), cssCtx);
return edge.contains(absX, absY) && getStyle().isVisible() ? this : null;
return edge.contains(absX, absY) && getStyle().isVisible(null, this) ? this : null;
}

public boolean isRoot() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void paintSelection(RenderingContext c) {
}

public void paintInline(RenderingContext c) {
if (! getStyle().isVisible()) {
if (! getStyle().isVisible(c, this)) {
return;
}

Expand Down Expand Up @@ -785,7 +785,7 @@ public Box find(CssContext cssCtx, int absX, int absY, boolean findAnonymous) {
}

Rectangle edge = getContentAreaEdge(getAbsX(), getAbsY(), cssCtx);
result = edge.contains(absX, absY) && getStyle().isVisible() ? this : null;
result = edge.contains(absX, absY) && getStyle().isVisible(null, this) ? this : null;

if (! findAnonymous && result != null && getElement() == null) {
return getParent().getParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public Rectangle getMarginEdge(CssContext cssCtx, int tx, int ty) {
}

public void paintInline(RenderingContext c) {
if (! getParent().getStyle().isVisible()) {
if (! getParent().getStyle().isVisible(c, this)) {
return;
}

Expand Down