United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4279855 : drawString() displays wrong glyphs in symbol fonts (e.g., Wingding)

Details
Type:
Bug
Submit Date:
1999-10-11
Status:
Closed
Updated Date:
1999-12-16
Project Name:
JDK
Resolved Date:
1999-12-16
Component:
client-libs
OS:
windows_nt
Sub-Component:
2d
CPU:
x86
Priority:
P4
Resolution:
Not an Issue
Affected Versions:
1.2.2
Fixed Versions:

Related Reports

Sub Tasks

Description

Name: dbT83986			Date: 10/10/99


The following program draws a string "& W w h q e" to a graphic object with the font Wingding.ttf (this one is installed on all Win platforms). This should result in glyphs like a book, a cross and waves - but only rectangles are displayed.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class FontTest extends JPanel{
	
    public FontTest() {
        GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
        String envfonts[] = gEnv.getAvailableFontFamilyNames();

        setFont(new Font("Wingdings",Font.PLAIN, 48));
    }

    public void paintComponent (Graphics g) {
        super.paintComponent( g );
        Graphics2D g2 = (Graphics2D) g;
        int w = getWidth();
        int h = getHeight();

        String text = "& W w h q e";
        FontMetrics metrics = g2.getFontMetrics();
        int width = metrics.stringWidth( text );
        int height = metrics.getHeight();
        g2.drawString( text, w/2-width/2, h/2-height/2 );
    }

    public static void main(String s[]) {
        JFrame f = new JFrame("FontTest");
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {System.exit(0);}
        });
        f.getContentPane().add(new FontTest(), BorderLayout.CENTER);

        f.setSize(new Dimension(550,250));
        f.setVisible(true);
    }
}
(Review ID: 96318) 
======================================================================

                                    

Comments
EVALUATION

The font being used is "Wingding" which has a special encoding - the string that is being entered is the Uincode equivalent of ascii - if you enter the correct range of Unicode Dingbats range in 0x2700 to 0x27be - you should get the right glyphs to display. In this case what you are asking to do is by using the font "Wingding" display the characters "& W w h"  etc. the font does not have these so obviously it is going to draw missing glyphs ( boxes ).
Thus it is not a bug.
parry.kejriwal@eng 1999-12-16
                                     
1999-12-16



Hardware and Software, Engineered to Work Together