Skip to content

Commit

Permalink
#180 #126 Implement CSS page property -fs-overflow-pages-direction.
Browse files Browse the repository at this point in the history
Controls whether cut-off content to the right (ltr) of the page is inserted or to the left (rtl).
  • Loading branch information
danfickle committed Aug 12, 2018
1 parent 64131d2 commit 5cadc6d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,9 @@ public final class CSSName implements Comparable {
new PrimitivePropertyBuilders.BoxSizing()
);

/**
* The maximum number of inserted shadow pages to insert for cut-off content.
*/
public final static CSSName FS_MAX_OVERFLOW_PAGES =
addProperty(
"-fs-max-overflow-pages",
Expand All @@ -1499,6 +1502,19 @@ public final class CSSName implements Comparable {
NOT_INHERITED,
new PrimitivePropertyBuilders.FSMaxOverflowPages()
);

/**
* Whether cut-off content to the right (default) of the page or left
* of the page should be inserted as shadow pages.
*/
public final static CSSName FS_OVERFLOW_PAGES_DIRECTION =
addProperty(
"-fs-overflow-pages-direction",
PRIMITIVE,
"ltr",
NOT_INHERITED,
new PrimitivePropertyBuilders.FSOverflowPagesDirection()
);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1855,4 +1855,14 @@ protected boolean isNegativeValuesAllowed() {
return false;
}
}

public static class FSOverflowPagesDirection extends SingleIdent {
private static final BitSet ALLOWED = setFor(new IdentValue[] { IdentValue.LTR, IdentValue.RTL });

@Override
protected BitSet getAllowed() {
return ALLOWED;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import java.io.Writer;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

import org.w3c.dom.Element;
import org.w3c.dom.css.CSSPrimitiveValue;

Expand Down Expand Up @@ -276,11 +274,14 @@ public Rectangle getDocumentCoordinatesContentBounds(CssContext c) {
/**
* Get the shadow page (a page inserted to carry cut off content) content area of the layed out document.
* For example: If a page one is 100 units high and 150 wide and has a margin of 10 then this will return a
* rect(130, 0, 130, 80) for the first shadow page and a rect(260, 0, 130, 80) for the second shadow page.
* rect(130, 0, 130, 80) for the first shadow page and a rect(260, 0, 130, 80) for the second shadow page
* assuming cut-off direction is LTR.
*
* For RTL the rects would be rect(-130, 0, 130, 80) and rect(-260, 0, 130, 80).
*/
public Rectangle getDocumentCoordinatesContentBoundsForInsertedPage(CssContext c, int shadowPageNumber) {
return new Rectangle(
getContentWidth(c) * (shadowPageNumber + 1),
getContentWidth(c) * (shadowPageNumber + 1) * (getCutOffPageDirection() == IdentValue.LTR ? 1 : -1),
getPaintingTop(),
getContentWidth(c),
getContentHeight(c));
Expand All @@ -300,6 +301,14 @@ public int getMaxInsertedPages() {
return getStyle().fsMaxOverflowPages();
}

/**
* @return Either ltr (should insert cut-off content to the right of the page) or
* rtl (should insert cut-off content to the left of the page).
*/
public IdentValue getCutOffPageDirection() {
return getStyle().getIdent(CSSName.FS_OVERFLOW_PAGES_DIRECTION);
}

public Rectangle getPagedViewClippingBounds(CssContext cssCtx, int additionalClearance) {
Rectangle result = new Rectangle(
additionalClearance +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.openhtmltopdf.bidi.BidiSplitterFactory;
import com.openhtmltopdf.bidi.SimpleBidiReorderer;
import com.openhtmltopdf.context.StyleReference;
import com.openhtmltopdf.css.constants.IdentValue;
import com.openhtmltopdf.css.style.CalculatedStyle;
import com.openhtmltopdf.extend.*;
import com.openhtmltopdf.layout.BoxBuilder;
Expand Down Expand Up @@ -610,7 +611,7 @@ private void writePDFFast(List<PageBox> pages, RenderingContext c, Rectangle2D f

if (!pageOperations.shadowPages().isEmpty()) {
// TODO.
int translateX = (int) (firstPageSize.getWidth() * _outputDevice.getDotsPerPoint());
int translateX = (int) (firstPageSize.getWidth() * _outputDevice.getDotsPerPoint()) * (currentPage.getCutOffPageDirection() == IdentValue.LTR ? 1 : -1);
for (DisplayListPageContainer shadowPage : pageOperations.shadowPages()) {
PDPage shadowPdPage = new PDPage(new PDRectangle((float) firstPageSize.getWidth(), (float) firstPageSize.getHeight()));
PDPageContentStream shadowCs = new PDPageContentStream(doc, shadowPdPage, AppendMode.APPEND, !_testMode);
Expand Down

0 comments on commit 5cadc6d

Please sign in to comment.