Skip to content

Commit 727a989

Browse files
committed
[RELEASE] iText 7 pdfHTML 4.0.4
2 parents 14c54b2 + 5e01170 commit 727a989

File tree

75 files changed

+725
-455
lines changed

Some content is hidden

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

75 files changed

+725
-455
lines changed

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<parent>
66
<groupId>com.itextpdf</groupId>
77
<artifactId>root</artifactId>
8-
<version>7.2.3</version>
8+
<version>7.2.4</version>
99
<relativePath />
1010
</parent>
1111

1212
<artifactId>html2pdf</artifactId>
13-
<version>4.0.3</version>
13+
<version>4.0.4</version>
1414

1515
<name>pdfHTML</name>
1616
<description>pdfHTML is an iText 7 add-on that lets you to parse (X)HTML snippets and the associated CSS and converts

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

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public ConverterProperties(ConverterProperties other) {
145145
this.charset = other.charset;
146146
this.metaInfo = other.metaInfo;
147147
this.limitOfLayouts = other.limitOfLayouts;
148+
this.immediateFlush = other.immediateFlush;
148149
}
149150

150151
/**

src/main/java/com/itextpdf/html2pdf/actions/data/PdfHtmlProductData.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ This file is part of the iText (R) project.
3030
*/
3131
public final class PdfHtmlProductData {
3232
private static final String PDF_HTML_PUBLIC_PRODUCT_NAME = "pdfHTML";
33-
private static final String PDF_HTML_VERSION = "4.0.3";
33+
private static final String PDF_HTML_VERSION = "4.0.4";
3434
private static final int PDF_HTML_COPYRIGHT_SINCE = 2000;
3535
private static final int PDF_HTML_COPYRIGHT_TO = 2022;
3636

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

-15
Original file line numberDiff line numberDiff line change
@@ -431,20 +431,6 @@ private ITagWorker processRunningElement(ITagWorker tagWorker, IElementNode elem
431431
return tagWorker;
432432
}
433433

434-
// TODO For now the whole ITagWorker of the running element is preserved inside RunningElementContainer
435-
// for the sake of future processing in page margin box. This is somewhat a workaround and storing
436-
// tag workers might be easily seen as something undesirable, however at least for now it seems to be
437-
// most suitable solution because:
438-
// - in any case, processing of the whole running element with it's children should be done in
439-
// "normal flow", i.e. in DefaultHtmlProcessor, based on the spec that says that element should be
440-
// processed as it was still in the same position in DOM, but visually as if "display: none" was set.
441-
// - the whole process would need to be repeated in PageContextProcessor again, so it's a double work;
442-
// also currently there is still no convenient way for unifying the processing here and in
443-
// PageContextProcessor, currently only running elements require processing of the whole hierarchy of
444-
// children outside of the default DOM processing and also it's unclear whether this code would be suitable
445-
// for the simplified approach of processing all other children of page margin boxes.
446-
// - ITagWorker is only publicly passed to the constructor, but there is no exposed way to get it out of
447-
// RunningElementContainer, so it would be fairly easy to change this approach in future if needed.
448434
RunningElementContainer runningElementContainer = new RunningElementContainer(element, tagWorker);
449435
context.getCssContext().getRunningManager().addRunningElement(runningElemName, runningElementContainer);
450436

@@ -455,7 +441,6 @@ private ITagWorker processRunningElement(ITagWorker tagWorker, IElementNode elem
455441
* Adds @font-face fonts to the FontProvider.
456442
*/
457443
private void addFontFaceFonts() {
458-
//TODO Shall we add getFonts() to ICssResolver?
459444
if (cssResolver instanceof DefaultCssResolver) {
460445
for (CssFontFaceRule fontFace : ((DefaultCssResolver) cssResolver).getFonts()) {
461446
boolean findSupportedSrc = false;

src/main/java/com/itextpdf/html2pdf/attach/util/WaitingInlineElementsHelper.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ private Paragraph createLeavesContainer() {
237237
}
238238
}
239239
if (runningElementsOnly) {
240-
// TODO this might be avoided in future if we will come up with removing of completely empty
241-
// (both in terms of content and possible properties like background and borders) tags from
242-
// logical structure of resultant PDF documents
240+
// TODO DEVSIX-7008 Remove completely empty tags from logical structure of resultant PDF documents
243241
p.getAccessibilityProperties().setRole(StandardRoles.ARTIFACT);
244242
}
245243
return p;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void apply(ProcessorContext context, IStylesContainer stylesContainer, IT
131131
marginBox.setProperty(Property.OVERFLOW_Y, OverflowPropertyValue.VISIBLE);
132132
}
133133

134-
// TODO outlines are currently not supported for page margin boxes, because of the outlines handling specificity (they are handled on renderer's parent level)
134+
//TODO DEVSIX-7024 Support outlines for page margin boxes
135135
OutlineApplierUtil.applyOutlines(boxStyles, context, marginBox);
136136

137137
marginBox.setProperty(Property.FONT_PROVIDER, context.getFontProvider());

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void apply(ProcessorContext context, IStylesContainer stylesContainer, IT
8181
Map<String, String> cssStyles = stylesContainer.getStyles();
8282
for (IPropertyContainer child : spanTagWorker.getOwnLeafElements()) {
8383
// Workaround for form fields so that SpanTagCssApplier does not apply its font-size to the child.
84-
// Form fields have their own CSS applier // TODO remove when form fields are not leaf elements anymore
84+
// Form fields have their own CSS applier
8585
if (!(child instanceof IFormField)) {
8686
applyChildElementStyles(child, cssStyles, context, stylesContainer);
8787
}

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ This file is part of the iText (R) project.
6161
import com.itextpdf.layout.properties.BlendMode;
6262
import com.itextpdf.layout.properties.BackgroundRepeat.BackgroundRepeatValue;
6363
import com.itextpdf.layout.properties.Property;
64+
import com.itextpdf.layout.properties.TransparentColor;
6465
import com.itextpdf.layout.properties.UnitValue;
6566
import com.itextpdf.styledxmlparser.css.CommonCssConstants;
6667
import com.itextpdf.styledxmlparser.css.util.CssBackgroundUtils;
@@ -298,10 +299,8 @@ private static int getBackgroundSidePropertyIndex(final int propertiesNumber, fi
298299
private static void applyBackgroundColor(final String backgroundColorStr, final IPropertyContainer element,
299300
BackgroundBox clip) {
300301
if (backgroundColorStr != null && !CssConstants.TRANSPARENT.equals(backgroundColorStr)) {
301-
float[] rgbaColor = CssDimensionParsingUtils.parseRgbaColor(backgroundColorStr);
302-
Color color = new DeviceRgb(rgbaColor[0], rgbaColor[1], rgbaColor[2]);
303-
float opacity = rgbaColor[3];
304-
final Background backgroundColor = new Background(color, opacity, clip);
302+
TransparentColor color = CssDimensionParsingUtils.parseColor(backgroundColorStr);
303+
final Background backgroundColor = new Background(color.getColor(), color.getOpacity(), clip);
305304
element.setProperty(Property.BACKGROUND, backgroundColor);
306305
}
307306
}

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

+31-8
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ This file is part of the iText (R) project.
4444

4545
import com.itextpdf.html2pdf.attach.ProcessorContext;
4646
import com.itextpdf.html2pdf.css.CssConstants;
47+
import com.itextpdf.kernel.colors.Color;
4748
import com.itextpdf.kernel.colors.ColorConstants;
49+
import com.itextpdf.kernel.colors.DeviceCmyk;
4850
import com.itextpdf.kernel.colors.DeviceRgb;
4951
import com.itextpdf.layout.IPropertyContainer;
5052
import com.itextpdf.layout.borders.Border;
@@ -58,6 +60,7 @@ This file is part of the iText (R) project.
5860
import com.itextpdf.layout.borders.SolidBorder;
5961
import com.itextpdf.layout.properties.BorderRadius;
6062
import com.itextpdf.layout.properties.Property;
63+
import com.itextpdf.layout.properties.TransparentColor;
6164
import com.itextpdf.layout.properties.UnitValue;
6265
import com.itextpdf.styledxmlparser.css.resolve.CssDefaults;
6366
import com.itextpdf.styledxmlparser.css.util.CssDimensionParsingUtils;
@@ -191,13 +194,13 @@ public static Border getCertainBorder(String borderWidth, String borderStyle, St
191194
borderWidthValue = unitValue.getValue();
192195
Border border = null;
193196
if (borderWidthValue > 0) {
194-
DeviceRgb color = (DeviceRgb) ColorConstants.BLACK;
197+
Color color = ColorConstants.BLACK;
195198
float opacity = 1f;
196199
if (borderColor != null) {
197200
if (!CssConstants.TRANSPARENT.equals(borderColor)) {
198-
float[] rgbaColor = CssDimensionParsingUtils.parseRgbaColor(borderColor);
199-
color = new DeviceRgb(rgbaColor[0], rgbaColor[1], rgbaColor[2]);
200-
opacity = rgbaColor[3];
201+
TransparentColor tColor = CssDimensionParsingUtils.parseColor(borderColor);
202+
color = tColor.getColor();
203+
opacity = tColor.getOpacity();
201204
} else {
202205
opacity = 0f;
203206
}
@@ -219,16 +222,36 @@ public static Border getCertainBorder(String borderWidth, String borderStyle, St
219222
border = new DoubleBorder(color, borderWidthValue, opacity);
220223
break;
221224
case CssConstants.GROOVE:
222-
border = new GrooveBorder(color, borderWidthValue, opacity);
225+
if (color instanceof DeviceRgb) {
226+
border = new GrooveBorder((DeviceRgb)color, borderWidthValue, opacity);
227+
}
228+
if (color instanceof DeviceCmyk) {
229+
border = new GrooveBorder((DeviceCmyk)color, borderWidthValue, opacity);
230+
}
223231
break;
224232
case CssConstants.RIDGE:
225-
border = new RidgeBorder(color, borderWidthValue, opacity);
233+
if (color instanceof DeviceRgb) {
234+
border = new RidgeBorder((DeviceRgb)color, borderWidthValue, opacity);
235+
}
236+
if (color instanceof DeviceCmyk) {
237+
border = new RidgeBorder((DeviceCmyk)color, borderWidthValue, opacity);
238+
}
226239
break;
227240
case CssConstants.INSET:
228-
border = new InsetBorder(color, borderWidthValue, opacity);
241+
if (color instanceof DeviceRgb) {
242+
border = new InsetBorder((DeviceRgb)color, borderWidthValue, opacity);
243+
}
244+
if (color instanceof DeviceCmyk) {
245+
border = new InsetBorder((DeviceCmyk)color, borderWidthValue, opacity);
246+
}
229247
break;
230248
case CssConstants.OUTSET:
231-
border = new OutsetBorder(color, borderWidthValue, opacity);
249+
if (color instanceof DeviceRgb) {
250+
border = new OutsetBorder((DeviceRgb)color, borderWidthValue, opacity);
251+
}
252+
if (color instanceof DeviceCmyk) {
253+
border = new OutsetBorder((DeviceCmyk)color, borderWidthValue, opacity);
254+
}
232255
break;
233256
default:
234257
border = null;

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ public static void applyFontStyles(Map<String, String> cssProps, ProcessorContex
125125
if (cssColorPropValue != null) {
126126
TransparentColor transparentColor;
127127
if (!CssConstants.TRANSPARENT.equals(cssColorPropValue)) {
128-
float[] rgbaColor = CssDimensionParsingUtils.parseRgbaColor(cssColorPropValue);
129-
Color color = new DeviceRgb(rgbaColor[0], rgbaColor[1], rgbaColor[2]);
130-
float opacity = rgbaColor[3];
128+
TransparentColor tColor = CssDimensionParsingUtils.parseColor(cssColorPropValue);
129+
Color color = tColor.getColor();
130+
float opacity = tColor.getOpacity();
131131
transparentColor = new TransparentColor(color, opacity);
132132
} else {
133133
transparentColor = new TransparentColor(ColorConstants.BLACK, 0f);
@@ -203,7 +203,7 @@ public static void applyFontStyles(Map<String, String> cssProps, ProcessorContex
203203
}
204204
}
205205

206-
float [] colors = new float[4];
206+
TransparentColor tColor;
207207
Color textDecorationColor;
208208
float opacity = 1f;
209209
String textDecorationColorProp = cssProps.get(CssConstants.TEXT_DECORATION_COLOR);
@@ -220,9 +220,9 @@ public static void applyFontStyles(Map<String, String> cssProps, ProcessorContex
220220
logger.error(Html2PdfLogMessageConstant.HSL_COLOR_NOT_SUPPORTED);
221221
textDecorationColor = ColorConstants.BLACK;
222222
} else {
223-
colors = CssDimensionParsingUtils.parseRgbaColor(textDecorationColorProp);
224-
textDecorationColor = new DeviceRgb(colors[0], colors[1], colors[2]);;
225-
opacity = colors[3];
223+
tColor = CssDimensionParsingUtils.parseColor(textDecorationColorProp);
224+
textDecorationColor = tColor.getColor();
225+
opacity = tColor.getOpacity();
226226
}
227227
}
228228

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

+31-8
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ This file is part of the iText (R) project.
4444

4545

4646
import com.itextpdf.html2pdf.attach.ProcessorContext;
47+
import com.itextpdf.kernel.colors.Color;
4748
import com.itextpdf.kernel.colors.ColorConstants;
49+
import com.itextpdf.kernel.colors.DeviceCmyk;
4850
import com.itextpdf.kernel.colors.DeviceRgb;
4951
import com.itextpdf.layout.IPropertyContainer;
5052
import com.itextpdf.layout.borders.Border;
@@ -57,6 +59,7 @@ This file is part of the iText (R) project.
5759
import com.itextpdf.layout.borders.RidgeBorder;
5860
import com.itextpdf.layout.borders.SolidBorder;
5961
import com.itextpdf.layout.properties.Property;
62+
import com.itextpdf.layout.properties.TransparentColor;
6063
import com.itextpdf.layout.properties.UnitValue;
6164
import com.itextpdf.html2pdf.css.CssConstants;
6265
import com.itextpdf.styledxmlparser.css.resolve.CssDefaults;
@@ -151,13 +154,13 @@ public static Border getCertainBorder(String outlineWidth, String outlineStyle,
151154
outlineWidthValue = unitValue.getValue();
152155
Border outline = null;
153156
if (outlineWidthValue > 0) {
154-
DeviceRgb color = (DeviceRgb) ColorConstants.BLACK;
157+
Color color = ColorConstants.BLACK;
155158
float opacity = 1f;
156159
if (outlineColor != null) {
157160
if (!CssConstants.TRANSPARENT.equals(outlineColor)) {
158-
float[] rgbaColor = CssDimensionParsingUtils.parseRgbaColor(outlineColor);
159-
color = new DeviceRgb(rgbaColor[0], rgbaColor[1], rgbaColor[2]);
160-
opacity = rgbaColor[3];
161+
TransparentColor tColor = CssDimensionParsingUtils.parseColor(outlineColor);
162+
color = tColor.getColor();
163+
opacity = tColor.getOpacity();
161164
} else {
162165
opacity = 0f;
163166
}
@@ -180,16 +183,36 @@ public static Border getCertainBorder(String outlineWidth, String outlineStyle,
180183
outline = new DoubleBorder(color, outlineWidthValue, opacity);
181184
break;
182185
case CssConstants.GROOVE:
183-
outline = new GrooveBorder(color, outlineWidthValue, opacity);
186+
if (color instanceof DeviceRgb) {
187+
outline = new GrooveBorder((DeviceRgb)color, outlineWidthValue, opacity);
188+
}
189+
if (color instanceof DeviceCmyk) {
190+
outline = new GrooveBorder((DeviceCmyk)color, outlineWidthValue, opacity);
191+
}
184192
break;
185193
case CssConstants.RIDGE:
186-
outline = new RidgeBorder(color, outlineWidthValue, opacity);
194+
if (color instanceof DeviceRgb) {
195+
outline = new RidgeBorder((DeviceRgb)color, outlineWidthValue, opacity);
196+
}
197+
if (color instanceof DeviceCmyk) {
198+
outline = new RidgeBorder((DeviceCmyk)color, outlineWidthValue, opacity);
199+
}
187200
break;
188201
case CssConstants.INSET:
189-
outline = new InsetBorder(color, outlineWidthValue, opacity);
202+
if (color instanceof DeviceRgb) {
203+
outline = new InsetBorder((DeviceRgb)color, outlineWidthValue, opacity);
204+
}
205+
if (color instanceof DeviceCmyk) {
206+
outline = new InsetBorder((DeviceCmyk)color, outlineWidthValue, opacity);
207+
}
190208
break;
191209
case CssConstants.OUTSET:
192-
outline = new OutsetBorder(color, outlineWidthValue, opacity);
210+
if (color instanceof DeviceRgb) {
211+
outline = new OutsetBorder((DeviceRgb)color, outlineWidthValue, opacity);
212+
}
213+
if (color instanceof DeviceCmyk) {
214+
outline = new OutsetBorder((DeviceCmyk)color, outlineWidthValue, opacity);
215+
}
193216
break;
194217
default:
195218
outline = null;

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

+3
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ public final class Html2PdfLogMessageConstant {
201201
/** The Constant WORKER_UNABLE_TO_PROCESS_OTHER_WORKER. */
202202
public static final String WORKER_UNABLE_TO_PROCESS_OTHER_WORKER = "Worker of type {0} unable to process {1}";
203203

204+
/** The Constant ELEMENT_DOES_NOT_FIT_CURRENT_AREA. */
205+
public static final String ELEMENT_DOES_NOT_FIT_CURRENT_AREA = "Element does not fit current area";
206+
204207
private Html2PdfLogMessageConstant() {
205208
//Private constructor will prevent the instantiation of this class directly
206209
}

src/test/java/com/itextpdf/html2pdf/ConverterPropertiesTest.java

+18
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ public void setEventMetaInfoAndGetTest() {
7474
Assert.assertSame(testMetaInfo, metaInfo);
7575
}
7676

77+
@Test
78+
public void checkDefaultsTest() {
79+
ConverterProperties properties = new ConverterProperties();
80+
81+
Assert.assertTrue(properties.isImmediateFlush());
82+
Assert.assertFalse(properties.isCreateAcroForm());
83+
Assert.assertEquals(10, properties.getLimitOfLayouts());
84+
85+
properties.setImmediateFlush(false);
86+
properties.setCreateAcroForm(true);
87+
properties.setLimitOfLayouts(20);
88+
ConverterProperties propertiesCopied = new ConverterProperties(properties);
89+
90+
Assert.assertFalse(propertiesCopied.isImmediateFlush());
91+
Assert.assertTrue(propertiesCopied.isCreateAcroForm());
92+
Assert.assertEquals(20, propertiesCopied.getLimitOfLayouts());
93+
}
94+
7795
private static class TestMetaInfo implements IMetaInfo {
7896
}
7997
}

0 commit comments

Comments
 (0)