5891N/A/*
5891N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5891N/A *
5891N/A * This code is free software; you can redistribute it and/or modify it
5891N/A * under the terms of the GNU General Public License version 2 only, as
5891N/A * published by the Free Software Foundation. Oracle designates this
5891N/A * particular file as subject to the "Classpath" exception as provided
5891N/A * by Oracle in the LICENSE file that accompanied this code.
5891N/A *
5891N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5891N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5891N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5891N/A * version 2 for more details (a copy is included in the LICENSE file that
5891N/A * accompanied this code).
5891N/A *
5891N/A * You should have received a copy of the GNU General Public License version
5891N/A * 2 along with this work; if not, write to the Free Software Foundation,
5891N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5891N/A *
5891N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5891N/A * or visit www.oracle.com if you need additional information or have any
5891N/A * questions.
5891N/A *
5891N/A */
5891N/A
5891N/A/*
5891N/A *
5891N/A * (C) Copyright IBM Corp. and others 1998-2013 - All Rights Reserved
5891N/A *
5891N/A */
5891N/A
5891N/A#include "LETypes.h"
5891N/A#include "MorphTables.h"
5891N/A#include "StateTables.h"
5891N/A#include "MorphStateTables.h"
5891N/A#include "SubtableProcessor2.h"
5891N/A#include "StateTableProcessor2.h"
5891N/A#include "LEGlyphStorage.h"
5891N/A#include "LESwaps.h"
5891N/A#include "LookupTables.h"
5891N/A
5891N/AU_NAMESPACE_BEGIN
5891N/A
5891N/AStateTableProcessor2::StateTableProcessor2()
5891N/A{
5891N/A}
5891N/A
5980N/AStateTableProcessor2::StateTableProcessor2(const LEReferenceTo<MorphSubtableHeader2> &morphSubtableHeader, LEErrorCode &success)
5980N/A : SubtableProcessor2(morphSubtableHeader, success), stateTableHeader(morphSubtableHeader, success),
5980N/A stHeader(stateTableHeader, success, (const StateTableHeader2*)&stateTableHeader->stHeader),
5980N/A nClasses(0), classTableOffset(0), stateArrayOffset(0), entryTableOffset(0), classTable(), format(0),
5980N/A stateArray()
5891N/A{
5980N/A if (LE_FAILURE(success)) {
5980N/A return;
5980N/A }
5980N/A nClasses = SWAPL(stHeader->nClasses);
5980N/A classTableOffset = SWAPL(stHeader->classTableOffset);
5980N/A stateArrayOffset = SWAPL(stHeader->stateArrayOffset);
5980N/A entryTableOffset = SWAPL(stHeader->entryTableOffset);
5891N/A
5980N/A classTable = LEReferenceTo<LookupTable>(stHeader, success, classTableOffset);
5980N/A format = SWAPW(classTable->format);
5891N/A
5980N/A stateArray = LEReferenceToArrayOf<EntryTableIndex2>(stHeader, success, stateArrayOffset, LE_UNBOUNDED_ARRAY);
5891N/A}
5891N/A
5891N/AStateTableProcessor2::~StateTableProcessor2()
5891N/A{
5891N/A}
5891N/A
5980N/Avoid StateTableProcessor2::process(LEGlyphStorage &glyphStorage, LEErrorCode &success)
5891N/A{
5980N/A if (LE_FAILURE(success)) return;
5891N/A // Start at state 0
5891N/A // XXX: How do we know when to start at state 1?
5891N/A le_uint16 currentState = 0;
5891N/A le_int32 glyphCount = glyphStorage.getGlyphCount();
5891N/A
5971N/A LE_STATE_PATIENCE_INIT();
5971N/A
5891N/A le_int32 currGlyph = 0;
5891N/A if ((coverage & scfReverse2) != 0) { // process glyphs in descending order
5891N/A currGlyph = glyphCount - 1;
5891N/A dir = -1;
5891N/A } else {
5891N/A dir = 1;
5891N/A }
5891N/A
5891N/A beginStateTable();
5891N/A switch (format) {
5891N/A case ltfSimpleArray: {
5891N/A#ifdef TEST_FORMAT
5980N/A LEReferenceTo<SimpleArrayLookupTable> lookupTable0(classTable, success);
5980N/A if(LE_FAILURE(success)) break;
5891N/A while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) {
5980N/A if (LE_FAILURE(success)) break;
5980N/A if (LE_STATE_PATIENCE_DECR()) {
5971N/A LE_DEBUG_BAD_FONT("patience exceeded - state table not moving")
5971N/A break; // patience exceeded.
5971N/A }
5891N/A LookupValue classCode = classCodeOOB;
5891N/A if (currGlyph == glyphCount || currGlyph == -1) {
5891N/A // XXX: How do we handle EOT vs. EOL?
5891N/A classCode = classCodeEOT;
5891N/A } else {
5891N/A LEGlyphID gid = glyphStorage[currGlyph];
5891N/A TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
5891N/A
5891N/A if (glyphCode == 0xFFFF) {
5891N/A classCode = classCodeDEL;
5891N/A } else {
5891N/A classCode = SWAPW(lookupTable0->valueArray[gid]);
5891N/A }
5891N/A }
5980N/A EntryTableIndex2 entryTableIndex = SWAPW(stateArray(classCode + currentState * nClasses, success));
5971N/A LE_STATE_PATIENCE_CURR(le_int32, currGlyph);
5891N/A currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex); // return a zero-based index instead of a byte offset
5971N/A LE_STATE_PATIENCE_INCR(currGlyph);
5891N/A }
5891N/A#endif
5891N/A break;
5891N/A }
5891N/A case ltfSegmentSingle: {
5980N/A LEReferenceTo<SegmentSingleLookupTable> lookupTable2(classTable, success);
5980N/A if(LE_FAILURE(success)) break;
5891N/A while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) {
5980N/A if (LE_FAILURE(success)) break;
5980N/A if (LE_STATE_PATIENCE_DECR()) {
5980N/A LE_DEBUG_BAD_FONT("patience exceeded - state table not moving")
5971N/A break; // patience exceeded.
5971N/A }
5891N/A LookupValue classCode = classCodeOOB;
5891N/A if (currGlyph == glyphCount || currGlyph == -1) {
5891N/A // XXX: How do we handle EOT vs. EOL?
5891N/A classCode = classCodeEOT;
5891N/A } else {
5891N/A LEGlyphID gid = glyphStorage[currGlyph];
5891N/A TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
5891N/A
5891N/A if (glyphCode == 0xFFFF) {
5891N/A classCode = classCodeDEL;
5891N/A } else {
5980N/A const LookupSegment *segment =
5980N/A lookupTable2->lookupSegment(lookupTable2, lookupTable2->segments, gid, success);
5980N/A if (segment != NULL && LE_SUCCESS(success)) {
5891N/A classCode = SWAPW(segment->value);
5891N/A }
5891N/A }
5891N/A }
5980N/A EntryTableIndex2 entryTableIndex = SWAPW(stateArray(classCode + currentState * nClasses,success));
5971N/A LE_STATE_PATIENCE_CURR(le_int32, currGlyph);
5980N/A currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex, success);
5971N/A LE_STATE_PATIENCE_INCR(currGlyph);
5891N/A }
5891N/A break;
5891N/A }
5891N/A case ltfSegmentArray: {
5971N/A //printf("Lookup Table Format4: specific interpretation needed!\n");
5891N/A break;
5891N/A }
5891N/A case ltfSingleTable: {
5980N/A LEReferenceTo<SingleTableLookupTable> lookupTable6(classTable, success);
5891N/A while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) {
5980N/A if (LE_FAILURE(success)) break;
5980N/A if (LE_STATE_PATIENCE_DECR()) {
5971N/A LE_DEBUG_BAD_FONT("patience exceeded - state table not moving")
5971N/A break; // patience exceeded.
5971N/A }
5891N/A LookupValue classCode = classCodeOOB;
5891N/A if (currGlyph == glyphCount || currGlyph == -1) {
5891N/A // XXX: How do we handle EOT vs. EOL?
5891N/A classCode = classCodeEOT;
5971N/A } else if(currGlyph > glyphCount) {
5971N/A // note if > glyphCount, we've run off the end (bad font)
5971N/A currGlyph = glyphCount;
5971N/A classCode = classCodeEOT;
5891N/A } else {
5891N/A LEGlyphID gid = glyphStorage[currGlyph];
5891N/A TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
5891N/A
5891N/A if (glyphCode == 0xFFFF) {
5891N/A classCode = classCodeDEL;
5891N/A } else {
5980N/A const LookupSingle *segment = lookupTable6->lookupSingle(lookupTable6, lookupTable6->entries, gid, success);
5891N/A if (segment != NULL) {
5891N/A classCode = SWAPW(segment->value);
5891N/A }
5891N/A }
5891N/A }
5980N/A EntryTableIndex2 entryTableIndex = SWAPW(stateArray(classCode + currentState * nClasses, success));
5971N/A LE_STATE_PATIENCE_CURR(le_int32, currGlyph);
5980N/A currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex, success);
5971N/A LE_STATE_PATIENCE_INCR(currGlyph);
5891N/A }
5891N/A break;
5891N/A }
5891N/A case ltfTrimmedArray: {
5980N/A LEReferenceTo<TrimmedArrayLookupTable> lookupTable8(classTable, success);
5980N/A if (LE_FAILURE(success)) break;
5891N/A TTGlyphID firstGlyph = SWAPW(lookupTable8->firstGlyph);
5891N/A TTGlyphID lastGlyph = firstGlyph + SWAPW(lookupTable8->glyphCount);
5891N/A
5891N/A while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) {
5971N/A if(LE_STATE_PATIENCE_DECR()) {
5971N/A LE_DEBUG_BAD_FONT("patience exceeded - state table not moving")
5971N/A break; // patience exceeded.
5971N/A }
5971N/A
5891N/A LookupValue classCode = classCodeOOB;
5891N/A if (currGlyph == glyphCount || currGlyph == -1) {
5891N/A // XXX: How do we handle EOT vs. EOL?
5891N/A classCode = classCodeEOT;
5891N/A } else {
5891N/A TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(glyphStorage[currGlyph]);
5891N/A if (glyphCode == 0xFFFF) {
5891N/A classCode = classCodeDEL;
5891N/A } else if ((glyphCode >= firstGlyph) && (glyphCode < lastGlyph)) {
5891N/A classCode = SWAPW(lookupTable8->valueArray[glyphCode - firstGlyph]);
5891N/A }
5891N/A }
5980N/A EntryTableIndex2 entryTableIndex = SWAPW(stateArray(classCode + currentState * nClasses, success));
5971N/A LE_STATE_PATIENCE_CURR(le_int32, currGlyph);
5980N/A currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex, success);
5971N/A LE_STATE_PATIENCE_INCR(currGlyph);
5891N/A }
5891N/A break;
5891N/A }
5891N/A default:
5891N/A break;
5891N/A }
5891N/A
5891N/A endStateTable();
5891N/A}
5891N/A
5891N/AU_NAMESPACE_END