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 "LigatureSubstProc2.h"
5891N/A#include "LEGlyphStorage.h"
5891N/A#include "LESwaps.h"
5891N/A
5891N/AU_NAMESPACE_BEGIN
5891N/A
5891N/A#define ExtendedComplement(m) ((le_int32) (~((le_uint32) (m))))
5891N/A#define SignBit(m) ((ExtendedComplement(m) >> 1) & (le_int32)(m))
5891N/A#define SignExtend(v,m) (((v) & SignBit(m))? ((v) | ExtendedComplement(m)): (v))
5891N/A
5891N/AUOBJECT_DEFINE_RTTI_IMPLEMENTATION(LigatureSubstitutionProcessor2)
5891N/A
5980N/ALigatureSubstitutionProcessor2::LigatureSubstitutionProcessor2(const LEReferenceTo<MorphSubtableHeader2> &morphSubtableHeader, LEErrorCode &success)
5980N/A : StateTableProcessor2(morphSubtableHeader, success),
5980N/A ligActionOffset(0),
5980N/A ligatureSubstitutionHeader(morphSubtableHeader, success), componentOffset(0), ligatureOffset(0), entryTable()
5891N/A{
5980N/A if (LE_FAILURE(success)) return;
5980N/A
5891N/A ligActionOffset = SWAPL(ligatureSubstitutionHeader->ligActionOffset);
5891N/A componentOffset = SWAPL(ligatureSubstitutionHeader->componentOffset);
5891N/A ligatureOffset = SWAPL(ligatureSubstitutionHeader->ligatureOffset);
5891N/A
5980N/A entryTable = LEReferenceToArrayOf<LigatureSubstitutionStateEntry2>(stHeader, success, entryTableOffset, LE_UNBOUNDED_ARRAY);
5891N/A}
5891N/A
5891N/ALigatureSubstitutionProcessor2::~LigatureSubstitutionProcessor2()
5891N/A{
5891N/A}
5891N/A
5891N/Avoid LigatureSubstitutionProcessor2::beginStateTable()
5891N/A{
5891N/A m = -1;
5891N/A}
5891N/A
5980N/Ale_uint16 LigatureSubstitutionProcessor2::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph, EntryTableIndex2 index, LEErrorCode &success)
5891N/A{
5980N/A const LigatureSubstitutionStateEntry2 *entry = entryTable.getAlias(index, success);
5980N/A if(LE_FAILURE(success)) return 0;
5980N/A
5891N/A le_uint16 nextStateIndex = SWAPW(entry->nextStateIndex);
5891N/A le_uint16 flags = SWAPW(entry->entryFlags);
5891N/A le_uint16 ligActionIndex = SWAPW(entry->ligActionIndex);
5891N/A
5891N/A if (flags & lsfSetComponent) {
5891N/A if (++m >= nComponents) {
5891N/A m = 0;
5891N/A }
5891N/A componentStack[m] = currGlyph;
5971N/A } else if ( m == -1) {
5971N/A // bad font- skip this glyph.
5980N/A //LE_DEBUG_BAD_FONT("m==-1 (componentCount went negative)")
5971N/A currGlyph+= dir;
5971N/A return nextStateIndex;
5891N/A }
5891N/A
5891N/A ByteOffset actionOffset = flags & lsfPerformAction;
5891N/A
5891N/A if (actionOffset != 0) {
5980N/A LEReferenceTo<LigatureActionEntry> ap(stHeader, success, ligActionOffset); // byte offset
5980N/A ap.addObject(ligActionIndex - 1, success); // index offset ( one before the actual start, because we will pre-increment)
5980N/A LEReferenceToArrayOf<TTGlyphID> ligatureTable(stHeader, success, ligatureOffset, LE_UNBOUNDED_ARRAY);
5891N/A LigatureActionEntry action;
5891N/A le_int32 offset, i = 0;
5891N/A le_int32 stack[nComponents];
5891N/A le_int16 mm = -1;
5891N/A
5980N/A LEReferenceToArrayOf<le_uint16> componentTable(stHeader, success, componentOffset, LE_UNBOUNDED_ARRAY);
5980N/A if(LE_FAILURE(success)) {
5971N/A currGlyph+= dir;
5971N/A return nextStateIndex; // get out! bad font
5971N/A }
5971N/A
5891N/A do {
5891N/A le_uint32 componentGlyph = componentStack[m--]; // pop off
5891N/A
5980N/A ap.addObject(success);
5980N/A action = SWAPL(*ap.getAlias());
5891N/A
5891N/A if (m < 0) {
5891N/A m = nComponents - 1;
5891N/A }
5891N/A
5891N/A offset = action & lafComponentOffsetMask;
5891N/A if (offset != 0) {
5971N/A if(componentGlyph > glyphStorage.getGlyphCount()) {
5971N/A LE_DEBUG_BAD_FONT("preposterous componentGlyph");
5971N/A currGlyph+= dir;
5971N/A return nextStateIndex; // get out! bad font
5971N/A }
5980N/A i += SWAPW(componentTable(LE_GET_GLYPH(glyphStorage[componentGlyph]) + (SignExtend(offset, lafComponentOffsetMask)),success));
5891N/A
5891N/A if (action & (lafLast | lafStore)) {
5980N/A TTGlyphID ligatureGlyph = SWAPW(ligatureTable(i,success));
5891N/A glyphStorage[componentGlyph] = LE_SET_GLYPH(glyphStorage[componentGlyph], ligatureGlyph);
5971N/A if(mm==nComponents) {
5971N/A LE_DEBUG_BAD_FONT("exceeded nComponents");
5971N/A mm--; // don't overrun the stack.
5971N/A }
5891N/A stack[++mm] = componentGlyph;
5891N/A i = 0;
5891N/A } else {
5891N/A glyphStorage[componentGlyph] = LE_SET_GLYPH(glyphStorage[componentGlyph], 0xFFFF);
5891N/A }
5891N/A }
5971N/A#if LE_ASSERT_BAD_FONT
5971N/A if(m<0) {
5971N/A LE_DEBUG_BAD_FONT("m<0")
5971N/A }
5971N/A#endif
5971N/A } while (!(action & lafLast) && (m>=0) ); // stop if last bit is set, or if run out of items
5891N/A
5891N/A while (mm >= 0) {
5891N/A if (++m >= nComponents) {
5891N/A m = 0;
5891N/A }
5891N/A
5891N/A componentStack[m] = stack[mm--];
5891N/A }
5891N/A }
5891N/A
5891N/A if (!(flags & lsfDontAdvance)) {
5891N/A currGlyph += dir;
5891N/A }
5891N/A
5891N/A return nextStateIndex;
5891N/A}
5891N/A
5891N/Avoid LigatureSubstitutionProcessor2::endStateTable()
5891N/A{
5891N/A}
5891N/A
5891N/AU_NAMESPACE_END