JDK-8153662 : SwingUtilities2.drawString()/getStringWidth()/clipString() should use more text attributes
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Incomplete
  • Submitted: 2016-04-06
  • Updated: 2017-09-07
  • Resolved: 2017-09-07
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.
JDK 10
10Resolved
Related Reports
Relates :  
Description
See the discussion: http://mail.openjdk.java.net/pipermail/swing-dev/2016-March/005622.html
-----------------
 i.e what about attributes on the font such as "tracking" ?
or on the graphics such as FRACTIONALMETRICS
It looks like Swing might already fail if that were used.

Look at this code :-

   public static int stringWidth(JComponent c, FontMetrics fm, String string){
        if (string == null || string.equals("")) {
            return 0;
        }
        boolean needsTextLayout = ((c != null) &&
(c.getClientProperty(TextAttribute.NUMERIC_SHAPING) != null));
        if (needsTextLayout) {
            synchronized(charsBufferLock) {
                int length = syncCharsBuffer(string);
                needsTextLayout = isComplexLayout(charsBuffer, 0, length);
            }
        }
        if (needsTextLayout) {
            TextLayout layout = createTextLayout(c, string,
                                    fm.getFont(), fm.getFontRenderContext());
            return (int) layout.getAdvance();
        } else {
            return fm.stringWidth(string);
        }
    }

The only thing Swing is looking at is one TextAttribute and whether we have complex text.
That is not enough. This is an existing implementation issue but one we should fix here. 
-----------------
Comments
The specification needs to be clarified. I guess the "tracking" is a text attribute which is a font attribute and it is taken into account by all those methods. The FRACTIONALMETRICS is a rendering hint and it is also taken into account in those methods through the rendering context.
07-09-2017

Targeted to 10 as an issue introduced in 8u or 9
17-02-2017

Approved by component triage team to defer and fix in 10/9u
06-07-2016

It can be implemented, but may it be approved in update release? If so, SQE is OK to defer.
06-07-2016

Defer request: this functionality can be implemented in JDK 9 update release.
29-06-2016

Given that this affects new public API in 9 we should fix in 9.
11-04-2016