Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,16 @@ public class Utils {
private static final TextBoundsType DEFAULT_BOUNDS_TYPE = textInstance.getBoundsType();
private static final AtomicBoolean helperGuard = new AtomicBoolean(false);

/* Using TextLayout directly for simple text measurement.
/**
* Using TextLayout directly for a simple text measurement.
* Instead of restoring the TextLayout attributes to default values
* (each renders the TextLayout unable to efficiently cache layout data).
* It always sets all the attributes pertinent to calculation being performed.
* Note that lineSpacing and boundsType are important when computing the height
* but irrelevant when computing the width.
*
* Note: This code assumes that TextBoundsType#VISUAL is never used by controls.
* */
* <br>
* Note: This code assumes that the callers never use TextBoundsType#VISUAL.
*/
private static final TextLayout layoutInstance = Toolkit.getToolkit().getTextLayoutFactory().createLayout();
private static final AtomicBoolean layoutGuard = new AtomicBoolean(false);

Expand Down Expand Up @@ -167,6 +168,8 @@ public static double computeTextWidth(Font font, String text, double wrappingWid
try {
layout.setContent(text != null ? text : "", FontHelper.getNativeFont(font));
layout.setWrapWidth((float)wrappingWidth);
layout.setLineSpacing(0);
layout.setBoundsType(TextLayout.BOUNDS_CENTER);
Comment thread
Maran23 marked this conversation as resolved.
return layout.getBounds().getWidth();
} finally {
release(layout);
Expand Down

This file was deleted.

Loading