pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1824664 - /pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/PDFontTest.java
Date Sun, 18 Feb 2018 12:12:23 GMT
Author: tilman
Date: Sun Feb 18 12:12:23 2018
New Revision: 1824664

URL: http://svn.apache.org/viewvc?rev=1824664&view=rev
Log:
PDFBOX-4115: add test

Modified:
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/PDFontTest.java

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/PDFontTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/PDFontTest.java?rev=1824664&r1=1824663&r2=1824664&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/PDFontTest.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/PDFontTest.java Sun Feb
18 12:12:23 2018
@@ -35,14 +35,23 @@ import org.apache.pdfbox.pdmodel.font.en
 import org.apache.pdfbox.rendering.PDFRenderer;
 import org.apache.pdfbox.text.PDFTextStripper;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
 /**
  * 
  * @author adam
+ * @author Tilman Hausherr
  */
 public class PDFontTest
 {
+    private static final File OUT_DIR = new File("target/test-output");
+
+    @Before
+    public void setUp() throws Exception
+    {
+        OUT_DIR.mkdirs();
+    }
 
     /**
      * Test of the error reported in PDFBOX-988
@@ -128,6 +137,54 @@ public class PDFontTest
         }
     }
 
+    /**
+     * PDFBOX-4115: Test ability to create PDF with german umlaut glyphs with a type 1 font.
+     * Test for everything that went wrong before this was fixed.
+     *
+     * @throws IOException 
+     */
+    @Test
+    public void testPDFBOX4115() throws IOException
+    {
+        File fontFile = new File("target/fonts", "n019003l.pfb");
+        File outputFile = new File(OUT_DIR, "FontType1.pdf");
+        String text = "äöüÄÖÜ";
+
+        try (PDDocument doc = new PDDocument())
+        {
+            PDPage page = new PDPage();
+            try (PDPageContentStream contentStream = new PDPageContentStream(doc, page))
+            {
+                PDType1Font font = new PDType1Font(doc, new FileInputStream(fontFile), WinAnsiEncoding.INSTANCE);
+
+                contentStream.beginText();
+                contentStream.setFont(font, 10);
+                contentStream.newLineAtOffset(10, 700);
+                contentStream.showText(text);
+                contentStream.endText();
+            }
+
+            doc.addPage(page);
+
+            doc.save(outputFile);
+        }
+        try (PDDocument doc = PDDocument.load(outputFile))
+        {
+            PDType1Font font = (PDType1Font) doc.getPage(0).getResources().getFont(COSName.getPDFName("F1"));
+            Assert.assertEquals(font.getEncoding(), WinAnsiEncoding.INSTANCE);
+            
+            for (char c : text.toCharArray())
+            {
+                String name = font.getEncoding().getName(c);
+                Assert.assertEquals("dieresis", name.substring(1));
+                Assert.assertFalse(font.getPath(name).getBounds2D().isEmpty());
+            }
+
+            PDFTextStripper stripper = new PDFTextStripper();
+            Assert.assertEquals(text, stripper.getText(doc).trim());
+        }
+    }
+
     private void testPDFBox3826checkFonts(byte[] byteArray, File fontFile) throws IOException
     {
         PDDocument doc = PDDocument.load(byteArray);



Mime
View raw message