Skip to content

Commit d6d7312

Browse files
author
Dmitry Radchuk
committed
Add column-gap and column-width support
DEVSIX-7553
1 parent 8a70d0a commit d6d7312

File tree

312 files changed

+152
-10
lines changed

Some content is hidden

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

312 files changed

+152
-10
lines changed

src/main/java/com/itextpdf/html2pdf/attach/impl/tags/DivTagWorker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class DivTagWorker implements ITagWorker, IDisplayAware {
6868
public DivTagWorker(IElementNode element, ProcessorContext context) {
6969
div = new Div();
7070
Map<String, String> styles = element.getStyles();
71-
if (styles != null && styles.containsKey(CssConstants.COLUMN_COUNT)) {
71+
if (styles != null && (styles.containsKey(CssConstants.COLUMN_COUNT) || styles.containsKey(CssConstants.COLUMN_WIDTH))) {
7272
multicolContainer = new MulticolContainer();
7373
multicolContainer.add(div);
7474
}

src/main/java/com/itextpdf/html2pdf/attach/impl/tags/PTagWorker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public class PTagWorker implements ITagWorker, IDisplayAware {
7878
public PTagWorker(IElementNode element, ProcessorContext context) {
7979
lastParagraph = new Paragraph();
8080

81-
if (element.getStyles().get(CssConstants.COLUMN_COUNT) != null ) {
81+
if (element.getStyles().get(CssConstants.COLUMN_COUNT) != null || element.getStyles().get(CssConstants.COLUMN_WIDTH) != null) {
8282
multicolContainer = new MulticolContainer();
8383
multicolContainer.add(lastParagraph);
8484
}

src/main/java/com/itextpdf/html2pdf/attach/impl/tags/TdTagWorker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public TdTagWorker(IElementNode element, ProcessorContext context) {
8686
cell.setPadding(0);
8787

8888
Map<String, String> styles = element.getStyles();
89-
if (styles.containsKey(CssConstants.COLUMN_COUNT)) {
89+
if (styles.containsKey(CssConstants.COLUMN_COUNT) || styles.containsKey(CssConstants.COLUMN_WIDTH)) {
9090
multicolContainer = new MulticolContainer();
9191
childOfMulticolContainer = new Div();
9292
multicolContainer.add(childOfMulticolContainer);

src/main/java/com/itextpdf/html2pdf/attach/impl/tags/UlOlTagWorker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public class UlOlTagWorker implements ITagWorker {
6565
public UlOlTagWorker(IElementNode element, ProcessorContext context) {
6666
list = new List().setListSymbol("");
6767

68-
if (element.getStyles().get(CssConstants.COLUMN_COUNT) != null ) {
68+
if (element.getStyles().get(CssConstants.COLUMN_COUNT) != null
69+
|| element.getStyles().containsKey(CssConstants.COLUMN_WIDTH)) {
6970
multicolContainer = new MulticolContainer();
7071
multicolContainer.add(list);
7172
}

src/main/java/com/itextpdf/html2pdf/css/apply/impl/ColumnCssApplierUtil.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ This file is part of the iText (R) project.
2626
import com.itextpdf.html2pdf.css.CssConstants;
2727
import com.itextpdf.layout.IPropertyContainer;
2828
import com.itextpdf.layout.properties.Property;
29+
import com.itextpdf.layout.properties.UnitValue;
2930
import com.itextpdf.styledxmlparser.css.CommonCssConstants;
3031
import com.itextpdf.styledxmlparser.css.util.CssDimensionParsingUtils;
31-
import com.itextpdf.styledxmlparser.css.util.CssTypesValidationUtils;
3232

3333
import java.util.Map;
3434

@@ -52,6 +52,29 @@ public static void applyColumnCount(Map<String, String> cssProps, ProcessorConte
5252
if (columnCount != null) {
5353
element.setProperty(Property.COLUMN_COUNT, columnCount);
5454
}
55+
56+
final float emValue = CssDimensionParsingUtils.parseAbsoluteFontSize(cssProps.get(CssConstants.FONT_SIZE));
57+
final float remValue = context.getCssContext().getRootFontSize();
58+
59+
UnitValue width = CssDimensionParsingUtils.parseLengthValueToPt(cssProps.get(CssConstants.COLUMN_WIDTH), emValue, remValue);
60+
if (width != null) {
61+
element.setProperty(Property.COLUMN_WIDTH, width.getValue());
62+
}
63+
64+
UnitValue gap = CssDimensionParsingUtils.parseLengthValueToPt(cssProps.get(CssConstants.COLUMN_GAP), emValue, remValue);
65+
if (gap != null) {
66+
element.setProperty(Property.COLUMN_GAP, gap.getValue());
67+
}
68+
69+
//Set default colum-gap to 1em
70+
if (!element.hasProperty(Property.COLUMN_GAP)) {
71+
element.setProperty(Property.COLUMN_GAP, CssDimensionParsingUtils.parseRelativeValue("1em", emValue));
72+
}
73+
if (!element.hasProperty(Property.COLUMN_COUNT) && !element.hasProperty(Property.COLUMN_WIDTH)
74+
&& (CommonCssConstants.AUTO.equals(cssProps.get(CssConstants.COLUMN_COUNT))
75+
|| CommonCssConstants.AUTO.equals(cssProps.get(CssConstants.COLUMN_WIDTH)))) {
76+
element.setProperty(Property.COLUMN_COUNT, 1);
77+
}
5578
}
5679
}
5780
}

src/test/java/com/itextpdf/html2pdf/css/multicol/ColumnCountTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public void basicOrphans2Test() throws IOException, InterruptedException {
269269
@Test
270270
@LogMessages(messages = {
271271
@LogMessage(messageTemplate = IoLogMessageConstant.WIDOWS_CONSTRAINT_VIOLATED, logLevel =
272-
LogLevelConstants.WARN, count = 2)
272+
LogLevelConstants.WARN)
273273
})
274274
public void basicWidows1Test() throws IOException, InterruptedException {
275275
runTest("basicWidows1Test");

src/test/java/com/itextpdf/html2pdf/css/multicol/ColumnGapTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public void convertFloatColumnGapValueTest() throws IOException, InterruptedExce
7171
runTest("floatColumnGapValueTest");
7272
}
7373

74+
//TODO: DEVSIX-3596 add support of relative units that currently are not supported
7475
@Test
7576
@LogMessages(messages = @LogMessage(messageTemplate =
7677
Html2PdfLogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION, count = 2))

src/test/java/com/itextpdf/html2pdf/css/multicol/ColumnWidthTest.java

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

2525
import com.itextpdf.html2pdf.ConverterProperties;
2626
import com.itextpdf.html2pdf.ExtendedHtmlConversionITextTest;
27+
import com.itextpdf.html2pdf.logs.Html2PdfLogMessageConstant;
28+
import com.itextpdf.layout.logs.LayoutLogMessageConstant;
29+
import com.itextpdf.test.annotations.LogMessage;
30+
import com.itextpdf.test.annotations.LogMessages;
2731
import com.itextpdf.test.annotations.type.IntegrationTest;
2832

2933
import java.io.IOException;
@@ -51,6 +55,9 @@ public void convertColumnWidthAutoTest() throws IOException, InterruptedExceptio
5155
runTest("columnWidthAutoTest");
5256
}
5357

58+
//TODO: DEVSIX-3596 add support of relative units that currently are not supported
59+
@LogMessages(messages =
60+
@LogMessage(messageTemplate = Html2PdfLogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION, count = 2))
5461
@Test
5562
public void convertDifferentUnitsTest() throws IOException, InterruptedException {
5663
runTest("differentUnitsTest");
@@ -131,6 +138,7 @@ public void convertOverlaidFlexContentInColumnContainerTest() throws IOException
131138
runTest("overlaidFlexContentInColumnContainerTest");
132139
}
133140

141+
@LogMessages(messages = {@LogMessage(messageTemplate = LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)})
134142
@Test
135143
public void convertBasicFloatPropertyTest() throws IOException, InterruptedException {
136144
runTest("basicFloatPropertyTest");
@@ -221,16 +229,19 @@ public void diffElementsInsidePTest() throws IOException, InterruptedException {
221229
runTest("diffElementsInsidePTest");
222230
}
223231

232+
//TODO: DEVSIX-7630
224233
@Test
225234
public void tableColspanTest() throws IOException, InterruptedException {
226235
runTest("tableColspanTest");
227236
}
228237

238+
//TODO: DEVSIX-7630
229239
@Test
230240
public void tableRowspanTest() throws IOException, InterruptedException {
231241
runTest("tableRowspanTest");
232242
}
233243

244+
//TODO: DEVSIX-7630
234245
@Test
235246
public void tableColspanRowspanTest() throws IOException, InterruptedException {
236247
runTest("tableColspanRowspanTest");
@@ -261,6 +272,20 @@ public void basicBlockquoteTest() throws IOException, InterruptedException {
261272
runTest("basicBlockquoteTest");
262273
}
263274

275+
276+
@LogMessages(messages =
277+
@LogMessage(messageTemplate = Html2PdfLogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION, count = 3))
278+
@Test
279+
public void invalidMulticolValuesTest() throws IOException, InterruptedException {
280+
runTest("invalidMulticolValuesTest");
281+
}
282+
283+
@Test
284+
public void columnWidthPercentageTest() throws IOException, InterruptedException {
285+
runTest("columnWidthPercentageTest");
286+
}
287+
288+
264289
private void runTest(String testName) throws IOException, InterruptedException {
265290
convertToPdfAndCompare(testName,
266291
SOURCE_FOLDER, DESTINATION_FOLDER, false,
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)