fontservices/textshaperplugin/IcuSource/layout/PairPositioningSubtables.cpp
changeset 0 1fb32624e06b
equal deleted inserted replaced
-1:000000000000 0:1fb32624e06b
       
     1 /*
       
     2  *
       
     3  * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
       
     4  *
       
     5  */
       
     6 
       
     7 #include "LETypes.h"
       
     8 #include "LEFontInstance.h"
       
     9 #include "OpenTypeTables.h"
       
    10 #include "GlyphPositioningTables.h"
       
    11 #include "PairPositioningSubtables.h"
       
    12 #include "ValueRecords.h"
       
    13 #include "GlyphIterator.h"
       
    14 #include "OpenTypeUtilities.h"
       
    15 #include "LESwaps.h"
       
    16 
       
    17 U_NAMESPACE_BEGIN
       
    18 
       
    19 le_uint32 PairPositioningSubtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
       
    20 {
       
    21     switch(SWAPW(subtableFormat))
       
    22     {
       
    23     case 0:
       
    24         return 0;
       
    25 
       
    26     case 1:
       
    27     {
       
    28         const PairPositioningFormat1Subtable *subtable = (const PairPositioningFormat1Subtable *) this;
       
    29 
       
    30         return subtable->process(glyphIterator, fontInstance);
       
    31     }
       
    32 
       
    33     case 2:
       
    34     {
       
    35         const PairPositioningFormat2Subtable *subtable = (const PairPositioningFormat2Subtable *) this;
       
    36 
       
    37         return subtable->process(glyphIterator, fontInstance);
       
    38     }
       
    39 
       
    40     default:
       
    41         return 0;
       
    42     }
       
    43 }
       
    44 
       
    45 le_uint32 PairPositioningFormat1Subtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
       
    46 {
       
    47     LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID();
       
    48     le_int32 coverageIndex = getGlyphCoverage(firstGlyph);
       
    49     GlyphIterator tempIterator(*glyphIterator);
       
    50 
       
    51     if (coverageIndex >= 0 && glyphIterator->next()) {
       
    52         Offset pairSetTableOffset = SWAPW(pairSetTableOffsetArray[coverageIndex]);
       
    53         PairSetTable *pairSetTable = (PairSetTable *) ((char *) this + pairSetTableOffset);
       
    54         le_uint16 pairValueCount = SWAPW(pairSetTable->pairValueCount);
       
    55         le_int16 valueRecord1Size = ValueRecord::getSize(SWAPW(valueFormat1));
       
    56         le_int16 valueRecord2Size = ValueRecord::getSize(SWAPW(valueFormat2));
       
    57         le_int16 recordSize = sizeof(PairValueRecord) - sizeof(ValueRecord) + valueRecord1Size + valueRecord2Size;
       
    58         LEGlyphID secondGlyph = glyphIterator->getCurrGlyphID();
       
    59         const PairValueRecord *pairValueRecord = NULL;
       
    60 
       
    61         if (pairValueCount != 0) {
       
    62             pairValueRecord = findPairValueRecord((TTGlyphID) LE_GET_GLYPH(secondGlyph), pairSetTable->pairValueRecordArray, pairValueCount, recordSize);
       
    63         }
       
    64 
       
    65         if (pairValueRecord == NULL) {
       
    66             return 0;
       
    67         }
       
    68 
       
    69         if (valueFormat1 != 0) {
       
    70             pairValueRecord->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, tempIterator, fontInstance);
       
    71         }
       
    72 
       
    73         if (valueFormat2 != 0) {
       
    74             const ValueRecord *valueRecord2 = (const ValueRecord *) ((char *) &pairValueRecord->valueRecord1 + valueRecord1Size);
       
    75 
       
    76             valueRecord2->adjustPosition(SWAPW(valueFormat2), (char *) this, *glyphIterator, fontInstance);
       
    77         }
       
    78 
       
    79         return 2;
       
    80     }
       
    81 
       
    82     return 0;
       
    83 }
       
    84 
       
    85 le_uint32 PairPositioningFormat2Subtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
       
    86 {
       
    87     LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID();
       
    88     le_int32 coverageIndex = getGlyphCoverage(firstGlyph);
       
    89     GlyphIterator tempIterator(*glyphIterator);
       
    90 
       
    91     if (coverageIndex >= 0 && glyphIterator->next()) {
       
    92         LEGlyphID secondGlyph = glyphIterator->getCurrGlyphID();
       
    93         const ClassDefinitionTable *classDef1 = (const ClassDefinitionTable *) ((char *) this + SWAPW(classDef1Offset));
       
    94         const ClassDefinitionTable *classDef2 = (const ClassDefinitionTable *) ((char *) this + SWAPW(classDef2Offset));
       
    95         le_int32 class1 = classDef1->getGlyphClass(firstGlyph);
       
    96         le_int32 class2 = classDef2->getGlyphClass(secondGlyph);
       
    97         le_int16 valueRecord1Size = ValueRecord::getSize(SWAPW(valueFormat1));
       
    98         le_int16 valueRecord2Size = ValueRecord::getSize(SWAPW(valueFormat2));
       
    99         le_int16 class2RecordSize = valueRecord1Size + valueRecord2Size;
       
   100         le_int16 class1RecordSize = class2RecordSize * SWAPW(class2Count);
       
   101         const Class1Record *class1Record = (const Class1Record *) ((char *) class1RecordArray + (class1RecordSize * class1));
       
   102         const Class2Record *class2Record = (const Class2Record *) ((char *) class1Record->class2RecordArray + (class2RecordSize * class2));
       
   103 
       
   104 
       
   105         if (valueFormat1 != 0) {
       
   106             class2Record->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, tempIterator, fontInstance);
       
   107         }
       
   108 
       
   109         if (valueFormat2 != 0) {
       
   110             const ValueRecord *valueRecord2 = (const ValueRecord *) ((char *) &class2Record->valueRecord1 + valueRecord1Size);
       
   111 
       
   112             valueRecord2->adjustPosition(SWAPW(valueFormat2), (const char *) this, *glyphIterator, fontInstance);
       
   113         }
       
   114 
       
   115         return 2;
       
   116     }
       
   117 
       
   118     return 0;
       
   119 }
       
   120 
       
   121 const PairValueRecord *PairPositioningFormat1Subtable::findPairValueRecord(TTGlyphID glyphID, const PairValueRecord *records, le_uint16 recordCount, le_uint16 recordSize) const
       
   122 {
       
   123     le_uint8 bit = OpenTypeUtilities::highBit(recordCount);
       
   124     le_uint16 power = 1 << bit;
       
   125     le_uint16 extra = (recordCount - power) * recordSize;
       
   126     le_uint16 probe = power * recordSize;
       
   127     const PairValueRecord *record = records;
       
   128     const PairValueRecord *trial = (const PairValueRecord *) ((char *) record + extra);
       
   129 
       
   130     if (SWAPW(trial->secondGlyph) <= glyphID) {
       
   131         record = trial;
       
   132     }
       
   133 
       
   134     while (probe > recordSize) {
       
   135         probe >>= 1;
       
   136         trial = (const PairValueRecord *) ((char *) record + probe);
       
   137 
       
   138         if (SWAPW(trial->secondGlyph) <= glyphID) {
       
   139             record = trial;
       
   140         }
       
   141     }
       
   142 
       
   143     if (SWAPW(record->secondGlyph) == glyphID) {
       
   144         return record;
       
   145     }
       
   146 
       
   147     return NULL;
       
   148 }
       
   149 
       
   150 U_NAMESPACE_END