Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6479552
Votes 0
Synopsis Type1 Courier font is not being measured consistently.
Category java:classes_2d
Reported Against
Release Fixed 7(b20)
State 10-Fix Delivered, request for enhancement
Priority: 3-Medium
Related Bugs
Submit Date 09-OCT-2006
Description
FULL PRODUCT VERSION :
java version "1.6.0-rc"
Java(TM) SE Runtime Environment (build 1.6.0-rc-b100)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0-rc-b100, mixed mode)

EXTRA RELEVANT SYSTEM CONFIGURATION :
Corporate hp4100
Running on SUSE 10.0 64 bit.

A DESCRIPTION OF THE REQUEST :
I am creating financial applications and my reports are generated by using a char[] to insert data bytes, aligning the period (decimal) by using String.indexOf(".") and subtracting that value from the string length.   I then use a Graphics2D to draw these strings to may page using a fixed width font (Courier).  With jdk 5 the periods align perfectly and the report is beautiful.  With jdk 6 I get dizzy looking at the far right columns which are significantly out of register.  The variation increases from left to right.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect the same code to produce the same effect on jdk 5 (original development platform) and jdk6 (current operating environment)
ACTUAL -
Financial data columns, columns of SQL formatted dates are out of alignment.

---------- BEGIN SOURCE ----------
Cannot be done without access to dozens of records from the database and a lot of formatting converting long values to financially formatted values such as 2,005.07, sticking these bytes into a char[], when the array is prepared, save it as a String added to a Vector of Strings.  When enough Strings are in the Vector to fill the particular size page start another Vector of Strings.  Following is my printing code:

pages = Vector of Vectors of Strings

	public int print(java.awt.Graphics graphics, PageFormat pageFormat, int param) throws java.awt.print.PrinterException {
		
		// Start 1/2 inch from the top
		h = 36;
		if(param > pages.size()) return Printable.NO_SUCH_PAGE;
		g2d = (Graphics2D)graphics;
		g2d.setFont(font);
		int x = g2d.getFontMetrics().getHeight();
		lines = (Vector<String>)pages.elementAt(param);
		if(header1 != null) g2d.drawString(header1, 36, h);
		String pageno = "Page: " + (param + 1);
		int w = g2d.getFontMetrics().stringWidth(pageno);
		
		g2d.drawString(pageno, 612 - 72 - w, h);
		h += x;
		if(header2 != null) g2d.drawString(header2, 36, h);
		h += x * 2;
		if (header3 != null) g2d.drawString(header3, 36, h);
		h += x;
		if(header4 != null) {
			g2d.drawString(header4, 36, h);
			h += x;
		}
		h += x;
		for (String s : lines) {
			g2d.drawString(s, 36, h);
			h += x;
		}
		return Printable.PAGE_EXISTS;
	}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Regarding severity level: I go on developing without a problem but cosmetically the effect is devastating!
Posted Date : 2006-10-09 04:19:36.0
Work Around
N/A
Evaluation
I believe this is caused by the fix "6320281: Type1 hinting support is missing"
which went back in b53 (the build this problem started)
The test program uses a Type1 font : Courier and since this is a monospaced font
then all strings with the same number of characters should be identical in length,
but as of this fix, they are not.
I have attached a program (CourMetrics.java) which does no printing,
it just measures text in a file 'data.txt'. Each line is 165 characters in length.
The program scales by 300/72 to emulate the printer device scale.
Prior to b53 we see every line is measured to have
FontMetrics.stringWidth() == 911
after the fix it varies from 907->910

A workaround (if you have the font) is to use "Courier New" as its a TrueType font
and it measures fine (I tested this). Failing that, some other fixed width
TrueType font.
Posted Date : 2006-10-09 23:30:50.0

Current implementation does not check if font is proportional or monospaced.
This information is available as value of isFixedPitch. 
For Courier it is true and we need to update hinting logic to preserve 
metrics if font is monospaced.
Posted Date : 2007-07-25 13:09:18.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang