Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/sun/font/layout/ContextualGlyphSubstProc2.cpp
38918 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425/*26*27* (C) Copyright IBM Corp. and others 1998-2013 - All Rights Reserved28*29*/3031#include "LETypes.h"32#include "MorphTables.h"33#include "StateTables.h"34#include "MorphStateTables.h"35#include "SubtableProcessor2.h"36#include "StateTableProcessor2.h"37#include "ContextualGlyphSubstProc2.h"38#include "LEGlyphStorage.h"39#include "LESwaps.h"4041U_NAMESPACE_BEGIN4243UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ContextualGlyphSubstitutionProcessor2)4445ContextualGlyphSubstitutionProcessor2::ContextualGlyphSubstitutionProcessor2(46const LEReferenceTo<MorphSubtableHeader2> &morphSubtableHeader, LEErrorCode &success)47: StateTableProcessor2(morphSubtableHeader, success), contextualGlyphHeader(morphSubtableHeader, success)48{49if(LE_FAILURE(success)) return;50le_uint32 perGlyphTableOffset = SWAPL(contextualGlyphHeader->perGlyphTableOffset);51perGlyphTable = LEReferenceToArrayOf<le_uint32> (stHeader, success, perGlyphTableOffset, LE_UNBOUNDED_ARRAY);52entryTable = LEReferenceToArrayOf<ContextualGlyphStateEntry2>(stHeader, success, entryTableOffset, LE_UNBOUNDED_ARRAY);53}5455ContextualGlyphSubstitutionProcessor2::~ContextualGlyphSubstitutionProcessor2()56{57}5859void ContextualGlyphSubstitutionProcessor2::beginStateTable()60{61markGlyph = 0;62}6364le_uint16 ContextualGlyphSubstitutionProcessor2::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph,65EntryTableIndex2 index, LEErrorCode &success)66{67if(LE_FAILURE(success)) return 0;68const ContextualGlyphStateEntry2 *entry = entryTable.getAlias(index, success);69if(LE_FAILURE(success)) return 0;70le_uint16 newState = SWAPW(entry->newStateIndex);71le_uint16 flags = SWAPW(entry->flags);72le_uint16 markIndex = SWAPW(entry->markIndex);73le_uint16 currIndex = SWAPW(entry->currIndex);7475if (markIndex != 0x0FFFF) {76if (markGlyph < 0 || markGlyph >= glyphStorage.getGlyphCount()) {77success = LE_INDEX_OUT_OF_BOUNDS_ERROR;78return 0;79}80le_uint32 offset = SWAPL(perGlyphTable(markIndex, success));81LEGlyphID mGlyph = glyphStorage[markGlyph];82TTGlyphID newGlyph = lookup(offset, mGlyph, success);83glyphStorage[markGlyph] = LE_SET_GLYPH(mGlyph, newGlyph);84}8586if (currIndex != 0x0FFFF) {87if (currGlyph < 0 || currGlyph >= glyphStorage.getGlyphCount()) {88success = LE_INDEX_OUT_OF_BOUNDS_ERROR;89return 0;90}91le_uint32 offset = SWAPL(perGlyphTable(currIndex, success));92LEGlyphID thisGlyph = glyphStorage[currGlyph];93TTGlyphID newGlyph = lookup(offset, thisGlyph, success);94glyphStorage[currGlyph] = LE_SET_GLYPH(thisGlyph, newGlyph);95}9697if (flags & cgsSetMark) {98markGlyph = currGlyph;99}100101if (!(flags & cgsDontAdvance)) {102currGlyph += dir;103}104105return newState;106}107108TTGlyphID ContextualGlyphSubstitutionProcessor2::lookup(le_uint32 offset, LEGlyphID gid, LEErrorCode &success)109{110TTGlyphID newGlyph = 0xFFFF;111if(LE_FAILURE(success)) return newGlyph;112LEReferenceTo<LookupTable> lookupTable(perGlyphTable, success, offset);113if(LE_FAILURE(success)) return newGlyph;114le_int16 format = SWAPW(lookupTable->format);115116switch (format) {117case ltfSimpleArray: {118#ifdef TEST_FORMAT119// Disabled pending for design review120LEReferenceTo<SimpleArrayLookupTable> lookupTable0(lookupTable, success);121LEReferenceToArrayOf<LookupValue> valueArray(lookupTable0, success, &lookupTable0->valueArray[0], LE_UNBOUNDED_ARRAY);122if(LE_FAILURE(success)) return newGlyph;123TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);124newGlyph = SWAPW(lookupTable0->valueArray(glyphCode, success));125#endif126break;127}128case ltfSegmentSingle: {129#ifdef TEST_FORMAT130// Disabled pending for design review131LEReferenceTo<SegmentSingleLookupTable> lookupTable2 = (SegmentSingleLookupTable *) lookupTable;132const LookupSegment *segment = lookupTable2->lookupSegment(lookupTable2->segments, gid);133if (segment != NULL) {134newGlyph = SWAPW(segment->value);135}136#endif137break;138}139case ltfSegmentArray: {140//printf("Context Lookup Table Format4: specific interpretation needed!\n");141break;142}143case ltfSingleTable:144{145#ifdef TEST_FORMAT146// Disabled pending for design review147LEReferenceTo<SingleTableLookupTable> lookupTable6 = (SingleTableLookupTable *) lookupTable;148const LEReferenceTo<LookupSingle> segment = lookupTable6->lookupSingle(lookupTable6->entries, gid);149if (segment != NULL) {150newGlyph = SWAPW(segment->value);151}152#endif153break;154}155case ltfTrimmedArray: {156LEReferenceTo<TrimmedArrayLookupTable> lookupTable8(lookupTable, success);157if (LE_FAILURE(success)) return newGlyph;158TTGlyphID firstGlyph = SWAPW(lookupTable8->firstGlyph);159TTGlyphID glyphCount = SWAPW(lookupTable8->glyphCount);160TTGlyphID lastGlyph = firstGlyph + glyphCount;161TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);162if ((glyphCode >= firstGlyph) && (glyphCode < lastGlyph)) {163LEReferenceToArrayOf<LookupValue> valueArray(lookupTable8, success, &lookupTable8->valueArray[0], glyphCount);164if (LE_FAILURE(success)) { return newGlyph; }165newGlyph = SWAPW(valueArray(glyphCode - firstGlyph, success));166}167}168default:169break;170}171return newGlyph;172}173174void ContextualGlyphSubstitutionProcessor2::endStateTable()175{176}177178U_NAMESPACE_END179180181