Skip to content

gpui: Add dynamic padding to prevent glyph clipping in text rendering on macOS#45957

Merged
reflectronic merged 2 commits intozed-industries:mainfrom
JonyLab:fix/macos-glyph-clipping
Jan 15, 2026
Merged

gpui: Add dynamic padding to prevent glyph clipping in text rendering on macOS#45957
reflectronic merged 2 commits intozed-industries:mainfrom
JonyLab:fix/macos-glyph-clipping

Conversation

@JonyLab
Copy link
Copy Markdown
Contributor

@JonyLab JonyLab commented Jan 2, 2026

Here may caused by font-kit, I was tried to use render-glyph example and also use the same option with Transform2F::from_scale(2.0) for raster_bounds.

Then the raster_bounds will result same issue like the GPUI's font rendering issue.

Transform2F::default() Transform2F::from_scale(2.)
image image

Before

SCR-20260105-pgcp-2

After

SCR-20260105-pfny-1

Release Notes:

  • Fixed incorrect rendering of characters at large font sizes on macOS
…dering

Fixes glyph clipping issues on macOS where characters (especially numbers,
colons, and characters with ascenders/descenders) were being cut off during
rendering.

The root cause was that font_kit's raster_bounds calculations were too tight
for antialiased rendering, not accounting for subpixel rendering effects.

This commit adds dynamic padding to the glyph bounds:
- Uses 8% of font size as padding ratio
- Ensures minimum 2 pixels padding
- Scales properly with different font sizes and DPI settings
- Applies padding to all four sides of the glyph bounds

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Jan 2, 2026

We require contributors to sign our Contributor License Agreement, and we don't have @JonyLab 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'.

@JonyLab
Copy link
Copy Markdown
Contributor Author

JonyLab commented Jan 2, 2026

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jan 2, 2026
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Jan 2, 2026

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

@Dima-369
Copy link
Copy Markdown
Contributor

Dima-369 commented Jan 2, 2026

Thanks!

Do you have before/after screenshots?

@maxdeviant maxdeviant changed the title fix(macos): Add dynamic padding to prevent glyph clipping in text rendering Jan 2, 2026
@JonyLab
Copy link
Copy Markdown
Contributor Author

JonyLab commented Jan 5, 2026

Thanks!

Do you have before/after screenshots?

Sure.

Before/After Comparison

Here are comparison screenshots showing the glyph clipping fix:

Before:

img_v3_02tl_927aca5f-9aa2-495c-9762-f10e1464812g

Notice how the numbers and characters are clipped at the edges, especially visible in:

  • Number 8 (top and bottom edges)
  • Letters with ascenders (like 'W', 'V')
  • Colon (:) - narrow character that clips severely

After (with dynamic padding):

img_v3_02tl_90eda52d-6335-4f02-bc34-248abf26a57g

All characters are now rendered completely without clipping. The fix adds 8% of font size as dynamic padding (minimum 2 pixels), which:
✅ Scales automatically with font size
✅ Works correctly on Retina and non-Retina displays
✅ Handles all problematic characters (colons, numbers, ascenders/descenders)

Test conditions:

  • Font sizes: 56px, 40px
  • Font weights: Bold and Regular
  • Test string: "UVW:12345678"
@huacnlee
Copy link
Copy Markdown
Contributor

huacnlee commented Jan 5, 2026

Here may caused by font-kit, I was tried to use render-glyph example and also use the same option with Transform2F::from_scale(2.0) for raster_bounds.

Then the raster_bounds will result same issue like the GPUI's font rendering issue.

Transform2F::default() Transform2F::from_scale(2.)
image image

So I have update the implementation of the changes by consider the scale_factor to fix the x offset.

Now result is correct now:

# Run this example to test
cargo run -p gpui --example text
SCR-20260105-tvho
@nicoburns
Copy link
Copy Markdown
Contributor

GPUI may wish to consider switching to https://github.com/servo/webrender/tree/main/wr_glyph_rasterizer which is what Servo and Firefox use to render glyphs these days (like font-kit it defers to the system renderers to do the actual rasterization, unlike font-kit it is actively maintained). I suspect it can compute correct bounds.

@reflectronic
Copy link
Copy Markdown
Member

GPUI may wish to consider switching to https://github.com/servo/webrender/tree/main/wr_glyph_rasterizer

From a brief look at the code, it looks like wr_glyph_rasterizer bakes the result of the gamma correction into the bitmap. I think we would prefer something that lets us store a single bitmap in the atlas and apply the gamma correction on the GPU. (This is what we have done on Windows and Linux.)

@reflectronic reflectronic merged commit 83ca310 into zed-industries:main Jan 15, 2026
25 of 26 checks passed
@filipwiech
Copy link
Copy Markdown

filipwiech commented Jan 15, 2026

@reflectronic, @JonyLab This seems to be causing problems with ligatures being cut, e.g. && (macOS Tahoe 26.2, Zed Nightly 0.221.0 83ca310, default Zed Mono font, buffer font size 16, internal Retina screen):
image
image
image
image
image
Or at least I think that's the most likely culprit, since last nightly from the day before was fine. 👍

@maxdeviant
Copy link
Copy Markdown
Member

@reflectronic, @JonyLab This seems to be causing problems with ligatures being cut, e.g. && (macOS Tahoe 26.2, Zed Nightly 0.221.0 83ca310, default Zed Mono font, buffer font size 16, internal Retina screen): image image image image image Or at least I think that's the most likely culprit, since last nightly from the day before was fine. 👍

Thanks for the report, we're reverting: #46906

maxdeviant added a commit that referenced this pull request Jan 15, 2026
…endering on macOS (#45957)" (#46906)

This reverts commit 83ca310.

This change produces bad clipping on macOS:

<img width="59" height="80" alt="Screenshot 2026-01-15 at 8 51 28 AM"
src="https://github.com/user-attachments/assets/e1e295a4-f25c-4144-aa85-ec2fbbba03a8"
/>

<img width="218" height="67" alt="Screenshot 2026-01-15 at 8 51 35 AM"
src="https://github.com/user-attachments/assets/e662f8df-b009-445e-afee-3440b7fc52f0"
/>

<img width="303" height="43" alt="Screenshot 2026-01-15 at 8 51 41 AM"
src="https://github.com/user-attachments/assets/c972a1be-a07b-4b5f-970b-f75a51dac6b8"
/>

https://zed-industries.slack.com/archives/C04S5TU0RSN/p1768473926260279

Release Notes:

- Reverted #45957
@nicoburns
Copy link
Copy Markdown
Contributor

GPUI may wish to consider switching to https://github.com/servo/webrender/tree/main/wr_glyph_rasterizer

From a brief look at the code, it looks like wr_glyph_rasterizer bakes the result of the gamma correction into the bitmap. I think we would prefer something that lets us store a single bitmap in the atlas and apply the gamma correction on the GPU. (This is what we have done on Windows and Linux.)

@reflectronic Interesting. Are there use cases where you need the same glyph with different gamma corrections?

@huacnlee

This comment was marked as outdated.

@huacnlee
Copy link
Copy Markdown
Contributor

Oh, I see the problem.

image

Strange, this happens with .ZedMono, but it works fine with several other fonts.

Veykril pushed a commit that referenced this pull request Mar 19, 2026
Continue #45957 #46906 to fix font render issue again.

Release Notes:

- Fixed macOS font render clipped bug when use `.SystemUIFont`.

| .SystemUIFont | .ZedMono |
| --- | --- |
| <img width="1034" height="978" alt="image"
src="https://github.com/user-attachments/assets/96b815a1-9484-4a38-8391-a4af3db51a36"
/> | <img width="1034" height="978" alt="image"
src="https://github.com/user-attachments/assets/1aaece42-9acd-47b0-a0a0-3cb425f40301"
/> |

```bash
cargo run -p gpui --example text
```

Test in Zed with `.ZedMono` font:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/1e44d186-cee5-4f54-910a-4c4602ca010e"
/>

With `.ZedSans`:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/1e502f3e-794c-4082-9faf-5a920adc1214"
/>

`Monaco`:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/906a3fd2-715a-4f53-b6fe-4614f4c6edab"
/>

`Menlo`:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/a8f8c302-2083-477c-ae72-f6e5c7f91d00"
/>
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 20, 2026
Continue zed-industries#45957 zed-industries#46906 to fix font render issue again.

Release Notes:

- Fixed macOS font render clipped bug when use `.SystemUIFont`.

| .SystemUIFont | .ZedMono |
| --- | --- |
| <img width="1034" height="978" alt="image"
src="https://github.com/user-attachments/assets/96b815a1-9484-4a38-8391-a4af3db51a36"
/> | <img width="1034" height="978" alt="image"
src="https://github.com/user-attachments/assets/1aaece42-9acd-47b0-a0a0-3cb425f40301"
/> |

```bash
cargo run -p gpui --example text
```

Test in Zed with `.ZedMono` font:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/1e44d186-cee5-4f54-910a-4c4602ca010e"
/>

With `.ZedSans`:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/1e502f3e-794c-4082-9faf-5a920adc1214"
/>

`Monaco`:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/906a3fd2-715a-4f53-b6fe-4614f4c6edab"
/>

`Menlo`:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/a8f8c302-2083-477c-ae72-f6e5c7f91d00"
/>
toshmukhamedov pushed a commit to toshmukhamedov/zed that referenced this pull request Mar 20, 2026
Continue zed-industries#45957 zed-industries#46906 to fix font render issue again.

Release Notes:

- Fixed macOS font render clipped bug when use `.SystemUIFont`.

| .SystemUIFont | .ZedMono |
| --- | --- |
| <img width="1034" height="978" alt="image"
src="https://github.com/user-attachments/assets/96b815a1-9484-4a38-8391-a4af3db51a36"
/> | <img width="1034" height="978" alt="image"
src="https://github.com/user-attachments/assets/1aaece42-9acd-47b0-a0a0-3cb425f40301"
/> |

```bash
cargo run -p gpui --example text
```

Test in Zed with `.ZedMono` font:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/1e44d186-cee5-4f54-910a-4c4602ca010e"
/>

With `.ZedSans`:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/1e502f3e-794c-4082-9faf-5a920adc1214"
/>

`Monaco`:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/906a3fd2-715a-4f53-b6fe-4614f4c6edab"
/>

`Menlo`:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/a8f8c302-2083-477c-ae72-f6e5c7f91d00"
/>
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 23, 2026
Continue zed-industries#45957 zed-industries#46906 to fix font render issue again.

Release Notes:

- Fixed macOS font render clipped bug when use `.SystemUIFont`.

| .SystemUIFont | .ZedMono |
| --- | --- |
| <img width="1034" height="978" alt="image"
src="https://github.com/user-attachments/assets/96b815a1-9484-4a38-8391-a4af3db51a36"
/> | <img width="1034" height="978" alt="image"
src="https://github.com/user-attachments/assets/1aaece42-9acd-47b0-a0a0-3cb425f40301"
/> |

```bash
cargo run -p gpui --example text
```

Test in Zed with `.ZedMono` font:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/1e44d186-cee5-4f54-910a-4c4602ca010e"
/>

With `.ZedSans`:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/1e502f3e-794c-4082-9faf-5a920adc1214"
/>

`Monaco`:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/906a3fd2-715a-4f53-b6fe-4614f4c6edab"
/>

`Menlo`:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/a8f8c302-2083-477c-ae72-f6e5c7f91d00"
/>
piper-of-dawn pushed a commit to piper-of-dawn/zed that referenced this pull request Apr 25, 2026
Continue zed-industries#45957 zed-industries#46906 to fix font render issue again.

Release Notes:

- Fixed macOS font render clipped bug when use `.SystemUIFont`.

| .SystemUIFont | .ZedMono |
| --- | --- |
| <img width="1034" height="978" alt="image"
src="https://github.com/user-attachments/assets/96b815a1-9484-4a38-8391-a4af3db51a36"
/> | <img width="1034" height="978" alt="image"
src="https://github.com/user-attachments/assets/1aaece42-9acd-47b0-a0a0-3cb425f40301"
/> |

```bash
cargo run -p gpui --example text
```

Test in Zed with `.ZedMono` font:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/1e44d186-cee5-4f54-910a-4c4602ca010e"
/>

With `.ZedSans`:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/1e502f3e-794c-4082-9faf-5a920adc1214"
/>

`Monaco`:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/906a3fd2-715a-4f53-b6fe-4614f4c6edab"
/>

`Menlo`:

<img width="815" height="844" alt="image"
src="https://github.com/user-attachments/assets/a8f8c302-2083-477c-ae72-f6e5c7f91d00"
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

7 participants