Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8153662

SwingUtilities2.drawString()/getStringWidth()/clipString() should use more text attributes

    Details

      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.
      -----------------

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ssadetsky Semyon Sadetsky (Inactive)
                Reporter:
                alexsch Alexandr Scherbatiy
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: