001: /*
002: * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.font;
027:
028: import java.awt.FontFormatException;
029: import java.awt.font.FontRenderContext;
030: import java.awt.geom.GeneralPath;
031: import java.awt.geom.Rectangle2D;
032: import java.util.HashMap;
033: import java.util.Locale;
034:
035: /*
036: * This needs work to distinguish between XMap's translation from unicode
037: * to the encoding used to access the X font, and whether a particular
038: * code point is in the font.
039: * ie a GlyphMapper ought to be able to say if a code point maps to a glyph
040: * IN THIS FONT, not just in this encoding.
041: * Because of the current lack of distinction the NativeGlyphMapper and
042: * XMap classes could be merged, however its cleaner to make them separate
043: * classes so we can build caches for a particular font.
044: */
045: public class NativeGlyphMapper extends CharToGlyphMapper {
046:
047: NativeFont font;
048: XMap xmapper;
049: int numGlyphs;
050:
051: NativeGlyphMapper(NativeFont f) {
052: font = f;
053: xmapper = XMap.getXMapper(font.encoding);
054: numGlyphs = f.getNumGlyphs();
055: missingGlyph = 0;
056: }
057:
058: public int getNumGlyphs() {
059: return numGlyphs;
060: }
061:
062: public int charToGlyph(char unicode) {
063: if (unicode >= xmapper.convertedGlyphs.length) {
064: return 0;
065: } else {
066: return xmapper.convertedGlyphs[unicode];
067: }
068: }
069:
070: public int charToGlyph(int unicode) {
071: if (unicode >= xmapper.convertedGlyphs.length) {
072: return 0;
073: } else {
074: return xmapper.convertedGlyphs[unicode];
075: }
076: }
077:
078: public void charsToGlyphs(int count, char[] unicodes, int[] glyphs) {
079: for (int i = 0; i < count; i++) {
080: char code = unicodes[i];
081: if (code >= xmapper.convertedGlyphs.length) {
082: glyphs[i] = 0;
083: } else {
084: glyphs[i] = xmapper.convertedGlyphs[code];
085: }
086: }
087: }
088:
089: public boolean charsToGlyphsNS(int count, char[] unicodes,
090: int[] glyphs) {
091: charsToGlyphs(count, unicodes, glyphs);
092: return false;
093: }
094:
095: public void charsToGlyphs(int count, int[] unicodes, int[] glyphs) {
096: for (int i = 0; i < count; i++) {
097: char code = (char) unicodes[i];
098: if (code >= xmapper.convertedGlyphs.length) {
099: glyphs[i] = 0;
100: } else {
101: glyphs[i] = xmapper.convertedGlyphs[code];
102: }
103: }
104: }
105:
106: }
|