Skip to content
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

add feature to disable text-to-pixel snapping during layout #5057

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

Conversation

drewmiller
Copy link

Recognizing that a switch to Cosmic Text is on the way per #56 , I also wanted to implement a temporary feature which disables what I call "text snapping"--i.e., where we round to the nearest pixel on the x and y axis when rendering text. This results in text being laid out in different ways across pixel_per_point values. Such snapping improves font rendering in the absence of other anti-aliasing approaches which will be provided by Cosmic Text. For some contexts, however, maintaining the layout is more important across pixel_per_point values. This feature allows for that until Cosmic Text saves the day.

  • I have followed the instructions in the PR template

## The side effect of such rounding is that text layout will likely be inconsistent across
## different values of `pixel_per_point`. Disabling such "snapping" will make the text fuzzy,
## but the layout will remain constant across `pixels_per_point`.
disable_text_snapping = []
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a runtime setting instead

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Let me revise it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, it makes the most sense to add this as a field of LayoutJob which would default to true for snapping. That would allow a user like myself to have, e.g., the UI elements all snap while retaining more granular control over a particular layout job. I'm not sure if adding a Struct field is considered a breaking change, so I'd welcome your thoughts on that. Thanks for a great library @emilk.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding it to LayoutJob is the right thing yes

@emilk
Copy link
Owner

emilk commented Sep 2, 2024

Note that we already have a setting for this, though maybe it is not by the actual text layout engine: https://docs.rs/epaint/latest/epaint/tessellator/struct.TessellationOptions.html#structfield.round_text_to_pixels

@drewmiller
Copy link
Author

Note that we already have a setting for this, though maybe it is not by the actual text layout engine: https://docs.rs/epaint/latest/epaint/tessellator/struct.TessellationOptions.html#structfield.round_text_to_pixels

My concerns are primarily around the layout of the text, so I haven't had a chance to investigate the interaction with tesselation, but I will. I'll come back to you.

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

Successfully merging this pull request may close these issues.

2 participants