On Tue, 14 Apr 2026 19:08:56 GMT, Marius Hanl <[email protected]> wrote:

>> oh right.  we can't really use the same code path, we'd need to release the 
>> layout after we get the requested value from it.  We could pass a lambda, 
>> but it's not worth it.  Please disregard.
>
> No problem, I was just confused if I miss something. 😁

there is another way to ensure that there is only one place where we configure 
the layout, something like this, but it's probably not for this PR:


    public static double getLineHeight(Font font, TextBoundsType boundsType) {
        // do it everywhere
        TextLayout layout = configureLayout("", font, boundsType, 0, 0);
        try {
            // JDK-8093957: Use the line bounds specifically, to include font 
leading.
            return layout.getLines()[0].getBounds().getHeight();
        } finally {
            release(layout);
        }
    }

    private static TextLayout configureLayout(String content, Font font, 
TextBoundsType boundsType, wrapWidth, linespacing) {
        TextLayout layout = layout();
        layout.setContent(content, FontHelper.getNativeFont(font));
        layout.setWrapWidth(wrapWidth);
        layout.setLineSpacing(linespacing);
        if (boundsType == TextBoundsType.LOGICAL_VERTICAL_CENTER) {
                layout.setBoundsType(TextLayout.BOUNDS_CENTER);
        } else {
                layout.setBoundsType(0);
        }
        return layout;
    }

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/2145#discussion_r3081813133

Reply via email to