8005007: Better glyph processing
authorprr
Mon, 01 Apr 2013 09:55:26 -0700
changeset 18219 d4cd832b9802
parent 18218 42b9377e6462
child 18220 1d724730bd2c
8005007: Better glyph processing Reviewed-by: srl, mschoene, bae
jdk/src/share/classes/sun/font/ExtendedTextSourceLabel.java
jdk/src/share/native/sun/font/layout/LEGlyphStorage.cpp
jdk/src/share/native/sun/font/layout/LookupProcessor.cpp
--- a/jdk/src/share/classes/sun/font/ExtendedTextSourceLabel.java	Sun Mar 31 23:47:55 2013 +0400
+++ b/jdk/src/share/classes/sun/font/ExtendedTextSourceLabel.java	Mon Apr 01 09:55:26 2013 -0700
@@ -367,6 +367,9 @@
     validate(index);
     float[] charinfo = getCharinfo();
     index = l2v(index) * numvals;
+    if ((index+vish) >= charinfo.length) {
+        return new Rectangle2D.Float();
+    }
     return new Rectangle2D.Float(
                                  charinfo[index + visx],
                                  charinfo[index + visy],
@@ -456,6 +459,10 @@
     int length = source.getLength();
     --start;
     while (width >= 0 && ++start < length) {
+      int cidx = l2v(start) * numvals + advx;
+      if (cidx >= charinfo.length) {
+          break; // layout bailed for some reason
+      }
       float adv = charinfo[l2v(start) * numvals + advx];
       width -= adv;
     }
@@ -469,7 +476,11 @@
     float[] charinfo = getCharinfo();
     --start;
     while (++start < limit) {
-      a += charinfo[l2v(start) * numvals + advx];
+      int cidx = l2v(start) * numvals + advx;
+      if (cidx >= charinfo.length) {
+          break; // layout bailed for some reason
+      }
+      a += charinfo[cidx];
     }
 
     return a;
--- a/jdk/src/share/native/sun/font/layout/LEGlyphStorage.cpp	Sun Mar 31 23:47:55 2013 +0400
+++ b/jdk/src/share/native/sun/font/layout/LEGlyphStorage.cpp	Mon Apr 01 09:55:26 2013 -0700
@@ -584,7 +584,7 @@
 {
     le_int32 growAmount = fInsertionList->getGrowAmount();
 
-    if (growAmount == 0) {
+    if (growAmount <= 0) {
         return fGlyphCount;
     }
 
@@ -613,7 +613,9 @@
         fAuxData = (le_uint32 *)newAuxData;
     }
 
-    fSrcIndex  = fGlyphCount - 1;
+    if (fGlyphCount > 0) {
+       fSrcIndex  = fGlyphCount - 1;
+    }
     fDestIndex = newGlyphCount - 1;
 
 #if 0
@@ -653,6 +655,10 @@
     }
 #endif
 
+    if (atPosition < 0 || fSrcIndex < 0 || fDestIndex < 0) {
+        return FALSE;
+    }
+
     if (fAuxData != NULL) {
         le_int32 src = fSrcIndex, dest = fDestIndex;
 
@@ -665,7 +671,7 @@
         }
     }
 
-    while (fSrcIndex > atPosition) {
+    while (fSrcIndex > atPosition && fSrcIndex >= 0 && fDestIndex >= 0) {
         fGlyphs[fDestIndex]      = fGlyphs[fSrcIndex];
         fCharIndices[fDestIndex] = fCharIndices[fSrcIndex];
 
@@ -673,7 +679,7 @@
         fSrcIndex  -= 1;
     }
 
-    for (le_int32 i = count - 1; i >= 0; i -= 1) {
+    for (le_int32 i = count - 1; i >= 0 && fDestIndex >= 0; i -= 1) {
         fGlyphs[fDestIndex]      = newGlyphs[i];
         fCharIndices[fDestIndex] = fCharIndices[atPosition];
 
@@ -682,7 +688,7 @@
 
     // the source glyph we're pointing at
     // just got replaced by the insertion
-    fSrcIndex -= 1;
+        fSrcIndex -= 1;
 
     return FALSE;
 }
--- a/jdk/src/share/native/sun/font/layout/LookupProcessor.cpp	Sun Mar 31 23:47:55 2013 +0400
+++ b/jdk/src/share/native/sun/font/layout/LookupProcessor.cpp	Mon Apr 01 09:55:26 2013 -0700
@@ -61,7 +61,7 @@
 
         delta = applySubtable(lookupSubtable, lookupType, glyphIterator, fontInstance, success);
 
-        if (delta > 0 && LE_FAILURE(success)) {
+        if (delta > 0 || LE_FAILURE(success)) {
             return 1;
         }