Skip to content

Commit d36238d

Browse files
author
Dmitry Radchuk
committed
Add grid shorthands
DEVSIX-8358
1 parent 87ed1ce commit d36238d

File tree

113 files changed

+464
-89
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+464
-89
lines changed

src/main/java/com/itextpdf/html2pdf/css/CssConstants.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -147,32 +147,8 @@ public class CssConstants extends CommonCssConstants {
147147
/** The Constant FIRST_EXCEPT. */
148148
public static final String FIRST_EXCEPT = "first-except";
149149

150-
/** The Constant GRID. */
151-
public static final String GRID = "grid";
152-
/** The Constant GRID_COLUMN_END. */
153-
public static final String GRID_COLUMN_END = "grid-column-end";
154-
/** The Constant GRID_COLUMN_START. */
155-
public static final String GRID_COLUMN_START = "grid-column-start";
156-
/** The Constant GRID_ROW_END. */
157-
public static final String GRID_ROW_END = "grid-row-end";
158-
/** The Constant GRID_ROW_START. */
159-
public static final String GRID_ROW_START = "grid-row-start";
160-
/** The Constant GRID_TEMPLATE_AREAS. */
161-
public static final String GRID_TEMPLATE_AREAS = "grid-template-areas";
162-
/** The Constant GRID_TEMPLATE_COLUMNS. */
163-
public static final String GRID_TEMPLATE_COLUMNS = "grid-template-columns";
164-
/** The Constant GRID_TEMPLATE_ROWS. */
165-
public static final String GRID_TEMPLATE_ROWS = "grid-template-rows";
166-
/** The Constant GRID_AUTO_ROWS. */
167-
public static final String GRID_AUTO_ROWS = "grid-auto-rows";
168-
/** The Constant GRID_AUTO_COLUMNS. */
169-
public static final String GRID_AUTO_COLUMNS = "grid-auto-columns";
170-
/** The Constant GRID_AUTO_FLOW. */
171-
public static final String GRID_AUTO_FLOW = "grid-auto-flow";
172150
/** The Constant GRID_AREA. */
173151
public static final String GRID_AREA = "grid-area";
174-
/** The Constant DENSE. */
175-
public static final String DENSE = "dense";
176152

177153
/** The Constant INLINE. */
178154
public static final String INLINE = "inline";

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ private static void applyTemplate(String templateStr, IPropertyContainer contain
255255
List<IElement> children = ((IAbstractElement) container).getChildren();
256256
for (IElement child : children) {
257257
substituteLinename(lineNumbersPerName, startProperty, child,
258-
Math.max(namedAreaLength + 1, currentLine));
258+
Math.max(namedAreaLength + 1, currentLine), "-start");
259259
substituteLinename(lineNumbersPerName, endProperty, child,
260-
Math.max(namedAreaLength + 1, currentLine));
260+
Math.max(namedAreaLength + 1, currentLine), "-end");
261261
substituteLinenameInSpan(lineNumbersPerName, startProperty, endProperty, spanProperty, child,
262262
Math.max(namedAreaLength + 1, currentLine));
263263
}
@@ -329,7 +329,7 @@ private static void substituteLinenameInSpan(Map<String, List<Integer>> lineNumb
329329
}
330330

331331
private static void substituteLinename(Map<String, List<Integer>> lineNumbersPerName, int property,
332-
IElement child, int lastLineNumber) {
332+
IElement child, int lastLineNumber, String alternateLineNameSuffix) {
333333
Object propValue = child.<Object>getProperty(property);
334334
if (!(propValue instanceof String)) {
335335
// It means it's null or we processed it earlier
@@ -340,9 +340,15 @@ private static void substituteLinename(Map<String, List<Integer>> lineNumbersPer
340340
Tuple2<Integer, String> parsedValue = parseStringValue((String) propValue);
341341
int idx = parsedValue.getFirst();
342342
String strValue = parsedValue.getSecond();
343+
if (idx == 0 || strValue == null) {
344+
return;
345+
}
343346

344347
List<Integer> lineNumbers = lineNumbersPerName.get(strValue);
345-
if (lineNumbers == null || idx == 0 || strValue == null) {
348+
if (lineNumbers == null) {
349+
lineNumbers = lineNumbersPerName.get(strValue + alternateLineNameSuffix);
350+
}
351+
if (lineNumbers == null) {
346352
return;
347353
}
348354

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,26 @@ public void templateAreasBasicTest() throws IOException, InterruptedException {
5959
runTest("templateAreasBasic");
6060
}
6161

62+
@Test
63+
public void templateAreasShorthandBasicTest() throws IOException, InterruptedException {
64+
runTest("templateAreasShorthandBasic");
65+
}
66+
67+
@Test
68+
public void templateAreasShorthandAdvancedTest() throws IOException, InterruptedException {
69+
runTest("templateAreasShorthandAdvanced");
70+
}
71+
72+
@Test
73+
public void gridShorthandAdvancedTest() throws IOException, InterruptedException {
74+
runTest("gridShorthandAdvanced");
75+
}
76+
77+
@Test
78+
public void templateShorthandWithoutLineNamesTest() throws IOException, InterruptedException {
79+
runTest("templateShorthandWithoutLineNames");
80+
}
81+
6282
@Test
6383
public void templateAreasInvalidNameTest() throws IOException, InterruptedException {
6484
runTest("templateAreasInvalidName");

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ This file is part of the iText (R) project.
3030

3131
import java.io.IOException;
3232
import org.junit.jupiter.api.BeforeAll;
33+
import org.junit.jupiter.api.Disabled;
3334
import org.junit.jupiter.api.Tag;
3435
import org.junit.jupiter.api.Test;
3536

@@ -56,6 +57,7 @@ public void templateNestedAreasWithBorderTest() throws IOException, InterruptedE
5657
runTest("grid-nested-areas-with-border");
5758
}
5859

60+
@Disabled("DEVSIX-8423")
5961
@Test
6062
public void templateNestedArticlesTest() throws IOException, InterruptedException {
6163
runTest("grid-nested-articles");
@@ -86,6 +88,7 @@ public void templateNestedMixedContentTest() throws IOException, InterruptedExce
8688
runTest("grid-nested-mixed-content");
8789
}
8890

91+
@Disabled("DEVSIX-8423")
8992
@Test
9093
public void templateNestedParagraphsTest() throws IOException, InterruptedException {
9194
runTest("grid-nested-paragraphs");
@@ -101,8 +104,6 @@ public void templateNestedTableTest() throws IOException, InterruptedException {
101104
runTest("grid-nested-table");
102105
}
103106

104-
@LogMessages(messages = @LogMessage(
105-
messageTemplate = IoLogMessageConstant.TABLE_WIDTH_IS_MORE_THAN_EXPECTED_DUE_TO_MIN_WIDTH, count = 4))
106107
@Test
107108
public void templateNestedTableNestedGridTest() throws IOException, InterruptedException {
108109
runTest("grid-nested-table-nested-grid");
@@ -113,11 +114,13 @@ public void templateNestedTableMixedContentTest() throws IOException, Interrupte
113114
runTest("grid-nested-table-with-mixed-content");
114115
}
115116

117+
@Disabled("DEVSIX-8423")
116118
@Test
117119
public void templateNested2LevelsWithAreasTest() throws IOException, InterruptedException {
118120
runTest("grid-nested-2-levels-areas");
119121
}
120122

123+
@Disabled("DEVSIX-8423")
121124
@LogMessages(messages = {
122125
@LogMessage(messageTemplate = IoLogMessageConstant.CLIP_ELEMENT, count = 4)
123126
})
@@ -126,11 +129,13 @@ public void templateNested3LevelsFormsTest() throws IOException, InterruptedExce
126129
runTest("grid-nested-3-forms");
127130
}
128131

132+
@Disabled("DEVSIX-8423")
129133
@Test
130134
public void templateNested3LevelsTest() throws IOException, InterruptedException {
131135
runTest("grid-nested-3-levels");
132136
}
133137

138+
@Disabled("DEVSIX-8423")
134139
@Test
135140
public void templateNested3LevelsMultipleTest() throws IOException, InterruptedException {
136141
runTest("grid-nested-3-levels-multiple");

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,26 @@ public void autoFitWithGapsTest() throws IOException, InterruptedException {
583583
runTest("autoFitWithGapsTest");
584584
}
585585

586+
@Test
587+
public void rowColumnShorthandSimpleTest() throws IOException, InterruptedException {
588+
runTest("rowColumnShorthandSimpleTest");
589+
}
590+
591+
@Test
592+
public void gridShorthandColumnAutoFlowTest() throws IOException, InterruptedException {
593+
runTest("gridShorthandColumnAutoFlowTest");
594+
}
595+
596+
@Test
597+
public void gridShorthandRowAutoFlowTest() throws IOException, InterruptedException {
598+
runTest("gridShorthandRowAutoFlowTest");
599+
}
600+
601+
@Test
602+
public void shrankTemplateAfterAutoFitTest() throws IOException, InterruptedException {
603+
runTest("shrankTemplateAfterAutoFitTest");
604+
}
605+
586606
@Test
587607
public void gridLayoutDisablingTest() throws IOException, InterruptedException {
588608
convertToPdfAndCompare("basicColumnFewDivsTest",

src/test/java/com/itextpdf/html2pdf/css/w3c/css_grid/abspos/AbsolutePositioningDefiniteSizes001Test.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ This file is part of the iText (R) project.
2727
import com.itextpdf.test.annotations.LogMessage;
2828
import com.itextpdf.test.annotations.LogMessages;
2929

30-
//TODO DEVSIX-8358: Support shorthands
3130
@LogMessages(messages = {
3231
@LogMessage(messageTemplate = Html2PdfLogMessageConstant.NO_WORKER_FOUND_FOR_TAG, count = 4)})
3332
public class AbsolutePositioningDefiniteSizes001Test extends W3CCssGridTest {

src/test/java/com/itextpdf/html2pdf/css/w3c/css_grid/abspos/AbsolutePositioningGridContainerParent001Test.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ This file is part of the iText (R) project.
2727
import com.itextpdf.test.annotations.LogMessage;
2828
import com.itextpdf.test.annotations.LogMessages;
2929

30-
//TODO DEVSIX-8358: Support shorthands
3130
public class AbsolutePositioningGridContainerParent001Test extends W3CCssGridTest {
3231
@Override
3332
protected String getHtmlFileName() {

src/test/java/com/itextpdf/html2pdf/css/w3c/css_grid/abspos/DescendantStaticPosition001Test.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ This file is part of the iText (R) project.
2424

2525
import com.itextpdf.html2pdf.css.w3c.css_grid.W3CCssGridTest;
2626

27-
//TODO DEVSIX-8358: Support shorthands
2827
public class DescendantStaticPosition001Test extends W3CCssGridTest {
2928
@Override
3029
protected String getHtmlFileName() {

src/test/java/com/itextpdf/html2pdf/css/w3c/css_grid/abspos/DescendantStaticPosition002Test.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ This file is part of the iText (R) project.
2727
import com.itextpdf.test.annotations.LogMessage;
2828
import com.itextpdf.test.annotations.LogMessages;
2929

30-
//TODO DEVSIX-8358: Support shorthands
3130
@LogMessages(messages = {
3231
@LogMessage(messageTemplate = IoLogMessageConstant.RECTANGLE_HAS_NEGATIVE_SIZE, count = 6)
3332
})

src/test/java/com/itextpdf/html2pdf/css/w3c/css_grid/abspos/GridAbsposStaticposAlignSelf001Test.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ This file is part of the iText (R) project.
2727
import com.itextpdf.test.annotations.LogMessage;
2828
import com.itextpdf.test.annotations.LogMessages;
2929

30-
//TODO DEVSIX-8358: Support shorthands
3130
//TODO DEVSIX-5166 change after align-self is supported is supported
3231
@LogMessages(messages = {
3332
@LogMessage(messageTemplate = IoLogMessageConstant.RECTANGLE_HAS_NEGATIVE_SIZE, count = 11)

0 commit comments

Comments
 (0)