Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/sun/font/layout/CoverageTables.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 "CoverageTables.h"35#include "LESwaps.h"3637U_NAMESPACE_BEGIN3839le_int32 CoverageTable::getGlyphCoverage(const LETableReference &base, LEGlyphID glyphID, LEErrorCode &success) const40{41if(LE_FAILURE(success)) return -1;4243switch(SWAPW(coverageFormat))44{45case 0:46return -1;4748case 1:49{50LEReferenceTo<CoverageFormat1Table> f1Table(base, success);5152return f1Table->getGlyphCoverage(f1Table, glyphID, success);53}5455case 2:56{57LEReferenceTo<CoverageFormat2Table> f2Table(base, success);5859return f2Table->getGlyphCoverage(f2Table, glyphID, success);60}6162default:63return -1;64}65}6667le_int32 CoverageFormat1Table::getGlyphCoverage(LEReferenceTo<CoverageFormat1Table> &base, LEGlyphID glyphID, LEErrorCode &success) const68{69if(LE_FAILURE(success)) return -1;7071TTGlyphID ttGlyphID = (TTGlyphID) LE_GET_GLYPH(glyphID);72le_uint16 count = SWAPW(glyphCount);73le_uint8 bit = OpenTypeUtilities::highBit(count);74le_uint16 power = 1 << bit;75le_uint16 extra = count - power;76le_uint16 probe = power;77le_uint16 index = 0;7879if (count == 0) {80return -1;81}8283LEReferenceToArrayOf<TTGlyphID>(base, success, glyphArray, count);84if(LE_FAILURE(success)) return -1; // range checks array858687if (SWAPW(glyphArray[extra]) <= ttGlyphID) {88index = extra;89}9091while (probe > (1 << 0)) {92probe >>= 1;9394if (SWAPW(glyphArray[index + probe]) <= ttGlyphID) {95index += probe;96}97}9899if (SWAPW(glyphArray[index]) == ttGlyphID) {100return index;101}102103return -1;104}105106le_int32 CoverageFormat2Table::getGlyphCoverage(LEReferenceTo<CoverageFormat2Table> &base, LEGlyphID glyphID, LEErrorCode &success) const107{108if(LE_FAILURE(success)) return -1;109110TTGlyphID ttGlyphID = (TTGlyphID) LE_GET_GLYPH(glyphID);111le_uint16 count = SWAPW(rangeCount);112113LEReferenceToArrayOf<GlyphRangeRecord> rangeRecordArrayRef(base, success, rangeRecordArray, count);114le_int32 rangeIndex =115OpenTypeUtilities::getGlyphRangeIndex(ttGlyphID, rangeRecordArrayRef, success);116117if (rangeIndex < 0 || LE_FAILURE(success)) { // could fail if array out of bounds118return -1;119}120121TTGlyphID firstInRange = SWAPW(rangeRecordArray[rangeIndex].firstGlyph);122le_uint16 startCoverageIndex = SWAPW(rangeRecordArray[rangeIndex].rangeValue);123124return startCoverageIndex + (ttGlyphID - firstInRange);125}126127U_NAMESPACE_END128129130