-
Bug
-
Resolution: Fixed
-
P3
-
1.4.2
-
b37
-
sparc
-
solaris_8
Swing underline drawing is incorrect. It paints the underline below the
text instead of below the baseline!
BasicGraphicsUtils.java:
public static void drawStringUnderlineCharAt(Graphics g, String
text,
int underlinedIndex, int x,int y) {
g.drawString(text,x,y);
if (underlinedIndex >= 0 && underlinedIndex < text.length() ) {
FontMetrics fm = g.getFontMetrics();
int underlineRectX = x +
fm.stringWidth(text.substring(0,underlinedIndex));
int underlineRectY = y;
int underlineRectWidth =
fm.charWidth(text.charAt(underlinedIndex));
int underlineRectHeight = 1;
==> g.fillRect(underlineRectX, underlineRectY +
fm.getDescent() - 1,
underlineRectWidth, underlineRectHeight);
}
}
This is wrong - the underline should be right under the text - not
offset by getDescent-1!
That only works for small fonts where the descent is small enough (2,3)
that you can't tell it's off.
E.g. that line should be
g.fillRect(underlineRectX, underlineRectY + 1,
underlineRectWidth, underlineRectHeight);
Note that the descenders are supposed to be chopped off. I'm usually an OSX
user (they get visual design right) - and if you look at underlines there
you'll see that they are right below the baseline - and chop descenders off.
But just in case, I fired up my Windows XP box, launched WordPad, and
pressed the alt key - and sure enough, same thing there. If you look in
the File menu, the "Page Setup" item for example has an underline under
the "u", and if extended to the "p" it would chop it off.
For other examples, look at hyperlinks in internet explorer. Go to
google for example; the underline cuts off the "g" in the "make Google
your homepage" link.
I really think Swing has this wrong; it's not matching underlining on
Windows and OSX, and probably elsewhere as well.
Scott Violet agreed to this and suggested I file this bug.
text instead of below the baseline!
BasicGraphicsUtils.java:
public static void drawStringUnderlineCharAt(Graphics g, String
text,
int underlinedIndex, int x,int y) {
g.drawString(text,x,y);
if (underlinedIndex >= 0 && underlinedIndex < text.length() ) {
FontMetrics fm = g.getFontMetrics();
int underlineRectX = x +
fm.stringWidth(text.substring(0,underlinedIndex));
int underlineRectY = y;
int underlineRectWidth =
fm.charWidth(text.charAt(underlinedIndex));
int underlineRectHeight = 1;
==> g.fillRect(underlineRectX, underlineRectY +
fm.getDescent() - 1,
underlineRectWidth, underlineRectHeight);
}
}
This is wrong - the underline should be right under the text - not
offset by getDescent-1!
That only works for small fonts where the descent is small enough (2,3)
that you can't tell it's off.
E.g. that line should be
g.fillRect(underlineRectX, underlineRectY + 1,
underlineRectWidth, underlineRectHeight);
Note that the descenders are supposed to be chopped off. I'm usually an OSX
user (they get visual design right) - and if you look at underlines there
you'll see that they are right below the baseline - and chop descenders off.
But just in case, I fired up my Windows XP box, launched WordPad, and
pressed the alt key - and sure enough, same thing there. If you look in
the File menu, the "Page Setup" item for example has an underline under
the "u", and if extended to the "p" it would chop it off.
For other examples, look at hyperlinks in internet explorer. Go to
google for example; the underline cuts off the "g" in the "make Google
your homepage" link.
I really think Swing has this wrong; it's not matching underlining on
Windows and OSX, and probably elsewhere as well.
Scott Violet agreed to this and suggested I file this bug.