1 /*
   2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.  Oracle designates this
   7  * particular file as subject to the "Classpath" exception as provided
   8  * by Oracle in the LICENSE file that accompanied this code.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 /*
  27  *
  28  *
  29  * (C) Copyright IBM Corp. 1998-2006 - All Rights Reserved
  30  *
  31  */
  32 
  33 #include "LETypes.h"
  34 #include "LEGlyphFilter.h"
  35 #include "OpenTypeTables.h"
  36 #include "GlyphSubstitutionTables.h"
  37 #include "LigatureSubstSubtables.h"
  38 #include "GlyphIterator.h"
  39 #include "LESwaps.h"
  40 
  41 U_NAMESPACE_BEGIN
  42 
  43 le_uint32 LigatureSubstitutionSubtable::process(const LETableReference &base, GlyphIterator *glyphIterator, LEErrorCode &success, const LEGlyphFilter *filter) const
  44 {
  45     LEGlyphID glyph = glyphIterator->getCurrGlyphID();
  46     le_int32 coverageIndex = getGlyphCoverage(base, glyph, success);
  47 
  48     if (coverageIndex >= 0) {
  49         Offset ligSetTableOffset = SWAPW(ligSetTableOffsetArray[coverageIndex]);
  50         const LigatureSetTable *ligSetTable = (const LigatureSetTable *) ((char *) this + ligSetTableOffset);
  51         le_uint16 ligCount = SWAPW(ligSetTable->ligatureCount);
  52 
  53         for (le_uint16 lig = 0; lig < ligCount; lig += 1) {
  54             Offset ligTableOffset = SWAPW(ligSetTable->ligatureTableOffsetArray[lig]);
  55             const LigatureTable *ligTable = (const LigatureTable *) ((char *)ligSetTable + ligTableOffset);
  56             le_uint16 compCount = SWAPW(ligTable->compCount) - 1;
  57             le_int32 startPosition = glyphIterator->getCurrStreamPosition();
  58             TTGlyphID ligGlyph = SWAPW(ligTable->ligGlyph);
  59             le_uint16 comp;
  60 
  61             for (comp = 0; comp < compCount; comp += 1) {
  62                 if (! glyphIterator->next()) {
  63                     break;
  64                 }
  65 
  66                 if (LE_GET_GLYPH(glyphIterator->getCurrGlyphID()) != SWAPW(ligTable->componentArray[comp])) {
  67                     break;
  68                 }
  69             }
  70 
  71             if (comp == compCount && (filter == NULL || filter->accept(LE_SET_GLYPH(glyph, ligGlyph)))) {
  72                 GlyphIterator tempIterator(*glyphIterator);
  73                 TTGlyphID deletedGlyph = tempIterator.ignoresMarks()? 0xFFFE : 0xFFFF;
  74 
  75                 while (comp > 0) {
  76                     tempIterator.setCurrGlyphID(deletedGlyph);
  77                     tempIterator.prev();
  78 
  79                     comp -= 1;
  80                 }
  81 
  82                 tempIterator.setCurrGlyphID(ligGlyph);
  83 
  84                 return compCount + 1;
  85             }
  86 
  87             glyphIterator->setCurrStreamPosition(startPosition);
  88         }
  89 
  90     }
  91 
  92     return 0;
  93 }
  94 
  95 U_NAMESPACE_END