Skip to content

Commit cead00e

Browse files
author
Dmitry Radchuk
committed
Remove multicolEnabled property and add continuousContainerEnabled property
DEVSIX-7594
1 parent dee8398 commit cead00e

File tree

275 files changed

+765
-707
lines changed

Some content is hidden

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

275 files changed

+765
-707
lines changed

src/main/java/com/itextpdf/html2pdf/ConverterProperties.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ public class ConverterProperties {
100100
*/
101101
private IMetaInfo metaInfo;
102102

103-
//TODO: DEVSIX-7594 remove this property
104-
private boolean multicolEnabled = false;
103+
/**
104+
* enables continuous container for all elements.
105+
*/
106+
private boolean continuousContainerEnabled;
105107

106108
/**
107109
* Instantiates a new {@link ConverterProperties} instance.
@@ -128,7 +130,7 @@ public ConverterProperties(ConverterProperties other) {
128130
this.metaInfo = other.metaInfo;
129131
this.limitOfLayouts = other.limitOfLayouts;
130132
this.immediateFlush = other.immediateFlush;
131-
this.multicolEnabled = other.multicolEnabled;
133+
this.continuousContainerEnabled = other.continuousContainerEnabled;
132134
}
133135

134136
/**
@@ -445,24 +447,23 @@ public ConverterProperties setEventMetaInfo(IMetaInfo metaInfo) {
445447
return this;
446448
}
447449

448-
//TODO: DEVSIX-7594 remove this property
449450
/**
450-
* check if multi-column layout is enabled
451+
* check if continuous container is enabled.
451452
*
452453
* @return true if enabled, false otherwise
453454
*/
454-
public boolean isMulticolEnabled() {
455-
return multicolEnabled;
455+
public boolean isContinuousContainerEnabled() {
456+
return continuousContainerEnabled;
456457
}
457458

458-
//TODO: DEVSIX-7594 remove this property
459459
/**
460-
* set multi-column layout support
461-
* @param multicolEnabled sets multi-column layout support
462-
* @return ConverterProperties
460+
* Sets continuous container support.
461+
*
462+
* @param value true to set continuous container, false otherwise
463+
* @return the {@link ConverterProperties} instance
463464
*/
464-
public ConverterProperties setMulticolEnabled(boolean multicolEnabled) {
465-
this.multicolEnabled = multicolEnabled;
465+
public ConverterProperties setContinuousContainerEnabled(boolean value) {
466+
continuousContainerEnabled = value;
466467
return this;
467468
}
468469
}

src/main/java/com/itextpdf/html2pdf/attach/ProcessorContext.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ public class ProcessorContext {
143143

144144
private final int limitOfLayouts;
145145

146-
//TODO: DEVSIX-7594 remove this property
147-
private boolean multicolEnabled;
146+
/**
147+
* enables continuous container for all elements.
148+
*/
149+
private boolean continuousContainerEnabled;
148150

149151
/**
150152
* Instantiates a new {@link ProcessorContext} instance.
@@ -198,7 +200,7 @@ public ProcessorContext(ConverterProperties converterProperties) {
198200
radioCheckResolver = new RadioCheckResolver();
199201
immediateFlush = converterProperties.isImmediateFlush();
200202
processingInlineSvg = false;
201-
multicolEnabled = converterProperties.isMulticolEnabled();
203+
continuousContainerEnabled = converterProperties.isContinuousContainerEnabled();
202204
}
203205

204206
/**
@@ -489,11 +491,13 @@ public void endProcessingInlineSvg(){
489491
processingInlineSvg = false;
490492
}
491493

494+
492495
/**
493-
* check if multicol layout is enabled
494-
* @return true if it's enabled, false otherwise
496+
* check if continuous container is enabled.
497+
*
498+
* @return true if enabled, false otherwise
495499
*/
496-
public boolean isMulticolEnabled() {
497-
return multicolEnabled;
500+
public boolean isContinuousContainerEnabled() {
501+
return continuousContainerEnabled;
498502
}
499503
}

src/main/java/com/itextpdf/html2pdf/attach/impl/DefaultHtmlProcessor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@ private void visit(INode node) {
360360
} else if (tagWorker.getElementResult() != null) {
361361
roots.add(tagWorker.getElementResult());
362362
}
363+
364+
if (tagWorker.getElementResult() != null && context.isContinuousContainerEnabled()) {
365+
tagWorker.getElementResult().setProperty(Property.COLLAPSING_MARGINS, Boolean.FALSE);
366+
tagWorker.getElementResult().setProperty(Property.TREAT_AS_CONTINUOUS_CONTAINER, true);
367+
}
363368
}
364369

365370
element.setStyles(null);

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

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,34 +47,32 @@ private ColumnCssApplierUtil() {
4747
* @param element the styles container
4848
*/
4949
public static void applyColumnCount(Map<String, String> cssProps, ProcessorContext context, IPropertyContainer element) {
50-
if (context.isMulticolEnabled()) {
51-
Integer columnCount = CssDimensionParsingUtils.parseInteger(cssProps.get(CssConstants.COLUMN_COUNT));
52-
if (columnCount != null) {
53-
element.setProperty(Property.COLUMN_COUNT, columnCount);
54-
}
50+
Integer columnCount = CssDimensionParsingUtils.parseInteger(cssProps.get(CssConstants.COLUMN_COUNT));
51+
if (columnCount != null) {
52+
element.setProperty(Property.COLUMN_COUNT, columnCount);
53+
}
5554

56-
final float emValue = CssDimensionParsingUtils.parseAbsoluteFontSize(cssProps.get(CssConstants.FONT_SIZE));
57-
final float remValue = context.getCssContext().getRootFontSize();
55+
final float emValue = CssDimensionParsingUtils.parseAbsoluteFontSize(cssProps.get(CssConstants.FONT_SIZE));
56+
final float remValue = context.getCssContext().getRootFontSize();
5857

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-
}
58+
UnitValue width = CssDimensionParsingUtils.parseLengthValueToPt(cssProps.get(CssConstants.COLUMN_WIDTH), emValue, remValue);
59+
if (width != null) {
60+
element.setProperty(Property.COLUMN_WIDTH, width.getValue());
61+
}
6362

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-
}
63+
UnitValue gap = CssDimensionParsingUtils.parseLengthValueToPt(cssProps.get(CssConstants.COLUMN_GAP), emValue, remValue);
64+
if (gap != null) {
65+
element.setProperty(Property.COLUMN_GAP, gap.getValue());
66+
}
6867

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-
}
68+
//Set default colum-gap to 1em
69+
if (!element.hasProperty(Property.COLUMN_GAP)) {
70+
element.setProperty(Property.COLUMN_GAP, CssDimensionParsingUtils.parseRelativeValue("1em", emValue));
71+
}
72+
if (!element.hasProperty(Property.COLUMN_COUNT) && !element.hasProperty(Property.COLUMN_WIDTH)
73+
&& (CommonCssConstants.AUTO.equals(cssProps.get(CssConstants.COLUMN_COUNT))
74+
|| CommonCssConstants.AUTO.equals(cssProps.get(CssConstants.COLUMN_WIDTH)))) {
75+
element.setProperty(Property.COLUMN_COUNT, 1);
7876
}
7977
}
8078
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2023 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;
24+
25+
import com.itextpdf.html2pdf.ConverterProperties;
26+
import com.itextpdf.html2pdf.ExtendedHtmlConversionITextTest;
27+
import com.itextpdf.test.annotations.type.IntegrationTest;
28+
29+
import java.io.IOException;
30+
import org.junit.BeforeClass;
31+
import org.junit.Test;
32+
import org.junit.experimental.categories.Category;
33+
34+
@Category(IntegrationTest.class)
35+
public class ContinuousContainerTest extends ExtendedHtmlConversionITextTest {
36+
public static final String SOURCE_FOLDER = "./src/test/resources/com/itextpdf/html2pdf/css/ContinuousContainerTest/";
37+
public static final String DESTINATION_FOLDER = "./target/test/com/itextpdf/html2pdf/css/ContinuousContainerTest/";
38+
39+
@BeforeClass
40+
public static void beforeClass() {
41+
createOrClearDestinationFolder(DESTINATION_FOLDER);
42+
}
43+
44+
@Test
45+
public void simpleDivTest() throws IOException, InterruptedException {
46+
runTest("divTest");
47+
}
48+
49+
@Test
50+
public void nestedDivTest() throws IOException, InterruptedException {
51+
runTest("nestedDivTest");
52+
}
53+
54+
@Test
55+
public void paragraphTest() throws IOException, InterruptedException {
56+
runTest("paragraphTest");
57+
}
58+
59+
@Test
60+
// TODO DEVSIX-7567 Support continuous container for tables (td)
61+
public void tableTest() throws IOException, InterruptedException {
62+
runTest("tableTest");
63+
}
64+
65+
@Test
66+
public void listTest() throws IOException, InterruptedException {
67+
runTest("listTest");
68+
}
69+
70+
private void runTest(String testName) throws IOException, InterruptedException {
71+
convertToPdfAndCompare(testName,
72+
SOURCE_FOLDER, DESTINATION_FOLDER, false,
73+
new ConverterProperties().setContinuousContainerEnabled(true));
74+
}
75+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,6 @@ public void convertBreakInsideAvoidColumnTest() throws IOException, InterruptedE
337337
private void runTest(String testName) throws IOException, InterruptedException {
338338
convertToPdfAndCompare(testName,
339339
SOURCE_FOLDER, DESTINATION_FOLDER, false,
340-
new ConverterProperties().setMulticolEnabled(true).setBaseUri(SOURCE_FOLDER));
340+
new ConverterProperties().setBaseUri(SOURCE_FOLDER));
341341
}
342342
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,6 @@ public void shortHandResolverTest01() throws IOException, InterruptedException {
415415
private void runTest(String testName) throws IOException, InterruptedException {
416416
convertToPdfAndCompare(testName,
417417
SOURCE_FOLDER, DESTINATION_FOLDER, false,
418-
new ConverterProperties().setMulticolEnabled(true).setBaseUri(SOURCE_FOLDER));
418+
new ConverterProperties().setBaseUri(SOURCE_FOLDER));
419419
}
420420
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,6 @@ public void convertGapShorthandTest() throws IOException, InterruptedException {
112112
private void runTest(String testName) throws IOException, InterruptedException {
113113
convertToPdfAndCompare(testName,
114114
SOURCE_FOLDER, DESTINATION_FOLDER, false,
115-
new ConverterProperties().setMulticolEnabled(true).setBaseUri(SOURCE_FOLDER));
115+
new ConverterProperties().setBaseUri(SOURCE_FOLDER));
116116
}
117117
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,6 @@ public void convertRuleShorthandTest() throws IOException, InterruptedException
134134
private void runTest(String testName) throws IOException, InterruptedException {
135135
convertToPdfAndCompare(testName,
136136
SOURCE_FOLDER, DESTINATION_FOLDER, false,
137-
new ConverterProperties().setMulticolEnabled(true).setBaseUri(SOURCE_FOLDER));
137+
new ConverterProperties().setBaseUri(SOURCE_FOLDER));
138138
}
139139
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,6 @@ public void columnWidthPercentageTest() throws IOException, InterruptedException
289289
private void runTest(String testName) throws IOException, InterruptedException {
290290
convertToPdfAndCompare(testName,
291291
SOURCE_FOLDER, DESTINATION_FOLDER, false,
292-
new ConverterProperties().setMulticolEnabled(true).setBaseUri(SOURCE_FOLDER));
292+
new ConverterProperties().setBaseUri(SOURCE_FOLDER));
293293
}
294294
}

0 commit comments

Comments
 (0)