0N/A/*
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A *
0N/A */
0N/A
0N/A/*
0N/A *
5971N/A * (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved
0N/A *
0N/A */
0N/A
0N/A#include "LETypes.h"
0N/A#include "MorphTables.h"
0N/A#include "StateTables.h"
0N/A#include "MorphStateTables.h"
0N/A#include "SubtableProcessor.h"
0N/A#include "StateTableProcessor.h"
0N/A#include "LigatureSubstProc.h"
0N/A#include "LEGlyphStorage.h"
0N/A#include "LESwaps.h"
0N/A
1693N/AU_NAMESPACE_BEGIN
1693N/A
0N/A#define ExtendedComplement(m) ((le_int32) (~((le_uint32) (m))))
0N/A#define SignBit(m) ((ExtendedComplement(m) >> 1) & (le_int32)(m))
0N/A#define SignExtend(v,m) (((v) & SignBit(m))? ((v) | ExtendedComplement(m)): (v))
0N/A
1693N/AUOBJECT_DEFINE_RTTI_IMPLEMENTATION(LigatureSubstitutionProcessor)
1693N/A
5980N/A LigatureSubstitutionProcessor::LigatureSubstitutionProcessor(const LEReferenceTo<MorphSubtableHeader> &morphSubtableHeader, LEErrorCode &success)
5980N/A: StateTableProcessor(morphSubtableHeader, success), ligatureSubstitutionHeader(morphSubtableHeader, success)
0N/A{
5980N/A if(LE_FAILURE(success)) return;
0N/A ligatureActionTableOffset = SWAPW(ligatureSubstitutionHeader->ligatureActionTableOffset);
0N/A componentTableOffset = SWAPW(ligatureSubstitutionHeader->componentTableOffset);
0N/A ligatureTableOffset = SWAPW(ligatureSubstitutionHeader->ligatureTableOffset);
0N/A
5980N/A entryTable = LEReferenceToArrayOf<LigatureSubstitutionStateEntry>(stHeader, success, entryTableOffset, LE_UNBOUNDED_ARRAY);
0N/A}
0N/A
0N/ALigatureSubstitutionProcessor::~LigatureSubstitutionProcessor()
0N/A{
0N/A}
0N/A
0N/Avoid LigatureSubstitutionProcessor::beginStateTable()
0N/A{
0N/A m = -1;
0N/A}
0N/A
1693N/AByteOffset LigatureSubstitutionProcessor::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph, EntryTableIndex index)
0N/A{
5980N/A LEErrorCode success = LE_NO_ERROR;
5980N/A const LigatureSubstitutionStateEntry *entry = entryTable.getAlias(index, success);
5980N/A
0N/A ByteOffset newState = SWAPW(entry->newStateOffset);
0N/A le_int16 flags = SWAPW(entry->flags);
0N/A
0N/A if (flags & lsfSetComponent) {
0N/A if (++m >= nComponents) {
0N/A m = 0;
0N/A }
0N/A
0N/A componentStack[m] = currGlyph;
5971N/A } else if ( m == -1) {
5971N/A // bad font- skip this glyph.
5971N/A currGlyph++;
5971N/A return newState;
0N/A }
0N/A
0N/A ByteOffset actionOffset = flags & lsfActionOffsetMask;
0N/A
0N/A if (actionOffset != 0) {
5980N/A LEReferenceTo<LigatureActionEntry> ap(stHeader, success, actionOffset);
0N/A LigatureActionEntry action;
0N/A le_int32 offset, i = 0;
0N/A le_int32 stack[nComponents];
0N/A le_int16 mm = -1;
0N/A
0N/A do {
0N/A le_uint32 componentGlyph = componentStack[m--];
0N/A
5980N/A action = SWAPL(*ap.getAlias());
5980N/A ap.addObject(success); // ap++
0N/A
0N/A if (m < 0) {
0N/A m = nComponents - 1;
0N/A }
0N/A
0N/A offset = action & lafComponentOffsetMask;
0N/A if (offset != 0) {
5980N/A LEReferenceToArrayOf<le_int16> offsetTable(stHeader, success, 2 * SignExtend(offset, lafComponentOffsetMask), LE_UNBOUNDED_ARRAY);
0N/A
5980N/A if(LE_FAILURE(success)) {
5971N/A currGlyph++;
5971N/A LE_DEBUG_BAD_FONT("off end of ligature substitution header");
5971N/A return newState; // get out! bad font
5980N/A }
5980N/A if(componentGlyph > glyphStorage.getGlyphCount()) {
5980N/A LE_DEBUG_BAD_FONT("preposterous componentGlyph");
5980N/A currGlyph++;
5980N/A return newState; // get out! bad font
5980N/A }
5980N/A i += SWAPW(offsetTable.getObject(LE_GET_GLYPH(glyphStorage[componentGlyph]), success));
0N/A
0N/A if (action & (lafLast | lafStore)) {
5980N/A LEReferenceTo<TTGlyphID> ligatureOffset(stHeader, success, i);
5980N/A TTGlyphID ligatureGlyph = SWAPW(*ligatureOffset.getAlias());
0N/A
5980N/A glyphStorage[componentGlyph] = LE_SET_GLYPH(glyphStorage[componentGlyph], ligatureGlyph);
5980N/A if(mm==nComponents) {
5980N/A LE_DEBUG_BAD_FONT("exceeded nComponents");
5980N/A mm--; // don't overrun the stack.
5980N/A }
5980N/A stack[++mm] = componentGlyph;
5980N/A i = 0;
0N/A } else {
5980N/A glyphStorage[componentGlyph] = LE_SET_GLYPH(glyphStorage[componentGlyph], 0xFFFF);
0N/A }
0N/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
0N/A
0N/A while (mm >= 0) {
5980N/A if (++m >= nComponents) {
5980N/A m = 0;
5980N/A }
0N/A
5980N/A componentStack[m] = stack[mm--];
0N/A }
0N/A }
0N/A
0N/A if (!(flags & lsfDontAdvance)) {
0N/A // should handle reverse too!
0N/A currGlyph += 1;
0N/A }
0N/A
0N/A return newState;
0N/A}
0N/A
0N/Avoid LigatureSubstitutionProcessor::endStateTable()
0N/A{
0N/A}
1693N/A
1693N/AU_NAMESPACE_END