You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2018/02/18 12:12:37 UTC

svn commit: r1824665 - /pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/PDFontTest.java

Author: tilman
Date: Sun Feb 18 12:12:36 2018
New Revision: 1824665

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

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

Modified: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/PDFontTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/PDFontTest.java?rev=1824665&r1=1824664&r2=1824665&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/PDFontTest.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/PDFontTest.java Sun Feb 18 12:12:36 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
@@ -133,6 +142,56 @@ public class PDFontTest
         ttf2.close();
     }
 
+    /**
+     * 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 = "äöüÄÖÜ";
+
+        PDDocument doc = new PDDocument();
+
+        PDPage page = new PDPage();
+        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();
+        contentStream.close();
+
+        doc.addPage(page);
+
+        doc.save(outputFile);
+        doc.close();
+
+        doc = PDDocument.load(outputFile);
+
+        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());
+
+        doc.close();
+    }
+
     private void testPDFBox3826checkFonts(byte[] byteArray, File fontFile) throws IOException
     {
         PDDocument doc = PDDocument.load(byteArray);