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 2015/11/06 16:49:51 UTC

svn commit: r1712980 - /pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java

Author: tilman
Date: Fri Nov  6 15:49:51 2015
New Revision: 1712980

URL: http://svn.apache.org/viewvc?rev=1712980&view=rev
Log:
PDFBOX-3088: don't cache and count null results; check whether cache is filled before counting and caching

Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java?rev=1712980&r1=1712979&r2=1712980&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java Fri Nov  6 15:49:51 2015
@@ -170,9 +170,6 @@ public class GlyphTable extends TTFTable
 
         synchronized (font)
         {
-            // save
-            long currentPosition = data.getCurrentPosition();
-
             // read a single glyph
             long[] offsets = loca.getOffsets();
 
@@ -184,9 +181,13 @@ public class GlyphTable extends TTFTable
             }
             else
             {
+                // save
+                long currentPosition = data.getCurrentPosition();
+
                 data.seek(getOffset() + offsets[gid]);
+
                 glyph = new GlyphData();
-                
+
                 HorizontalMetricsTable hmt = font.getHorizontalMetrics();
                 int leftSideBearing = hmt == null ? 0 : hmt.getLeftSideBearing(gid);
 
@@ -197,16 +198,17 @@ public class GlyphTable extends TTFTable
                 {
                     glyph.getDescription().resolve();
                 }
+                
+                // restore
+                data.seek(currentPosition);
+                
+                if (glyphs != null && glyphs[gid] == null && cached < MAX_CACHED_GLYPHS)
+                {
+                    glyphs[gid] = glyph;
+                    ++cached;
+                }
             }
-
-            // restore
-            data.seek(currentPosition);
-
-            if (glyphs != null && cached < MAX_CACHED_GLYPHS)
-            {
-                glyphs[gid] = glyph;
-                ++cached;
-            }            
+               
             return glyph;
         }
     }