1

I am trying to draw characters from Wingding.ttf font with Java Graphics.DrawString. But resulting image contains only rectangle instead of char.

BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_4BYTE_ABGR);

Graphics graphics = image.getGraphics();

Font font = new Font("Wingdings", Font.PLAIN, 20);
graphics.setFont(font);

graphics.setColor(Color.BLACK);

graphics.drawString("\u00d8", 10, 10); // THREE-D TOP-LIGHTED RIGHTWARDS ARROWHEAD char

ImageIO.write(image, "PNG", new File(TEST_DATA_DIR + "bullet_char.png"));

How can I do this?

Viktor
  • 164
  • 1
  • 14

2 Answers2

1

I dont think wingdings is one of the "standard" fonts

Font font = null;
try {
    font=Font.createFont( Font.TRUETYPE_FONT,
        new FileInputStream(new File("/pathto/WINGDINGS.TTF")) );
} catch(Exception e) {
    System.out.println(e);
}
font=font.deriveFont(Font.PLAIN, 200);
graphics.setFont(font);

once you load the font (its always PLANE 1 pnt) you can the derive the style and size you want....

Chris Camacho
  • 1,164
  • 1
  • 9
  • 31
0

As similar questions has been answered here: Drawing exotic fonts in a java applet, you need to pass \uF0d8 instead of \u00d8.

graphics.drawString("\uF0d8", 10, 10);
Community
  • 1
  • 1
David
  • 3,957
  • 2
  • 28
  • 52