sl@0: /* sl@0: * sl@0: * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved sl@0: * sl@0: */ sl@0: sl@0: #include "LETypes.h" sl@0: #include "LEFontInstance.h" sl@0: #include "OpenTypeTables.h" sl@0: #include "GlyphPositioningTables.h" sl@0: #include "PairPositioningSubtables.h" sl@0: #include "ValueRecords.h" sl@0: #include "GlyphIterator.h" sl@0: #include "OpenTypeUtilities.h" sl@0: #include "LESwaps.h" sl@0: sl@0: U_NAMESPACE_BEGIN sl@0: sl@0: le_uint32 PairPositioningSubtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const sl@0: { sl@0: switch(SWAPW(subtableFormat)) sl@0: { sl@0: case 0: sl@0: return 0; sl@0: sl@0: case 1: sl@0: { sl@0: const PairPositioningFormat1Subtable *subtable = (const PairPositioningFormat1Subtable *) this; sl@0: sl@0: return subtable->process(glyphIterator, fontInstance); sl@0: } sl@0: sl@0: case 2: sl@0: { sl@0: const PairPositioningFormat2Subtable *subtable = (const PairPositioningFormat2Subtable *) this; sl@0: sl@0: return subtable->process(glyphIterator, fontInstance); sl@0: } sl@0: sl@0: default: sl@0: return 0; sl@0: } sl@0: } sl@0: sl@0: le_uint32 PairPositioningFormat1Subtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const sl@0: { sl@0: LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID(); sl@0: le_int32 coverageIndex = getGlyphCoverage(firstGlyph); sl@0: GlyphIterator tempIterator(*glyphIterator); sl@0: sl@0: if (coverageIndex >= 0 && glyphIterator->next()) { sl@0: Offset pairSetTableOffset = SWAPW(pairSetTableOffsetArray[coverageIndex]); sl@0: PairSetTable *pairSetTable = (PairSetTable *) ((char *) this + pairSetTableOffset); sl@0: le_uint16 pairValueCount = SWAPW(pairSetTable->pairValueCount); sl@0: le_int16 valueRecord1Size = ValueRecord::getSize(SWAPW(valueFormat1)); sl@0: le_int16 valueRecord2Size = ValueRecord::getSize(SWAPW(valueFormat2)); sl@0: le_int16 recordSize = sizeof(PairValueRecord) - sizeof(ValueRecord) + valueRecord1Size + valueRecord2Size; sl@0: LEGlyphID secondGlyph = glyphIterator->getCurrGlyphID(); sl@0: const PairValueRecord *pairValueRecord = NULL; sl@0: sl@0: if (pairValueCount != 0) { sl@0: pairValueRecord = findPairValueRecord((TTGlyphID) LE_GET_GLYPH(secondGlyph), pairSetTable->pairValueRecordArray, pairValueCount, recordSize); sl@0: } sl@0: sl@0: if (pairValueRecord == NULL) { sl@0: return 0; sl@0: } sl@0: sl@0: if (valueFormat1 != 0) { sl@0: pairValueRecord->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, tempIterator, fontInstance); sl@0: } sl@0: sl@0: if (valueFormat2 != 0) { sl@0: const ValueRecord *valueRecord2 = (const ValueRecord *) ((char *) &pairValueRecord->valueRecord1 + valueRecord1Size); sl@0: sl@0: valueRecord2->adjustPosition(SWAPW(valueFormat2), (char *) this, *glyphIterator, fontInstance); sl@0: } sl@0: sl@0: return 2; sl@0: } sl@0: sl@0: return 0; sl@0: } sl@0: sl@0: le_uint32 PairPositioningFormat2Subtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const sl@0: { sl@0: LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID(); sl@0: le_int32 coverageIndex = getGlyphCoverage(firstGlyph); sl@0: GlyphIterator tempIterator(*glyphIterator); sl@0: sl@0: if (coverageIndex >= 0 && glyphIterator->next()) { sl@0: LEGlyphID secondGlyph = glyphIterator->getCurrGlyphID(); sl@0: const ClassDefinitionTable *classDef1 = (const ClassDefinitionTable *) ((char *) this + SWAPW(classDef1Offset)); sl@0: const ClassDefinitionTable *classDef2 = (const ClassDefinitionTable *) ((char *) this + SWAPW(classDef2Offset)); sl@0: le_int32 class1 = classDef1->getGlyphClass(firstGlyph); sl@0: le_int32 class2 = classDef2->getGlyphClass(secondGlyph); sl@0: le_int16 valueRecord1Size = ValueRecord::getSize(SWAPW(valueFormat1)); sl@0: le_int16 valueRecord2Size = ValueRecord::getSize(SWAPW(valueFormat2)); sl@0: le_int16 class2RecordSize = valueRecord1Size + valueRecord2Size; sl@0: le_int16 class1RecordSize = class2RecordSize * SWAPW(class2Count); sl@0: const Class1Record *class1Record = (const Class1Record *) ((char *) class1RecordArray + (class1RecordSize * class1)); sl@0: const Class2Record *class2Record = (const Class2Record *) ((char *) class1Record->class2RecordArray + (class2RecordSize * class2)); sl@0: sl@0: sl@0: if (valueFormat1 != 0) { sl@0: class2Record->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, tempIterator, fontInstance); sl@0: } sl@0: sl@0: if (valueFormat2 != 0) { sl@0: const ValueRecord *valueRecord2 = (const ValueRecord *) ((char *) &class2Record->valueRecord1 + valueRecord1Size); sl@0: sl@0: valueRecord2->adjustPosition(SWAPW(valueFormat2), (const char *) this, *glyphIterator, fontInstance); sl@0: } sl@0: sl@0: return 2; sl@0: } sl@0: sl@0: return 0; sl@0: } sl@0: sl@0: const PairValueRecord *PairPositioningFormat1Subtable::findPairValueRecord(TTGlyphID glyphID, const PairValueRecord *records, le_uint16 recordCount, le_uint16 recordSize) const sl@0: { sl@0: le_uint8 bit = OpenTypeUtilities::highBit(recordCount); sl@0: le_uint16 power = 1 << bit; sl@0: le_uint16 extra = (recordCount - power) * recordSize; sl@0: le_uint16 probe = power * recordSize; sl@0: const PairValueRecord *record = records; sl@0: const PairValueRecord *trial = (const PairValueRecord *) ((char *) record + extra); sl@0: sl@0: if (SWAPW(trial->secondGlyph) <= glyphID) { sl@0: record = trial; sl@0: } sl@0: sl@0: while (probe > recordSize) { sl@0: probe >>= 1; sl@0: trial = (const PairValueRecord *) ((char *) record + probe); sl@0: sl@0: if (SWAPW(trial->secondGlyph) <= glyphID) { sl@0: record = trial; sl@0: } sl@0: } sl@0: sl@0: if (SWAPW(record->secondGlyph) == glyphID) { sl@0: return record; sl@0: } sl@0: sl@0: return NULL; sl@0: } sl@0: sl@0: U_NAMESPACE_END