The code is:
package ssl;
import javax.swing.*;
import java.awt.*;
public class WebDingsPhontGlyph extends JFrame {
public WebDingsPhontGlyph() {
setTitle("WebDings Phone Glyph");
setSize(200, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setFont(new Font("Webdings", Font.PLAIN, 50));
g2d.setColor(Color.BLUE);
g2d.drawString("^", 50, 100); // Phone glyph
g2d.drawString("É", 100, 100); // Messaging glyph
}
};
add(panel);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
WebDingsPhontGlyph webDingsPhoneGlyph = new WebDingsPhontGlyph();
webDingsPhoneGlyph.setVisible(true);
});
}
}
and the JPanel view is, despite of I expect specific WebDings glyphs.
If I use another font name, that definitely doesn't exits, like
g2d.setFont(new Font("webdings33", Font.PLAIN, 50));
it uses Arial font and shows the glyps.
I have Webdings installed:
String [] fonts = ge.getAvailableFontFamilyNames();
for (String fontname: fonts) {
System.out.println(fontname);
}
outputs among others
Trebuchet MS
TypoUpright BT
Verdana
Webdings
Wingdings
Wingdings 2
Wingdings 3
Yu Gothic
UPD.
I'm trying to test the metadata:
Font webdingsFont = new Font("WebDings", Font.PLAIN, 12);
System.out.println(webdingsFont.isBold());
System.out.println(webdingsFont.isItalic());
System.out.println(webdingsFont.isTransformed());
System.out.println(webdingsFont.isPlain());
System.out.println(webdingsFont.getNumGlyphs());
System.out.println(webdingsFont.getStyle());
System.out.println(webdingsFont.getFamily());
for (int i = 0; i < 65536; i++) {
if (webdingsFont.canDisplay((char) i)) {
// g2d.drawString(Character.toString((char) i), 50, i*12); // Display the glyph at a specific position
System.out.println(i+" "+Character.toString((char) i));
}
}
and I'm getting the ouptut not of the Webdings
, but Wingdings
font!
false
false
false
true
227
0
Webdings
9
10
13 8204 8205 61472 61473 61474 61475
and if I try to load a real Wingdings, I get exactly the same output and visible behavior. So, it looks like Wingdings is installed as a Webdings at least in my windows version.
The Windows Character Map is lying in order to be “helpful.” (Ironically, it is doing the opposite.)
The characters are not at ASCII codepoints at all. Wingdings and Webdings generally place their characters in the Unicode Private Use Area starting at U+F020. Add 0xf000 to each character to get its true position in the font.
For example, instead of "^"
, use String.format("%c", '^' + 0xf000)
. Instead of "É"
, use String.format("%c", 'É' + 0xf000)
.
Of course, one can also write "\uf05e"
and "\uf0c9"
. I find using String.format and adding 0xf000 a little easier to understand and maintain.