Ejemplo n.º 1
0
  private void establishFontMetrics() {
    final BufferedImage img = createBufferedImage(1, 1);
    final Graphics2D graphics = img.createGraphics();
    graphics.setFont(myNormalFont);

    final float lineSpace = mySettingsProvider.getLineSpace();
    final FontMetrics fo = graphics.getFontMetrics();

    myDescent = fo.getDescent();
    myCharSize.width = fo.charWidth('W');
    myCharSize.height = fo.getHeight() + (int) (lineSpace * 2);
    myDescent += lineSpace;

    myMonospaced = isMonospaced(fo);
    if (!myMonospaced) {
      LOG.info("WARNING: Font " + myNormalFont.getName() + " is non-monospaced");
    }

    img.flush();
    graphics.dispose();
  }
Ejemplo n.º 2
0
 private static boolean isMonospaced(FontMetrics fontMetrics) {
   boolean isMonospaced = true;
   int charWidth = -1;
   for (int codePoint = 0; codePoint < 128; codePoint++) {
     if (Character.isValidCodePoint(codePoint)) {
       char character = (char) codePoint;
       if (isWordCharacter(character)) {
         int w = fontMetrics.charWidth(character);
         if (charWidth != -1) {
           if (w != charWidth) {
             isMonospaced = false;
             break;
           }
         } else {
           charWidth = w;
         }
       }
     }
   }
   return isMonospaced;
 }