-
Bug
-
Resolution: Unresolved
-
P3
-
7
-
generic
-
generic
SYNOPSIS
--------
TextLayout.getLogicalHighlightShape of Italic font returns wrong values
OPERATING SYSTEM
----------------
Probably Generic.
Reported on RHEL 5, Win XP
Reproducible on Sol 11 x86.
FULL JDK VERSION
----------------
All 1.4.2, 5.0, 6 and 7.
DESCRIPTION
-----------
TextLayout.getLogicalHighlightShape of some Italic fonts returns an incorrect Shape object. Specifically, the left side of boundary of the characters is sloped correctly, but the right side is vertical, which is incorrect.
REPRODUCTION INSTRUCTIONS from LICENSEE
---------------------------------------
Run the sample code below with some sizes of font. For example:
java Outline LucidaSansRegular 30 a
java Outline LucidaSansRegular 32 a
The problem seems to depend on the font configuration. In one environment, LucidaSansRegular 30 point font recreated the problem, but LucidaSansRegular 32 point font did not. In another, the reverse was true.
Example screenshots of correct/incorrect behaviour are attached.
TESTCASE SOURCE
---------------
import java.awt.*;
import javax.swing.*;
import java.awt.geom.AffineTransform;
import java.awt.font.TextLayout;
import java.awt.font.FontRenderContext;
public class Outline extends JPanel {
String testString;
String fontName;
int fontSize;
public Outline(String fontName, int fontSize, String testString) {
this.fontName = fontName;
this.testString = testString;
this.fontSize = fontSize;
setBackground(Color.white);
}
public Outline() {
this("dialog", 31, "a");
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
FontRenderContext frc = g2.getFontRenderContext();
Font f = new Font(fontName,Font.PLAIN, fontSize);
AffineTransform fontAT = new AffineTransform();
fontAT.shear(-0.4, 0);
Font derivedFont = f.deriveFont(fontAT);
TextLayout tl = new TextLayout(testString , derivedFont, frc);
Shape sha = tl.getOutline(AffineTransform.getTranslateInstance(50,100));
Shape hilite = tl.getLogicalHighlightShape(0, testString.length());
hilite = (AffineTransform.getTranslateInstance(50,100)).createTransformedShape(hilite);
g2.setColor(Color.black);
g2.draw(hilite);
g2.setColor(Color.green);
g2.fill(sha);
}
public static void main(String[] args) {
Outline outline = (args.length < 3) ? new Outline(): new Outline(args[0], Integer.parseInt(args[1]), args[2]);
Frame f = new Frame();
f.add(outline);
f.pack();
f.setSize(new Dimension(200,200));
f.show();
}
}
SUGGESTED FIX
-------------
See suggested fix section for Licensee's suggested fix.
--------
TextLayout.getLogicalHighlightShape of Italic font returns wrong values
OPERATING SYSTEM
----------------
Probably Generic.
Reported on RHEL 5, Win XP
Reproducible on Sol 11 x86.
FULL JDK VERSION
----------------
All 1.4.2, 5.0, 6 and 7.
DESCRIPTION
-----------
TextLayout.getLogicalHighlightShape of some Italic fonts returns an incorrect Shape object. Specifically, the left side of boundary of the characters is sloped correctly, but the right side is vertical, which is incorrect.
REPRODUCTION INSTRUCTIONS from LICENSEE
---------------------------------------
Run the sample code below with some sizes of font. For example:
java Outline LucidaSansRegular 30 a
java Outline LucidaSansRegular 32 a
The problem seems to depend on the font configuration. In one environment, LucidaSansRegular 30 point font recreated the problem, but LucidaSansRegular 32 point font did not. In another, the reverse was true.
Example screenshots of correct/incorrect behaviour are attached.
TESTCASE SOURCE
---------------
import java.awt.*;
import javax.swing.*;
import java.awt.geom.AffineTransform;
import java.awt.font.TextLayout;
import java.awt.font.FontRenderContext;
public class Outline extends JPanel {
String testString;
String fontName;
int fontSize;
public Outline(String fontName, int fontSize, String testString) {
this.fontName = fontName;
this.testString = testString;
this.fontSize = fontSize;
setBackground(Color.white);
}
public Outline() {
this("dialog", 31, "a");
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
FontRenderContext frc = g2.getFontRenderContext();
Font f = new Font(fontName,Font.PLAIN, fontSize);
AffineTransform fontAT = new AffineTransform();
fontAT.shear(-0.4, 0);
Font derivedFont = f.deriveFont(fontAT);
TextLayout tl = new TextLayout(testString , derivedFont, frc);
Shape sha = tl.getOutline(AffineTransform.getTranslateInstance(50,100));
Shape hilite = tl.getLogicalHighlightShape(0, testString.length());
hilite = (AffineTransform.getTranslateInstance(50,100)).createTransformedShape(hilite);
g2.setColor(Color.black);
g2.draw(hilite);
g2.setColor(Color.green);
g2.fill(sha);
}
public static void main(String[] args) {
Outline outline = (args.length < 3) ? new Outline(): new Outline(args[0], Integer.parseInt(args[1]), args[2]);
Frame f = new Frame();
f.add(outline);
f.pack();
f.setSize(new Dimension(200,200));
f.show();
}
}
SUGGESTED FIX
-------------
See suggested fix section for Licensee's suggested fix.