Skip to content

gpui_macos: restore size-dependent glyph padding - #63469

Open
VladimirKras wants to merge 1 commit into
zed-industries:mainfrom
VladimirKras:fix-macos-glyph-clipping
Open

gpui_macos: restore size-dependent glyph padding#63469
VladimirKras wants to merge 1 commit into
zed-industries:mainfrom
VladimirKras:fix-macos-glyph-clipping

Conversation

@VladimirKras

Copy link
Copy Markdown

AI disclosure: Codex assisted with this change; I reviewed and verified the result.

Objective

Fix clipped left edges when CoreGraphics rasterizes larger glyphs on macOS.

font-kit scales typographic bounds from the base font, but CoreGraphics renders a size-specific font whose ink can extend farther left. The regression became visible after the size-dependent left margin introduced in #47001 was replaced with a uniform one-device-pixel margin in #54886.

For example, a bold tabular system-font 0 at 48 px and 2× scale lost pixels along its left curve.

Solution

Restore the previous size-dependent left margin:

  • Scale it with device-space font size.
  • Clamp it between 1 and 5 device pixels to limit glyph-atlas overhead.
  • Preserve the one-device-pixel margin on the top, right, and bottom required for antialiasing and glyph dilation.
  • Express the asymmetric expansion immutably with Bounds::extend(Edges).

The left margin is the historical total margin; the uniform one-pixel margin is not added to it again.

Add two macOS regression tests:

  • Verify that the selected GPUI raster bounds produce the same ink as an oversized reference buffer.
  • Render the exact size-specific CoreText font through AppKit and verify that its pixel coverage matches GPUI exactly.

The additional objc2-app-kit feature flags are test-only dev-dependencies and do not affect normal debug or production builds.

Testing

Tested on macOS with:

  • cargo test -p gpui_macos --features font-kit
    • 12 passed, 0 failed.
  • cargo clippy -p gpui_macos --features font-kit --all-targets -- -D warnings
    • Passed.
  • cargo fmt -p gpui_macos
    • Passed.

The regression tests cover a bold tabular SF-system 0 at 48 px and 2× scale, matching the observed failure.

A paired release microbenchmark of the production bounds calculation found no performance regression:

  • Before: 334.59 ns/op
  • After: 332.02 ns/op
  • Ratio: 0.9924, approximate 95% CI ±0.0044
  • 60 paired samples with 60,000 operations per sample

This change only affects the macOS text backend. Other platforms were not tested because their implementations are unchanged.

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content adheres to Zed's UI standards (UX/UI and icon guidelines)
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Showcase

All images show the same bold tabular system-font 0 at 48 px and 2× scale.

GPUI before fix GPUI after fix Native AppKit
gpui-before-48px gpui-after-48px appkit-48px

The GPUI rendering after the fix and the native AppKit reference are pixel-identical.


Release Notes:

  • Fixed clipped glyph edges at larger font sizes on macOS.

@cla-bot

cla-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @VladimirKras on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Aug 31, 2026
@VladimirKras

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Aug 31, 2026
@cla-bot

cla-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

@ChristopherBiscardi ChristopherBiscardi added platform:macOS Platform-specific feedback for macOS behaviors, features, design, etc area:gpui GPUI rendering framework support labels Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpui GPUI rendering framework support cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions platform:macOS Platform-specific feedback for macOS behaviors, features, design, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants