X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..ef6cf650f4a75c3f97de06b51fa104f2069b9ea2:/icuSources/layout/PairPositioningSubtables.cpp?ds=inline diff --git a/icuSources/layout/PairPositioningSubtables.cpp b/icuSources/layout/PairPositioningSubtables.cpp index 1aa8a772..2ff3383a 100644 --- a/icuSources/layout/PairPositioningSubtables.cpp +++ b/icuSources/layout/PairPositioningSubtables.cpp @@ -1,7 +1,6 @@ /* - * @(#)PairPositioningSubtables.cpp 1.7 00/03/15 * - * (C) Copyright IBM Corp. 1998-2003 - All Rights Reserved + * (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved * */ @@ -12,13 +11,12 @@ #include "PairPositioningSubtables.h" #include "ValueRecords.h" #include "GlyphIterator.h" -#include "GlyphPositionAdjustments.h" #include "OpenTypeUtilities.h" #include "LESwaps.h" U_NAMESPACE_BEGIN -le_uint32 PairPositioningSubtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const +le_uint32 PairPositioningSubtable::process(const LEReferenceTo &base, GlyphIterator *glyphIterator, const LEFontInstance *fontInstance, LEErrorCode &success) const { switch(SWAPW(subtableFormat)) { @@ -27,70 +25,75 @@ le_uint32 PairPositioningSubtable::process(GlyphIterator *glyphIterator, const L case 1: { - const PairPositioningFormat1Subtable *subtable = (const PairPositioningFormat1Subtable *) this; + const LEReferenceTo subtable(base, success, (const PairPositioningFormat1Subtable *) this); - return subtable->process(glyphIterator, fontInstance); + if(LE_SUCCESS(success)) + return subtable->process(subtable, glyphIterator, fontInstance, success); + else + return 0; } case 2: { - const PairPositioningFormat2Subtable *subtable = (const PairPositioningFormat2Subtable *) this; + const LEReferenceTo subtable(base, success, (const PairPositioningFormat2Subtable *) this); - return subtable->process(glyphIterator, fontInstance); + if(LE_SUCCESS(success)) + return subtable->process(subtable, glyphIterator, fontInstance, success); + else + return 0; } - default: - return 0; + return 0; } } -le_uint32 PairPositioningFormat1Subtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const +le_uint32 PairPositioningFormat1Subtable::process(const LEReferenceTo &base, GlyphIterator *glyphIterator, const LEFontInstance *fontInstance, LEErrorCode &success) const { LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID(); - le_int32 coverageIndex = getGlyphCoverage(firstGlyph); + le_int32 coverageIndex = getGlyphCoverage(base, firstGlyph, success); GlyphIterator tempIterator(*glyphIterator); if (coverageIndex >= 0 && glyphIterator->next()) { Offset pairSetTableOffset = SWAPW(pairSetTableOffsetArray[coverageIndex]); PairSetTable *pairSetTable = (PairSetTable *) ((char *) this + pairSetTableOffset); + le_uint16 pairValueCount = SWAPW(pairSetTable->pairValueCount); le_int16 valueRecord1Size = ValueRecord::getSize(SWAPW(valueFormat1)); le_int16 valueRecord2Size = ValueRecord::getSize(SWAPW(valueFormat2)); le_int16 recordSize = sizeof(PairValueRecord) - sizeof(ValueRecord) + valueRecord1Size + valueRecord2Size; LEGlyphID secondGlyph = glyphIterator->getCurrGlyphID(); - const PairValueRecord *pairValueRecord = - findPairValueRecord((TTGlyphID) LE_GET_GLYPH(secondGlyph), pairSetTable->pairValueRecordArray, SWAPW(pairSetTable->pairValueCount), recordSize); + const PairValueRecord *pairValueRecord = NULL; + + if (pairValueCount != 0) { + pairValueRecord = findPairValueRecord((TTGlyphID) LE_GET_GLYPH(secondGlyph), pairSetTable->pairValueRecordArray, pairValueCount, recordSize); + } if (pairValueRecord == NULL) { return 0; } if (valueFormat1 != 0) { - GlyphPositionAdjustment adjustment; - - tempIterator.getCurrGlyphPositionAdjustment(adjustment); - pairValueRecord->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, adjustment, fontInstance); - tempIterator.setCurrGlyphPositionAdjustment(&adjustment); + pairValueRecord->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, tempIterator, fontInstance); } if (valueFormat2 != 0) { const ValueRecord *valueRecord2 = (const ValueRecord *) ((char *) &pairValueRecord->valueRecord1 + valueRecord1Size); - GlyphPositionAdjustment adjustment; - glyphIterator->getCurrGlyphPositionAdjustment(adjustment); - valueRecord2->adjustPosition(SWAPW(valueFormat2), (char *) this, adjustment, fontInstance); - glyphIterator->setCurrGlyphPositionAdjustment(&adjustment); + valueRecord2->adjustPosition(SWAPW(valueFormat2), (char *) this, *glyphIterator, fontInstance); } - return 2; + // back up glyphIterator so second glyph can be + // first glyph in the next pair + glyphIterator->prev(); + return 1; } return 0; } -le_uint32 PairPositioningFormat2Subtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const +le_uint32 PairPositioningFormat2Subtable::process(const LEReferenceTo &base, GlyphIterator *glyphIterator, const LEFontInstance *fontInstance, LEErrorCode &success) const { LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID(); - le_int32 coverageIndex = getGlyphCoverage(firstGlyph); + le_int32 coverageIndex = getGlyphCoverage(base, firstGlyph, success); GlyphIterator tempIterator(*glyphIterator); if (coverageIndex >= 0 && glyphIterator->next()) { @@ -108,23 +111,19 @@ le_uint32 PairPositioningFormat2Subtable::process(GlyphIterator *glyphIterator, if (valueFormat1 != 0) { - GlyphPositionAdjustment adjustment; - - tempIterator.getCurrGlyphPositionAdjustment(adjustment); - class2Record->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, adjustment, fontInstance); - tempIterator.setCurrGlyphPositionAdjustment(&adjustment); + class2Record->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, tempIterator, fontInstance); } if (valueFormat2 != 0) { const ValueRecord *valueRecord2 = (const ValueRecord *) ((char *) &class2Record->valueRecord1 + valueRecord1Size); - GlyphPositionAdjustment adjustment; - glyphIterator->getCurrGlyphPositionAdjustment(adjustment); - valueRecord2->adjustPosition(SWAPW(valueFormat2), (const char *) this, adjustment, fontInstance); - glyphIterator->setCurrGlyphPositionAdjustment(&adjustment); + valueRecord2->adjustPosition(SWAPW(valueFormat2), (const char *) this, *glyphIterator, fontInstance); } - return 2; + // back up glyphIterator so second glyph can be + // first glyph in the next pair + glyphIterator->prev(); + return 1; } return 0; @@ -132,6 +131,20 @@ le_uint32 PairPositioningFormat2Subtable::process(GlyphIterator *glyphIterator, const PairValueRecord *PairPositioningFormat1Subtable::findPairValueRecord(TTGlyphID glyphID, const PairValueRecord *records, le_uint16 recordCount, le_uint16 recordSize) const { +#if 1 + // The OpenType spec. says that the ValueRecord table is + // sorted by secondGlyph. Unfortunately, there are fonts + // around that have an unsorted ValueRecord table. + const PairValueRecord *record = records; + + for(le_int32 r = 0; r < recordCount; r += 1) { + if (SWAPW(record->secondGlyph) == glyphID) { + return record; + } + + record = (const PairValueRecord *) ((char *) record + recordSize); + } +#else le_uint8 bit = OpenTypeUtilities::highBit(recordCount); le_uint16 power = 1 << bit; le_uint16 extra = (recordCount - power) * recordSize; @@ -155,6 +168,7 @@ const PairValueRecord *PairPositioningFormat1Subtable::findPairValueRecord(TTGly if (SWAPW(record->secondGlyph) == glyphID) { return record; } +#endif return NULL; }