Skip to content

Commit cce00e1

Browse files
Kate IvanovaiText-CI
authored andcommitted
Move html with svg tests
DEVSIX-3038
1 parent dab38ed commit cce00e1

File tree

101 files changed

+19125
-3
lines changed

Some content is hidden

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

101 files changed

+19125
-3
lines changed

src/test/java/com/itextpdf/html2pdf/element/SvgTest.java

Lines changed: 189 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ This file is part of the iText (R) project.
4242
*/
4343
package com.itextpdf.html2pdf.element;
4444

45+
import com.itextpdf.html2pdf.ConverterProperties;
4546
import com.itextpdf.html2pdf.HtmlConverter;
47+
import com.itextpdf.kernel.pdf.PdfDocument;
48+
import com.itextpdf.kernel.pdf.PdfWriter;
4649
import com.itextpdf.kernel.utils.CompareTool;
4750
import com.itextpdf.styledxmlparser.LogMessageConstant;
4851
import com.itextpdf.svg.exceptions.SvgLogMessageConstant;
@@ -56,7 +59,6 @@ This file is part of the iText (R) project.
5659
import org.junit.Test;
5760
import org.junit.experimental.categories.Category;
5861
import org.junit.rules.ExpectedException;
59-
6062
import java.io.File;
6163
import java.io.IOException;
6264

@@ -66,6 +68,7 @@ public class SvgTest extends ExtendedITextTest {
6668
public static final String sourceFolder = "./src/test/resources/com/itextpdf/html2pdf/element/SvgTest/";
6769
public static final String destinationFolder = "./target/test/com/itextpdf/html2pdf/element/SvgTest/";
6870

71+
6972
@Rule
7073
public ExpectedException junitExpectedException = ExpectedException.none();
7174

@@ -103,6 +106,159 @@ public void inlineSvgExternalFontUrlTest() throws IOException, InterruptedExcept
103106
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + name + ".pdf", sourceFolder + "cmp_" + name + ".pdf", destinationFolder, "diff_" + name + "_"));
104107
}
105108

109+
@Test
110+
@LogMessages(messages = {
111+
@LogMessage(messageTemplate = com.itextpdf.io.LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA),
112+
})
113+
public void convert_inline_Svg_path_in_HTML() throws IOException, InterruptedException {
114+
String name = "HTML_with_inline_svg_path";
115+
HtmlConverter.convertToPdf(new File(sourceFolder + name + ".html"), new File(destinationFolder + name + ".pdf"));
116+
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + name + ".pdf", sourceFolder + "cmp_" + name + ".pdf", destinationFolder, "diff_" + name + "_"));
117+
}
118+
119+
@Test
120+
@LogMessages(messages = {
121+
@LogMessage(messageTemplate = com.itextpdf.io.LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA),
122+
})
123+
// TODO: Update cmp_ file when DEVSIX-2719 resolved
124+
public void convert_inline_Svg_polygon_in_HTML() throws IOException, InterruptedException {
125+
String name = "HTML_with_inline_svg_polygon";
126+
HtmlConverter.convertToPdf(new File(sourceFolder + name + ".html"), new File(destinationFolder + name + ".pdf"));
127+
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + name + ".pdf", sourceFolder + "cmp_" + name + ".pdf", destinationFolder, "diff_" + name + "_"));
128+
}
129+
130+
@Test
131+
@LogMessages(messages = {
132+
@LogMessage(messageTemplate = com.itextpdf.io.LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA),
133+
})
134+
public void convert_namespace_Svg_in_HTML() throws IOException, InterruptedException {
135+
String name = "namespace_svg";
136+
HtmlConverter.convertToPdf(new File(sourceFolder + name + ".html"), new File(destinationFolder + name + ".pdf"));
137+
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + name + ".pdf", sourceFolder + "cmp_" + name + ".pdf", destinationFolder, "diff_" + name + "_"));
138+
}
139+
140+
@Test
141+
public void convertInlineSvgCircle() throws IOException, InterruptedException {
142+
String html = "inline_svg_circle";
143+
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(destinationFolder + html + ".pdf"));
144+
pdfDoc.addNewPage();
145+
String string_file = "<!DOCTYPE html>\n" +
146+
"<html>\n" +
147+
"<body>\n" +
148+
"\n" +
149+
"<svg width=\"100\" height=\"100\">\n" +
150+
" <circle cx=\"50\" cy=\"50\" r=\"40\" stroke=\"green\" stroke-width=\"4\" fill=\"yellow\" />\n" +
151+
"</svg>\n" +
152+
"\n" +
153+
"</body>\n" +
154+
155+
"</html>";
156+
HtmlConverter.convertToPdf(string_file, pdfDoc, new ConverterProperties());
157+
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + html + ".pdf", sourceFolder + "cmp_" + html + ".pdf", destinationFolder));
158+
}
159+
160+
161+
@Test
162+
public void convertInlineSvgRectangle() throws IOException, InterruptedException {
163+
String html = "inline_svg_rectangle";
164+
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(destinationFolder + html + ".pdf"));
165+
pdfDoc.addNewPage();
166+
String string_file = "<!DOCTYPE html>\n" +
167+
"<html>\n" +
168+
"<body>\n" +
169+
"\n" +
170+
"<svg width=\"400\" height=\"100\">\n" +
171+
" <rect width=\"400\" height=\"100\" \n" +
172+
" style=\"fill:rgb(0,0,255);stroke-width:10;stroke:rgb(0,0,0)\" />\n" +
173+
"Sorry, your browser does not support inline SVG.\n" +
174+
"</svg>\n" +
175+
" \n" +
176+
"</body>\n" +
177+
"</html>\n";
178+
179+
HtmlConverter.convertToPdf(string_file, pdfDoc, new ConverterProperties());
180+
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + html + ".pdf", sourceFolder + "cmp_" + html + ".pdf", destinationFolder));
181+
}
182+
183+
@Test
184+
public void convertInlineSvgRoundedRectangle() throws IOException, InterruptedException {
185+
String html = "inline_svg_rounded_rect";
186+
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(destinationFolder + html + ".pdf"));
187+
pdfDoc.addNewPage();
188+
String string_file = "<!DOCTYPE html>\n" +
189+
"<html>\n" +
190+
"<body>\n" +
191+
"\n" +
192+
"<svg width=\"400\" height=\"180\">\n" +
193+
" <rect x=\"50\" y=\"20\" rx=\"20\" ry=\"20\" width=\"150\" height=\"150\"\n" +
194+
" style=\"fill:red;stroke:black;stroke-width:5;opacity:0.5\" />\n" +
195+
"Sorry, your browser does not support inline SVG.\n" +
196+
"</svg>\n" +
197+
"\n" +
198+
"</body>\n" +
199+
"</html>\n";
200+
201+
HtmlConverter.convertToPdf(string_file, pdfDoc, new ConverterProperties());
202+
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + html + ".pdf", sourceFolder + "cmp_" + html + ".pdf", destinationFolder));
203+
}
204+
205+
@Test
206+
// TODO: Update cmp_ file when DEVSIX-2719 resolved
207+
public void convertInlineSvgStar() throws IOException, InterruptedException {
208+
String html = "inline_svg_star";
209+
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(destinationFolder + html + ".pdf"));
210+
pdfDoc.addNewPage();
211+
String string_file = "<!DOCTYPE html>\n" +
212+
"<html>\n" +
213+
"<body>\n" +
214+
"\n" +
215+
"<svg width=\"300\" height=\"200\">\n" +
216+
" <polygon points=\"100,10 40,198 190,78 10,78 160,198\"\n" +
217+
" style=\"fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;\" />\n" +
218+
"Sorry, your browser does not support inline SVG.\n" +
219+
"</svg>\n" +
220+
" \n" +
221+
"</body>\n" +
222+
"</html>\n";
223+
224+
HtmlConverter.convertToPdf(string_file, pdfDoc, new ConverterProperties());
225+
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + html + ".pdf", sourceFolder + "cmp_" + html + ".pdf", destinationFolder));
226+
}
227+
228+
@Test
229+
@LogMessages(messages = {
230+
@LogMessage(messageTemplate = SvgLogMessageConstant.UNMAPPEDTAG),
231+
})
232+
public void convertInlineSvgLogo() throws IOException, InterruptedException {
233+
String html = "inline_svg_logo";
234+
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(destinationFolder + html + ".pdf"));
235+
pdfDoc.addNewPage();
236+
String string_file = "<!DOCTYPE html>\n" +
237+
" <html>\n" +
238+
" <body>\n" +
239+
"\n" +
240+
" <svg height=\"130\" width=\"500\">\n" +
241+
" <defs>\n" +
242+
" <linearGradient id=\"grad1\" x1=\"0%\" y1=\"0%\" x2=\"100%\" y2=\"0%\">\n" +
243+
" <stop offset=\"0%\"\n" +
244+
" style=\"stop-color:rgb(255,255,0);stop-opacity:1\" />\n" +
245+
" <stop offset=\"100%\"\n" +
246+
" style=\"stop-color:rgb(255,0,0);stop-opacity:1\" />\n" +
247+
" </linearGradient>\n" +
248+
" </defs>\n" +
249+
" <ellipse cx=\"100\" cy=\"70\" rx=\"85\" ry=\"55\" fill=\"url(#grad1)\" />\n" +
250+
" <text fill=\"#ffffff\" font-size=\"45\" font-family=\"Verdana\"\n" +
251+
" x=\"50\" y=\"86\">SVG</text>\n" +
252+
" Sorry, your browser does not support inline SVG.\n" +
253+
" </svg>\n" +
254+
"\n" +
255+
" </body>\n" +
256+
" </html>\n";
257+
258+
HtmlConverter.convertToPdf(string_file, pdfDoc, new ConverterProperties());
259+
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + html + ".pdf", sourceFolder + "cmp_" + html + ".pdf", destinationFolder));
260+
}
261+
106262
@Test
107263
public void externalImageSuccessTest() throws IOException, InterruptedException {
108264
String name = "external_img";
@@ -124,6 +280,10 @@ public void externalImageNonExistentRefTest() throws IOException, InterruptedExc
124280
}
125281

126282
@Test
283+
//TODO update after DEVSIX-3034
284+
@LogMessages(messages = {
285+
@LogMessage(messageTemplate = com.itextpdf.html2pdf.LogMessageConstant.WORKER_UNABLE_TO_PROCESS_OTHER_WORKER, count = 2)
286+
})
127287
public void externalObjectSuccessTest() throws IOException, InterruptedException {
128288
String name = "external_object";
129289
HtmlConverter.convertToPdf(new File(sourceFolder + name + ".html"), new File(destinationFolder + name + ".pdf"));
@@ -138,6 +298,18 @@ public void externalObjectWithResourceTest() throws IOException, InterruptedExce
138298
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + name + ".pdf", sourceFolder + "cmp_" + name + ".pdf", destinationFolder, "diff_" + name + "_"));
139299
}
140300

301+
@Test
302+
@LogMessages(messages = {
303+
@LogMessage(messageTemplate = com.itextpdf.io.LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA, count = 66),
304+
@LogMessage(messageTemplate = SvgLogMessageConstant.UNMAPPEDTAG, count = 67),
305+
})
306+
public void externalObjectWithGoogleCharts() throws IOException, InterruptedException {
307+
//TODO update after DEVSIX-2239
308+
String name = "inlineSvg_googleCharts";
309+
HtmlConverter.convertToPdf(new File(sourceFolder + name + ".html"), new File(destinationFolder + name + ".pdf"));
310+
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + name + ".pdf", sourceFolder + "cmp_" + name + ".pdf", destinationFolder, "diff_" + name + "_"));
311+
}
312+
141313
@Test
142314
@LogMessages(messages = {
143315
@LogMessage(messageTemplate = LogMessageConstant.UNABLE_TO_RETRIEVE_STREAM_WITH_GIVEN_BASE_URI),
@@ -149,6 +321,22 @@ public void externalObjectNonExistentRefTest() throws IOException, InterruptedEx
149321
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + name + ".pdf", sourceFolder + "cmp_" + name + ".pdf", destinationFolder, "diff_" + name + "_"));
150322
}
151323

324+
@Test
325+
//TODO: Update cmp_ file when DEVSIX-2731 resolved
326+
public void htmlWithSvgBackground() throws IOException, InterruptedException {
327+
String name = "HTML_with_svg_background";
328+
HtmlConverter.convertToPdf(new File(sourceFolder + name + ".html"), new File(destinationFolder + name + ".pdf"));
329+
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + name + ".pdf", sourceFolder + "cmp_" + name + ".pdf", destinationFolder, "diff_" + name + "_"));
330+
}
331+
332+
@Test
333+
//TODO: Update cmp_ file when DEVSIX-2731 resolved
334+
public void htmlWithSvgBackgroundNoViewbox() throws IOException, InterruptedException {
335+
String name = "Html_with_svg_background_no_viewbox";
336+
HtmlConverter.convertToPdf(new File(sourceFolder + name + ".html"), new File(destinationFolder + name + ".pdf"));
337+
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + name + ".pdf", sourceFolder + "cmp_" + name + ".pdf", destinationFolder, "diff_" + name + "_"));
338+
}
339+
152340
@Test
153341
@LogMessages(messages = {
154342
@LogMessage(messageTemplate = SvgLogMessageConstant.MISSING_WIDTH),
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Embedded SVG</title>
6+
</head>
7+
<body>
8+
<h1>Embedded SVG</h1>
9+
<svg viewBox="0 0 1200 600" version="1.1">
10+
<path fill="red" stroke="blue" stroke-width="10"
11+
d= "M 150,205 L179,291 L269,291 L197,345
12+
L223,431 L150,380 L77,431 L103,345
13+
L31,291 L121,291 z"/>
14+
<path fill="lime" stroke="blue" stroke-width="10"
15+
d="M 400,205 L508,267.5 L508,392.5
16+
L400,455 L292,392.6 L292,267.5 z"/>
17+
</svg>
18+
</body>
19+
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Embedded SVG</title>
6+
</head>
7+
<body>
8+
<h1>Embedded SVG</h1>
9+
<svg viewBox="0 0 1200 600" version="1.1">
10+
<polygon fill="red" stroke="blue" stroke-width="10"
11+
points = "150,205 179,291 269,291 197,345
12+
223,431 150,380 77,431 103,345
13+
31,291 121,291"/>
14+
<polygon fill="lime" stroke="blue" stroke-width="10"
15+
points="400,205 508,267.5 508,392.5
16+
400,455 292,392.6 292,267.5"/>
17+
</svg>
18+
</body>
19+
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Embedded SVG</title>
6+
<style type="text/css">
7+
.picture {
8+
width: 600;
9+
height: 700;
10+
background-image: url(SVG_picture.svg);
11+
background-size: 600, 700;
12+
}
13+
</style>
14+
</head>
15+
<body>
16+
<h1>Embedded SVG</h1>
17+
<div class="picture">SVG-image</div>
18+
</body>
19+
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Embedded SVG</title>
6+
<style type="text/css">
7+
.picture {
8+
width: 600;
9+
height: 700;
10+
background-image: url(SvgFile.svg);
11+
background-size: 600, 700;
12+
}
13+
</style>
14+
</head>
15+
<body>
16+
<h1>Embedded SVG</h1>
17+
<div class="picture">SVG-image</div>
18+
</body>
19+
</html>
Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 11 additions & 0 deletions
Loading
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)