pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1790573 - /pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/PDFontTest.java
Date Fri, 07 Apr 2017 16:00:02 GMT
Author: tilman
Date: Fri Apr  7 16:00:02 2017
New Revision: 1790573

URL: http://svn.apache.org/viewvc?rev=1790573&view=rev
Log:
PDFBOX-3747: added test, cleaned existing code, use junit 4 style

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=1790573&r1=1790572&r2=1790573&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
Fri Apr  7 16:00:02 2017
@@ -20,9 +20,10 @@
 package org.apache.pdfbox.pdmodel.font;
 
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import junit.framework.TestCase;
+import java.net.URISyntaxException;
 import org.apache.fontbox.ttf.TTFParser;
 import org.apache.fontbox.ttf.TrueTypeFont;
 import org.apache.pdfbox.pdmodel.PDDocument;
@@ -30,23 +31,30 @@ import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.PDPageContentStream;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.rendering.PDFRenderer;
+import org.apache.pdfbox.text.PDFTextStripper;
+import org.junit.Assert;
+import org.junit.Test;
 
 /**
  * 
  * @author adam
  */
-public class PDFontTest extends TestCase
+public class PDFontTest
 {
 
     /**
-     * Test of the error reported in PDFBox-988
+     * Test of the error reported in PDFBOX-988
+     *
+     * @throws IOException
+     * @throws URISyntaxException
      */
-    public void testPDFBox988() throws Exception
+    @Test
+    public void testPDFBox988() throws IOException, URISyntaxException
     {
         PDDocument doc = null;
         try
         {
-            doc = PDDocument.load(PDFontTest.class.getResourceAsStream("F001u_3_7j.pdf"));
+            doc = PDDocument.load(new File(PDFontTest.class.getResource("F001u_3_7j.pdf").toURI()));
             PDFRenderer renderer = new PDFRenderer(doc);
             renderer.renderImage(0);
             // the allegation is that renderImage() will crash the JVM or hang
@@ -64,8 +72,9 @@ public class PDFontTest extends TestCase
      * PDFBOX-3337: Test ability to reuse a TrueTypeFont for several PDFs to avoid parsing
it over
      * and over again.
      *
-     * @throws java.io.IOException
+     * @throws IOException
      */
+    @Test
     public void testPDFBox3337() throws IOException
     {
         InputStream ttfStream = PDFontTest.class.getClassLoader().getResourceAsStream(
@@ -90,4 +99,43 @@ public class PDFontTest extends TestCase
             doc.close();
         }
     }
+
+    /**
+     * PDFBOX-3747: Test that using "-" with Calibri in Windows 7 has "-" in text extraction
and not
+     * \u2010, which was because of a wrong ToUnicode mapping because prior to the bugfix,
+     * CmapSubtable#getCharCodes provided values in random order.
+     *
+     * @throws IOException
+     */
+    @Test
+    public void testPDFBox3747() throws IOException
+    {
+        File file = new File("c:/windows/fonts", "calibri.ttf");
+        if (!file.exists())
+        {
+            System.out.println("testPDFBox3747 skipped");
+            return;
+        }
+        PDDocument doc = new PDDocument();
+        PDPage page = new PDPage();
+        doc.addPage(page);
+        PDFont font = PDType0Font.load(doc, file);
+        
+        PDPageContentStream cs = new PDPageContentStream(doc, page);
+        cs.beginText();
+        cs.setFont(font, 10);
+        cs.showText("PDFBOX-3747");
+        cs.endText();
+        cs.close();
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        doc.save(baos);
+        doc.close();
+        
+        doc = PDDocument.load(baos.toByteArray());
+        PDFTextStripper stripper = new PDFTextStripper();
+        String text = stripper.getText(doc);
+        Assert.assertEquals("PDFBOX-3747", text.trim());
+        doc.close();
+    }
 }



Mime
View raw message