J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 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. Sun designates this |
| 7 | * particular file as subject to the "Classpath" exception as provided |
| 8 | * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 21 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 22 | * have any questions. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | /* |
| 27 | * |
| 28 | * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved |
| 29 | * |
| 30 | */ |
| 31 | |
| 32 | #include "LETypes.h" |
| 33 | #include "MorphTables.h" |
| 34 | #include "StateTables.h" |
| 35 | #include "MorphStateTables.h" |
| 36 | #include "SubtableProcessor.h" |
| 37 | #include "StateTableProcessor.h" |
| 38 | #include "ContextualGlyphSubstProc.h" |
| 39 | #include "LEGlyphStorage.h" |
| 40 | #include "LESwaps.h" |
| 41 | |
| 42 | ContextualGlyphSubstitutionProcessor::ContextualGlyphSubstitutionProcessor(const MorphSubtableHeader *morphSubtableHeader) |
| 43 | : StateTableProcessor(morphSubtableHeader) |
| 44 | { |
| 45 | contextualGlyphSubstitutionHeader = (const ContextualGlyphSubstitutionHeader *) morphSubtableHeader; |
| 46 | substitutionTableOffset = SWAPW(contextualGlyphSubstitutionHeader->substitutionTableOffset); |
| 47 | |
| 48 | entryTable = (const ContextualGlyphSubstitutionStateEntry *) ((char *) &stateTableHeader->stHeader + entryTableOffset); |
| 49 | } |
| 50 | |
| 51 | ContextualGlyphSubstitutionProcessor::~ContextualGlyphSubstitutionProcessor() |
| 52 | { |
| 53 | } |
| 54 | |
| 55 | void ContextualGlyphSubstitutionProcessor::beginStateTable() |
| 56 | { |
| 57 | markGlyph = 0; |
| 58 | } |
| 59 | |
| 60 | ByteOffset ContextualGlyphSubstitutionProcessor::processStateEntry(LEGlyphStorage &glyphStorage, |
| 61 | le_int32 &currGlyph, EntryTableIndex index) |
| 62 | { |
| 63 | const ContextualGlyphSubstitutionStateEntry *entry = &entryTable[index]; |
| 64 | ByteOffset newState = SWAPW(entry->newStateOffset); |
| 65 | le_int16 flags = SWAPW(entry->flags); |
| 66 | WordOffset markOffset = SWAPW(entry->markOffset); |
| 67 | WordOffset currOffset = SWAPW(entry->currOffset); |
| 68 | |
| 69 | if (markOffset != 0) { |
| 70 | const le_int16 *table = (const le_int16 *) ((char *) &stateTableHeader->stHeader + markOffset * 2); |
| 71 | LEGlyphID mGlyph = glyphStorage[markGlyph]; |
| 72 | TTGlyphID newGlyph = SWAPW(table[LE_GET_GLYPH(mGlyph)]); |
| 73 | |
| 74 | glyphStorage[markGlyph] = LE_SET_GLYPH(mGlyph, newGlyph); |
| 75 | } |
| 76 | |
| 77 | if (currOffset != 0) { |
| 78 | const le_int16 *table = (const le_int16 *) ((char *) &stateTableHeader->stHeader + currOffset * 2); |
| 79 | LEGlyphID thisGlyph = glyphStorage[currGlyph]; |
| 80 | TTGlyphID newGlyph = SWAPW(table[LE_GET_GLYPH(thisGlyph)]); |
| 81 | |
| 82 | glyphStorage[currGlyph] = LE_SET_GLYPH(thisGlyph, newGlyph); |
| 83 | } |
| 84 | |
| 85 | if (flags & cgsSetMark) { |
| 86 | markGlyph = currGlyph; |
| 87 | } |
| 88 | |
| 89 | if (!(flags & cgsDontAdvance)) { |
| 90 | // should handle reverse too! |
| 91 | currGlyph += 1; |
| 92 | } |
| 93 | |
| 94 | return newState; |
| 95 | } |
| 96 | |
| 97 | void ContextualGlyphSubstitutionProcessor::endStateTable() |
| 98 | { |
| 99 | } |