jdk/src/share/native/sun/font/layout/PairPositioningSubtables.cpp
changeset 18254 e4083179f1c9
parent 16891 91e99bed64ae
child 18256 79d3f8278a38
equal deleted inserted replaced
18253:4323a5fe8bc4 18254:e4083179f1c9
    74 
    74 
    75 le_uint32 PairPositioningFormat1Subtable::process(const LEReferenceTo<PairPositioningFormat1Subtable> &base, GlyphIterator *glyphIterator, const LEFontInstance *fontInstance, LEErrorCode &success) const
    75 le_uint32 PairPositioningFormat1Subtable::process(const LEReferenceTo<PairPositioningFormat1Subtable> &base, GlyphIterator *glyphIterator, const LEFontInstance *fontInstance, LEErrorCode &success) const
    76 {
    76 {
    77     LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID();
    77     LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID();
    78     le_int32 coverageIndex = getGlyphCoverage(base, firstGlyph, success);
    78     le_int32 coverageIndex = getGlyphCoverage(base, firstGlyph, success);
       
    79 
       
    80     if (LE_FAILURE(success)) {
       
    81       return 0;
       
    82     }
    79     GlyphIterator tempIterator(*glyphIterator);
    83     GlyphIterator tempIterator(*glyphIterator);
    80 
    84 
    81     if (coverageIndex >= 0 && glyphIterator->next()) {
    85     if (coverageIndex >= 0 && glyphIterator->next()) {
    82         Offset pairSetTableOffset = SWAPW(pairSetTableOffsetArray[coverageIndex]);
    86         Offset pairSetTableOffset = SWAPW(pairSetTableOffsetArray[coverageIndex]);
    83         PairSetTable *pairSetTable = (PairSetTable *) ((char *) this + pairSetTableOffset);
    87         LEReferenceTo<PairSetTable> pairSetTable(base, success, ((char *) this + pairSetTableOffset));
       
    88         if (LE_FAILURE(success)) {
       
    89           return 0;
       
    90         }
    84         le_uint16 pairValueCount = SWAPW(pairSetTable->pairValueCount);
    91         le_uint16 pairValueCount = SWAPW(pairSetTable->pairValueCount);
    85         le_int16 valueRecord1Size = ValueRecord::getSize(SWAPW(valueFormat1));
    92         le_int16 valueRecord1Size = ValueRecord::getSize(SWAPW(valueFormat1));
    86         le_int16 valueRecord2Size = ValueRecord::getSize(SWAPW(valueFormat2));
    93         le_int16 valueRecord2Size = ValueRecord::getSize(SWAPW(valueFormat2));
    87         le_int16 recordSize = sizeof(PairValueRecord) - sizeof(ValueRecord) + valueRecord1Size + valueRecord2Size;
    94         le_int16 recordSize = sizeof(PairValueRecord) - sizeof(ValueRecord) + valueRecord1Size + valueRecord2Size;
    88         LEGlyphID secondGlyph = glyphIterator->getCurrGlyphID();
    95         LEGlyphID secondGlyph = glyphIterator->getCurrGlyphID();
    89         const PairValueRecord *pairValueRecord = NULL;
    96         LEReferenceTo<PairValueRecord> pairValueRecord;
    90 
    97 
    91         if (pairValueCount != 0) {
    98         if (pairValueCount != 0) {
    92             pairValueRecord = findPairValueRecord((TTGlyphID) LE_GET_GLYPH(secondGlyph), pairSetTable->pairValueRecordArray, pairValueCount, recordSize);
    99             pairValueRecord = findPairValueRecord(base, (TTGlyphID) LE_GET_GLYPH(secondGlyph), pairSetTable->pairValueRecordArray, pairValueCount, recordSize, success);
    93         }
   100         }
    94 
   101 
    95         if (pairValueRecord == NULL) {
   102         if (pairValueRecord.isEmpty()) {
    96             return 0;
   103             return 0;
    97         }
   104         }
    98 
   105 
    99         if (valueFormat1 != 0) {
   106         if (valueFormat1 != 0) {
   100             pairValueRecord->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, tempIterator, fontInstance);
   107             pairValueRecord->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, tempIterator, fontInstance);
   152     }
   159     }
   153 
   160 
   154     return 0;
   161     return 0;
   155 }
   162 }
   156 
   163 
   157 const PairValueRecord *PairPositioningFormat1Subtable::findPairValueRecord(TTGlyphID glyphID, const PairValueRecord *records, le_uint16 recordCount, le_uint16 recordSize) const
   164 LEReferenceTo<PairValueRecord> PairPositioningFormat1Subtable::findPairValueRecord(const LETableReference &base, TTGlyphID glyphID, const PairValueRecord *records, le_uint16 recordCount, le_uint16 recordSize, LEErrorCode &success) const
   158 {
   165 {
   159 #if 1
   166 #if 1
   160         // The OpenType spec. says that the ValueRecord table is
   167         // The OpenType spec. says that the ValueRecord table is
   161         // sorted by secondGlyph. Unfortunately, there are fonts
   168         // sorted by secondGlyph. Unfortunately, there are fonts
   162         // around that have an unsorted ValueRecord table.
   169         // around that have an unsorted ValueRecord table.
   163         const PairValueRecord *record = records;
   170         LEReferenceTo<PairValueRecord> record(base, success, records);
       
   171         record.verifyLength(0, recordSize, success);
   164 
   172 
   165         for(le_int32 r = 0; r < recordCount; r += 1) {
   173         for(le_int32 r = 0; r < recordCount; r += 1) {
       
   174            if (LE_FAILURE(success)) return (const PairValueRecord*)NULL;
   166                 if (SWAPW(record->secondGlyph) == glyphID) {
   175                 if (SWAPW(record->secondGlyph) == glyphID) {
   167                         return record;
   176                         return record;
   168                 }
   177                 }
   169 
   178 
   170                 record = (const PairValueRecord *) ((char *) record + recordSize);
   179                 record =  LEReferenceTo<PairValueRecord>(base, success, ((const char*)record.getAlias())+ recordSize);
       
   180                 record.verifyLength(0, recordSize, success);
   171         }
   181         }
   172 #else
   182 #else
       
   183   #error dead code - not updated.
   173     le_uint8 bit = OpenTypeUtilities::highBit(recordCount);
   184     le_uint8 bit = OpenTypeUtilities::highBit(recordCount);
   174     le_uint16 power = 1 << bit;
   185     le_uint16 power = 1 << bit;
   175     le_uint16 extra = (recordCount - power) * recordSize;
   186     le_uint16 extra = (recordCount - power) * recordSize;
   176     le_uint16 probe = power * recordSize;
   187     le_uint16 probe = power * recordSize;
   177     const PairValueRecord *record = records;
   188     const PairValueRecord *record = records;
   193     if (SWAPW(record->secondGlyph) == glyphID) {
   204     if (SWAPW(record->secondGlyph) == glyphID) {
   194         return record;
   205         return record;
   195     }
   206     }
   196 #endif
   207 #endif
   197 
   208 
   198     return NULL;
   209     return (const PairValueRecord*)NULL;
   199 }
   210 }
   200 
   211 
   201 U_NAMESPACE_END
   212 U_NAMESPACE_END