Skip to content

Commit 40c0033

Browse files
SnipxiText-CI
authored andcommitted
Fix parsing named page size declarations with orientation in @page media
The problem happened for page sizes which are in landscape orientation by default DEVSIX-3072
1 parent bf3279b commit 40c0033

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/main/java/com/itextpdf/html2pdf/attach/impl/layout/PageSizeParser.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,15 @@ static PageSize fetchPageSize(String pageSizeStr, float em, float rem, PageSize
119119
}
120120
}
121121

122-
boolean b1 = pageSizeChunks.length == 1 && (namedPageSize != null || landscape != null);
123-
boolean b2 = namedPageSize != null && landscape != null;
124-
if (b1 || b2) {
122+
boolean isValidSingleWordDeclaration = pageSizeChunks.length == 1 && (namedPageSize != null || landscape != null);
123+
boolean isValidTwoWordDeclaration = namedPageSize != null && landscape != null;
124+
if (isValidSingleWordDeclaration || isValidTwoWordDeclaration) {
125125
if (namedPageSize != null) {
126126
pageSize = namedPageSize;
127127
}
128-
if (Boolean.TRUE.equals(landscape)) {
128+
boolean landscapeRequestedAndNeedRotation = Boolean.TRUE.equals(landscape) && pageSize.getWidth() < pageSize.getHeight();
129+
boolean portraitRequestedAndNeedRotation = Boolean.FALSE.equals(landscape) && pageSize.getHeight() < pageSize.getWidth();
130+
if (landscapeRequestedAndNeedRotation || portraitRequestedAndNeedRotation) {
129131
pageSize = pageSize.rotate();
130132
}
131133
} else {

src/test/java/com/itextpdf/html2pdf/attach/impl/layout/PageSizeParserTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.itextpdf.html2pdf.attach.impl.layout;
22

33
import com.itextpdf.kernel.geom.PageSize;
4+
import com.itextpdf.test.ExtendedITextTest;
45
import com.itextpdf.test.annotations.type.UnitTest;
56
import org.junit.Assert;
6-
import org.junit.Ignore;
77
import org.junit.Test;
88
import org.junit.experimental.categories.Category;
99

1010
@Category(UnitTest.class)
11-
public class PageSizeParserTest {
11+
public class PageSizeParserTest extends ExtendedITextTest {
1212

1313
private static final double EPS = 1e-9;
1414

@@ -27,15 +27,13 @@ public void simpleLedgerTest() {
2727
}
2828

2929
@Test
30-
@Ignore("To be fixed in DEVSIX-3072")
3130
public void ledgerLandscapeIsSameAsLedgerTest() {
3231
PageSize expected = PageSize.LEDGER;
3332
PageSize actual = PageSizeParser.fetchPageSize("ledger landscape", 10, 10, PageSize.A0);
3433
assertSizesAreSame(expected, actual);
3534
}
3635

3736
@Test
38-
@Ignore("To be fixed in DEVSIX-3072")
3937
public void ledgerPortraitIsRotatedLedgerTest() {
4038
PageSize expected = PageSize.LEDGER.rotate();
4139
PageSize actual = PageSizeParser.fetchPageSize("ledger portrait", 10, 10, PageSize.A0);

0 commit comments

Comments
 (0)