Skip to content

vello_research: Draw glyphs with mask bitmaps from their outlines - #2122

Merged
waywardmonkeys merged 1 commit into
linebender:mainfrom
waywardmonkeys:fix/bitmap-mask-outline-fallback
Dec 4, 2026
Merged

waywardmonkeys merged 1 commit into
linebender:mainfrom
waywardmonkeys:fix/bitmap-mask-outline-fallback

Conversation

@waywardmonkeys

Copy link
Copy Markdown
Collaborator

Fixes #2019.

Fonts such as Calibri and Cambria have glyf outlines plus monochrome EBDT strikes, which are meant only for a few exact sizes. Any font with a bitmap strike took the color glyph path, and each glyph with a bitmap was drawn from it at any size. Calibri's bitmaps have byte-aligned rows, which the mask code skipped, so those glyphs were dropped and most text vanished.

This takes glifo's approach: grayscale and monochrome masks are never drawn, and those glyphs are drawn from their outlines. Fonts whose only strikes are EBDT (which can only hold masks) go straight to the outline path. Color bitmaps (PNG and BGRA, from CBDT and sbix) are drawn as before.

The mask code is removed rather than kept for fonts without outlines, because it was wrong for the masks it did accept: it didn't scale 1, 2 and 4 bpp values up to a full alpha, read the pixels in each byte in reverse, and filled with white instead of the brush. With the new test font, the bit-aligned glyph drew as a box at alpha 1/255. Only 8 bpp masks in fonts without outlines drew roughly right (in white); those glyphs are now not drawn, as in glifo.

The test font, assets/ebdt/ebdt.ttf, is generated by assets/ebdt/generate.py (as for the sbix fonts). Its glyphs have outlines plus a solid-box bitmap: A with byte-aligned rows as in Calibri, B with bit-aligned rows. Without the fix, the snapshot shows no A and a nearly invisible box for B. I also checked the snapshot with the EBDT shortcut disabled, so the per-glyph check is exercised too.

@waywardmonkeys
waywardmonkeys force-pushed the fix/bitmap-mask-outline-fallback branch from 765b71d to e012619 Compare December 1, 2026 15:31
@waywardmonkeys

Copy link
Copy Markdown
Collaborator Author

LLM contributions: Generated by Opus 5.5

@LaurenzV LaurenzV left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Optionally, I think some of the comments can be dropped.

Comment thread research/vello_research/src/scene.rs Outdated
let font = skrifa::FontRef::from_index(self.run.font.data.as_ref(), font_index).unwrap();
let bitmaps = font.bitmap_strikes();
if font.colr().is_ok() && font.cpal().is_ok() || !bitmaps.is_empty() {
// `EBDT` strikes only hold masks, which are drawn from the outlines.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we need this comment here if we already mention it further below?

Comment on lines +271 to +273
/// The font's glyphs have outlines, and also monochrome bitmaps in an `EBDT` strike, as Calibri's
/// do. The glyphs should be drawn from their outlines (blocky letters in the brush's color), not
/// from the bitmaps (solid boxes) or not at all.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Up to you, but it seems to me like the link to the issue should be enough.

A font with any bitmap strike took the color glyph path, where each glyph
with a bitmap at any size was drawn from it. Fonts such as Calibri and
Cambria have glyf outlines plus monochrome EBDT strikes, meant only for a
few exact sizes. Their rows are byte-aligned, which the mask code didn't
support, so those glyphs were dropped and most text vanished (linebender#2019).

The mask code was also wrong for the bit-aligned masks it did accept: it
didn't scale 1, 2 and 4 bpp values up to a full alpha, read the pixels in
each byte in reverse, and filled with white instead of the brush. So a
1 bpp glyph drew a box at alpha 1/255.

As glifo does, grayscale and monochrome masks are now never drawn; those
glyphs are drawn from their outlines. Fonts whose only strikes are EBDT go
straight to the outline path. Color bitmaps (PNG and BGRA, from CBDT and
sbix) are drawn as before.

The test font is generated by assets/ebdt/generate.py.
@waywardmonkeys
waywardmonkeys force-pushed the fix/bitmap-mask-outline-fallback branch from 006d920 to 916fffc Compare December 4, 2026 16:44
@waywardmonkeys
waywardmonkeys added this pull request to the merge queue Dec 4, 2026
Merged via the queue into linebender:main with commit 01090de Dec 4, 2026
18 checks passed
@waywardmonkeys
waywardmonkeys deleted the fix/bitmap-mask-outline-fallback branch December 4, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Glyphs with monochrome EBDT bitmaps are dropped instead of drawn from their outlines (Calibri draws almost nothing)

2 participants