os/textandloc/fontservices/textshaperplugin/IcuSource/layout/LigatureSubstSubtables.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2  * %W% %E%
     3  *
     4  * (C) Copyright IBM Corp. 1998-2003 - All Rights Reserved
     5  *
     6  */
     7 
     8 #include "LETypes.h"
     9 #include "LEGlyphFilter.h"
    10 #include "OpenTypeTables.h"
    11 #include "GlyphSubstitutionTables.h"
    12 #include "LigatureSubstSubtables.h"
    13 #include "GlyphIterator.h"
    14 #include "LESwaps.h"
    15 
    16 U_NAMESPACE_BEGIN
    17 
    18 le_uint32 LigatureSubstitutionSubtable::process(GlyphIterator *glyphIterator, const LEGlyphFilter *filter) const
    19 {
    20     LEGlyphID glyph = glyphIterator->getCurrGlyphID();
    21     le_int32 coverageIndex = getGlyphCoverage(glyph);
    22 
    23     if (coverageIndex >= 0) {
    24         Offset ligSetTableOffset = SWAPW(ligSetTableOffsetArray[coverageIndex]);
    25         const LigatureSetTable *ligSetTable = (const LigatureSetTable *) ((char *) this + ligSetTableOffset);
    26         le_uint16 ligCount = SWAPW(ligSetTable->ligatureCount);
    27 
    28         for (le_uint16 lig = 0; lig < ligCount; lig += 1) {
    29             Offset ligTableOffset = SWAPW(ligSetTable->ligatureTableOffsetArray[lig]);
    30             const LigatureTable *ligTable = (const LigatureTable *) ((char *)ligSetTable + ligTableOffset);
    31             le_uint16 compCount = SWAPW(ligTable->compCount) - 1;
    32             le_int32 startPosition = glyphIterator->getCurrStreamPosition();
    33             TTGlyphID ligGlyph = SWAPW(ligTable->ligGlyph);
    34             le_uint16 comp;
    35 
    36             if (filter != NULL && ! filter->accept(LE_SET_GLYPH(glyph, ligGlyph))) {
    37                 continue;
    38             }
    39 
    40             for (comp = 0; comp < compCount; comp += 1) {
    41                 if (! glyphIterator->next()) {
    42                     break;
    43                 }
    44 
    45                 if (LE_GET_GLYPH(glyphIterator->getCurrGlyphID()) != SWAPW(ligTable->componentArray[comp])) {
    46                     break;
    47                 }
    48             }
    49 
    50             if (comp == compCount) {
    51                 GlyphIterator tempIterator(*glyphIterator);
    52                 TTGlyphID deletedGlyph = tempIterator.ignoresMarks()? 0xFFFE : 0xFFFF;
    53 
    54                 while (comp > 0) {
    55                     tempIterator.setCurrGlyphID(deletedGlyph);
    56                     tempIterator.prev();
    57 
    58                     comp -= 1;
    59                 }
    60 
    61                 tempIterator.setCurrGlyphID(ligGlyph);
    62 
    63                 return compCount + 1;
    64             }
    65 
    66             glyphIterator->setCurrStreamPosition(startPosition);
    67         }
    68 
    69     }
    70 
    71     return 0;
    72 }
    73 
    74 U_NAMESPACE_END