Skip to content

Commit 7103548

Browse files
author
Veronika Lisovskaya
committed
Add test for layout NonBreakingHyphenTest
DEVSIX-2034
1 parent 5d08610 commit 7103548

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2018 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.layout;
44+
45+
import com.itextpdf.io.font.PdfEncodings;
46+
import com.itextpdf.io.font.constants.StandardFonts;
47+
import com.itextpdf.kernel.font.PdfFontFactory;
48+
import com.itextpdf.kernel.pdf.PdfDocument;
49+
import com.itextpdf.kernel.pdf.PdfWriter;
50+
import com.itextpdf.kernel.utils.CompareTool;
51+
import com.itextpdf.layout.element.Paragraph;
52+
import com.itextpdf.layout.font.FontProvider;
53+
import com.itextpdf.layout.property.TextAlignment;
54+
import com.itextpdf.test.ExtendedITextTest;
55+
import com.itextpdf.test.annotations.type.IntegrationTest;
56+
import org.junit.Assert;
57+
import org.junit.BeforeClass;
58+
import org.junit.Test;
59+
import org.junit.experimental.categories.Category;
60+
61+
import java.io.IOException;
62+
63+
@Category(IntegrationTest.class)
64+
public class NonBreakingHyphenTest extends ExtendedITextTest {
65+
public static final String sourceFolder = "./src/test/resources/com/itextpdf/layout/NonBreakingHyphenTest/";
66+
public static final String destinationFolder = "./target/test/com/itextpdf/layout/NonBreakingHyphenTest/";
67+
public static final String fontsFolder = "./src/test/resources/com/itextpdf/layout/fonts/";
68+
69+
@BeforeClass
70+
public static void beforeClass() {
71+
createOrClearDestinationFolder(destinationFolder);
72+
}
73+
74+
@Test
75+
public void nonBreakingHyphenDifferentFonts() throws IOException, InterruptedException {
76+
//TODO: update after fix of DEVSIX-2034
77+
String outFileName = destinationFolder + "nonBreakingHyphenDifferentFonts.pdf";
78+
String cmpFileName = sourceFolder + "cmp_nonBreakingHyphenDifferentFonts.pdf";
79+
String diffPrefix = "diff01_";
80+
81+
Document document = new Document(new PdfDocument(new PdfWriter(outFileName)));
82+
83+
FontProvider sel = new FontProvider();
84+
sel.getFontSet().addFont(StandardFonts.TIMES_ROMAN);
85+
sel.getFontSet().addFont(StandardFonts.COURIER);
86+
sel.getFontSet().addFont(fontsFolder + "Puritan2.otf", PdfEncodings.IDENTITY_H, "Puritan2");
87+
sel.getFontSet().addFont(fontsFolder + "NotoSans-Regular.ttf", PdfEncodings.IDENTITY_H, "NotoSans");
88+
document.setFontProvider(sel);
89+
document.add(new Paragraph("StandardFonts - non-breaking hyphen \\u2011")
90+
.setUnderline()
91+
.setTextAlignment(TextAlignment.CENTER));
92+
document.add(new Paragraph("for Standard font TIMES_ROMAN: <&#8209;> non-breaking hyphen <\u2011> 2 hyphens<\u2011\u2011>here ")
93+
.setFont(StandardFonts.TIMES_ROMAN));
94+
document.add(new Paragraph("for Standard font COURIER: <&#8209;> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here ")
95+
.setFont(StandardFonts.COURIER));
96+
document.add(new Paragraph("for Standard font HELVETICA_BOLD: <&#8209;> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here ")
97+
.setFont(PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD)));
98+
document.add(new Paragraph("for Standard font SYMBOL: <&#8209;> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here ")
99+
.setFont(PdfFontFactory.createFont(StandardFonts.SYMBOL)));
100+
101+
document.add(new Paragraph("Non-Standard fonts - non-breaking hyphen \\u2011")
102+
.setUnderline()
103+
.setTextAlignment(TextAlignment.CENTER));
104+
document.add(new Paragraph("for NotoSans: <&#8209;> hyphen<\u2011> 2hyphens <\u2011\u2011>here")
105+
.setFont("NotoSans"));
106+
document.add(new Paragraph("for Puritan2: <&#8209;> hyphen<\u2011> 2hyphens <\u2011\u2011>here")
107+
.setFont("Puritan2"));
108+
109+
110+
sel.getFontSet().addFont(fontsFolder + "FreeSans.ttf", PdfEncodings.IDENTITY_H, "FreeSans");
111+
document.add(new Paragraph("AFTER adding of FreeSans font with non-breaking hyphen \\u2011 support")
112+
.setUnderline()
113+
.setTextAlignment(TextAlignment.CENTER));
114+
document.add(new Paragraph("for Standard font TIMES_ROMAN: <&#8209;> non-breaking hyphen <\u2011> 2 hyphens<\u2011\u2011>here ")
115+
.setFont(StandardFonts.TIMES_ROMAN));
116+
document.add(new Paragraph("for Standard font COURIER: <&#8209;> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here ")
117+
.setFont(StandardFonts.COURIER));
118+
document.add(new Paragraph("for Standard font HELVETICA_BOLD: <&#8209;> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here ")
119+
.setFont(PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD)));
120+
document.add(new Paragraph("for Standard font SYMBOL: <&#8209;> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here ")
121+
.setFont(PdfFontFactory.createFont(StandardFonts.SYMBOL)));
122+
document.add(new Paragraph("for FreeSans: <&#8209;> hyphen<\u2011> 2hyphens <\u2011\u2011>here")
123+
.setFont("FreeSans"));
124+
document.add(new Paragraph("for NotoSans: <&#8209;> hyphen<\u2011> 2hyphens <\u2011\u2011>here")
125+
.setFont("NotoSans"));
126+
document.add(new Paragraph("for Puritan2: <&#8209;> hyphen<\u2011> 2hyphens <\u2011\u2011>here")
127+
.setFont("Puritan2"));
128+
129+
document.close();
130+
131+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, diffPrefix));
132+
}
133+
}

0 commit comments

Comments
 (0)