JDK-4140220 : JLabel cuts off front of 'W' if it begins the text with 11pt SansSerif font
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0,1.2.2,1.3.0,1.3.1,1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS:
    solaris_7,windows_95,windows_98,windows_nt solaris_7,windows_95,windows_98,windows_nt
  • CPU: unknown,x86,sparc
  • Submitted: 1998-05-19
  • Updated: 2003-09-12
  • Resolved: 2002-07-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other Other
1.2.2_007 007Fixed 1.3.0_02Fixed 1.3.1Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Description

Name: rk38400			Date: 05/19/98


JLabel jl = new JLabel("Workgroup");
jl.setFont(new Font("SansSerif",Font.PLAIN,11));
(Review ID: 30738)
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.2.2_007 1.3.0_02 1.3.1 FIXED IN: 1.2.2_007 1.3.0_02 1.3.1 INTEGRATED IN: 1.2.2_007 1.3.0_02 1.3.1 VERIFIED IN: 1.2.2_007 1.3.0_02
14-06-2004

SUGGESTED FIX This is the suggested fix (by carriez) from bug report 4372087. Following is the suggested fix: under src/share/native/sun/awt/font/ *** GlyphVector.cpp.bak Thu Sep 7 17:38:36 2000 --- GlyphVector.cpp Fri Sep 8 15:36:45 2000 *************** *** 1,5 **** /* ! * @(#)GlyphVector.cpp 1.28 99/04/27 * * Copyright 1998, 1999 by Sun Microsystems, Inc., * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. --- 1,5 ---- /* ! * %W% %E% * * Copyright 1998, 1999 by Sun Microsystems, Inc., * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. *************** *** 462,467 **** --- 462,471 ---- if (!glyphRef.fImage && glyphRef.fWidth && glyphRef.fHeight) { fImageRefs[i].pixels = theStrike.getImage(fGlyphs[i]); } + jfloat fX = hsFixedToFloat(glyphRef.fTopLeft.fX); + if (i == 0 && fX < 0) { + if (fFontTX.m00 > 0 && fFontTX.m10 == 0 && fFontTX.m01 == 0 ) { + x -= fX; + } + } if (loadPositions) { fPositions[i*2] = x + hsFixedToFloat(glyphRef.fTopLeft.fX); fPositions[i*2+1] = y + hsFixedToFloat(glyphRef.fTopLeft.fY);
11-06-2004

EVALUATION This bug occurs on Windows NT with JDK1.1.6 and swing-1.0.2 (promoted), but does NOT occur on Solaris. The top left corner of the W is missing. The code below demonstrates the bug: import java.awt.*; import java.awt.event.*; import com.sun.java.swing.*; public class labelbug extends JFrame { public labelbug() { super( "Demonstrates labelbug" ); JLabel jl = new JLabel("Workgroup"); jl.setFont(new Font("SansSerif",Font.PLAIN,11)); JPanel panelOne = new JPanel(); panelOne.add( jl ); getContentPane().add(panelOne); pack(); setVisible( true ); } public static void main(String[] args) { new labelbug(); } } nancy.schorr@eng 1998-05-28 The bug now occurs on Solaris 2.7 with JDK-1.3-fcs-P. Also occurs on win98. It does NOT occur with 10pt or 12pt. Only 11pt. Workaround: Put a space before the W in the label text. nancy.schorr@eng 1999-11-30 The problem appears to be that this font is returning the wrong metrics for the "W" character. I've reassigned the bug to classes_2d. hans.muller@Eng 1999-12-17 I tried this on Solaris 2.7 and this bug still occurs. In fact it occurs on both jdk1.1.8 and the latest Kestrel builds. The interesting thing is if the point size is changed to 10 or 12 the bug seems to go away. There are couple of things I suspect may be happening either there is a rounding off problem in the metrics calculation or there is a clipping problem, when the labels are being drawn. I have examined the font and seen if there is a left side bearing -- but the character does not have any bits drawn to the left of the origin, unless due to poor hinting it may be drawing to the left of the origin just for the 11 point size case, and not handling the metrics accurately, however I have not verified that. One may get the character bounding boxes and verify the bounding box at various point sizes. Since it is occuring on 1.1.8 it is not a 2D bug. IT seems to be most likely an AWT problem. parry.kejriwal@eng 1999-12-17 I looked at this briefly: One thing I noticed: if you replace the JLabel with an AWT Label in the test case, the 'W' shows up just fine under Kestrel-FCS-R and Kestrel-beta-N. However, it is wrong under 1.1.8, 1.2, and 1.2.2. It looks like something got fixed in Kestrel-beta, at least on the AWT side. It's still wrong with the JLabel, though. I tested on NT4 SP4. eric.hawkes@eng 2000-02-01 It sounds like there were two separate problems originally: one in the AWT, and one in Swing. The AWT problem seems to have been fixed in Kestrel, but the Swing problem still exists. I am reassigning back to 2D so they can look at the Swing problem. Tested with Kestrel-C (FCS). eric.hawkes@eng 2000-06-13 Note: I tested with Merlin build b21 on both Solaris 2.7 and windows 95. The AWT problem does not exist on either platform, but the Swing problem appears on both. eric.hawkes@eng 2000-06-28 If a similar string is drawn with any of the 2d primitives like drawString, TextLayout etc we do not see this behavior, it seems like some clipping problem in the jLabel component. The W character looks fine from a font perspective. parry.kejriwal@eng 2000-07-11 Yeesh, I am going to continue with what everyone else has been doing and reasign this. The problem appears to be that when you issue drawString("W", x, y) with this particular font, the top left edge of the W is drawn at x-1. As Swing does not add any padding to the left side the top left edge of the W gets clipped. I have attached a test case for this (Test.java). It creates a JLabel that exhibits the problem, as well as a custom component that issues the draw string with the W. Further, this component will fill in its background, fill a white rectangle at 20,20 with a width of 100 and height of 20. It will then issue drawString with "W" at 20, 35. You can see that the left edge of the W is drawn outside of the box, further if you click on the clip button the Graphics is clipped to 20,20,100,20 before drawString is issued, and you can then see the same behavior that happens with JLabel. I am going to bump the priority too, this bug has been around for more than 2 years now:( Also, you can see this bug with the latest Merlin builds (b22) on both Windows and Solaris. scott.violet@eng 2000-07-14 Swing needs to into account characters with a negative offset, when they are at the beginning of a line. parry.kejriwal@eng 2000-07-25 This was putback into ladybird by CTE. jeannette.hung@Eng 2000-11-28 The problem is visible on Merlin, b56, b58. jeannette.hung@Eng 2001-04-02 The bounds need tobe calculated correctly in Swing components - to take into account negative left side bearing for the first and last glyphs in a string. I have discussed with Scott Violet on this issue. ###@###.### 2001-09-11 Refer to bug 4262130 for details on this, including what Swing should be doing to calculate sizes. ###@###.### 2001-09-11 While this bug is in a verified state, the fix was not approved for 1.4, and therefore this is currently broken in >= 1.4. ###@###.### 2002-07-19 Let me explain the state of this bug at this time: this bug is marked integrated into 1.3.0_02 and 1.3.1, which is true. The fix that went into these releases was in the 2D side and was innitially approved. During the 1.4 merge time it was decided that the fix should not have been in the 2D code, but rather swing should be using TextLayout to get the correct sizing information. We investigated making the necessary changes but they caused a slow down of ~50% for swing marks, and therefore we didn't do the change. The 2D team has since made improvements in TextLayout performance but because of the risk involved with the change and the scope of the change we do not plan on addressing this until 1.5. This bug is therefore commited to tiger. Related bugs: 4262130: Describes slow down in using TextLayout in greater detail, ultimately closed as a dup of this. 4414577: Describes slowness of TextLayout for latin1. 4365284: getStringBounds that takes a FRC. We may need 4365284 fixed, but that will have to be investigated. ###@###.### 2002-07-19
19-07-2002

WORK AROUND Name: rk38400 Date: 05/19/98 Use either 10 or 12 point font and it doesn't happen. It also doesn't happen with different fonts such as Serif. Another workaround: one could put a space before the W. eric.hawkes@eng 2000-02-01
01-02-2000