|
9 | 9 | import com.itextpdf.io.font.TrueTypeFont;
|
10 | 10 | import com.itextpdf.io.font.Type1Font;
|
11 | 11 | import com.itextpdf.io.source.ByteArrayOutputStream;
|
12 |
| -import com.itextpdf.kernel.font.*; |
| 12 | +import com.itextpdf.kernel.color.DeviceRgb; |
| 13 | +import com.itextpdf.kernel.font.PdfFont; |
| 14 | +import com.itextpdf.kernel.font.PdfFontFactory; |
| 15 | +import com.itextpdf.kernel.font.PdfTrueTypeFont; |
| 16 | +import com.itextpdf.kernel.font.PdfType0Font; |
| 17 | +import com.itextpdf.kernel.font.PdfType1Font; |
| 18 | +import com.itextpdf.kernel.font.PdfType3Font; |
| 19 | +import com.itextpdf.kernel.font.Type3Glyph; |
13 | 20 | import com.itextpdf.kernel.pdf.PdfDictionary;
|
14 | 21 | import com.itextpdf.kernel.pdf.PdfDocument;
|
15 | 22 | import com.itextpdf.kernel.pdf.PdfOutputStream;
|
@@ -484,9 +491,9 @@ public void createDocumentWithTrueTypeFont1() throws IOException, InterruptedExc
|
484 | 491 | }
|
485 | 492 |
|
486 | 493 | @Test
|
487 |
| - public void createDocumentWithTrueTypeFont2() throws IOException, InterruptedException { |
488 |
| - String filename = destinationFolder + "DocumentWithTrueTypeFont2.pdf"; |
489 |
| - String cmpFilename = sourceFolder + "cmp_DocumentWithTrueTypeFont2.pdf"; |
| 494 | + public void createDocumentWithTrueTypeOtfFont() throws IOException, InterruptedException { |
| 495 | + String filename = destinationFolder + "DocumentWithTrueTypeOtfFont.pdf"; |
| 496 | + String cmpFilename = sourceFolder + "cmp_DocumentWithTrueTypeOtfFont.pdf"; |
490 | 497 | final String title = "Empty iText 6 Document";
|
491 | 498 |
|
492 | 499 | FileOutputStream fos = new FileOutputStream(filename);
|
@@ -538,6 +545,61 @@ public void createDocumentWithTrueTypeFont2() throws IOException, InterruptedExc
|
538 | 545 | Assert.assertNull(new CompareTool().compareByContent(filename, cmpFilename, destinationFolder, "diff_"));
|
539 | 546 | }
|
540 | 547 |
|
| 548 | + @Test |
| 549 | + public void createDocumentWithType0OtfFont() throws IOException, InterruptedException { |
| 550 | + String filename = destinationFolder + "DocumentWithType0OtfFont.pdf"; |
| 551 | + String cmpFilename = sourceFolder + "cmp_DocumentWithType0OtfFont.pdf"; |
| 552 | + final String title = "Empty iText 6 Document"; |
| 553 | + |
| 554 | + FileOutputStream fos = new FileOutputStream(filename); |
| 555 | + PdfWriter writer = new PdfWriter(fos); |
| 556 | + writer.setCompressionLevel(PdfOutputStream.NO_COMPRESSION); |
| 557 | + PdfDocument pdfDoc = new PdfDocument(writer); |
| 558 | + pdfDoc.getInfo().setAuthor(author). |
| 559 | + setCreator(creator). |
| 560 | + setTitle(title); |
| 561 | + |
| 562 | + String font = fontsFolder + "Puritan2.otf"; |
| 563 | + |
| 564 | + PdfFont pdfFont = PdfFontFactory.createFont(font, "Identity-H"); |
| 565 | + Assert.assertTrue("PdfType0Font expected", pdfFont instanceof PdfType0Font); |
| 566 | + pdfFont.setSubset(true); |
| 567 | + PdfPage page = pdfDoc.addNewPage(); |
| 568 | + PdfCanvas canvas = new PdfCanvas(page); |
| 569 | + canvas |
| 570 | + .saveState() |
| 571 | + .beginText() |
| 572 | + .moveText(36, 700) |
| 573 | + .setFontAndSize(pdfFont, 72) |
| 574 | + .showText("Hello world") |
| 575 | + .endText() |
| 576 | + .restoreState(); |
| 577 | + canvas.rectangle(100, 500, 100, 100).fill(); |
| 578 | + canvas.release(); |
| 579 | + page.flush(); |
| 580 | + |
| 581 | + byte[] ttf = Utilities.inputStreamToArray(new FileInputStream(font)); |
| 582 | + pdfFont = PdfFontFactory.createFont(ttf, "Identity-H"); |
| 583 | + Assert.assertTrue("PdfTrueTypeFont expected", pdfFont instanceof PdfType0Font); |
| 584 | + pdfFont.setSubset(true); |
| 585 | + page = pdfDoc.addNewPage(); |
| 586 | + canvas = new PdfCanvas(page); |
| 587 | + canvas |
| 588 | + .saveState() |
| 589 | + .beginText() |
| 590 | + .moveText(36, 700) |
| 591 | + .setFontAndSize(pdfFont, 72) |
| 592 | + .showText("Hello world") |
| 593 | + .endText() |
| 594 | + .restoreState(); |
| 595 | + canvas.rectangle(100, 500, 100, 100).fill(); |
| 596 | + canvas.release(); |
| 597 | + |
| 598 | + pdfDoc.close(); |
| 599 | + |
| 600 | + Assert.assertNull(new CompareTool().compareByContent(filename, cmpFilename, destinationFolder, "diff_")); |
| 601 | + } |
| 602 | + |
541 | 603 | @Test
|
542 | 604 | public void testUpdateType3FontBasedExistingFont() throws IOException, InterruptedException {
|
543 | 605 | String inputFileName = sourceFolder + "type3Font.pdf";
|
@@ -1108,6 +1170,40 @@ public void testWriteTTC() throws IOException, InterruptedException {
|
1108 | 1170 |
|
1109 | 1171 | }
|
1110 | 1172 |
|
| 1173 | + @Test |
| 1174 | + @Ignore("Invalid subset") |
| 1175 | + public void NotoSansCJKjpTest() throws IOException, InterruptedException { |
| 1176 | + String filename = destinationFolder + "NotoSansCJKjpTest.pdf"; |
| 1177 | + String cmpFilename = sourceFolder + "cmp_DocumentWithTTC.pdf"; |
| 1178 | + |
| 1179 | + PdfWriter writer = new PdfWriter(new FileOutputStream(filename)); |
| 1180 | + PdfDocument doc = new PdfDocument(writer); |
| 1181 | + PdfPage page = doc.addNewPage(); |
| 1182 | + // Identity-H must be embedded |
| 1183 | + PdfFont font = PdfFontFactory.createFont(sourceFolder + "NotoSansCJKjp-Bold.otf", "Identity-H"); |
| 1184 | + //font.setSubset(false); |
| 1185 | + PdfCanvas canvas = new PdfCanvas(page); |
| 1186 | + canvas.saveState() |
| 1187 | + .setFillColor(DeviceRgb.GREEN) |
| 1188 | + .beginText() |
| 1189 | + .moveText(36, 700) |
| 1190 | + .setFontAndSize(font, 12) |
| 1191 | + .showText(pangramme) |
| 1192 | + .endText() |
| 1193 | + .restoreState(); |
| 1194 | + canvas.saveState() |
| 1195 | + .setFillColor(DeviceRgb.RED) |
| 1196 | + .beginText() |
| 1197 | + .moveText(36, 680) |
| 1198 | + .setFontAndSize(font, 12) |
| 1199 | + .showText("1234567890") |
| 1200 | + .endText() |
| 1201 | + .restoreState(); |
| 1202 | + |
| 1203 | + doc.close(); |
| 1204 | + Assert.assertNull(new CompareTool().compareByContent(filename, cmpFilename, destinationFolder, "diff_")); |
| 1205 | + } |
| 1206 | + |
1111 | 1207 | @Test
|
1112 | 1208 | public void testCheckTTCSize() throws IOException {
|
1113 | 1209 | TrueTypeCollection collection = new TrueTypeCollection(fontsFolder + "uming.ttc", "WinAnsi");
|
|
0 commit comments