# Implement luminance-based glyph dilation for macOS \(\#54886\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/a38fc8c8de6e4010fadcfde7dd111d90dfd66845)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: a38fc8c8de6e4010fadcfde7dd111d90dfd66845

Requested commit: a38fc8c8de6e4010fadcfde7dd111d90dfd66845

Commit: a38fc8c8de6e4010fadcfde7dd111d90dfd66845

Tree: 49b4eab27fad1b79cfe00ac90b6a52159a6dbb7e

Author: John Tur

Committer: GitHub

## Message

```
Implement luminance-based glyph dilation for macOS (#54886)

Apple's text rendering stack dilates glyph outlines for text rendered
with a light foreground color. Zed doesn't consider this nuance today;
we populate our atlas using glyphs rendered with a dark foreground
color. This means that, particularly in dark themes, text in Zed looks
thin and blurry, and doesn't match the look of native macOS
applications.

This pull request replicates the native behavior of Core Graphics. Some
reverse-engineering revealed that CG computes the foreground color
luminance using the Rec. 709 formula ($Y=0.2126R + 0.7152B + 0.0722G$)
and quantizes it into five levels (0, 0.25, 0.5, 0.75, and 1). Each
level uses a different dilation factor.

With this patch, we calculate this same luminance bucket and supply it
as the foreground color during rasterization. The correct dilation will
be applied, and we'll store this glyph in the atlas keyed by this
luminance bucket. So, we'll generate and use up to 5 different bitmaps
for each glyph based on its foreground color.

I've confirmed that text rendered by Zed now exactly matches native
applications like Safari, TextEdit, etc.

Release Notes:

- Improved text rendering clarity on macOS, particularly in dark themes.

---------

Co-authored-by: Zed Zippy <234243425+zed-zippy[bot]@users.noreply.github.com>
```

## Parents

- [3014170d7e4dfbe8379beda4dec92d6256b41209](https://git.cafe/gitcafe/zed/commit/3014170d7e4dfbe8379beda4dec92d6256b41209?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/a38fc8c8de6e4010fadcfde7dd111d90dfd66845?format=markdown)
