# HG changeset patch
# User vadim
# Date 1381851333 -3600
#      Tue Oct 15 16:35:33 2013 +0100
# Node ID a28b8ce4d90e7d7bc1fab599298831e0d62e171e
# Parent  c428e65fa8fd127058ea33ef728391887ea108e6
8013514: Improve stability of cmap class
Reviewed-by: mschoene, prr, bae

diff -r c428e65fa8fd -r a28b8ce4d90e src/share/classes/sun/font/FileFont.java
--- openjdk/jdk/src/share/classes/sun/font/FileFont.java	Thu May 09 11:23:18 2013 -0700
+++ openjdk/jdk/src/share/classes/sun/font/FileFont.java	Tue Oct 15 16:35:33 2013 +0100
@@ -174,7 +174,9 @@
                 }
             }
         }
-        scaler.dispose();
+        if (scaler != null) {
+            scaler.dispose();
+        }
         scaler = FontManager.getNullScaler();
     }
 
diff -r c428e65fa8fd -r a28b8ce4d90e src/share/classes/sun/font/StandardGlyphVector.java
--- openjdk/jdk/src/share/classes/sun/font/StandardGlyphVector.java	Thu May 09 11:23:18 2013 -0700
+++ openjdk/jdk/src/share/classes/sun/font/StandardGlyphVector.java	Tue Oct 15 16:35:33 2013 +0100
@@ -1733,8 +1733,9 @@
                                                      tx,
                                                      sgv.font.getStyle(),
                                                      aa, fm);
-
-            FontStrike strike = sgv.font2D.getStrike(desc);  // !!! getStrike(desc, false)
+            // Get the strike via the handle. Shouldn't matter
+            // if we've invalidated the font but its an extra precaution.
+            FontStrike strike = sgv.font2D.handle.font2D.getStrike(desc);  // !!! getStrike(desc, false)
 
             return new GlyphStrike(sgv, strike, dx, dy);
         }
diff -r c428e65fa8fd -r a28b8ce4d90e src/share/classes/sun/font/TrueTypeFont.java
--- openjdk/jdk/src/share/classes/sun/font/TrueTypeFont.java	Thu May 09 11:23:18 2013 -0700
+++ openjdk/jdk/src/share/classes/sun/font/TrueTypeFont.java	Tue Oct 15 16:35:33 2013 +0100
@@ -559,6 +559,9 @@
         if (head_Table != null && head_Table.capacity() >= 18) {
             ShortBuffer sb = head_Table.asShortBuffer();
             upem = sb.get(9) & 0xffff;
+            if (upem < 16 || upem > 16384) {
+                upem = 2048;
+            }
         }
         setStrikethroughMetrics(os2_Table, upem);
 
