Skip to content

Commit 229d27c

Browse files
committed
Support linenames for grid-template-columns/rows
DEVSIX-8368
1 parent 7b2a1a8 commit 229d27c

33 files changed

+1475
-102
lines changed

src/main/java/com/itextpdf/html2pdf/css/apply/util/GridApplierUtil.java

Lines changed: 377 additions & 88 deletions
Large diffs are not rendered by default.

src/main/java/com/itextpdf/html2pdf/logs/Html2PdfLogMessageConstant.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ public final class Html2PdfLogMessageConstant {
175175
public static final String IMMEDIATE_FLUSH_DISABLED = "Setting createAcroForm disables immediateFlush property";
176176
public static final String GRID_TEMPLATE_AREAS_IS_INVALID = "grid-template-areas property is invalid. "
177177
+ "The result is nondeterministic";
178+
public static final String LINENAMES_ARE_NOT_SUPPORTED_WITHIN_AUTO_REPEAT = "Line names are not supported "
179+
+ "with auto-repeat as a track-size";
180+
public static final String ADDING_GRID_LINES_TO_THE_LEFT_OR_TOP_IS_NOT_SUPPORTED = "Adding grid lines to the left "
181+
+ "or to the top is not supported";
178182

179183
private Html2PdfLogMessageConstant() {
180184
//Private constructor will prevent the instantiation of this class directly

src/test/java/com/itextpdf/html2pdf/css/apply/util/GridApplierUtilTest.java

Lines changed: 354 additions & 10 deletions
Large diffs are not rendered by default.

src/test/java/com/itextpdf/html2pdf/css/grid/GridAreaTest.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ This file is part of the iText (R) project.
2525
import com.itextpdf.html2pdf.ConverterProperties;
2626
import com.itextpdf.html2pdf.ExtendedHtmlConversionITextTest;
2727
import com.itextpdf.html2pdf.logs.Html2PdfLogMessageConstant;
28-
import com.itextpdf.styledxmlparser.logs.StyledXmlParserLogMessageConstant;
29-
import com.itextpdf.test.LogLevelConstants;
3028
import com.itextpdf.test.annotations.LogMessage;
3129
import com.itextpdf.test.annotations.LogMessages;
3230

@@ -119,6 +117,23 @@ public void invalidTemplateAreasTest() throws IOException, InterruptedException
119117
runTest("invalidTemplateAreas");
120118
}
121119

120+
@Test
121+
public void templateAreasStartAutoTest() throws IOException, InterruptedException {
122+
runTest("templateAreasStartAuto");
123+
}
124+
125+
@Test
126+
public void templateAreasStartTest() throws IOException, InterruptedException {
127+
// Here browser result seems strange. We specified only row starts but it somehow applies to column starts also.
128+
// I'd expect the same result as for templateAreasStartAutoTest
129+
runTest("templateAreasStart");
130+
}
131+
132+
@Test
133+
public void templateAreasStartEndTest() throws IOException, InterruptedException {
134+
runTest("templateAreasStartEnd");
135+
}
136+
122137
private void runTest(String testName) throws IOException, InterruptedException {
123138
convertToPdfAndCompare(testName,
124139
SOURCE_FOLDER, DESTINATION_FOLDER, false,
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2024 Apryse Group NV
4+
Authors: Apryse Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
package com.itextpdf.html2pdf.css.grid;
24+
25+
import com.itextpdf.html2pdf.ConverterProperties;
26+
import com.itextpdf.html2pdf.ExtendedHtmlConversionITextTest;
27+
import com.itextpdf.html2pdf.logs.Html2PdfLogMessageConstant;
28+
import com.itextpdf.test.annotations.LogMessage;
29+
import com.itextpdf.test.annotations.LogMessages;
30+
import org.junit.jupiter.api.Test;
31+
import org.junit.jupiter.api.BeforeAll;
32+
import org.junit.jupiter.api.Tag;
33+
34+
import java.io.IOException;
35+
36+
@Tag("IntegrationTest")
37+
public class GridLinenameTest extends ExtendedHtmlConversionITextTest {
38+
public static final String SOURCE_FOLDER = "./src/test/resources/com/itextpdf/html2pdf/css/grid/GridLinenameTest/";
39+
public static final String DESTINATION_FOLDER = "./target/test/com/itextpdf/html2pdf/css/grid/GridLinenameTest/";
40+
41+
42+
@BeforeAll
43+
public static void beforeClass() {
44+
createOrClearDestinationFolder(DESTINATION_FOLDER);
45+
}
46+
47+
@Test
48+
public void linenamesCombinedTest() throws IOException, InterruptedException {
49+
runTest("linenamesCombined");
50+
}
51+
52+
@Test
53+
public void linenameSpanTest() throws IOException, InterruptedException {
54+
runTest("linenameSpan");
55+
}
56+
57+
@Test
58+
public void linenameNthTest() throws IOException, InterruptedException {
59+
runTest("linenameNth");
60+
}
61+
62+
@Test
63+
public void duplicateLineNamesTest() throws IOException, InterruptedException {
64+
runTest("duplicateLineNames");
65+
}
66+
67+
@Test
68+
public void linenameGridAreaTest() throws IOException, InterruptedException {
69+
runTest("linenameGridArea");
70+
}
71+
72+
@Test
73+
public void customIndentSpanTest() throws IOException, InterruptedException {
74+
runTest("customIndentSpan");
75+
}
76+
77+
@Test
78+
public void customIndentTrickySpanTest() throws IOException, InterruptedException {
79+
runTest("customIndentTrickySpan");
80+
}
81+
82+
@Test
83+
public void templateAreasNamesTest() throws IOException, InterruptedException {
84+
runTest("templateAreasNames");
85+
}
86+
87+
@Test
88+
public void linenameRepeatTest() throws IOException, InterruptedException {
89+
runTest("linenameRepeat");
90+
}
91+
92+
@Test
93+
@LogMessages(messages = @LogMessage(
94+
messageTemplate = Html2PdfLogMessageConstant.LINENAMES_ARE_NOT_SUPPORTED_WITHIN_AUTO_REPEAT))
95+
public void linenameAutoRepeatTest() throws IOException, InterruptedException {
96+
runTest("linenameAutoRepeat");
97+
}
98+
99+
private void runTest(String testName) throws IOException, InterruptedException {
100+
convertToPdfAndCompare(testName,
101+
SOURCE_FOLDER, DESTINATION_FOLDER, false,
102+
new ConverterProperties().setBaseUri(SOURCE_FOLDER).setCssGridEnabled(true));
103+
}
104+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

src/test/resources/com/itextpdf/html2pdf/css/grid/GridAreaTest/templateAreasInvalidName.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
height: 250px;
1212
grid-template-areas:
1313
"head head"
14-
"nav 1"
14+
"nav 3"
1515
"nav foot";
1616
grid-template-rows: 50px 100px 30px;
1717
grid-template-columns: 150px 200px;
@@ -28,7 +28,7 @@
2828
}
2929

3030
#page > main {
31-
grid-area: 1;
31+
grid-area: 3;
3232
background-color: #ffff64;
3333
}
3434

0 commit comments

Comments
 (0)