FIX: FontMetrics.charWidth() function returns incorrect values for some international language fonts (244553)



The information in this article applies to:

  • Microsoft virtual machine

This article was previously published under Q244553

SYMPTOMS

Using the FontMetrics.charWidth() method to get the width of a character might return zero or an incorrect value when using the GulimChe font (a Korean language font).

RESOLUTION

To resolve this problem, update your version of the Microsoft virtual machine (Microsoft VM) for Java to build 3188 or later. See "References" section for links to download the latest Microsoft VM.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
This bug was corrected in Microsoft VM build 3188 and later.

MORE INFORMATION

Steps to Reproduce Behavior

  1. On a computer with a Microsoft VM version earlier than 3188 installed, create a file Test.java with the following code:
    import java.awt.*;
    import java.awt.event.*;
    
    import com.ms.awt.FontX;
    
    public class Test
    {
    	static public final void main( String[] args )
    	{
    		Test t = new Test();
    	}
    
    	public Test()
    	{
    		FontX f = new FontX( "GulimChe", Font.PLAIN, 11 );
    		FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics( f );
    
    		System.out.println("Font: " + f.getFamily());
    	
    		System.out.println( "Width of the character "+'A'+" is "+fm.charWidth( 'A') );
    		System.out.println( "Width of the String "+"A"+" is "+fm.stringWidth( "A" ) );
    
    		System.exit( 0 );
    	}
    }
    					
  2. In a Command window compile Test.java using the following command:
    jvc Test.java
    					
  3. Run the generated Test.class file using the following command:
    jview Test.class
    					
    You should see the following output:

    C:\>jview Test.class
    Font: GulimChe
    Width of the character A is 0
    Width of the String A is 6
    						

REFERENCES

The latest Microsoft VM is available for download at the following Web site: For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:

Modification Type:MajorLast Reviewed:6/14/2006
Keywords:kbbug kbfix KB244553