56 missingGlyph = 0; /* standard for TrueType fonts */
57 ByteBuffer buffer = font.getTableBuffer(TrueTypeFont.maxpTag);
58 if (buffer != null && buffer.capacity() >= 6) {
59 numGlyphs = buffer.getChar(4); // offset 4 bytes in MAXP table.
60 } else {
61 handleBadCMAP();
62 }
63 }
64
65 public int getNumGlyphs() {
66 return numGlyphs;
67 }
68
69 private char getGlyphFromCMAP(int charCode) {
70 try {
71 char glyphCode = cmap.getGlyph(charCode);
72 if (glyphCode < numGlyphs ||
73 glyphCode >= FileFontStrike.INVISIBLE_GLYPHS) {
74 return glyphCode;
75 } else {
76 if (FontUtilities.isLogging()) {
77 FontUtilities.getLogger().warning
78 (font + " out of range glyph id=" +
79 Integer.toHexString((int)glyphCode) +
80 " for char " + Integer.toHexString(charCode));
81 }
82 return (char)missingGlyph;
83 }
84 } catch(Exception e) {
85 handleBadCMAP();
86 return (char) missingGlyph;
87 }
88 }
89
90 private char getGlyphFromCMAP(int charCode, int variationSelector) {
91 if (variationSelector == 0) {
92 return getGlyphFromCMAP(charCode);
93 }
94 try {
95 char glyphCode = cmap.getVariationGlyph(charCode,
96 variationSelector);
97 if (glyphCode < numGlyphs ||
98 glyphCode >= FileFontStrike.INVISIBLE_GLYPHS) {
99 return glyphCode;
100 } else {
101 if (FontUtilities.isLogging()) {
102 FontUtilities.getLogger().warning
103 (font + " out of range glyph id=" +
104 Integer.toHexString((int)glyphCode) +
105 " for char " + Integer.toHexString(charCode) +
106 " for vs " + Integer.toHexString(variationSelector));
107 }
108 return (char)missingGlyph;
109 }
110 } catch (Exception e) {
111 handleBadCMAP();
112 return (char) missingGlyph;
113 }
114 }
115
116 private void handleBadCMAP() {
117 if (FontUtilities.isLogging()) {
118 FontUtilities.getLogger().severe("Null Cmap for " + font +
119 "substituting for this font");
120 }
121 SunFontManager.getInstance().deRegisterBadFont(font);
122 /* The next line is not really a solution, but might
123 * reduce the exceptions until references to this font2D
124 * are gone.
125 */
126 cmap = CMap.theNullCmap;
127 }
128
129 private char remapJAChar(char unicode) {
130 return (unicode == REVERSE_SOLIDUS) ? JA_YEN : unicode;
131 }
132
133 private int remapJAIntChar(int unicode) {
134 return (unicode == REVERSE_SOLIDUS) ? JA_YEN : unicode;
135 }
136
137 public int charToGlyph(char unicode) {
138 int glyph = getGlyphFromCMAP(unicode);
139 return glyph;
140 }
|
56 missingGlyph = 0; /* standard for TrueType fonts */
57 ByteBuffer buffer = font.getTableBuffer(TrueTypeFont.maxpTag);
58 if (buffer != null && buffer.capacity() >= 6) {
59 numGlyphs = buffer.getChar(4); // offset 4 bytes in MAXP table.
60 } else {
61 handleBadCMAP();
62 }
63 }
64
65 public int getNumGlyphs() {
66 return numGlyphs;
67 }
68
69 private char getGlyphFromCMAP(int charCode) {
70 try {
71 char glyphCode = cmap.getGlyph(charCode);
72 if (glyphCode < numGlyphs ||
73 glyphCode >= FileFontStrike.INVISIBLE_GLYPHS) {
74 return glyphCode;
75 } else {
76 FontUtilities.logWarning(font + " out of range glyph id=" +
77 Integer.toHexString((int)glyphCode) +
78 " for char " + Integer.toHexString(charCode));
79 return (char)missingGlyph;
80 }
81 } catch(Exception e) {
82 handleBadCMAP();
83 return (char) missingGlyph;
84 }
85 }
86
87 private char getGlyphFromCMAP(int charCode, int variationSelector) {
88 if (variationSelector == 0) {
89 return getGlyphFromCMAP(charCode);
90 }
91 try {
92 char glyphCode = cmap.getVariationGlyph(charCode,
93 variationSelector);
94 if (glyphCode < numGlyphs ||
95 glyphCode >= FileFontStrike.INVISIBLE_GLYPHS) {
96 return glyphCode;
97 } else {
98 FontUtilities.logWarning(font + " out of range glyph id=" +
99 Integer.toHexString((int)glyphCode) +
100 " for char " + Integer.toHexString(charCode) +
101 " for vs " + Integer.toHexString(variationSelector));
102 return (char)missingGlyph;
103 }
104 } catch (Exception e) {
105 handleBadCMAP();
106 return (char) missingGlyph;
107 }
108 }
109
110 private void handleBadCMAP() {
111 FontUtilities.logSevere("Null Cmap for " + font +
112 "substituting for this font");
113
114 SunFontManager.getInstance().deRegisterBadFont(font);
115 /* The next line is not really a solution, but might
116 * reduce the exceptions until references to this font2D
117 * are gone.
118 */
119 cmap = CMap.theNullCmap;
120 }
121
122 private char remapJAChar(char unicode) {
123 return (unicode == REVERSE_SOLIDUS) ? JA_YEN : unicode;
124 }
125
126 private int remapJAIntChar(int unicode) {
127 return (unicode == REVERSE_SOLIDUS) ? JA_YEN : unicode;
128 }
129
130 public int charToGlyph(char unicode) {
131 int glyph = getGlyphFromCMAP(unicode);
132 return glyph;
133 }
|