Skip to content

Commit 09833be

Browse files
authored
Merge pull request #171 from rototor/fix-css-rotate-multipage
Testcase and fix for rotation on the second and following pages.
2 parents c8ff009 + 43689c2 commit 09833be

File tree

6 files changed

+3440
-16
lines changed

6 files changed

+3440
-16
lines changed

openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Layer.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,16 @@ protected List<AffineTransform> applyTranform(RenderingContext c, Box box) {
429429
RectPropertySet margin = c.getPage().getMargin(c);
430430
relTranslateX += margin.left();
431431
relTranslateY += margin.top();
432+
433+
/*
434+
* We must apply the top/bottom margins from the previous pages, otherwise
435+
* our transform center is wrong.
436+
*/
437+
for (int i = 0; i < c.getPageNo(); i++) {
438+
RectPropertySet prevMargin = getPages().get(i).getMargin(c);
439+
relTranslateY += prevMargin.top() + prevMargin.bottom();
440+
}
441+
432442

433443
MarginBoxName[] marginBoxNames = c.getPage().getCurrentMarginBoxNames();
434444
if (marginBoxNames != null) {
@@ -494,6 +504,14 @@ protected List<AffineTransform> applyTranform(RenderingContext c, Box box) {
494504

495505
resultTransforms.add(translateToOrigin);
496506

507+
applyTransformFunctions(flipFactor, transformList, resultTransforms);
508+
509+
resultTransforms.add(translateBackFromOrigin);
510+
511+
return c.getOutputDevice().pushTransforms(resultTransforms);
512+
}
513+
514+
private void applyTransformFunctions(float flipFactor, List<PropertyValue> transformList, List<AffineTransform> resultTransforms) {
497515
for (PropertyValue transform : transformList) {
498516
String fName = transform.getFunction().getName();
499517
List<PropertyValue> params = transform.getFunction().getParameters();
@@ -536,13 +554,9 @@ protected List<AffineTransform> applyTranform(RenderingContext c, Box box) {
536554
XRLog.layout(Level.WARNING, "translateY function not implemented at this time");
537555
}
538556
}
539-
540-
resultTransforms.add(translateBackFromOrigin);
541-
542-
return c.getOutputDevice().pushTransforms(resultTransforms);
543557
}
544558

545-
private Box find(CssContext cssCtx, int absX, int absY, List layers, boolean findAnonymous) {
559+
private Box find(CssContext cssCtx, int absX, int absY, List layers, boolean findAnonymous) {
546560
Box result = null;
547561
// Work backwards since layers are painted forwards and we're looking
548562
// for the top-most box
@@ -904,7 +918,9 @@ private void position(LayoutContext c) {
904918
}
905919

906920
public List<PageBox> getPages() {
907-
return _pages == null ? Collections.<PageBox>emptyList(): _pages;
921+
if (_pages == null)
922+
return _parent == null ? Collections.<PageBox> emptyList() : _parent.getPages();
923+
return _pages;
908924
}
909925

910926
public void setPages(List<PageBox> pages) {

openhtmltopdf-examples/src/main/java/com/openhtmltopdf/testcases/TestcaseRunner.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ public static void main(String[] args) throws Exception {
103103

104104
runTestCase("math-ml");
105105

106+
/*
107+
* Broken rotate() on the second page
108+
*/
109+
runTestCase("RepeatedTableTransformSample");
106110
/* Add additional test cases here. */
107111
}
108112

0 commit comments

Comments
 (0)