Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/font/NativeGlyphMapper.java
32287 views
/*1* Copyright (c) 2003, 2005, 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;2627import java.awt.FontFormatException;28import java.awt.font.FontRenderContext;29import java.awt.geom.GeneralPath;30import java.awt.geom.Rectangle2D;31import java.util.HashMap;32import java.util.Locale;3334/*35* This needs work to distinguish between XMap's translation from unicode36* to the encoding used to access the X font, and whether a particular37* code point is in the font.38* ie a GlyphMapper ought to be able to say if a code point maps to a glyph39* IN THIS FONT, not just in this encoding.40* Because of the current lack of distinction the NativeGlyphMapper and41* XMap classes could be merged, however its cleaner to make them separate42* classes so we can build caches for a particular font.43*/44public class NativeGlyphMapper extends CharToGlyphMapper {4546NativeFont font;47XMap xmapper;48int numGlyphs;4950NativeGlyphMapper(NativeFont f) {51font = f;52xmapper = XMap.getXMapper(font.encoding);53numGlyphs = f.getNumGlyphs();54missingGlyph = 0;55}5657public int getNumGlyphs() {58return numGlyphs;59}6061public int charToGlyph(char unicode) {62if (unicode >= xmapper.convertedGlyphs.length) {63return 0;64} else {65return xmapper.convertedGlyphs[unicode];66}67}6869public int charToGlyph(int unicode) {70if (unicode >= xmapper.convertedGlyphs.length) {71return 0;72} else {73return xmapper.convertedGlyphs[unicode];74}75}7677public void charsToGlyphs(int count, char[] unicodes, int[] glyphs) {78for (int i=0; i<count; i++) {79char code = unicodes[i];80if (code >= xmapper.convertedGlyphs.length) {81glyphs[i] = 0;82} else {83glyphs[i] = xmapper.convertedGlyphs[code];84}85}86}8788public boolean charsToGlyphsNS(int count, char[] unicodes, int[] glyphs) {89charsToGlyphs(count, unicodes, glyphs);90return false;91}9293public void charsToGlyphs(int count, int[] unicodes, int[] glyphs) {94for (int i=0; i<count; i++) {95char code = (char)unicodes[i];96if (code >= xmapper.convertedGlyphs.length) {97glyphs[i] = 0;98} else {99glyphs[i] = xmapper.convertedGlyphs[code];100}101}102}103104}105106107