blob: 0c6ced698e71a22f175b82aca4709a3aa3883474 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package sun.font;
27
28import java.awt.FontFormatException;
29import java.awt.font.FontRenderContext;
30import java.awt.geom.GeneralPath;
31import java.awt.geom.Rectangle2D;
32import java.util.HashMap;
33import java.util.Locale;
34
35/*
36 * This needs work to distinguish between XMap's translation from unicode
37 * to the encoding used to access the X font, and whether a particular
38 * code point is in the font.
39 * ie a GlyphMapper ought to be able to say if a code point maps to a glyph
40 * IN THIS FONT, not just in this encoding.
41 * Because of the current lack of distinction the NativeGlyphMapper and
42 * XMap classes could be merged, however its cleaner to make them separate
43 * classes so we can build caches for a particular font.
44 */
45public class NativeGlyphMapper extends CharToGlyphMapper {
46
47 NativeFont font;
48 XMap xmapper;
49 int numGlyphs;
50
51 NativeGlyphMapper(NativeFont f) {
52 font = f;
53 xmapper = XMap.getXMapper(font.encoding);
54 numGlyphs = f.getNumGlyphs();
55 missingGlyph = 0;
56 }
57
58 public int getNumGlyphs() {
59 return numGlyphs;
60 }
61
62 public int charToGlyph(char unicode) {
63 if (unicode >= xmapper.convertedGlyphs.length) {
64 return 0;
65 } else {
66 return xmapper.convertedGlyphs[unicode];
67 }
68 }
69
70 public int charToGlyph(int unicode) {
71 if (unicode >= xmapper.convertedGlyphs.length) {
72 return 0;
73 } else {
74 return xmapper.convertedGlyphs[unicode];
75 }
76 }
77
78 public void charsToGlyphs(int count, char[] unicodes, int[] glyphs) {
79 for (int i=0; i<count; i++) {
80 char code = unicodes[i];
81 if (code >= xmapper.convertedGlyphs.length) {
82 glyphs[i] = 0;
83 } else {
84 glyphs[i] = xmapper.convertedGlyphs[code];
85 }
86 }
87 }
88
89 public boolean charsToGlyphsNS(int count, char[] unicodes, int[] glyphs) {
90 charsToGlyphs(count, unicodes, glyphs);
91 return false;
92 }
93
94 public void charsToGlyphs(int count, int[] unicodes, int[] glyphs) {
95 for (int i=0; i<count; i++) {
96 char code = (char)unicodes[i];
97 if (code >= xmapper.convertedGlyphs.length) {
98 glyphs[i] = 0;
99 } else {
100 glyphs[i] = xmapper.convertedGlyphs[code];
101 }
102 }
103 }
104
105}