Skip to content

Commit f508bfe

Browse files
rototordanfickle
authored andcommitted
Add visibility:-fs-table-paginate-repeated-visible for paginated tables. (#32)
This allows to render some elements on the continuation of a repeated table header on a new page. E.g. a span containing the word "continued". For this to work the table must have -fs-table-paginate: paginate; set. Using visibility the element is always correctly layouted, but only painted after the table is broken into a new page.
1 parent 18520bf commit f508bfe

File tree

10 files changed

+62
-16
lines changed

10 files changed

+62
-16
lines changed

openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/constants/IdentValue.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public class IdentValue implements FSDerivedValue {
103103
public final static IdentValue FONT_WEIGHT_900 = addValue("900");
104104
public final static IdentValue FS_CONTENT_PLACEHOLDER = addValue("-fs-content-placeholder");
105105
public final static IdentValue FS_INITIAL_VALUE = addValue("-fs-initial-value");
106+
public final static IdentValue FS_TABLE_PAGINATE_REPEATED_VISIBLE = addValue("-fs-table-paginate-repeated-visible");
106107
public final static IdentValue GEORGIAN = addValue("georgian");
107108
public final static IdentValue GROOVE = addValue("groove");
108109
public final static IdentValue HEBREW = addValue("hebrew");

openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/parser/property/PrimitivePropertyBuilders.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,10 +1518,11 @@ protected BitSet getAllowed() {
15181518
}
15191519

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

15261527
protected BitSet getAllowed() {
15271528
return ALLOWED;

openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/style/CalculatedStyle.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@
4343
import com.openhtmltopdf.css.style.derived.NumberValue;
4444
import com.openhtmltopdf.css.style.derived.RectPropertySet;
4545
import com.openhtmltopdf.css.value.FontSpecification;
46+
import com.openhtmltopdf.newtable.TableBox;
47+
import com.openhtmltopdf.render.Box;
4648
import com.openhtmltopdf.render.FSFont;
4749
import com.openhtmltopdf.render.FSFontMetrics;
50+
import com.openhtmltopdf.render.RenderingContext;
4851
import com.openhtmltopdf.util.XRLog;
4952
import com.openhtmltopdf.util.XRRuntimeException;
5053

@@ -1026,8 +1029,42 @@ public boolean isListItem() {
10261029
return isIdent(CSSName.DISPLAY, IdentValue.LIST_ITEM);
10271030
}
10281031

1029-
public boolean isVisible() {
1030-
return isIdent(CSSName.VISIBILITY, IdentValue.VISIBLE);
1032+
/**
1033+
* Determine if the element is visible. This is normaly the case
1034+
* if visibility == visible. Only when visibilty is
1035+
* -fs-table-paginate-repeated-visible and we are in a repeated table header
1036+
* the element will also be visible. This allows to only show an element in the table header
1037+
* after a page break.
1038+
* @param renderingContext null or the current renderingContext. If null,
1039+
* then the -fs-table-paginate-repeated-visible logic
1040+
* will not work.
1041+
* @param thisElement the element for which the visibility should be determined. Only required if
1042+
* -fs-table-paginate-repeated-visible is specified.
1043+
* @return true if the element is visible
1044+
*/
1045+
public boolean isVisible(RenderingContext renderingContext, Box thisElement) {
1046+
IdentValue val = getIdent(CSSName.VISIBILITY);
1047+
if (val == IdentValue.VISIBLE)
1048+
return true;
1049+
if (renderingContext != null) {
1050+
if (val == IdentValue.FS_TABLE_PAGINATE_REPEATED_VISIBLE) {
1051+
/*
1052+
* We need to find the parent TableBox which has a
1053+
* ContentLimitContainer and can be repeated.
1054+
*/
1055+
Box parentElement = thisElement.getParent();
1056+
while (parentElement != null
1057+
&& !(parentElement.getStyle().isTable()
1058+
&& ((TableBox) parentElement).hasContentLimitContainer()))
1059+
parentElement = parentElement.getDocumentParent();
1060+
1061+
if (parentElement != null) {
1062+
TableBox tableBox = (TableBox) parentElement;
1063+
return !tableBox.isTableRenderedOnFirstPage(renderingContext);
1064+
}
1065+
}
1066+
}
1067+
return false;
10311068
}
10321069

10331070
public boolean isForcePageBreakBefore() {

openhtmltopdf-core/src/main/java/com/openhtmltopdf/newtable/TableBox.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ public void analyzePageBreaks(LayoutContext c, ContentLimitContainer container)
398398
public void paintBackground(RenderingContext c) {
399399
if (_contentLimitContainer == null) {
400400
super.paintBackground(c);
401-
} else if (getStyle().isVisible()) {
401+
} else if (getStyle().isVisible(c, this)) {
402402
c.getOutputDevice().paintBackground(
403403
c, getStyle(), getContentLimitedBorderEdge(c), getPaintingBorderEdge(c),
404404
getStyle().getBorder(c));
@@ -408,7 +408,7 @@ c, getStyle(), getContentLimitedBorderEdge(c), getPaintingBorderEdge(c),
408408
public void paintBorder(RenderingContext c) {
409409
if (_contentLimitContainer == null) {
410410
super.paintBorder(c);
411-
} else if (getStyle().isVisible()) {
411+
} else if (getStyle().isVisible(c, this)) {
412412
c.getOutputDevice().paintBorder(c, getStyle(), getContentLimitedBorderEdge(c), getBorderSides());
413413
}
414414
}
@@ -866,6 +866,13 @@ public boolean hasContentLimitContainer() {
866866
return _contentLimitContainer != null;
867867
}
868868

869+
/**
870+
* @return true if the table is rendered on its first page. false if the table is rendered after a page break
871+
*/
872+
public boolean isTableRenderedOnFirstPage(RenderingContext context){
873+
return hasContentLimitContainer() && _contentLimitContainer.getInitialPageNo() == context.getPageNo();
874+
}
875+
869876
public int getExtraSpaceTop() {
870877
return _extraSpaceTop;
871878
}

openhtmltopdf-core/src/main/java/com/openhtmltopdf/newtable/TableCellBox.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ private boolean isPaintBackgroundsAndBorders() {
260260
}
261261

262262
public void paintBackground(RenderingContext c) {
263-
if (isPaintBackgroundsAndBorders() && getStyle().isVisible()) {
263+
if (isPaintBackgroundsAndBorders() && getStyle().isVisible(c, this)) {
264264
Rectangle bounds;
265265
if (c.isPrint() && getTable().getStyle().isPaginateTable()) {
266266
bounds = getContentLimitedBorderEdge(c);
@@ -315,7 +315,7 @@ bounds, getTable().getColumnBounds(c, getCol()),
315315
public void paintBorder(RenderingContext c) {
316316
if (isPaintBackgroundsAndBorders() && ! hasCollapsedPaintingBorder()) {
317317
// Collapsed table borders are painted separately
318-
if (c.isPrint() && getTable().getStyle().isPaginateTable() && getStyle().isVisible()) {
318+
if (c.isPrint() && getTable().getStyle().isPaginateTable() && getStyle().isVisible(c, this)) {
319319
Rectangle bounds = getContentLimitedBorderEdge(c);
320320
if (bounds != null) {
321321
c.getOutputDevice().paintBorder(c, getStyle(), bounds, getBorderSides());

openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/AbstractOutputDevice.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void paintCollapsedBorder(
167167
}
168168

169169
public void paintBorder(RenderingContext c, Box box) {
170-
if (! box.getStyle().isVisible()) {
170+
if (! box.getStyle().isVisible(c, box)) {
171171
return;
172172
}
173173

@@ -200,7 +200,7 @@ public void paintBackground(
200200
}
201201

202202
public void paintBackground(RenderingContext c, Box box) {
203-
if (! box.getStyle().isVisible()) {
203+
if (! box.getStyle().isVisible(c, box)) {
204204
return;
205205
}
206206

openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BlockBox.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public String dump(LayoutContext c, String indent, int which) {
256256
}
257257

258258
public void paintListMarker(RenderingContext c) {
259-
if (! getStyle().isVisible()) {
259+
if (! getStyle().isVisible(c, this)) {
260260
return;
261261
}
262262

@@ -281,7 +281,7 @@ public Rectangle getPaintingClipEdge(CssContext cssCtx) {
281281
}
282282

283283
public void paintInline(RenderingContext c) {
284-
if (! getStyle().isVisible()) {
284+
if (! getStyle().isVisible(c, this)) {
285285
return;
286286
}
287287

openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/Box.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ public Box find(CssContext cssCtx, int absX, int absY, boolean findAnonymous) {
691691
}
692692

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

697697
public boolean isRoot() {

openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/InlineLayoutBox.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public void paintSelection(RenderingContext c) {
251251
}
252252

253253
public void paintInline(RenderingContext c) {
254-
if (! getStyle().isVisible()) {
254+
if (! getStyle().isVisible(c, this)) {
255255
return;
256256
}
257257

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

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

790790
if (! findAnonymous && result != null && getElement() == null) {
791791
return getParent().getParent();

openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/LineBox.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public Rectangle getMarginEdge(CssContext cssCtx, int tx, int ty) {
109109
}
110110

111111
public void paintInline(RenderingContext c) {
112-
if (! getParent().getStyle().isVisible()) {
112+
if (! getParent().getStyle().isVisible(c, this)) {
113113
return;
114114
}
115115

0 commit comments

Comments
 (0)