I'm posting with the hopes that someone working on 2D at Sun can say
if this kind of regression bug is accpetable to go to FCS with.
I can say that our product relies on this for accurate text rendering
and won't be able to use 1.4 unless this is fixed or a suitable
workaround is found. (I haven't found one yet).
Here is the problem:
FontRenderContext.transform not being applied in TextLayout.draw()
A DESCRIPTION OF THE PROBLEM :
When using TextLayout to render a string, we supply the
font attribute map and a FontRenderContext which contains a
transformation to user space. (we convert from 72dpi to
device dpi; i.e. 400dpi for output, 60-80dpi for preview)
This method has allowed us to match preview and printed
output with great precision.
Doing this in jdk1.3 give the expected results where the
font is scaled based on the scale transform supplied. Using
jdk1.4-rc, the font is drawn in its original size (no
transform was applied).
REGRESSION. Last worked in version 1.3
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the sample code I've included under jdk1.3 and
jdk1.4-rc and observe the results.
EXPECTED VERSUS ACTUAL BEHAVIOR :
My test code displays a window with two strings shown. The
first string is not scaled, the second should be. Under
1.4-rc, the second is the same size as the first.
... internal review ID of: 138490
I'd appreciate ANY insights or comments...
Thanks,
David Kavanagh
BTW, our site is www.epixography.com . click "Start using ePixography"
to run the app.
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.font.FontRenderContext;
import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform;
import java.util.Map;
import java.util.HashMap;
import javax.swing.JPanel;
import javax.swing.JFrame;
public class TestFontScale extends JPanel {
Map fontAttrs;
public TestFontScale() {
fontAttrs = new HashMap();
fontAttrs.put(TextAttribute.FAMILY, "Courier");
fontAttrs.put(TextAttribute.SIZE, new Float(50));
}
public void paint(Graphics g) {
g.setColor(Color.black);
// this draws the string at normal size
TextLayout tl = new TextLayout("Hello - no scale", fontAttrs,
new FontRenderContext(null, true, true));
tl.draw((Graphics2D)g, 25, 100);
// this draws the string 50% smaller
AffineTransform trans = AffineTransform.getScaleInstance(0.5, 0.5);
tl = new TextLayout("Hello - with scale", fontAttrs,
new FontRenderContext(trans, true, true));
tl.draw((Graphics2D)g, 25, 200);
}
public static void main(String [] args) {
JFrame f = new JFrame("Font Scale Tester");
f.setSize(600, 300);
f.setContentPane(new TestFontScale());
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0); }
});
f.setVisible(true);
}
}