Skip to content

Commit

Permalink
[RELEASE] iText 7 pdfHTML 4.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
iText-CI committed Oct 13, 2022
2 parents 14c54b2 + 5e01170 commit 727a989
Show file tree
Hide file tree
Showing 75 changed files with 725 additions and 455 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<groupId>com.itextpdf</groupId>
<artifactId>root</artifactId>
<version>7.2.3</version>
<version>7.2.4</version>
<relativePath />
</parent>

<artifactId>html2pdf</artifactId>
<version>4.0.3</version>
<version>4.0.4</version>

<name>pdfHTML</name>
<description>pdfHTML is an iText 7 add-on that lets you to parse (X)HTML snippets and the associated CSS and converts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public ConverterProperties(ConverterProperties other) {
this.charset = other.charset;
this.metaInfo = other.metaInfo;
this.limitOfLayouts = other.limitOfLayouts;
this.immediateFlush = other.immediateFlush;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ This file is part of the iText (R) project.
*/
public final class PdfHtmlProductData {
private static final String PDF_HTML_PUBLIC_PRODUCT_NAME = "pdfHTML";
private static final String PDF_HTML_VERSION = "4.0.3";
private static final String PDF_HTML_VERSION = "4.0.4";
private static final int PDF_HTML_COPYRIGHT_SINCE = 2000;
private static final int PDF_HTML_COPYRIGHT_TO = 2022;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,20 +431,6 @@ private ITagWorker processRunningElement(ITagWorker tagWorker, IElementNode elem
return tagWorker;
}

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

Expand All @@ -455,7 +441,6 @@ private ITagWorker processRunningElement(ITagWorker tagWorker, IElementNode elem
* Adds @font-face fonts to the FontProvider.
*/
private void addFontFaceFonts() {
//TODO Shall we add getFonts() to ICssResolver?
if (cssResolver instanceof DefaultCssResolver) {
for (CssFontFaceRule fontFace : ((DefaultCssResolver) cssResolver).getFonts()) {
boolean findSupportedSrc = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,7 @@ private Paragraph createLeavesContainer() {
}
}
if (runningElementsOnly) {
// TODO this might be avoided in future if we will come up with removing of completely empty
// (both in terms of content and possible properties like background and borders) tags from
// logical structure of resultant PDF documents
// TODO DEVSIX-7008 Remove completely empty tags from logical structure of resultant PDF documents
p.getAccessibilityProperties().setRole(StandardRoles.ARTIFACT);
}
return p;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void apply(ProcessorContext context, IStylesContainer stylesContainer, IT
marginBox.setProperty(Property.OVERFLOW_Y, OverflowPropertyValue.VISIBLE);
}

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

marginBox.setProperty(Property.FONT_PROVIDER, context.getFontProvider());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void apply(ProcessorContext context, IStylesContainer stylesContainer, IT
Map<String, String> cssStyles = stylesContainer.getStyles();
for (IPropertyContainer child : spanTagWorker.getOwnLeafElements()) {
// Workaround for form fields so that SpanTagCssApplier does not apply its font-size to the child.
// Form fields have their own CSS applier // TODO remove when form fields are not leaf elements anymore
// Form fields have their own CSS applier
if (!(child instanceof IFormField)) {
applyChildElementStyles(child, cssStyles, context, stylesContainer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ This file is part of the iText (R) project.
import com.itextpdf.layout.properties.BlendMode;
import com.itextpdf.layout.properties.BackgroundRepeat.BackgroundRepeatValue;
import com.itextpdf.layout.properties.Property;
import com.itextpdf.layout.properties.TransparentColor;
import com.itextpdf.layout.properties.UnitValue;
import com.itextpdf.styledxmlparser.css.CommonCssConstants;
import com.itextpdf.styledxmlparser.css.util.CssBackgroundUtils;
Expand Down Expand Up @@ -298,10 +299,8 @@ private static int getBackgroundSidePropertyIndex(final int propertiesNumber, fi
private static void applyBackgroundColor(final String backgroundColorStr, final IPropertyContainer element,
BackgroundBox clip) {
if (backgroundColorStr != null && !CssConstants.TRANSPARENT.equals(backgroundColorStr)) {
float[] rgbaColor = CssDimensionParsingUtils.parseRgbaColor(backgroundColorStr);
Color color = new DeviceRgb(rgbaColor[0], rgbaColor[1], rgbaColor[2]);
float opacity = rgbaColor[3];
final Background backgroundColor = new Background(color, opacity, clip);
TransparentColor color = CssDimensionParsingUtils.parseColor(backgroundColorStr);
final Background backgroundColor = new Background(color.getColor(), color.getOpacity(), clip);
element.setProperty(Property.BACKGROUND, backgroundColor);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ This file is part of the iText (R) project.

import com.itextpdf.html2pdf.attach.ProcessorContext;
import com.itextpdf.html2pdf.css.CssConstants;
import com.itextpdf.kernel.colors.Color;
import com.itextpdf.kernel.colors.ColorConstants;
import com.itextpdf.kernel.colors.DeviceCmyk;
import com.itextpdf.kernel.colors.DeviceRgb;
import com.itextpdf.layout.IPropertyContainer;
import com.itextpdf.layout.borders.Border;
Expand All @@ -58,6 +60,7 @@ This file is part of the iText (R) project.
import com.itextpdf.layout.borders.SolidBorder;
import com.itextpdf.layout.properties.BorderRadius;
import com.itextpdf.layout.properties.Property;
import com.itextpdf.layout.properties.TransparentColor;
import com.itextpdf.layout.properties.UnitValue;
import com.itextpdf.styledxmlparser.css.resolve.CssDefaults;
import com.itextpdf.styledxmlparser.css.util.CssDimensionParsingUtils;
Expand Down Expand Up @@ -191,13 +194,13 @@ public static Border getCertainBorder(String borderWidth, String borderStyle, St
borderWidthValue = unitValue.getValue();
Border border = null;
if (borderWidthValue > 0) {
DeviceRgb color = (DeviceRgb) ColorConstants.BLACK;
Color color = ColorConstants.BLACK;
float opacity = 1f;
if (borderColor != null) {
if (!CssConstants.TRANSPARENT.equals(borderColor)) {
float[] rgbaColor = CssDimensionParsingUtils.parseRgbaColor(borderColor);
color = new DeviceRgb(rgbaColor[0], rgbaColor[1], rgbaColor[2]);
opacity = rgbaColor[3];
TransparentColor tColor = CssDimensionParsingUtils.parseColor(borderColor);
color = tColor.getColor();
opacity = tColor.getOpacity();
} else {
opacity = 0f;
}
Expand All @@ -219,16 +222,36 @@ public static Border getCertainBorder(String borderWidth, String borderStyle, St
border = new DoubleBorder(color, borderWidthValue, opacity);
break;
case CssConstants.GROOVE:
border = new GrooveBorder(color, borderWidthValue, opacity);
if (color instanceof DeviceRgb) {
border = new GrooveBorder((DeviceRgb)color, borderWidthValue, opacity);
}
if (color instanceof DeviceCmyk) {
border = new GrooveBorder((DeviceCmyk)color, borderWidthValue, opacity);
}
break;
case CssConstants.RIDGE:
border = new RidgeBorder(color, borderWidthValue, opacity);
if (color instanceof DeviceRgb) {
border = new RidgeBorder((DeviceRgb)color, borderWidthValue, opacity);
}
if (color instanceof DeviceCmyk) {
border = new RidgeBorder((DeviceCmyk)color, borderWidthValue, opacity);
}
break;
case CssConstants.INSET:
border = new InsetBorder(color, borderWidthValue, opacity);
if (color instanceof DeviceRgb) {
border = new InsetBorder((DeviceRgb)color, borderWidthValue, opacity);
}
if (color instanceof DeviceCmyk) {
border = new InsetBorder((DeviceCmyk)color, borderWidthValue, opacity);
}
break;
case CssConstants.OUTSET:
border = new OutsetBorder(color, borderWidthValue, opacity);
if (color instanceof DeviceRgb) {
border = new OutsetBorder((DeviceRgb)color, borderWidthValue, opacity);
}
if (color instanceof DeviceCmyk) {
border = new OutsetBorder((DeviceCmyk)color, borderWidthValue, opacity);
}
break;
default:
border = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ public static void applyFontStyles(Map<String, String> cssProps, ProcessorContex
if (cssColorPropValue != null) {
TransparentColor transparentColor;
if (!CssConstants.TRANSPARENT.equals(cssColorPropValue)) {
float[] rgbaColor = CssDimensionParsingUtils.parseRgbaColor(cssColorPropValue);
Color color = new DeviceRgb(rgbaColor[0], rgbaColor[1], rgbaColor[2]);
float opacity = rgbaColor[3];
TransparentColor tColor = CssDimensionParsingUtils.parseColor(cssColorPropValue);
Color color = tColor.getColor();
float opacity = tColor.getOpacity();
transparentColor = new TransparentColor(color, opacity);
} else {
transparentColor = new TransparentColor(ColorConstants.BLACK, 0f);
Expand Down Expand Up @@ -203,7 +203,7 @@ public static void applyFontStyles(Map<String, String> cssProps, ProcessorContex
}
}

float [] colors = new float[4];
TransparentColor tColor;
Color textDecorationColor;
float opacity = 1f;
String textDecorationColorProp = cssProps.get(CssConstants.TEXT_DECORATION_COLOR);
Expand All @@ -220,9 +220,9 @@ public static void applyFontStyles(Map<String, String> cssProps, ProcessorContex
logger.error(Html2PdfLogMessageConstant.HSL_COLOR_NOT_SUPPORTED);
textDecorationColor = ColorConstants.BLACK;
} else {
colors = CssDimensionParsingUtils.parseRgbaColor(textDecorationColorProp);
textDecorationColor = new DeviceRgb(colors[0], colors[1], colors[2]);;
opacity = colors[3];
tColor = CssDimensionParsingUtils.parseColor(textDecorationColorProp);
textDecorationColor = tColor.getColor();
opacity = tColor.getOpacity();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ This file is part of the iText (R) project.


import com.itextpdf.html2pdf.attach.ProcessorContext;
import com.itextpdf.kernel.colors.Color;
import com.itextpdf.kernel.colors.ColorConstants;
import com.itextpdf.kernel.colors.DeviceCmyk;
import com.itextpdf.kernel.colors.DeviceRgb;
import com.itextpdf.layout.IPropertyContainer;
import com.itextpdf.layout.borders.Border;
Expand All @@ -57,6 +59,7 @@ This file is part of the iText (R) project.
import com.itextpdf.layout.borders.RidgeBorder;
import com.itextpdf.layout.borders.SolidBorder;
import com.itextpdf.layout.properties.Property;
import com.itextpdf.layout.properties.TransparentColor;
import com.itextpdf.layout.properties.UnitValue;
import com.itextpdf.html2pdf.css.CssConstants;
import com.itextpdf.styledxmlparser.css.resolve.CssDefaults;
Expand Down Expand Up @@ -151,13 +154,13 @@ public static Border getCertainBorder(String outlineWidth, String outlineStyle,
outlineWidthValue = unitValue.getValue();
Border outline = null;
if (outlineWidthValue > 0) {
DeviceRgb color = (DeviceRgb) ColorConstants.BLACK;
Color color = ColorConstants.BLACK;
float opacity = 1f;
if (outlineColor != null) {
if (!CssConstants.TRANSPARENT.equals(outlineColor)) {
float[] rgbaColor = CssDimensionParsingUtils.parseRgbaColor(outlineColor);
color = new DeviceRgb(rgbaColor[0], rgbaColor[1], rgbaColor[2]);
opacity = rgbaColor[3];
TransparentColor tColor = CssDimensionParsingUtils.parseColor(outlineColor);
color = tColor.getColor();
opacity = tColor.getOpacity();
} else {
opacity = 0f;
}
Expand All @@ -180,16 +183,36 @@ public static Border getCertainBorder(String outlineWidth, String outlineStyle,
outline = new DoubleBorder(color, outlineWidthValue, opacity);
break;
case CssConstants.GROOVE:
outline = new GrooveBorder(color, outlineWidthValue, opacity);
if (color instanceof DeviceRgb) {
outline = new GrooveBorder((DeviceRgb)color, outlineWidthValue, opacity);
}
if (color instanceof DeviceCmyk) {
outline = new GrooveBorder((DeviceCmyk)color, outlineWidthValue, opacity);
}
break;
case CssConstants.RIDGE:
outline = new RidgeBorder(color, outlineWidthValue, opacity);
if (color instanceof DeviceRgb) {
outline = new RidgeBorder((DeviceRgb)color, outlineWidthValue, opacity);
}
if (color instanceof DeviceCmyk) {
outline = new RidgeBorder((DeviceCmyk)color, outlineWidthValue, opacity);
}
break;
case CssConstants.INSET:
outline = new InsetBorder(color, outlineWidthValue, opacity);
if (color instanceof DeviceRgb) {
outline = new InsetBorder((DeviceRgb)color, outlineWidthValue, opacity);
}
if (color instanceof DeviceCmyk) {
outline = new InsetBorder((DeviceCmyk)color, outlineWidthValue, opacity);
}
break;
case CssConstants.OUTSET:
outline = new OutsetBorder(color, outlineWidthValue, opacity);
if (color instanceof DeviceRgb) {
outline = new OutsetBorder((DeviceRgb)color, outlineWidthValue, opacity);
}
if (color instanceof DeviceCmyk) {
outline = new OutsetBorder((DeviceCmyk)color, outlineWidthValue, opacity);
}
break;
default:
outline = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ public final class Html2PdfLogMessageConstant {
/** The Constant WORKER_UNABLE_TO_PROCESS_OTHER_WORKER. */
public static final String WORKER_UNABLE_TO_PROCESS_OTHER_WORKER = "Worker of type {0} unable to process {1}";

/** The Constant ELEMENT_DOES_NOT_FIT_CURRENT_AREA. */
public static final String ELEMENT_DOES_NOT_FIT_CURRENT_AREA = "Element does not fit current area";

private Html2PdfLogMessageConstant() {
//Private constructor will prevent the instantiation of this class directly
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/com/itextpdf/html2pdf/ConverterPropertiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ public void setEventMetaInfoAndGetTest() {
Assert.assertSame(testMetaInfo, metaInfo);
}

@Test
public void checkDefaultsTest() {
ConverterProperties properties = new ConverterProperties();

Assert.assertTrue(properties.isImmediateFlush());
Assert.assertFalse(properties.isCreateAcroForm());
Assert.assertEquals(10, properties.getLimitOfLayouts());

properties.setImmediateFlush(false);
properties.setCreateAcroForm(true);
properties.setLimitOfLayouts(20);
ConverterProperties propertiesCopied = new ConverterProperties(properties);

Assert.assertFalse(propertiesCopied.isImmediateFlush());
Assert.assertTrue(propertiesCopied.isCreateAcroForm());
Assert.assertEquals(20, propertiesCopied.getLimitOfLayouts());
}

private static class TestMetaInfo implements IMetaInfo {
}
}
Loading

0 comments on commit 727a989

Please sign in to comment.