private static char[] getGlyphToCharMapForFont(Font2D font2D) { /* NB Composites report the number of glyphs in slot 0. * So if a string uses a char from a later slot, or a fallback slot, * it will not be able to use this faster path. */ int numGlyphs = font2D.getNumGlyphs(); int missingGlyph = font2D.getMissingGlyphCode(); char[] glyphToCharMap = new char[numGlyphs]; int glyph; for (int i=0;i<numGlyphs; i++) { glyphToCharMap[i] = CharToGlyphMapper.INVISIBLE_GLYPH_ID; } /* Consider refining the ranges to try to map by asking the font * what ranges it supports. * Since a glyph may be mapped by multiple code points, and this * code can't handle that, we always prefer the earlier code point. */ for (char c=0; c<0xFFFF; c++) { if (c >= CharToGlyphMapper.HI_SURROGATE_START && c <= CharToGlyphMapper.LO_SURROGATE_END) { continue; } glyph = font2D.charToGlyph(c); if (glyph != missingGlyph && glyph >= 0 && glyph < numGlyphs && (glyphToCharMap[glyph] == CharToGlyphMapper.INVISIBLE_GLYPH_ID)) { glyphToCharMap[glyph] = c; } } return glyphToCharMap; }
private static char[] getGlyphToCharMapForFont(Font2D font2D) { /* NB Composites report the number of glyphs in slot 0. * So if a string uses a char from a later slot, or a fallback slot, * it will not be able to use this faster path. */ int numGlyphs = font2D.getNumGlyphs(); int missingGlyph = font2D.getMissingGlyphCode(); char[] glyphToCharMap = new char[numGlyphs]; int glyph; for (int i=0;i<numGlyphs; i++) { glyphToCharMap[i] = CharToGlyphMapper.INVISIBLE_GLYPH_ID; } /* Consider refining the ranges to try to map by asking the font * what ranges it supports. * Since a glyph may be mapped by multiple code points, and this * code can't handle that, we always prefer the earlier code point. */ for (char c=0; c<0xFFFF; c++) { if (c >= CharToGlyphMapper.HI_SURROGATE_START && c <= CharToGlyphMapper.LO_SURROGATE_END) { continue; } glyph = font2D.charToGlyph(c); if (glyph != missingGlyph && glyph < numGlyphs && (glyphToCharMap[glyph] == CharToGlyphMapper.INVISIBLE_GLYPH_ID)) { glyphToCharMap[glyph] = c; } } return glyphToCharMap; }