|
| 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 | +using System; |
| 44 | +using iText.IO.Font; |
| 45 | +using iText.IO.Font.Constants; |
| 46 | +using iText.Kernel.Font; |
| 47 | +using iText.Kernel.Pdf; |
| 48 | +using iText.Kernel.Utils; |
| 49 | +using iText.Layout.Element; |
| 50 | +using iText.Layout.Font; |
| 51 | +using iText.Layout.Properties; |
| 52 | +using iText.Test; |
| 53 | + |
| 54 | +namespace iText.Layout { |
| 55 | + public class NonBreakingHyphenTest : ExtendedITextTest { |
| 56 | + public static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext |
| 57 | + .CurrentContext.TestDirectory) + "/resources/itext/layout/NonBreakingHyphenTest/"; |
| 58 | + |
| 59 | + public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory |
| 60 | + + "/test/itext/layout/NonBreakingHyphenTest/"; |
| 61 | + |
| 62 | + public static readonly String fontsFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext |
| 63 | + .CurrentContext.TestDirectory) + "/resources/itext/layout/fonts/"; |
| 64 | + |
| 65 | + [NUnit.Framework.OneTimeSetUp] |
| 66 | + public static void BeforeClass() { |
| 67 | + CreateOrClearDestinationFolder(destinationFolder); |
| 68 | + } |
| 69 | + |
| 70 | + /// <exception cref="System.IO.IOException"/> |
| 71 | + /// <exception cref="System.Exception"/> |
| 72 | + [NUnit.Framework.Test] |
| 73 | + public virtual void NonBreakingHyphenDifferentFonts() { |
| 74 | + //TODO: update after fix of DEVSIX-2034 |
| 75 | + String outFileName = destinationFolder + "nonBreakingHyphenDifferentFonts.pdf"; |
| 76 | + String cmpFileName = sourceFolder + "cmp_nonBreakingHyphenDifferentFonts.pdf"; |
| 77 | + String diffPrefix = "diff01_"; |
| 78 | + Document document = new Document(new PdfDocument(new PdfWriter(outFileName))); |
| 79 | + FontProvider sel = new FontProvider(); |
| 80 | + sel.GetFontSet().AddFont(StandardFonts.TIMES_ROMAN); |
| 81 | + sel.GetFontSet().AddFont(StandardFonts.COURIER); |
| 82 | + sel.GetFontSet().AddFont(fontsFolder + "Puritan2.otf", PdfEncodings.IDENTITY_H, "Puritan2"); |
| 83 | + sel.GetFontSet().AddFont(fontsFolder + "NotoSans-Regular.ttf", PdfEncodings.IDENTITY_H, "NotoSans"); |
| 84 | + document.SetFontProvider(sel); |
| 85 | + document.Add(new Paragraph("StandardFonts - non-breaking hyphen \\u2011").SetUnderline().SetTextAlignment( |
| 86 | + TextAlignment.CENTER)); |
| 87 | + document.Add(new Paragraph("for Standard font TIMES_ROMAN: <‑> non-breaking hyphen <\u2011> 2 hyphens<\u2011\u2011>here " |
| 88 | + ).SetFont(StandardFonts.TIMES_ROMAN)); |
| 89 | + document.Add(new Paragraph("for Standard font COURIER: <‑> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here " |
| 90 | + ).SetFont(StandardFonts.COURIER)); |
| 91 | + document.Add(new Paragraph("for Standard font HELVETICA_BOLD: <‑> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here " |
| 92 | + ).SetFont(PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD))); |
| 93 | + document.Add(new Paragraph("for Standard font SYMBOL: <‑> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here " |
| 94 | + ).SetFont(PdfFontFactory.CreateFont(StandardFonts.SYMBOL))); |
| 95 | + document.Add(new Paragraph("Non-Standard fonts - non-breaking hyphen \\u2011").SetUnderline().SetTextAlignment |
| 96 | + (TextAlignment.CENTER)); |
| 97 | + document.Add(new Paragraph("for NotoSans: <‑> hyphen<\u2011> 2hyphens <\u2011\u2011>here").SetFont("NotoSans" |
| 98 | + )); |
| 99 | + document.Add(new Paragraph("for Puritan2: <‑> hyphen<\u2011> 2hyphens <\u2011\u2011>here").SetFont("Puritan2" |
| 100 | + )); |
| 101 | + sel.GetFontSet().AddFont(fontsFolder + "FreeSans.ttf", PdfEncodings.IDENTITY_H, "FreeSans"); |
| 102 | + document.Add(new Paragraph("AFTER adding of FreeSans font with non-breaking hyphen \\u2011 support").SetUnderline |
| 103 | + ().SetTextAlignment(TextAlignment.CENTER)); |
| 104 | + document.Add(new Paragraph("for Standard font TIMES_ROMAN: <‑> non-breaking hyphen <\u2011> 2 hyphens<\u2011\u2011>here " |
| 105 | + ).SetFont(StandardFonts.TIMES_ROMAN)); |
| 106 | + document.Add(new Paragraph("for Standard font COURIER: <‑> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here " |
| 107 | + ).SetFont(StandardFonts.COURIER)); |
| 108 | + document.Add(new Paragraph("for Standard font HELVETICA_BOLD: <‑> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here " |
| 109 | + ).SetFont(PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD))); |
| 110 | + document.Add(new Paragraph("for Standard font SYMBOL: <‑> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here " |
| 111 | + ).SetFont(PdfFontFactory.CreateFont(StandardFonts.SYMBOL))); |
| 112 | + document.Add(new Paragraph("for FreeSans: <‑> hyphen<\u2011> 2hyphens <\u2011\u2011>here").SetFont("FreeSans" |
| 113 | + )); |
| 114 | + document.Add(new Paragraph("for NotoSans: <‑> hyphen<\u2011> 2hyphens <\u2011\u2011>here").SetFont("NotoSans" |
| 115 | + )); |
| 116 | + document.Add(new Paragraph("for Puritan2: <‑> hyphen<\u2011> 2hyphens <\u2011\u2011>here").SetFont("Puritan2" |
| 117 | + )); |
| 118 | + document.Close(); |
| 119 | + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder |
| 120 | + , diffPrefix)); |
| 121 | + } |
| 122 | + } |
| 123 | +} |
0 commit comments