Skip to content

Commit 3fafddc

Browse files
IdamkinIiText-CI
authored andcommitted
Add tests for generic font families
DEVSIX-1034
1 parent 844ca55 commit 3fafddc

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2019 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License version 3
8+
as published by the Free Software Foundation with the addition of the
9+
following permission added to Section 15 as permitted in Section 7(a):
10+
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
11+
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
12+
OF THIRD PARTY RIGHTS
13+
14+
This program is distributed in the hope that it will be useful, but
15+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
or FITNESS FOR A PARTICULAR PURPOSE.
17+
See the GNU Affero General Public License for more details.
18+
You should have received a copy of the GNU Affero General Public License
19+
along with this program; if not, see http://www.gnu.org/licenses or write to
20+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21+
Boston, MA, 02110-1301 USA, or download the license from the following URL:
22+
http://itextpdf.com/terms-of-use/
23+
24+
The interactive user interfaces in modified source and object code versions
25+
of this program must display Appropriate Legal Notices, as required under
26+
Section 5 of the GNU Affero General Public License.
27+
28+
In accordance with Section 7(b) of the GNU Affero General Public License,
29+
a covered work must retain the producer line in every PDF that is created
30+
or manipulated using iText.
31+
32+
You can be released from the requirements of the license by purchasing
33+
a commercial license. Buying such a license is mandatory as soon as you
34+
develop commercial activities involving the iText software without
35+
disclosing the source code of your own applications.
36+
These activities include: offering paid services to customers as an ASP,
37+
serving PDFs on the fly in a web application, shipping iText with a closed
38+
source product.
39+
40+
For more information, please contact iText Software Corp. at this
41+
42+
*/
43+
package com.itextpdf.html2pdf.css;
44+
45+
import com.itextpdf.html2pdf.ConverterProperties;
46+
import com.itextpdf.html2pdf.HtmlConverter;
47+
import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
48+
import com.itextpdf.kernel.utils.CompareTool;
49+
import com.itextpdf.layout.font.FontProvider;
50+
import com.itextpdf.test.ExtendedITextTest;
51+
import com.itextpdf.test.annotations.type.IntegrationTest;
52+
import org.junit.Assert;
53+
import org.junit.BeforeClass;
54+
import org.junit.Test;
55+
import org.junit.experimental.categories.Category;
56+
57+
import java.io.File;
58+
import java.io.IOException;
59+
60+
@Category(IntegrationTest.class)
61+
//TODO(DEVSIX-1034): serif, sans-serif font families are not supported
62+
//TODO(DEVSIX-1036): cursive, fantasy, system-ui font-families are not supported
63+
public class FontSelectorGenericFamiliesTest extends ExtendedITextTest {
64+
public static final String sourceFolder = "./src/test/resources/com/itextpdf/html2pdf/css/FontSelectorGenericFamiliesTest/";
65+
public static final String destinationFolder = "./target/test/com/itextpdf/html2pdf/css/FontSelectorGenericFamiliesTest/";
66+
67+
@BeforeClass
68+
public static void beforeClass() {
69+
createDestinationFolder(destinationFolder);
70+
}
71+
72+
@Test
73+
public void standardFontsTest() throws IOException, InterruptedException {
74+
runTest("standardFonts", new DefaultFontProvider(true, false, false));
75+
}
76+
77+
@Test
78+
public void embeddedFontsTest() throws IOException, InterruptedException {
79+
runTest("embeddedFonts", new DefaultFontProvider(false, true, false));
80+
}
81+
82+
public void runTest(String testName, FontProvider fontProvider) throws IOException, InterruptedException {
83+
String outPdf = destinationFolder + testName + ".pdf";
84+
String cmpPdf = sourceFolder + "cmp_" + testName + ".pdf";
85+
String srcHtml = sourceFolder + "genericFontFamilies.html";
86+
ConverterProperties properties = new ConverterProperties().setFontProvider(fontProvider);
87+
HtmlConverter.convertToPdf(new File(srcHtml), new File(outPdf), properties);
88+
Assert.assertNull(new CompareTool().compareByContent(outPdf, cmpPdf, destinationFolder, "diff_" + testName + "_"));
89+
}
90+
}
34.3 KB
Binary file not shown.
3.2 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html><head><title>Font Family Test</title><style>
2+
th, td {text-align: center;
3+
height: 45px; border: 1px solid black; }
4+
table {font-family: monospace; } </style>
5+
</head><body><h1>Font Family Test</h1><table><col width='50'><col width='50'><col width='50'><col width='300'><tr><th scope='col'>Font-family</th><th scope='col'>Font-weight</th><th scope='col'>Font-style</th><th scope='col' >Result</th></tr><tr><td>serif</td><td>normal</td><td>normal</td><td style = " font-family: serif; font-weight: normal; font-style: normal";>quick brown fox jumps over the lazy dog</td></tr><tr><td>sans-serif</td><td>normal</td><td>normal</td><td style = " font-family: sans-serif; font-weight: normal; font-style: normal";>quick brown fox jumps over the lazy dog</td></tr><tr><td>monospace</td><td>normal</td><td>normal</td><td style = " font-family: monospace; font-weight: normal; font-style: normal";>quick brown fox jumps over the lazy dog</td></tr><tr><td>cursive</td><td>normal</td><td>normal</td><td style = " font-family: cursive; font-weight: normal; font-style: normal";>quick brown fox jumps over the lazy dog</td></tr><tr><td>fantasy</td><td>normal</td><td>normal</td><td style = " font-family: fantasy; font-weight: normal; font-style: normal";>quick brown fox jumps over the lazy dog</td></tr><tr><td>system-ui</td><td>normal</td><td>normal</td><td style = " font-family: system-ui; font-weight: normal; font-style: normal";>quick brown fox jumps over the lazy dog</td></tr></table></body></html>

0 commit comments

Comments
 (0)