private static int getCharWidth(Font font, char ch) {
    if (font.canDisplay(ch)) {
      Rectangle bounds = font.getStringBounds(new char[]{ch}, 0, 1, DEFAULT_CONTEXT).getBounds();
      if (!bounds.isEmpty()) return bounds.width;
    }
    return 0;
  }
private static int getCharWidth(Font font, char ch)