< prev index next >

src/java.desktop/share/classes/sun/font/TrueTypeGlyphMapper.java

Print this page
rev 60064 : 8248802: Add log helper methods to FontUtilities.java


  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     }




  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.logWarning(font + " out of range glyph id=" +

  78                              Integer.toHexString((int)glyphCode) +
  79                              " for char " + Integer.toHexString(charCode));
  80                 }
  81                 return (char)missingGlyph;
  82             }
  83         } catch(Exception e) {
  84             handleBadCMAP();
  85             return (char) missingGlyph;
  86         }
  87     }
  88 
  89     private char getGlyphFromCMAP(int charCode, int variationSelector) {
  90         if (variationSelector == 0) {
  91             return getGlyphFromCMAP(charCode);
  92         }
  93         try {
  94             char glyphCode = cmap.getVariationGlyph(charCode,
  95                                                     variationSelector);
  96             if (glyphCode < numGlyphs ||
  97                 glyphCode >= FileFontStrike.INVISIBLE_GLYPHS) {
  98                 return glyphCode;
  99             } else {
 100                 if (FontUtilities.isLogging()) {
 101                     FontUtilities.logWarning(font + " out of range glyph id=" +

 102                          Integer.toHexString((int)glyphCode) +
 103                          " for char " + Integer.toHexString(charCode) +
 104                          " for vs " + Integer.toHexString(variationSelector));
 105                 }
 106                 return (char)missingGlyph;
 107             }
 108         } catch (Exception e) {
 109              handleBadCMAP();
 110              return (char) missingGlyph;
 111         }
 112     }
 113 
 114     private void handleBadCMAP() {
 115         if (FontUtilities.isLogging()) {
 116             FontUtilities.logSevere("Null Cmap for " + font +
 117                                     "substituting for this font");
 118         }
 119 
 120         SunFontManager.getInstance().deRegisterBadFont(font);
 121         /* The next line is not really a solution, but might
 122          * reduce the exceptions until references to this font2D
 123          * are gone.
 124          */
 125         cmap = CMap.theNullCmap;
 126     }
 127 
 128     private char remapJAChar(char unicode) {
 129         return (unicode == REVERSE_SOLIDUS) ? JA_YEN : unicode;
 130     }
 131 
 132     private int remapJAIntChar(int unicode) {
 133         return (unicode == REVERSE_SOLIDUS) ? JA_YEN : unicode;
 134     }
 135 
 136     public int charToGlyph(char unicode) {
 137         int glyph = getGlyphFromCMAP(unicode);
 138         return glyph;
 139     }


< prev index next >