Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/sun/font/layout/ContextualGlyphInsertionProc2.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 "ContextualGlyphInsertionProc2.h"38#include "LEGlyphStorage.h"39#include "LESwaps.h"4041U_NAMESPACE_BEGIN4243UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ContextualGlyphInsertionProcessor2)4445ContextualGlyphInsertionProcessor2::ContextualGlyphInsertionProcessor2(46const LEReferenceTo<MorphSubtableHeader2> &morphSubtableHeader, LEErrorCode &success)47: StateTableProcessor2(morphSubtableHeader, success)48{49contextualGlyphHeader = LEReferenceTo<ContextualGlyphInsertionHeader2>(morphSubtableHeader, success);50if(LE_FAILURE(success) || !contextualGlyphHeader.isValid()) return;51le_uint32 insertionTableOffset = SWAPL(contextualGlyphHeader->insertionTableOffset);52insertionTable = LEReferenceToArrayOf<le_uint16>(stHeader, success, insertionTableOffset, LE_UNBOUNDED_ARRAY);53entryTable = LEReferenceToArrayOf<ContextualGlyphInsertionStateEntry2>(stHeader, success, entryTableOffset, LE_UNBOUNDED_ARRAY);54}5556ContextualGlyphInsertionProcessor2::~ContextualGlyphInsertionProcessor2()57{58}5960void ContextualGlyphInsertionProcessor2::beginStateTable()61{62markGlyph = 0;63}6465void ContextualGlyphInsertionProcessor2::doInsertion(LEGlyphStorage &glyphStorage,66le_int16 atGlyph,67le_int16 &index,68le_int16 count,69le_bool /* isKashidaLike */,70le_bool isBefore,71LEErrorCode &success) {72LEGlyphID *insertGlyphs = glyphStorage.insertGlyphs(atGlyph, count + 1, success);7374if(LE_FAILURE(success) || insertGlyphs==NULL) {75return;76}7778// Note: Kashida vs Split Vowel seems to only affect selection and highlighting.79// We note the flag, but do not layout different.80// https://developer.apple.com/fonts/TTRefMan/RM06/Chap6mort.html8182le_int16 targetIndex = 0;83if(isBefore) {84// insert at beginning85insertGlyphs[targetIndex++] = glyphStorage[atGlyph];86} else {87// insert at end88insertGlyphs[count] = glyphStorage[atGlyph];89}9091while(count--) {92insertGlyphs[targetIndex++] = insertionTable.getObject(index++, success);93}94glyphStorage.applyInsertions();95}9697le_uint16 ContextualGlyphInsertionProcessor2::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph,98EntryTableIndex2 index, LEErrorCode &success)99{100const ContextualGlyphInsertionStateEntry2 *entry = entryTable.getAlias(index, success);101102if(LE_FAILURE(success)) return 0; // TODO- which state?103104le_uint16 newState = SWAPW(entry->newStateIndex);105le_uint16 flags = SWAPW(entry->flags);106107le_int16 markIndex = SWAPW(entry->markedInsertionListIndex);108if (markIndex > 0) {109if (markGlyph < 0 || markGlyph >= glyphStorage.getGlyphCount()) {110success = LE_INDEX_OUT_OF_BOUNDS_ERROR;111return 0;112}113le_int16 count = (flags & cgiMarkedInsertCountMask) >> 5;114le_bool isKashidaLike = (flags & cgiMarkedIsKashidaLike);115le_bool isBefore = (flags & cgiMarkInsertBefore);116doInsertion(glyphStorage, markGlyph, markIndex, count, isKashidaLike, isBefore, success);117}118119le_int16 currIndex = SWAPW(entry->currentInsertionListIndex);120if (currIndex > 0) {121if (currGlyph < 0 || currGlyph >= glyphStorage.getGlyphCount()) {122success = LE_INDEX_OUT_OF_BOUNDS_ERROR;123return 0;124}125le_int16 count = flags & cgiCurrentInsertCountMask;126le_bool isKashidaLike = (flags & cgiCurrentIsKashidaLike);127le_bool isBefore = (flags & cgiCurrentInsertBefore);128doInsertion(glyphStorage, currGlyph, currIndex, count, isKashidaLike, isBefore, success);129}130131if (flags & cgiSetMark) {132markGlyph = currGlyph;133}134135if (!(flags & cgiDontAdvance)) {136currGlyph += dir;137}138139return newState;140}141142void ContextualGlyphInsertionProcessor2::endStateTable()143{144}145146U_NAMESPACE_END147148149