Skip to content

Conversation

danielwe
Copy link
Contributor

Follow-up to #8720 adding

  • Two improvements to FreeType glyph measurements:
    • Ensuring that glyphs are measured with the same hinting as they are rendered, ref #8720#issuecomment-3305408157;
    • For outline glyphs, using the outline bbox instead of the built-in metrics, like renderGlyph().
  • Basic unit tests for face metrics and their estimators, using the narrowest and widest fonts from the resource directory, Cozette Vector and Geist Mono.

I also made one unrelated change to freetype.zig, replacing @alignCast(@ptrCast(...)) with @ptrCast(@alignCast(...)) on line 173. Autoformatting has been making this change on every save for weeks, and reverting the hunk before each commit is getting old, so I hope it's OK that I use this PR to upstream this decree from the formatter.

@danielwe danielwe requested a review from a team as a code owner September 18, 2025 06:25
@danielwe
Copy link
Contributor Author

Pushed an update with a better design for sharing FreeType load flags between measurements and rendering. The previous CI failures seemed to be a matter of CI resource constraints, not an issue with the code.

.ascent = 12.3046875,
.descent = -3.6953125,
.line_gap = 0.0,
.underline_position = -1.2265625,
Copy link
Contributor

Choose a reason for hiding this comment

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

comparing floats like this is going to be super sketchy. We should use std.math.approxEqRel. It's going to be tedious to pull them all out but that will be significantly more robust.

Copy link
Contributor Author

@danielwe danielwe Sep 18, 2025

Choose a reason for hiding this comment

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

I know, never compare floats for equality. I was actually surprised when the values came out exactly equal in CoreText and FreeType (modulo the ones affected by hinting), but given that they did I figured the calculations producing these values don't have a lot of potential for reassociations that would change the exact result (basically, they are all some variant of value_in_integer_design_units * px_per_unit, so to reassociate you'd probably have to split up the px_per_unit ratio), so I went with the quick and dirty.

Will fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed an update that addresses this.

danielwe

This comment was marked as duplicate.

@00-kat 00-kat added the font Issue within the font stack (typically src/font) label Sep 21, 2025
@danielwe danielwe requested a review from mitchellh September 21, 2025 18:34
@danielwe
Copy link
Contributor Author

Anything else I should do to get this ready? Merging the tests isn't that urgent/consequential of course, but the bounding box measurements fix is necessary to make #8720 work as intended (the metrics-based bounding box can be quite a bit too large).

@danielwe danielwe changed the title font: Improve FreeType glyph measurements and add unit tests for face metrics fix(font): Improve FreeType glyph measurements and add unit tests for face metrics Sep 24, 2025
@mitchellh mitchellh merged commit 0bddaed into ghostty-org:main Sep 29, 2025
37 checks passed
@github-actions github-actions bot added this to the 1.2.1 milestone Sep 29, 2025
mitchellh added a commit that referenced this pull request Sep 29, 2025
… face metrics (#8738)

Follow-up to #8720 adding

* Two improvements to FreeType glyph measurements:
- Ensuring that glyphs are measured with the same hinting as they are
rendered, ref
[#8720#issuecomment-3305408157](#8720 (comment));
- For outline glyphs, using the outline bbox instead of the built-in
metrics, like `renderGlyph()`.
* Basic unit tests for face metrics and their estimators, using the
narrowest and widest fonts from the resource directory, Cozette Vector
and Geist Mono.

---

I also made one unrelated change to `freetype.zig`, replacing
`@alignCast(@ptrCast(...))` with `@ptrCast(@alignCast(...))` on line
173. Autoformatting has been making this change on every save for weeks,
and reverting the hunk before each commit is getting old, so I hope it's
OK that I use this PR to upstream this decree from the formatter.
@danielwe danielwe deleted the font_metrics_tests branch September 29, 2025 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
font Issue within the font stack (typically src/font)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants