Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/sun/font/layout/CanonShaping.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. 1998-2005 - All Rights Reserved28*29*/3031#include "LETypes.h"32#include "LEGlyphStorage.h"33#include "CanonShaping.h"34#include "GlyphDefinitionTables.h"35#include "ClassDefinitionTables.h"3637U_NAMESPACE_BEGIN3839void CanonShaping::sortMarks(le_int32 *indices, const le_int32 *combiningClasses, le_int32 index, le_int32 limit)40{41for (le_int32 j = index + 1; j < limit; j += 1) {42le_int32 i;43le_int32 v = indices[j];44le_int32 c = combiningClasses[v];4546for (i = j - 1; i >= index; i -= 1) {47if (c >= combiningClasses[indices[i]]) {48break;49}5051indices[i + 1] = indices[i];52}5354indices[i + 1] = v;55}56}5758void CanonShaping::reorderMarks(const LEUnicode *inChars, le_int32 charCount, le_bool rightToLeft,59LEUnicode *outChars, LEGlyphStorage &glyphStorage)60{61LEErrorCode success = LE_NO_ERROR;62LEReferenceTo<GlyphDefinitionTableHeader> gdefTable(LETableReference::kStaticData, CanonShaping::glyphDefinitionTable, CanonShaping::glyphDefinitionTableLen);63LEReferenceTo<ClassDefinitionTable> classTable = gdefTable->getMarkAttachClassDefinitionTable(gdefTable, success);64le_int32 *combiningClasses = LE_NEW_ARRAY(le_int32, charCount);65le_int32 *indices = LE_NEW_ARRAY(le_int32, charCount);66le_int32 i;6768if (combiningClasses == NULL || indices == NULL) {69if (combiningClasses != NULL) {70LE_DELETE_ARRAY(combiningClasses);71}72if (indices != NULL) {73LE_DELETE_ARRAY(indices);74}75return;76}7778for (i = 0; i < charCount; i += 1) {79combiningClasses[i] = classTable->getGlyphClass(classTable, (LEGlyphID) inChars[i], success);80indices[i] = i;81}8283for (i = 0; i < charCount; i += 1) {84if (combiningClasses[i] != 0) {85le_int32 mark;8687for (mark = i; mark < charCount; mark += 1) {88if (combiningClasses[mark] == 0) {89break;90}91}9293sortMarks(indices, combiningClasses, i, mark);94}95}9697le_int32 out = 0, dir = 1;9899if (rightToLeft) {100out = charCount - 1;101dir = -1;102}103104for (i = 0; i < charCount; i += 1, out += dir) {105le_int32 index = indices[i];106107outChars[i] = inChars[index];108glyphStorage.setCharIndex(out, index, success);109}110111LE_DELETE_ARRAY(indices);112LE_DELETE_ARRAY(combiningClasses);113}114115U_NAMESPACE_END116117118