Skip to content

Fix overcounting letter spacing in calculating final layout - #642

Open
pope wants to merge 1 commit into
nicbarker:mainfrom
pope:letterspacing-fix
Open

pope wants to merge 1 commit into
nicbarker:mainfrom
pope:letterspacing-fix

Conversation

@pope

@pope pope commented Jul 13, 2026

Copy link
Copy Markdown

When calculating the width of a line, the width excludes the trailing letter spacing value:

    measuredWidth = CLAY__MAX(lineWidth, measuredWidth) - config->letterSpacing;

But when the final layout is being calculated, the letter spacing is added to the line width of the text. So when it's time to render, the line is actually longer than the intial max line, so it gets broken up, even though it should fit.

https://github.com/pope/clay-letterspacing-poc is a little bit of code to test a before and after. Though I recognize there may be other use-cases I'm not hip to.

If this PR isn't the move, I don't mind opening up an issue to track this.

When calculating the width of a line, the width excludes the trailing letter
spacing value:

```c
    measuredWidth = CLAY__MAX(lineWidth, measuredWidth) - config->letterSpacing;
```

But when the final layout is being calculated, the letter spacing is added to
the line width of the text. So when it's time to render, the line is actually
longer than the intial max line, so it gets broken up, even though it should
fit.

https://github.com/pope/clay-letterspacing-poc is a little bit of code to test
a before and after.
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.

1 participant