pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1626652 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font: PDFont.java PDType1Font.java
Date Mon, 22 Sep 2014 00:55:23 GMT
Author: jahewson
Date: Mon Sep 22 00:55:22 2014
New Revision: 1626652

URL: http://svn.apache.org/r1626652
Log:
PDFBOX-2298: Use FontMatrix from embedded Type 1 fonts

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java?rev=1626652&r1=1626651&r2=1626652&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java Mon Sep 22
00:55:22 2014
@@ -45,7 +45,7 @@ import org.apache.pdfbox.util.Vector;
 public abstract class PDFont implements COSObjectable, PDFontLike
 {
     private static final Log LOG = LogFactory.getLog(PDFont.class);
-    private static final Matrix DEFAULT_FONT_MATRIX = new Matrix(0.001f, 0, 0, 0.001f, 0,
0);
+    protected static final Matrix DEFAULT_FONT_MATRIX = new Matrix(0.001f, 0, 0, 0.001f,
0, 0);
 
     protected final COSDictionary dict;
     private final CMap toUnicodeCMap;

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java?rev=1626652&r1=1626651&r2=1626652&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java Mon
Sep 22 00:55:22 2014
@@ -22,6 +22,7 @@ import java.io.InputStream;
 import java.net.URL;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
@@ -40,6 +41,7 @@ import org.apache.pdfbox.encoding.Type1E
 import org.apache.pdfbox.encoding.WinAnsiEncoding;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.common.PDStream;
+import org.apache.pdfbox.util.Matrix;
 
 /**
  * A PostScript Type 1 Font.
@@ -139,6 +141,7 @@ public class PDType1Font extends PDSimpl
     private final Type1Font type1font; // embedded font
     private final Type1Equivalent type1Equivalent; // embedded or system font for rendering
     private final boolean isEmbedded;
+    private Matrix fontMatrix;
 
     /**
      * Creates a Type 1 standard 14 font for embedding.
@@ -451,4 +454,34 @@ public class PDType1Font extends PDSimpl
             return type1Equivalent.getPath(name);
         }
     }
+
+    @Override
+    public Matrix getFontMatrix()
+    {
+        if (fontMatrix == null)
+        {
+            // PDF specified that Type 1 fonts use a 1000upem matrix, but some fonts specify
+            // their own custom matrix anyway, for example PDFBOX-2298
+            if (type1font != null)
+            {
+                List<Number> numbers = type1font.getFontMatrix();
+                if (numbers != null && numbers.size() == 6)
+                {
+                    fontMatrix = new Matrix(
+                            numbers.get(0).floatValue(), numbers.get(1).floatValue(),
+                            numbers.get(2).floatValue(), numbers.get(3).floatValue(),
+                            numbers.get(4).floatValue(), numbers.get(5).floatValue());
+                }
+                else
+                {
+                    return super.getFontMatrix();
+                }
+            }
+            else
+            {
+                fontMatrix = DEFAULT_FONT_MATRIX;
+            }
+        }
+        return fontMatrix;
+    }
 }



Mime
View raw message