Skip to content

[JEWEL-830] Fix Editor TextStyle line height #3064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rock3r
Copy link
Collaborator

@rock3r rock3r commented May 30, 2025

Swing is not using the font size when computing the base lineHeight, that is then multiplied by the user-set factor (default 1.2). Instead, they use FontMetrics.getHeight(), which computes it as leading + ascent + descent.

This changes the Jewel line height computation for the editor text style to use the same logic. It requires a Graphics2D instance, which is obtained from a Swing BufferedImage on demand, to get the same font metrics as the Swing UI uses.

This gets us a much closer result, but is still not 100% matching. It looks like this introduces a ~10% extra line height in Compose compared to Swing:

image

I will make a follow-up change when I figure out where in Skia’s line height usage there is a divergence from Swing’s, but for now this is already much better than what we did before.

This change also fixes the Jewel sample plugin.xml so it doesn’t crash at startup when run in the IJP build.

Swing is not using the font size when computing the base
lineHeight, that is then multiplied by the user-set factor
(default 1.2). Instead, they use FontMetrics.getHeight(),
which computes it as leading + ascent + descent.

This changes the Jewel line height computation for the
editor text style to use the same logic. It requires a
Graphics2D instance, which is obtained from a Swing
BufferedImage on demand, to obtain the same font metrics
as the Swing UI uses.

This gets us a much closer result, but is still not 100%
matching. It looks like this introduces a ~10% extra line
height in Compose compared to Swing. I will make a follow
up change when I figure out where in Skia's line height
usage there is a divergence from Swing's, but for now this
is already much better than what we did before.

This change also fixes the Jewel sample plugin.xml so it
doesn't crash at startup when run in the IJP build.
@rock3r rock3r self-assigned this May 30, 2025
@rock3r rock3r added the Jewel label May 30, 2025
@rock3r rock3r marked this pull request as draft May 30, 2025 10:59
@rock3r rock3r marked this pull request as ready for review May 30, 2025 11:45
@rock3r
Copy link
Collaborator Author

rock3r commented May 30, 2025

Reopening — this works fine for the bridge, but we'll need to tweak standalone too at some point. I decided to split it out to another issue since it's growing in scope quite rapidly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant