servo / servo/font-kit

Anti-aliased glyphs sometimes get pixels clipped off during rasterization on MacOS

Open
#194 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
840
Forks
137
Avg merge
4h 56m
Merged PRs (30d)
1

Description

We use font-kit for font rendering in our MacOS app (https://github.com/warpdotdev/Warp), and I noticed that characters sometimes are rendered without the top row of pixels. For example, when using Courier New, 13pt, with greyscale AA, the top row of pixels for "l" and "f" are missing.

I hacked around it by adding vec2i(1, 1) to the size of the computed raster bounds and subtracting vec2i(1, 1) from the origin of the computed raster bounds. This causes glyphs to draw in the same location, but without any clipping.

I don't know (at a deeper level) why the clipping occurs, nor why it only affects some glyphs. I chose not to attempt an upstream fix at the moment due to this lack of understanding, and not being sure whether this is an issue specific to font-kit on MacOS or whether a fix would need to also touch other supported platforms.

Screenshot of "l" with clipping:
warp-with-clipping

Screenshot of "l" with my patch applied:
warp-no-clipping

In the above screenshots, the 1px box is placed in the same position relative to the glyph body/baseline. You can see how the second screenshot includes an extra row of pixels at the top that are missing from the first screenshot. The same clipping issue can also be seen on the "f" at the right side of each screenshot.

I'm not sure if I've observed clipping on the sides of glyphs; unclear whether the adjustment only needs to be applied for rows (y-component) or is also required for columns (x-component).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start by reproducing the clipping with font-kit on macOS using Courier New at 13pt with greyscale antialiasing, then trace the computed raster bounds and compare the reported vec2i adjustment across supported platforms. Done means the affected glyphs render without clipped pixels and any side-clipping behavior is understood.

Written by the indexing model from the issue text.

Assessment

Tech stack
macos, rust
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.