< prev index next >

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

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


 383      */
 384     static char[] getConverterMap(short encodingID) {
 385         if (converterMaps[encodingID] == null) {
 386            converterMaps[encodingID] = getConverter(encodingID);
 387         }
 388         return converterMaps[encodingID];
 389     }
 390 
 391 
 392     static CMap createCMap(ByteBuffer buffer, int offset, char[] xlat) {
 393         /* First do a sanity check that this cmap subtable is contained
 394          * within the cmap table.
 395          */
 396         int subtableFormat = buffer.getChar(offset);
 397         long subtableLength;
 398         if (subtableFormat < 8) {
 399             subtableLength = buffer.getChar(offset+2);
 400         } else {
 401             subtableLength = buffer.getInt(offset+4) & INTMASK;
 402         }
 403         if (offset+subtableLength > buffer.capacity()) {
 404             if (FontUtilities.isLogging()) {
 405                 FontUtilities.getLogger().warning("Cmap subtable overflows buffer.");
 406             }
 407         }
 408         switch (subtableFormat) {
 409         case 0:  return new CMapFormat0(buffer, offset);
 410         case 2:  return new CMapFormat2(buffer, offset, xlat);
 411         case 4:  return new CMapFormat4(buffer, offset, xlat);
 412         case 6:  return new CMapFormat6(buffer, offset, xlat);
 413         case 8:  return new CMapFormat8(buffer, offset, xlat);
 414         case 10: return new CMapFormat10(buffer, offset, xlat);
 415         case 12: return new CMapFormat12(buffer, offset, xlat);
 416         default: throw new RuntimeException("Cmap format unimplemented: " +
 417                                             (int)buffer.getChar(offset));
 418         }
 419     }
 420 
 421     private void createUVS(ByteBuffer buffer, int offset) {
 422         int subtableFormat = buffer.getChar(offset);
 423         if (subtableFormat == 14) {
 424             long subtableLength = buffer.getInt(offset + 2) & INTMASK;
 425             if (offset + subtableLength > buffer.capacity()) {
 426                 if (FontUtilities.isLogging()) {
 427                     FontUtilities.getLogger()
 428                             .warning("Cmap UVS subtable overflows buffer.");
 429                 }
 430             }
 431             try {
 432                 this.uvs = new UVS(buffer, offset);
 433             } catch (Throwable t) {
 434                 t.printStackTrace();
 435             }
 436         }
 437         return;
 438     }
 439 
 440 /*
 441     final char charVal(byte[] cmap, int index) {
 442         return (char)(((0xff & cmap[index]) << 8)+(0xff & cmap[index+1]));
 443     }
 444 
 445     final short shortVal(byte[] cmap, int index) {
 446         return (short)(((0xff & cmap[index]) << 8)+(0xff & cmap[index+1]));
 447     }
 448 */
 449     abstract char getGlyph(int charCode);




 383      */
 384     static char[] getConverterMap(short encodingID) {
 385         if (converterMaps[encodingID] == null) {
 386            converterMaps[encodingID] = getConverter(encodingID);
 387         }
 388         return converterMaps[encodingID];
 389     }
 390 
 391 
 392     static CMap createCMap(ByteBuffer buffer, int offset, char[] xlat) {
 393         /* First do a sanity check that this cmap subtable is contained
 394          * within the cmap table.
 395          */
 396         int subtableFormat = buffer.getChar(offset);
 397         long subtableLength;
 398         if (subtableFormat < 8) {
 399             subtableLength = buffer.getChar(offset+2);
 400         } else {
 401             subtableLength = buffer.getInt(offset+4) & INTMASK;
 402         }
 403         if (FontUtilities.isLogging() && offset + subtableLength > buffer.capacity()) {
 404             FontUtilities.logWarning("Cmap subtable overflows buffer.");


 405         }
 406         switch (subtableFormat) {
 407         case 0:  return new CMapFormat0(buffer, offset);
 408         case 2:  return new CMapFormat2(buffer, offset, xlat);
 409         case 4:  return new CMapFormat4(buffer, offset, xlat);
 410         case 6:  return new CMapFormat6(buffer, offset, xlat);
 411         case 8:  return new CMapFormat8(buffer, offset, xlat);
 412         case 10: return new CMapFormat10(buffer, offset, xlat);
 413         case 12: return new CMapFormat12(buffer, offset, xlat);
 414         default: throw new RuntimeException("Cmap format unimplemented: " +
 415                                             (int)buffer.getChar(offset));
 416         }
 417     }
 418 
 419     private void createUVS(ByteBuffer buffer, int offset) {
 420         int subtableFormat = buffer.getChar(offset);
 421         if (subtableFormat == 14) {
 422             long subtableLength = buffer.getInt(offset + 2) & INTMASK;
 423             if (FontUtilities.isLogging() && offset + subtableLength > buffer.capacity()) {
 424                 FontUtilities.logWarning("Cmap UVS subtable overflows buffer.");



 425             }
 426             try {
 427                 this.uvs = new UVS(buffer, offset);
 428             } catch (Throwable t) {
 429                 t.printStackTrace();
 430             }
 431         }
 432         return;
 433     }
 434 
 435 /*
 436     final char charVal(byte[] cmap, int index) {
 437         return (char)(((0xff & cmap[index]) << 8)+(0xff & cmap[index+1]));
 438     }
 439 
 440     final short shortVal(byte[] cmap, int index) {
 441         return (short)(((0xff & cmap[index]) << 8)+(0xff & cmap[index+1]));
 442     }
 443 */
 444     abstract char getGlyph(int charCode);


< prev index next >