X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/51004dcb01e06fef634b61be77ed73dd61cb6db9..a961784b162035fa3dc7db15b9576b6cd23462ab:/icuSources/layout/ContextualGlyphSubstProc2.cpp diff --git a/icuSources/layout/ContextualGlyphSubstProc2.cpp b/icuSources/layout/ContextualGlyphSubstProc2.cpp index b57030bb..ba7bd36f 100644 --- a/icuSources/layout/ContextualGlyphSubstProc2.cpp +++ b/icuSources/layout/ContextualGlyphSubstProc2.cpp @@ -13,19 +13,19 @@ #include "ContextualGlyphSubstProc2.h" #include "LEGlyphStorage.h" #include "LESwaps.h" -#include U_NAMESPACE_BEGIN UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ContextualGlyphSubstitutionProcessor2) -ContextualGlyphSubstitutionProcessor2::ContextualGlyphSubstitutionProcessor2(const MorphSubtableHeader2 *morphSubtableHeader) - : StateTableProcessor2(morphSubtableHeader) +ContextualGlyphSubstitutionProcessor2::ContextualGlyphSubstitutionProcessor2( + const LEReferenceTo &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 (stHeader, success, perGlyphTableOffset, LE_UNBOUNDED_ARRAY); + entryTable = LEReferenceToArrayOf(stHeader, success, entryTableOffset, LE_UNBOUNDED_ARRAY); } ContextualGlyphSubstitutionProcessor2::~ContextualGlyphSubstitutionProcessor2() @@ -37,25 +37,28 @@ void ContextualGlyphSubstitutionProcessor2::beginStateTable() 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); } @@ -70,26 +73,30 @@ le_uint16 ContextualGlyphSubstitutionProcessor2::processStateEntry(LEGlyphStorag 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)); - le_int16 format = SWAPW(lookupTable->format); TTGlyphID newGlyph = 0xFFFF; + if(LE_FAILURE(success)) return newGlyph; + LEReferenceTo lookupTable(perGlyphTable, success, offset); + if(LE_FAILURE(success)) return newGlyph; + le_int16 format = SWAPW(lookupTable->format); switch (format) { case ltfSimpleArray: { #ifdef TEST_FORMAT // Disabled pending for design review - SimpleArrayLookupTable *lookupTable0 = (SimpleArrayLookupTable *) lookupTable; + LEReferenceTo lookupTable0(lookupTable, success); + LEReferenceToArrayOf 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 lookupTable2 = (SegmentSingleLookupTable *) lookupTable; const LookupSegment *segment = lookupTable2->lookupSegment(lookupTable2->segments, gid); if (segment != NULL) { newGlyph = SWAPW(segment->value); @@ -98,15 +105,15 @@ TTGlyphID ContextualGlyphSubstitutionProcessor2::lookup(le_uint32 offset, LEGlyp break; } case ltfSegmentArray: { - printf("Context Lookup Table Format4: specific interpretation needed!\n"); + //printf("Context Lookup Table Format4: specific interpretation needed!\n"); break; } case ltfSingleTable: { #ifdef TEST_FORMAT // Disabled pending for design review - SingleTableLookupTable *lookupTable6 = (SingleTableLookupTable *) lookupTable; - const LookupSingle *segment = lookupTable6->lookupSingle(lookupTable6->entries, gid); + LEReferenceTo lookupTable6 = (SingleTableLookupTable *) lookupTable; + const LEReferenceTo segment = lookupTable6->lookupSingle(lookupTable6->entries, gid); if (segment != NULL) { newGlyph = SWAPW(segment->value); } @@ -114,12 +121,15 @@ TTGlyphID ContextualGlyphSubstitutionProcessor2::lookup(le_uint32 offset, LEGlyp break; } case ltfTrimmedArray: { - TrimmedArrayLookupTable *lookupTable8 = (TrimmedArrayLookupTable *) lookupTable; + LEReferenceTo 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 valueArray(lookupTable8, success, &lookupTable8->valueArray[0], glyphCount); + newGlyph = SWAPW(valueArray(glyphCode - firstGlyph, success)); } } default: