pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1745866 - in /pdfbox/branches/2.0: ./ fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java
Date Sat, 28 May 2016 10:54:00 GMT
Author: lehmi
Date: Sat May 28 10:54:00 2016
New Revision: 1745866

URL: http://svn.apache.org/viewvc?rev=1745866&view=rev
Log:
PDFBOX-3089: cache GlyphDescription

Modified:
    pdfbox/branches/2.0/   (props changed)
    pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java

Propchange: pdfbox/branches/2.0/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat May 28 10:54:00 2016
@@ -1,3 +1,3 @@
 /pdfbox/branches/no-awt:1618517-1621410
 /pdfbox/no-awt:1618514-1618516
-/pdfbox/trunk:1736223,1736227,1736615,1737043,1737130,1737599-1737600,1738755,1740160,1742437,1742442,1745595,1745606,1745774,1745776,1745779
+/pdfbox/trunk:1736223,1736227,1736615,1737043,1737130,1737599-1737600,1738755,1740160,1742437,1742442,1745595,1745606,1745772,1745774,1745776,1745779

Modified: pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java?rev=1745866&r1=1745865&r2=1745866&view=diff
==============================================================================
--- pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java
(original)
+++ pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java
Sat May 28 10:54:00 2016
@@ -20,8 +20,11 @@ package org.apache.fontbox.ttf;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -41,10 +44,13 @@ public class GlyfCompositeDescript exten
     private static final Log LOG = LogFactory.getLog(GlyfCompositeDescript.class);
 
     private final List<GlyfCompositeComp> components = new ArrayList<GlyfCompositeComp>();
+    private final Map<Integer,GlyphDescription> descriptions = new HashMap<Integer,GlyphDescription>();
     private GlyphTable glyphTable = null;
     private boolean beingResolved = false;
     private boolean resolved = false;
     private int pointCount = -1;
+    private int contourCount = -1;
+
     /**
      * Constructor.
      * 
@@ -72,6 +78,7 @@ public class GlyfCompositeDescript exten
         {
             readInstructions(bais, (bais.readUnsignedShort()));
         }
+        initDescriptions();
     }
 
     /**
@@ -101,8 +108,7 @@ public class GlyfCompositeDescript exten
             comp.setFirstIndex(firstIndex);
             comp.setFirstContour(firstContour);
 
-            GlyphDescription desc;
-            desc = getGlypDescription(comp.getGlyphIndex());
+            GlyphDescription desc = descriptions.get(comp.getGlyphIndex());
             if (desc != null)
             {
                 desc.resolve();
@@ -123,7 +129,7 @@ public class GlyfCompositeDescript exten
         GlyfCompositeComp c = getCompositeCompEndPt(i);
         if (c != null)
         {
-            GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
+            GlyphDescription gd = descriptions.get(c.getGlyphIndex());
             return gd.getEndPtOfContours(i - c.getFirstContour()) + c.getFirstIndex();
         }
         return 0;
@@ -138,7 +144,7 @@ public class GlyfCompositeDescript exten
         GlyfCompositeComp c = getCompositeComp(i);
         if (c != null)
         {
-            GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
+            GlyphDescription gd = descriptions.get(c.getGlyphIndex());
             return gd.getFlags(i - c.getFirstIndex());
         }
         return 0;
@@ -153,7 +159,7 @@ public class GlyfCompositeDescript exten
         GlyfCompositeComp c = getCompositeComp(i);
         if (c != null)
         {
-            GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
+            GlyphDescription gd = descriptions.get(c.getGlyphIndex());
             int n = i - c.getFirstIndex();
             int x = gd.getXCoordinate(n);
             int y = gd.getYCoordinate(n);
@@ -173,7 +179,7 @@ public class GlyfCompositeDescript exten
         GlyfCompositeComp c = getCompositeComp(i);
         if (c != null)
         {
-            GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
+            GlyphDescription gd = descriptions.get(c.getGlyphIndex());
             int n = i - c.getFirstIndex();
             int x = gd.getXCoordinate(n);
             int y = gd.getYCoordinate(n);
@@ -206,7 +212,7 @@ public class GlyfCompositeDescript exten
         if (pointCount < 0)
         {
             GlyfCompositeComp c = components.get(components.size() - 1);
-            GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
+            GlyphDescription gd = descriptions.get(c.getGlyphIndex());
             if (gd == null)
             {
                 LOG.error("getGlypDescription(" + c.getGlyphIndex() + ") is null, returning
0");
@@ -230,8 +236,12 @@ public class GlyfCompositeDescript exten
         {
             LOG.error("getContourCount called on unresolved GlyfCompositeDescript");
         }
-        GlyfCompositeComp c = components.get(components.size() - 1);
-        return c.getFirstContour() + getGlypDescription(c.getGlyphIndex()).getContourCount();
+        if (contourCount < 0)
+        {
+            GlyfCompositeComp c = components.get(components.size() - 1);
+            contourCount = c.getFirstContour() + descriptions.get(c.getGlyphIndex()).getContourCount();
+        }
+        return contourCount;
     }
 
     /**
@@ -248,7 +258,7 @@ public class GlyfCompositeDescript exten
     {
         for (GlyfCompositeComp c : components)
         {
-            GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
+            GlyphDescription gd = descriptions.get(c.getGlyphIndex());
             if (c.getFirstIndex() <= i && i < (c.getFirstIndex() + gd.getPointCount()))
             {
                 return c;
@@ -261,7 +271,7 @@ public class GlyfCompositeDescript exten
     {
         for (GlyfCompositeComp c : components)
         {
-            GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
+            GlyphDescription gd = descriptions.get(c.getGlyphIndex());
             if (c.getFirstContour() <= i && i < (c.getFirstContour() + gd.getContourCount()))
             {
                 return c;
@@ -270,21 +280,23 @@ public class GlyfCompositeDescript exten
         return null;
     }
 
-    private GlyphDescription getGlypDescription(int index)
+    private void initDescriptions()
     {
-        try
+        for (GlyfCompositeComp component : components)
         {
-            GlyphData glyph = glyphTable.getGlyph(index);
-            if (glyph != null)
+            try
             {
-                return glyph.getDescription();
+                int index = component.getGlyphIndex();
+                GlyphData glyph = glyphTable.getGlyph(index);
+                if (glyph != null)
+                {
+                    descriptions.put(index, glyph.getDescription());
+                }
             }
-            return null;
-        }
-        catch (IOException e)
-        {
-            LOG.error(e);
-            return null;
+            catch (IOException e)
+            {
+                LOG.error(e);
+            }            
         }
     }
 }



Mime
View raw message