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

Improve performance for text calculations in skin.Utils

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 8
    • 8
    • javafx
    • None

      IMO the helper strategy in skin.Utils will never give us the best possible performance.

      In TextLayout I added very aggressive caching mechanism to allow incremental changes.
      For example, if you keep the same text and font, you can change the wrap width and text alignment a lot faster (as the heavy work to produces glyphs and advances is cached).

      In the helper we flip the text and font every time. That wipes our caches.

      The way I think this should be done would be something like this
      static double computeTextWidth(Text labeledText, double wrappingWidth) {
        TextLayout layout = labeledText.getTextLayout(); //new API in Text, private or public...
        layout.setWrappingWidth(0);
        float width = layout.getBounds().width;
        if (wrappingWidth < width) {
      layout.setWrappingWidth(wrappingWidth);
             width = layout.getBounds().width;
        }
         layout.setWrappingWidth(labeledText.getWrappingWidth());//restore
        return width;
      }


      Not sure this code is 100% correct, but by re-using the internal TextLayout from Text we don't have to set the font and text (which preserve glyphs and advances).

            fheidric Felipe Heidrich (Inactive)
            fheidric Felipe Heidrich (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: