Skip to content

Conversation

@martincapello
Copy link
Member

This PR modifies the order in which some things are done when each run of text is processed when the shaping function is executed:

  • Now, the selected text background drawing is delegated before drawing any character. In this way if the glyphs in a run overlap with each other the background drawing of the current glyph won't overwrite the previous glyph.
  • Now, if there is a background color set, it is painted before drawing any character and before delegating the selected text background painting.

Both of the above things are possible because now we first calculate the union of all glyphs bounds.

Copy link
Member

@dacap dacap left a comment

Choose a reason for hiding this comment

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

I didn't test this yet, so here are some minor changes.

The DrawTextDelegate is deprecated and we'd like to remove it in the future, but it's still used in ui::Entry so it's fine to fix bugs on it 👍

@dacap dacap assigned martincapello and unassigned dacap Nov 7, 2025
@martincapello martincapello force-pushed the draw-text-shaper-improvement branch from 6db938c to 08332c8 Compare November 7, 2025 20:19
@martincapello martincapello assigned dacap and unassigned martincapello Nov 7, 2025
Copy link
Member

@dacap dacap left a comment

Choose a reason for hiding this comment

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

A minor change, I've tested on Linux and macOS with "Apple Chancery" and it works great 👍

Comment on lines 54 to 57
std::vector<gfx::RectF> glyphsBounds;
for (int i = 0; i < info.glyphCount; ++i) {
auto bounds = info.getGlyphBounds(i);
glyphsBounds.push_back(bounds);
Copy link
Member

Choose a reason for hiding this comment

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

We can prealloc the expected size of glyphsBounds:

Suggested change
std::vector<gfx::RectF> glyphsBounds;
for (int i = 0; i < info.glyphCount; ++i) {
auto bounds = info.getGlyphBounds(i);
glyphsBounds.push_back(bounds);
std::vector<gfx::RectF> glyphsBounds(info.glyphCount);
for (int i = 0; i < info.glyphCount; ++i) {
auto bounds = info.getGlyphBounds(i);
glyphsBounds[i] = bounds;

@dacap dacap assigned martincapello and unassigned dacap Nov 17, 2025
@martincapello martincapello force-pushed the draw-text-shaper-improvement branch from 08332c8 to 822afab Compare November 17, 2025 18:46
Add new methods to DrawTextDelegate to allow drawing the background
of the selected text before drawing each character. This fixes an issue
when the glyphs used by a TTF were overlapped.
@martincapello martincapello force-pushed the draw-text-shaper-improvement branch from 822afab to 866cf6e Compare November 17, 2025 18:47
@martincapello martincapello assigned dacap and unassigned martincapello Nov 17, 2025
@dacap dacap merged commit 866cf6e into aseprite:main Nov 17, 2025
12 checks passed
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