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 * (C) Copyright IBM Corp. 1998-2003 - All Rights Reserved 29 * 30 */ 31 32 #include "LETypes.h" 33 #include "LEGlyphFilter.h" 34 #include "OpenTypeTables.h" 35 #include "GlyphSubstitutionTables.h" 36 #include "LigatureSubstSubtables.h" 37 #include "GlyphIterator.h" 38 #include "LESwaps.h" 39 40 le_uint32 LigatureSubstitutionSubtable::process(GlyphIterator *glyphIterator, const LEGlyphFilter *filter) const 41 { 42 LEGlyphID glyph = glyphIterator->getCurrGlyphID(); 43 le_int32 coverageIndex = getGlyphCoverage(glyph); 44 45 if (coverageIndex >= 0) { 46 Offset ligSetTableOffset = SWAPW(ligSetTableOffsetArray[coverageIndex]); 47 const LigatureSetTable *ligSetTable = (const LigatureSetTable *) ((char *) this + ligSetTableOffset); 48 le_uint16 ligCount = SWAPW(ligSetTable->ligatureCount); 49 50 for (le_uint16 lig = 0; lig < ligCount; lig += 1) { 51 Offset ligTableOffset = SWAPW(ligSetTable->ligatureTableOffsetArray[lig]); 52 const LigatureTable *ligTable = (const LigatureTable *) ((char *)ligSetTable + ligTableOffset); 53 le_uint16 compCount = SWAPW(ligTable->compCount) - 1; 54 le_int32 startPosition = glyphIterator->getCurrStreamPosition(); 55 TTGlyphID ligGlyph = SWAPW(ligTable->ligGlyph); 56 le_uint16 comp; 57 58 if (filter != NULL && ! filter->accept(LE_SET_GLYPH(glyph, ligGlyph))) { 59 continue; 60 } 61 62 for (comp = 0; comp < compCount; comp += 1) { 63 if (! glyphIterator->next()) { 64 break; 65 } 66 67 if (LE_GET_GLYPH(glyphIterator->getCurrGlyphID()) != SWAPW(ligTable->componentArray[comp])) { 68 break; 69 } 70 } 71 72 if (comp == compCount) { 73 GlyphIterator tempIterator(*glyphIterator); 74 TTGlyphID deletedGlyph = tempIterator.ignoresMarks()? 0xFFFE : 0xFFFF; 75 76 while (comp > 0) { 77 tempIterator.setCurrGlyphID(deletedGlyph); 78 tempIterator.prev(); 79 80 comp -= 1; 81 } 82 83 tempIterator.setCurrGlyphID(ligGlyph); 84 85 return compCount + 1; 86 } 87 88 glyphIterator->setCurrStreamPosition(startPosition); 89 } 90 91 } 92 93 return 0; 94 }