Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/sun/font/layout/ClassDefinitionTables.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-2004 - All Rights Reserved28*29*/3031#include "LETypes.h"32#include "OpenTypeTables.h"33#include "OpenTypeUtilities.h"34#include "ClassDefinitionTables.h"35#include "LESwaps.h"3637U_NAMESPACE_BEGIN3839le_int32 ClassDefinitionTable::getGlyphClass(const LETableReference& base, LEGlyphID glyphID, LEErrorCode &success) const40{41LEReferenceTo<ClassDefinitionTable> thisRef(base, success);42if (LE_FAILURE(success)) return 0;4344switch(SWAPW(classFormat)) {45case 0:46return 0;4748case 1:49{50const LEReferenceTo<ClassDefFormat1Table> f1Table(thisRef, success);51return f1Table->getGlyphClass(f1Table, glyphID, success);52}5354case 2:55{56const LEReferenceTo<ClassDefFormat2Table> f2Table(thisRef, success);57return f2Table->getGlyphClass(f2Table, glyphID, success);58}5960default:61return 0;62}63}6465le_bool ClassDefinitionTable::hasGlyphClass(const LETableReference &base, le_int32 glyphClass, LEErrorCode &success) const66{67LEReferenceTo<ClassDefinitionTable> thisRef(base, success);68if (LE_FAILURE(success)) return 0;6970switch(SWAPW(classFormat)) {71case 0:72return 0;7374case 1:75{76const LEReferenceTo<ClassDefFormat1Table> f1Table(thisRef, success);77return f1Table->hasGlyphClass(f1Table, glyphClass, success);78}7980case 2:81{82const LEReferenceTo<ClassDefFormat2Table> f2Table(thisRef, success);83return f2Table->hasGlyphClass(f2Table, glyphClass, success);84}8586default:87return 0;88}89}9091le_int32 ClassDefFormat1Table::getGlyphClass(const LETableReference& base, LEGlyphID glyphID, LEErrorCode &success) const92{93if(LE_FAILURE(success)) return 0;9495le_uint16 count = SWAPW(glyphCount);96LEReferenceToArrayOf<le_uint16> classValueArrayRef(base, success, &classValueArray[0], count);97TTGlyphID ttGlyphID = (TTGlyphID) LE_GET_GLYPH(glyphID);98TTGlyphID firstGlyph = SWAPW(startGlyph);99TTGlyphID lastGlyph = firstGlyph + count;100101if (LE_SUCCESS(success) && ttGlyphID >= firstGlyph && ttGlyphID < lastGlyph) {102return SWAPW( classValueArrayRef(ttGlyphID - firstGlyph, success) );103}104105return 0;106}107108le_bool ClassDefFormat1Table::hasGlyphClass(const LETableReference &base, le_int32 glyphClass, LEErrorCode &success) const109{110if(LE_FAILURE(success)) return 0;111le_uint16 count = SWAPW(glyphCount);112LEReferenceToArrayOf<le_uint16> classValueArrayRef(base, success, &classValueArray[0], count);113int i;114115for (i = 0; LE_SUCCESS(success)&& (i < count); i += 1) {116if (SWAPW(classValueArrayRef(i,success)) == glyphClass) {117return TRUE;118}119}120121return FALSE;122}123124le_int32 ClassDefFormat2Table::getGlyphClass(const LETableReference& base, LEGlyphID glyphID, LEErrorCode &success) const125{126if(LE_FAILURE(success)) return 0;127TTGlyphID ttGlyph = (TTGlyphID) LE_GET_GLYPH(glyphID);128le_uint16 rangeCount = SWAPW(classRangeCount);129LEReferenceToArrayOf<GlyphRangeRecord> classRangeRecordArrayRef(base, success, &classRangeRecordArray[0], rangeCount);130le_int32 rangeIndex =131OpenTypeUtilities::getGlyphRangeIndex(ttGlyph, classRangeRecordArrayRef, success);132133if (rangeIndex < 0 || LE_FAILURE(success)) {134return 0;135}136137return SWAPW(classRangeRecordArrayRef(rangeIndex, success).rangeValue);138}139140le_bool ClassDefFormat2Table::hasGlyphClass(const LETableReference &base, le_int32 glyphClass, LEErrorCode &success) const141{142if(LE_FAILURE(success)) return 0;143le_uint16 rangeCount = SWAPW(classRangeCount);144LEReferenceToArrayOf<GlyphRangeRecord> classRangeRecordArrayRef(base, success, &classRangeRecordArray[0], rangeCount);145int i;146147for (i = 0; i < rangeCount && LE_SUCCESS(success); i += 1) {148if (SWAPW(classRangeRecordArrayRef(i,success).rangeValue) == glyphClass) {149return TRUE;150}151}152153return FALSE;154}155156U_NAMESPACE_END157158159