Skip to content

Commit a7a478a

Browse files
committed
[RELEASE] iText 7 pdfHTML - 3.0.5
https://github.com/itext/i7j-pdfhtml/releases/tag/3.0.5 * release_branch_DEVSIX-5154: [RELEASE] pdfHTML 3.0.5 Add support of attr() with type for url and string Add support of attr() with fallback for url and string Add support of attr() in target-counter Add tests Add new test demonstratic incorrect total page count when last page is trimmed Move target counter handler preparation on relayot from HtmlDocument to Document Add test for bug when floating element is not included in the div Update ToDo remarks Add test for case with empty tr Consider several TODOs without DEVSIX ticket Fix try-with-resource in HtmlConverter Add Document constructor to try-with-resources Add test demonstrating the problem of collision of internal doument links with OutlineHandler First iteration Replace tests from html2pdf-private: CalligraphyFontsTest#comparatorErrorTest Override getNextRenderer and createCopy in custom counter renderers Update cmp files after font selection changes Fix documentation error in pdfHTML Update cmp files. Replace html2pdf-private tests: ExternalImageTest and ExternalResourcesTest Add integration tests for page-break-inside: avoid inconsistent behavior Add missing copyright headers Add tests about intrinsic aspect ratio in flex algorithm. Fix already existing tests [AFTER RELEASE] pdfHTML 3.0.4 Replace html2pdf-private tests: FloatTest Add some height tests with resources Add missing copyright headers Add transform tests with resources Replace html2pdf-private tests: CssCollapsingMarginsTest
2 parents b864a82 + 9e19521 commit a7a478a

File tree

415 files changed

+5072
-271
lines changed

Some content is hidden

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

415 files changed

+5072
-271
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
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.1.15</version>
8+
<version>7.1.16</version>
99
<relativePath />
1010
</parent>
1111

1212
<artifactId>html2pdf</artifactId>
13-
<version>3.0.4</version>
13+
<version>3.0.5</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/HtmlConverter.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@ public static void convertToPdf(String html, PdfWriter pdfWriter, ConverterPrope
128128
}
129129

130130
/**
131-
* Converts HTML obtained from an {@link InputStream} to objects that
131+
* Converts a {@link String} containing HTML to objects that
132132
* will be added to a {@link PdfDocument}, using specific {@link ConverterProperties}.
133133
*
134-
* @param html the html in the form of a {@link String}
135-
* @param pdfDocument the {@link PdfDocument} instance
134+
* @param html the html in the form of a {@link String}
135+
* @param pdfDocument the {@link PdfDocument} instance
136136
* @param converterProperties a {@link ConverterProperties} instance
137137
*/
138138
public static void convertToPdf(String html, PdfDocument pdfDocument, ConverterProperties converterProperties) {
139-
Document document = convertToDocument(html, pdfDocument, converterProperties);
139+
final Document document = convertToDocument(html, pdfDocument, converterProperties);
140140
document.close();
141141
}
142142

@@ -247,12 +247,12 @@ public static void convertToPdf(InputStream htmlStream, PdfWriter pdfWriter, Con
247247
* @throws IOException Signals that an I/O exception has occurred.
248248
*/
249249
public static void convertToPdf(InputStream htmlStream, PdfDocument pdfDocument, ConverterProperties converterProperties) throws IOException {
250-
Document document = convertToDocument(htmlStream, pdfDocument, converterProperties);
250+
final Document document = convertToDocument(htmlStream, pdfDocument, converterProperties);
251251
document.close();
252252
}
253253

254254
/**
255-
* Converts HTML obtained from an {@link InputStream} to content that
255+
* Converts a {@link String} containing HTML to content that
256256
* will be written to a {@link PdfWriter}, returning a {@link Document} instance.
257257
*
258258
* @param html the html in the form of a {@link String}
@@ -277,7 +277,7 @@ public static Document convertToDocument(InputStream htmlStream, PdfWriter pdfWr
277277
}
278278

279279
/**
280-
* Converts HTML obtained from an {@link InputStream} to content that
280+
* Converts a {@link String} containing HTML to content that
281281
* will be written to a {@link PdfWriter}, using specific
282282
* {@link ConverterProperties}, returning a {@link Document} instance.
283283
*
@@ -306,7 +306,7 @@ public static Document convertToDocument(InputStream htmlStream, PdfWriter pdfWr
306306
}
307307

308308
/**
309-
* Converts HTML obtained from an {@link InputStream} to objects that
309+
* Converts a {@link String} containing HTML to objects that
310310
* will be added to a {@link PdfDocument}, using specific {@link ConverterProperties},
311311
* returning a {@link Document} instance.
312312
*

src/main/java/com/itextpdf/html2pdf/attach/impl/layout/HtmlDocument.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public HtmlDocument(PdfDocument pdfDoc, PageSize pageSize, boolean immediateFlus
5252
public void relayout() {
5353
if (rootRenderer instanceof HtmlDocumentRenderer) {
5454
((HtmlDocumentRenderer) rootRenderer).removeEventHandlers();
55-
((HtmlDocumentRenderer) rootRenderer).getTargetCounterHandler().prepareHandlerToRelayout();
5655
super.relayout();
5756
((HtmlDocumentRenderer) rootRenderer).processWaitingElement();
5857
}

src/main/java/com/itextpdf/html2pdf/attach/impl/layout/PageCountRenderer.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ This file is part of the iText (R) project.
4444

4545
import com.itextpdf.html2pdf.css.resolve.func.counter.CounterDigitsGlyphStyle;
4646
import com.itextpdf.html2pdf.html.HtmlUtils;
47+
import com.itextpdf.io.LogMessageConstant;
48+
import com.itextpdf.io.font.otf.GlyphLine;
49+
import com.itextpdf.io.util.MessageFormatUtil;
50+
import com.itextpdf.kernel.font.PdfFont;
4751
import com.itextpdf.layout.Document;
4852
import com.itextpdf.layout.layout.LayoutContext;
4953
import com.itextpdf.layout.layout.LayoutResult;
@@ -55,6 +59,8 @@ This file is part of the iText (R) project.
5559

5660
import java.util.ArrayList;
5761
import java.util.List;
62+
import org.slf4j.Logger;
63+
import org.slf4j.LoggerFactory;
5864

5965
/**
6066
* {@link TextRenderer} implementation for the page count.
@@ -70,7 +76,12 @@ class PageCountRenderer extends TextRenderer {
7076
*/
7177
PageCountRenderer(PageCountElement textElement) {
7278
super(textElement);
73-
digitsGlyphStyle = textElement.getDigitsGlyphStyle();
79+
this.digitsGlyphStyle = textElement.getDigitsGlyphStyle();
80+
}
81+
82+
protected PageCountRenderer(TextRenderer other) {
83+
super(other);
84+
this.digitsGlyphStyle = ((PageCountRenderer)other).digitsGlyphStyle;
7485
}
7586

7687
/* (non-Javadoc)
@@ -111,6 +122,33 @@ public LayoutResult layout(LayoutContext layoutContext) {
111122
return result;
112123
}
113124

125+
/**
126+
* {@inheritDoc}
127+
*/
128+
@Override
129+
public IRenderer getNextRenderer() {
130+
if (PageCountRenderer.class != this.getClass()) {
131+
Logger logger = LoggerFactory.getLogger(PageCountRenderer.class);
132+
logger.error(MessageFormatUtil.format(
133+
com.itextpdf.io.LogMessageConstant.GET_NEXT_RENDERER_SHOULD_BE_OVERRIDDEN));
134+
}
135+
return new PageCountRenderer((PageCountElement) modelElement);
136+
}
137+
138+
/**
139+
* {@inheritDoc}
140+
*/
141+
@Override
142+
protected TextRenderer createCopy(GlyphLine gl, PdfFont font) {
143+
if (PageCountRenderer.class != this.getClass()) {
144+
Logger logger = LoggerFactory.getLogger(PageCountRenderer.class);
145+
logger.error(MessageFormatUtil.format(LogMessageConstant.CREATE_COPY_SHOULD_BE_OVERRIDDEN));
146+
}
147+
PageCountRenderer copy = new PageCountRenderer(this);
148+
copy.setProcessedGlyphLineAndFont(gl, font);
149+
return copy;
150+
}
151+
114152
/* (non-Javadoc)
115153
* @see com.itextpdf.layout.renderer.TextRenderer#resolveFonts(java.util.List)
116154
*/

src/main/java/com/itextpdf/html2pdf/attach/impl/layout/PageTargetCountRenderer.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ This file is part of the iText (R) project.
2525
import com.itextpdf.html2pdf.LogMessageConstant;
2626
import com.itextpdf.html2pdf.css.resolve.func.counter.CounterDigitsGlyphStyle;
2727
import com.itextpdf.html2pdf.html.HtmlUtils;
28+
import com.itextpdf.io.font.otf.GlyphLine;
2829
import com.itextpdf.io.util.MessageFormatUtil;
30+
import com.itextpdf.kernel.font.PdfFont;
2931
import com.itextpdf.layout.layout.LayoutContext;
3032
import com.itextpdf.layout.layout.LayoutResult;
3133
import com.itextpdf.layout.property.Property;
@@ -62,6 +64,12 @@ public class PageTargetCountRenderer extends TextRenderer {
6264
target = textElement.getTarget();
6365
}
6466

67+
protected PageTargetCountRenderer(TextRenderer other) {
68+
super(other);
69+
this.digitsGlyphStyle = ((PageTargetCountRenderer)other).digitsGlyphStyle;
70+
this.target = ((PageTargetCountRenderer)other).target;
71+
}
72+
6573
/**
6674
* {@inheritDoc}
6775
*/
@@ -95,7 +103,27 @@ public void draw(DrawContext drawContext) {
95103
*/
96104
@Override
97105
public IRenderer getNextRenderer() {
98-
return this;
106+
if (PageTargetCountRenderer.class != this.getClass()) {
107+
Logger logger = LoggerFactory.getLogger(PageTargetCountRenderer.class);
108+
logger.error(MessageFormatUtil.format(
109+
com.itextpdf.io.LogMessageConstant.GET_NEXT_RENDERER_SHOULD_BE_OVERRIDDEN));
110+
}
111+
return new PageTargetCountRenderer((PageTargetCountElement) modelElement);
112+
}
113+
114+
/**
115+
* {@inheritDoc}
116+
*/
117+
@Override
118+
protected TextRenderer createCopy(GlyphLine gl, PdfFont font) {
119+
if (PageTargetCountRenderer.class != this.getClass()) {
120+
Logger logger = LoggerFactory.getLogger(PageTargetCountRenderer.class);
121+
logger.error(MessageFormatUtil.format(
122+
com.itextpdf.io.LogMessageConstant.CREATE_COPY_SHOULD_BE_OVERRIDDEN));
123+
}
124+
PageTargetCountRenderer copy = new PageTargetCountRenderer(this);
125+
copy.setProcessedGlyphLineAndFont(gl, font);
126+
return copy;
99127
}
100128

101129
/**

src/main/java/com/itextpdf/html2pdf/css/resolve/CssContentPropertyResolver.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ This file is part of the iText (R) project.
5252
import com.itextpdf.html2pdf.html.TagConstants;
5353
import com.itextpdf.io.util.MessageFormatUtil;
5454
import com.itextpdf.html2pdf.html.AttributeConstants;
55+
import com.itextpdf.styledxmlparser.css.CommonCssConstants;
5556
import com.itextpdf.styledxmlparser.css.page.PageMarginBoxContextNode;
5657
import com.itextpdf.html2pdf.css.page.PageMarginRunningElementNode;
5758
import com.itextpdf.styledxmlparser.css.parse.CssDeclarationValueTokenizer;
59+
import com.itextpdf.styledxmlparser.css.parse.CssDeclarationValueTokenizer.Token;
5860
import com.itextpdf.styledxmlparser.css.pseudo.CssPseudoElementNode;
5961
import com.itextpdf.styledxmlparser.css.resolve.CssQuotes;
6062
import com.itextpdf.styledxmlparser.css.util.CssGradientUtil;
@@ -164,7 +166,12 @@ static List<INode> resolveContent(Map<String, String> styles, INode contentConta
164166
if (params.size() < TARGET_COUNTER_MIN_PARAMS_SIZE) {
165167
return errorFallback(contentStr);
166168
}
167-
final String target = CssUtils.extractUrl(params.get(0));
169+
final String target = params.get(0).startsWith(CommonCssConstants.ATTRIBUTE + "(") ? CssUtils
170+
.extractAttributeValue(params.get(0), (IElementNode) contentContainer.parentNode())
171+
: CssUtils.extractUrl(params.get(0));
172+
if (target == null) {
173+
return errorFallback(contentStr);
174+
}
168175
final String counterName = params.get(1).trim();
169176
final CounterDigitsGlyphStyle listStyleType = HtmlUtils.convertStringCounterGlyphStyleToEnum(
170177
params.size() > TARGET_COUNTER_MIN_PARAMS_SIZE ?
@@ -188,7 +195,12 @@ static List<INode> resolveContent(Map<String, String> styles, INode contentConta
188195
if (params.size() < TARGET_COUNTERS_MIN_PARAMS_SIZE) {
189196
return errorFallback(contentStr);
190197
}
191-
final String target = CssUtils.extractUrl(params.get(0));
198+
final String target = params.get(0).startsWith(CommonCssConstants.ATTRIBUTE + "(") ? CssUtils
199+
.extractAttributeValue(params.get(0), (IElementNode) contentContainer.parentNode())
200+
: CssUtils.extractUrl(params.get(0));
201+
if (target == null) {
202+
return errorFallback(contentStr);
203+
}
192204
final String counterName = params.get(1).trim();
193205
String counterSeparator = params.get(2).trim();
194206
counterSeparator = counterSeparator.substring(1, counterSeparator.length() - 1);
@@ -220,18 +232,14 @@ static List<INode> resolveContent(Map<String, String> styles, INode contentConta
220232
+ CssConstants.HEIGHT + ":" + CssConstants.INHERIT + ";"
221233
+ CssConstants.WIDTH + ":" + CssConstants.INHERIT + ";");
222234
result.add(new CssContentElementNode(contentContainer, TagConstants.DIV, attributes));
223-
} else if (token.getValue().startsWith("attr(") && contentContainer instanceof CssPseudoElementNode) {
224-
int endBracket = token.getValue().indexOf(')');
225-
if (endBracket > 5) {
226-
String attrName = token.getValue().substring(5, endBracket);
227-
if (attrName.contains("(") || attrName.contains(" ")
228-
|| attrName.contains("'") || attrName.contains("\"")) {
229-
return errorFallback(contentStr);
230-
}
231-
IElementNode element = (IElementNode) contentContainer.parentNode();
232-
String value = element.getAttribute(attrName);
233-
result.add(new ContentTextNode(contentContainer, value == null ? "" : value));
235+
} else if (token.getValue().startsWith(CommonCssConstants.ATTRIBUTE + "(")
236+
&& contentContainer instanceof CssPseudoElementNode) {
237+
String value = CssUtils
238+
.extractAttributeValue(token.getValue(), (IElementNode) contentContainer.parentNode());
239+
if (value == null) {
240+
return errorFallback(contentStr);
234241
}
242+
result.add(new ContentTextNode(contentContainer, value));
235243
} else if (token.getValue().endsWith("quote") && contentContainer instanceof IStylesContainer) {
236244
if (quotes == null) {
237245
quotes = CssQuotes.createQuotes(styles.get(CssConstants.QUOTES), true);

0 commit comments

Comments
 (0)