Path: blob/master/src/java.desktop/share/classes/sun/font/CharToGlyphMapper.java
41154 views
/*1* Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.font;2627/*28* NB the versions that take a char as an int are used by the opentype29* layout engine. If that remains in native these methods may not be30* needed in the Java class.31*/32public abstract class CharToGlyphMapper {3334public static final int HI_SURROGATE_START = 0xD800;35public static final int HI_SURROGATE_END = 0xDBFF;36public static final int LO_SURROGATE_START = 0xDC00;37public static final int LO_SURROGATE_END = 0xDFFF;38public static final int VS_START = 0xFE00;39public static final int VS_END = 0xFE0F;40public static final int VSS_START = 0xE0100;41public static final int VSS_END = 0xE01FF;4243public static final int UNINITIALIZED_GLYPH = -1;44public static final int INVISIBLE_GLYPH_ID = 0xffff;45public static final int INVISIBLE_GLYPHS = 0xfffe; // and above4647protected int missingGlyph = CharToGlyphMapper.UNINITIALIZED_GLYPH;4849public int getMissingGlyphCode() {50return missingGlyph;51}5253/* Default implementations of these methods may be overridden by54* subclasses which have special requirements or optimisations55*/5657public boolean canDisplay(char ch) {58int glyph = charToGlyph(ch);59return glyph != missingGlyph;60}6162public boolean canDisplay(int cp) {63int glyph = charToGlyph(cp);64return glyph != missingGlyph;65}6667public int charToGlyph(char unicode) {68char[] chars = new char[1];69int[] glyphs = new int[1];70chars[0] = unicode;71charsToGlyphs(1, chars, glyphs);72return glyphs[0];73}7475public int charToGlyph(int unicode) {76int[] chars = new int[1];77int [] glyphs = new int[1];78chars[0] = unicode;79charsToGlyphs(1, chars, glyphs);80return glyphs[0];81}8283public int charToVariationGlyph(int unicode, int variationSelector) {84// Override this if variation selector is supported.85return charToGlyph(unicode);86}8788public abstract int getNumGlyphs();8990public abstract void charsToGlyphs(int count,91char[] unicodes, int[] glyphs);9293public abstract boolean charsToGlyphsNS(int count,94char[] unicodes, int[] glyphs);9596public abstract void charsToGlyphs(int count,97int[] unicodes, int[] glyphs);9899public static boolean isVariationSelector(int charCode) {100return ((charCode >= VSS_START && charCode <= VSS_END) ||101(charCode >= VS_START && charCode <= VS_END));102}103104}105106107