jdk/src/share/native/sun/font/layout/ContextualGlyphSubstProc2.cpp
changeset 16891 91e99bed64ae
parent 16890 36b30720a997
child 23908 fdbaab67db73
--- a/jdk/src/share/native/sun/font/layout/ContextualGlyphSubstProc2.cpp	Tue Feb 26 10:07:26 2013 -0800
+++ b/jdk/src/share/native/sun/font/layout/ContextualGlyphSubstProc2.cpp	Thu Mar 07 10:02:20 2013 -0800
@@ -43,13 +43,14 @@
 
 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ContextualGlyphSubstitutionProcessor2)
 
-ContextualGlyphSubstitutionProcessor2::ContextualGlyphSubstitutionProcessor2(const MorphSubtableHeader2 *morphSubtableHeader)
-  : StateTableProcessor2(morphSubtableHeader)
+ContextualGlyphSubstitutionProcessor2::ContextualGlyphSubstitutionProcessor2(
+                                  const LEReferenceTo<MorphSubtableHeader2> &morphSubtableHeader, LEErrorCode &success)
+  : StateTableProcessor2(morphSubtableHeader, success), contextualGlyphHeader(morphSubtableHeader, success)
 {
-    contextualGlyphHeader = (const ContextualGlyphHeader2 *) morphSubtableHeader;
+    if(LE_FAILURE(success)) return;
     le_uint32 perGlyphTableOffset = SWAPL(contextualGlyphHeader->perGlyphTableOffset);
-    perGlyphTable = ((le_uint32 *) ((char *)&stateTableHeader->stHeader + perGlyphTableOffset));
-    entryTable = (const ContextualGlyphStateEntry2 *) ((char *) &stateTableHeader->stHeader + entryTableOffset);
+    perGlyphTable = LEReferenceToArrayOf<le_uint32> (stHeader, success, perGlyphTableOffset, LE_UNBOUNDED_ARRAY);
+    entryTable = LEReferenceToArrayOf<ContextualGlyphStateEntry2>(stHeader, success, entryTableOffset, LE_UNBOUNDED_ARRAY);
 }
 
 ContextualGlyphSubstitutionProcessor2::~ContextualGlyphSubstitutionProcessor2()
@@ -61,25 +62,28 @@
     markGlyph = 0;
 }
 
-le_uint16 ContextualGlyphSubstitutionProcessor2::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph, EntryTableIndex2 index)
+le_uint16 ContextualGlyphSubstitutionProcessor2::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph,
+    EntryTableIndex2 index, LEErrorCode &success)
 {
-    const ContextualGlyphStateEntry2 *entry = &entryTable[index];
+    if(LE_FAILURE(success)) return 0;
+    const ContextualGlyphStateEntry2 *entry = entryTable.getAlias(index, success);
+    if(LE_FAILURE(success)) return 0;
     le_uint16 newState = SWAPW(entry->newStateIndex);
     le_uint16 flags = SWAPW(entry->flags);
     le_int16 markIndex = SWAPW(entry->markIndex);
     le_int16 currIndex = SWAPW(entry->currIndex);
 
     if (markIndex != -1) {
-        le_uint32 offset = SWAPL(perGlyphTable[markIndex]);
+        le_uint32 offset = SWAPL(perGlyphTable(markIndex, success));
         LEGlyphID mGlyph = glyphStorage[markGlyph];
-        TTGlyphID newGlyph = lookup(offset, mGlyph);
+        TTGlyphID newGlyph = lookup(offset, mGlyph, success);
         glyphStorage[markGlyph] = LE_SET_GLYPH(mGlyph, newGlyph);
     }
 
     if (currIndex != -1) {
-        le_uint32 offset = SWAPL(perGlyphTable[currIndex]);
+        le_uint32 offset = SWAPL(perGlyphTable(currIndex, success));
         LEGlyphID thisGlyph = glyphStorage[currGlyph];
-        TTGlyphID newGlyph = lookup(offset, thisGlyph);
+        TTGlyphID newGlyph = lookup(offset, thisGlyph, success);
         glyphStorage[currGlyph] = LE_SET_GLYPH(thisGlyph, newGlyph);
     }
 
@@ -94,26 +98,30 @@
     return newState;
 }
 
-TTGlyphID ContextualGlyphSubstitutionProcessor2::lookup(le_uint32 offset, LEGlyphID gid)
+TTGlyphID ContextualGlyphSubstitutionProcessor2::lookup(le_uint32 offset, LEGlyphID gid, LEErrorCode &success)
 {
-    LookupTable *lookupTable = ((LookupTable *) ((char *)perGlyphTable + offset));
+    TTGlyphID newGlyph = 0xFFFF;
+    if(LE_FAILURE(success))  return newGlyph;
+    LEReferenceTo<LookupTable> lookupTable(perGlyphTable, success, offset);
+    if(LE_FAILURE(success))  return newGlyph;
     le_int16 format = SWAPW(lookupTable->format);
-    TTGlyphID newGlyph = 0xFFFF;
 
     switch (format) {
         case ltfSimpleArray: {
 #ifdef TEST_FORMAT
             // Disabled pending for design review
-            SimpleArrayLookupTable *lookupTable0 = (SimpleArrayLookupTable *) lookupTable;
+            LEReferenceTo<SimpleArrayLookupTable> lookupTable0(lookupTable, success);
+            LEReferenceToArrayOf<LookupValue> valueArray(lookupTable0, success, &lookupTable0->valueArray[0], LE_UNBOUNDED_ARRAY);
+            if(LE_FAILURE(success))  return newGlyph;
             TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
-            newGlyph = SWAPW(lookupTable0->valueArray[glyphCode]);
+            newGlyph = SWAPW(lookupTable0->valueArray(glyphCode, success));
 #endif
             break;
         }
         case ltfSegmentSingle: {
 #ifdef TEST_FORMAT
             // Disabled pending for design review
-            SegmentSingleLookupTable *lookupTable2 = (SegmentSingleLookupTable *) lookupTable;
+            LEReferenceTo<SegmentSingleLookupTable> lookupTable2 = (SegmentSingleLookupTable *) lookupTable;
             const LookupSegment *segment = lookupTable2->lookupSegment(lookupTable2->segments, gid);
             if (segment != NULL) {
                 newGlyph = SWAPW(segment->value);
@@ -129,8 +137,8 @@
         {
 #ifdef TEST_FORMAT
             // Disabled pending for design review
-            SingleTableLookupTable *lookupTable6 = (SingleTableLookupTable *) lookupTable;
-            const LookupSingle *segment = lookupTable6->lookupSingle(lookupTable6->entries, gid);
+            LEReferenceTo<SingleTableLookupTable> lookupTable6 = (SingleTableLookupTable *) lookupTable;
+            const LEReferenceTo<LookupSingle> segment = lookupTable6->lookupSingle(lookupTable6->entries, gid);
             if (segment != NULL) {
                 newGlyph = SWAPW(segment->value);
             }
@@ -138,12 +146,15 @@
             break;
         }
         case ltfTrimmedArray: {
-            TrimmedArrayLookupTable *lookupTable8 = (TrimmedArrayLookupTable *) lookupTable;
+            LEReferenceTo<TrimmedArrayLookupTable> lookupTable8(lookupTable, success);
+            if (LE_FAILURE(success)) return newGlyph;
             TTGlyphID firstGlyph = SWAPW(lookupTable8->firstGlyph);
-            TTGlyphID lastGlyph  = firstGlyph + SWAPW(lookupTable8->glyphCount);
+            TTGlyphID glyphCount = SWAPW(lookupTable8->glyphCount);
+            TTGlyphID lastGlyph  = firstGlyph + glyphCount;
             TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
             if ((glyphCode >= firstGlyph) && (glyphCode < lastGlyph)) {
-                newGlyph = SWAPW(lookupTable8->valueArray[glyphCode - firstGlyph]);
+              LEReferenceToArrayOf<LookupValue> valueArray(lookupTable8, success, &lookupTable8->valueArray[0], glyphCount);
+              newGlyph = SWAPW(valueArray(glyphCode - firstGlyph, success));
             }
         }
         default: