|
| 1 | +package com.itextpdf.kernel.font; |
| 2 | + |
| 3 | +import com.itextpdf.io.font.CMapEncoding; |
| 4 | +import com.itextpdf.io.font.PdfEncodings; |
| 5 | +import com.itextpdf.io.font.TrueTypeFont; |
| 6 | +import com.itextpdf.kernel.PdfException; |
| 7 | +import com.itextpdf.kernel.pdf.PdfDictionary; |
| 8 | +import com.itextpdf.kernel.pdf.PdfDocument; |
| 9 | +import com.itextpdf.kernel.pdf.PdfName; |
| 10 | +import com.itextpdf.kernel.pdf.PdfReader; |
| 11 | +import com.itextpdf.test.ExtendedITextTest; |
| 12 | +import com.itextpdf.test.annotations.type.UnitTest; |
| 13 | + |
| 14 | +import java.io.IOException; |
| 15 | +import org.junit.Assert; |
| 16 | +import org.junit.Rule; |
| 17 | +import org.junit.Test; |
| 18 | +import org.junit.experimental.categories.Category; |
| 19 | +import org.junit.rules.ExpectedException; |
| 20 | + |
| 21 | +@Category(UnitTest.class) |
| 22 | +public class PdfType0FontTest extends ExtendedITextTest { |
| 23 | + |
| 24 | + public static final String sourceFolder = "./src/test/resources/com/itextpdf/kernel/font/PdfType0FontTest/"; |
| 25 | + |
| 26 | + @Rule |
| 27 | + public ExpectedException junitExpectedException = ExpectedException.none(); |
| 28 | + |
| 29 | + @Test |
| 30 | + public void trueTypeFontAndCmapConstructorTest() throws IOException { |
| 31 | + TrueTypeFont ttf = new TrueTypeFont(sourceFolder + "NotoSerif-Regular_v1.7.ttf"); |
| 32 | + |
| 33 | + PdfType0Font type0Font = new PdfType0Font(ttf, PdfEncodings.IDENTITY_H); |
| 34 | + |
| 35 | + CMapEncoding cmap = type0Font.getCmap(); |
| 36 | + |
| 37 | + Assert.assertNotNull(cmap); |
| 38 | + Assert.assertTrue(cmap.isDirect()); |
| 39 | + Assert.assertFalse(cmap.hasUniMap()); |
| 40 | + Assert.assertNull(cmap.getUniMapName()); |
| 41 | + Assert.assertEquals("Adobe", cmap.getRegistry()); |
| 42 | + Assert.assertEquals("Identity", cmap.getOrdering()); |
| 43 | + Assert.assertEquals(0, cmap.getSupplement()); |
| 44 | + Assert.assertEquals(PdfEncodings.IDENTITY_H, cmap.getCmapName()); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void unsupportedCmapTest() throws IOException { |
| 49 | + junitExpectedException.expect(PdfException.class); |
| 50 | + junitExpectedException.expectMessage(PdfException.OnlyIdentityCMapsSupportsWithTrueType); |
| 51 | + |
| 52 | + TrueTypeFont ttf = new TrueTypeFont(sourceFolder + "NotoSerif-Regular_v1.7.ttf"); |
| 53 | + PdfType0Font type0Font = new PdfType0Font(ttf, PdfEncodings.WINANSI); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void dictionaryConstructorTest() throws IOException { |
| 58 | + String filePath = sourceFolder + "documentWithType0Noto.pdf"; |
| 59 | + |
| 60 | + PdfDocument pdfDocument = new PdfDocument(new PdfReader(filePath)); |
| 61 | + |
| 62 | + PdfDictionary fontDict = pdfDocument.getPage(1).getResources() |
| 63 | + .getResource(PdfName.Font).getAsDictionary(new PdfName("F1")); |
| 64 | + |
| 65 | + PdfType0Font type0Font = new PdfType0Font(fontDict); |
| 66 | + |
| 67 | + CMapEncoding cmap = type0Font.getCmap(); |
| 68 | + |
| 69 | + Assert.assertNotNull(cmap); |
| 70 | + Assert.assertTrue(cmap.isDirect()); |
| 71 | + Assert.assertFalse(cmap.hasUniMap()); |
| 72 | + Assert.assertNull(cmap.getUniMapName()); |
| 73 | + Assert.assertEquals("Adobe", cmap.getRegistry()); |
| 74 | + Assert.assertEquals("Identity", cmap.getOrdering()); |
| 75 | + Assert.assertEquals(0, cmap.getSupplement()); |
| 76 | + Assert.assertEquals(PdfEncodings.IDENTITY_H, cmap.getCmapName()); |
| 77 | + } |
| 78 | +} |
0 commit comments