You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2011/02/28 19:13:04 UTC

svn commit: r1075455 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java

Author: lehmi
Date: Mon Feb 28 18:13:04 2011
New Revision: 1075455

URL: http://svn.apache.org/viewvc?rev=1075455&view=rev
Log:
PDFBOX-967: Create font metrics only when needed

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java?rev=1075455&r1=1075454&r2=1075455&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java Mon Feb 28 18:13:04 2011
@@ -149,7 +149,7 @@ public class PDType1CFont extends PDSimp
         Float width = (Float)this.glyphWidths.get(name);
         if( width == null )
         {
-            width = Float.valueOf(this.fontMetric.getCharacterWidth(name));
+            width = Float.valueOf(getFontMetric().getCharacterWidth(name));
             this.glyphWidths.put(name, width);
         }
 
@@ -172,7 +172,7 @@ public class PDType1CFont extends PDSimp
         Float height = (Float)this.glyphHeights.get(name);
         if( height == null )
         {
-            height = Float.valueOf(this.fontMetric.getCharacterHeight(name));
+            height = Float.valueOf(getFontMetric().getCharacterHeight(name));
             this.glyphHeights.put(name, height);
         }
 
@@ -233,7 +233,7 @@ public class PDType1CFont extends PDSimp
     {
         if( this.avgWidth == null )
         {
-            this.avgWidth = Float.valueOf(this.fontMetric.getAverageCharacterWidth());
+            this.avgWidth = Float.valueOf(getFontMetric().getAverageCharacterWidth());
         }
 
         return this.avgWidth.floatValue();
@@ -246,7 +246,7 @@ public class PDType1CFont extends PDSimp
     {
         if( this.fontBBox == null )
         {
-            this.fontBBox = new PDRectangle(this.fontMetric.getFontBBox());
+            this.fontBBox = new PDRectangle(getFontMetric().getFontBBox());
         }
 
         return this.fontBBox;
@@ -289,6 +289,21 @@ public class PDType1CFont extends PDSimp
         return awtFont;
     }
     
+    private FontMetric getFontMetric() 
+    {
+        if (fontMetric == null)
+        {
+            try
+            {
+                fontMetric = prepareFontMetric(cffFont);
+            }
+            catch (IOException exception)
+            {
+                log.error("An error occured while extracting the font metrics!", exception);
+            }
+        }
+        return fontMetric;
+    }
 
     private void load() throws IOException
     {
@@ -378,7 +393,6 @@ public class PDType1CFont extends PDSimp
         this.cffFont.setCharset(pdfCharset);
         charStringsDict.clear();
         charStringsDict.putAll(pdfCharStringsDict);
-        this.fontMetric = prepareFontMetric(this.cffFont);
         Number defaultWidthX = (Number)this.cffFont.getProperty("defaultWidthX");
         this.glyphWidths.put(null, Float.valueOf(defaultWidthX.floatValue()));
     }
@@ -497,7 +511,7 @@ public class PDType1CFont extends PDSimp
         return string;
     }
 
-    private static FontMetric prepareFontMetric( CFFFont font ) throws IOException
+    private FontMetric prepareFontMetric( CFFFont font ) throws IOException
     {
         byte[] afmBytes = AFMFormatter.format(font);