|
| 1 | +using System; |
| 2 | +using iText.IO.Font; |
| 3 | +using iText.Kernel; |
| 4 | +using iText.Kernel.Pdf; |
| 5 | +using iText.Test; |
| 6 | + |
| 7 | +namespace iText.Kernel.Font { |
| 8 | + public class PdfType0FontTest : ExtendedITextTest { |
| 9 | + public static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext |
| 10 | + .CurrentContext.TestDirectory) + "/resources/itext/kernel/font/PdfType0FontTest/"; |
| 11 | + |
| 12 | + [NUnit.Framework.Test] |
| 13 | + public virtual void TrueTypeFontAndCmapConstructorTest() { |
| 14 | + TrueTypeFont ttf = new TrueTypeFont(sourceFolder + "NotoSerif-Regular_v1.7.ttf"); |
| 15 | + PdfType0Font type0Font = new PdfType0Font(ttf, PdfEncodings.IDENTITY_H); |
| 16 | + CMapEncoding cmap = type0Font.GetCmap(); |
| 17 | + NUnit.Framework.Assert.IsNotNull(cmap); |
| 18 | + NUnit.Framework.Assert.IsTrue(cmap.IsDirect()); |
| 19 | + NUnit.Framework.Assert.IsFalse(cmap.HasUniMap()); |
| 20 | + NUnit.Framework.Assert.IsNull(cmap.GetUniMapName()); |
| 21 | + NUnit.Framework.Assert.AreEqual("Adobe", cmap.GetRegistry()); |
| 22 | + NUnit.Framework.Assert.AreEqual("Identity", cmap.GetOrdering()); |
| 23 | + NUnit.Framework.Assert.AreEqual(0, cmap.GetSupplement()); |
| 24 | + NUnit.Framework.Assert.AreEqual(PdfEncodings.IDENTITY_H, cmap.GetCmapName()); |
| 25 | + } |
| 26 | + |
| 27 | + [NUnit.Framework.Test] |
| 28 | + public virtual void UnsupportedCmapTest() { |
| 29 | + NUnit.Framework.Assert.That(() => { |
| 30 | + TrueTypeFont ttf = new TrueTypeFont(sourceFolder + "NotoSerif-Regular_v1.7.ttf"); |
| 31 | + PdfType0Font type0Font = new PdfType0Font(ttf, PdfEncodings.WINANSI); |
| 32 | + } |
| 33 | + , NUnit.Framework.Throws.InstanceOf<PdfException>().With.Message.EqualTo(PdfException.OnlyIdentityCMapsSupportsWithTrueType)) |
| 34 | +; |
| 35 | + } |
| 36 | + |
| 37 | + [NUnit.Framework.Test] |
| 38 | + public virtual void DictionaryConstructorTest() { |
| 39 | + String filePath = sourceFolder + "documentWithType0Noto.pdf"; |
| 40 | + PdfDocument pdfDocument = new PdfDocument(new PdfReader(filePath)); |
| 41 | + PdfDictionary fontDict = pdfDocument.GetPage(1).GetResources().GetResource(PdfName.Font).GetAsDictionary(new |
| 42 | + PdfName("F1")); |
| 43 | + PdfType0Font type0Font = new PdfType0Font(fontDict); |
| 44 | + CMapEncoding cmap = type0Font.GetCmap(); |
| 45 | + NUnit.Framework.Assert.IsNotNull(cmap); |
| 46 | + NUnit.Framework.Assert.IsTrue(cmap.IsDirect()); |
| 47 | + NUnit.Framework.Assert.IsFalse(cmap.HasUniMap()); |
| 48 | + NUnit.Framework.Assert.IsNull(cmap.GetUniMapName()); |
| 49 | + NUnit.Framework.Assert.AreEqual("Adobe", cmap.GetRegistry()); |
| 50 | + NUnit.Framework.Assert.AreEqual("Identity", cmap.GetOrdering()); |
| 51 | + NUnit.Framework.Assert.AreEqual(0, cmap.GetSupplement()); |
| 52 | + NUnit.Framework.Assert.AreEqual(PdfEncodings.IDENTITY_H, cmap.GetCmapName()); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments