Skip to content

fix(skia): Outline plain COLR glyphs on Apple - #26671

Open
mikernet wants to merge 2 commits into
unoplatform:masterfrom
mikernet:dev/mikernet/skia-apple-colr-outlines
Open

mikernet wants to merge 2 commits into
unoplatform:masterfrom
mikernet:dev/mikernet/skia-apple-colr-outlines

Conversation

@mikernet

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #26670

PR Type:

🐞 Bugfix

What changed? 🚀

On iOS with the WebGPU renderer (and likely macOS and Mac Catalyst, which use the same scaler), every glyph of a font with a COLR table drew black, including the glyphs without colour layers (#26670). For example, all the monochrome icons of an icon font that has a few COLR colour icons drew black, whatever the Foreground.

Cause: Skia's CoreText scaler treats the font's colour-glyphs trait, which CoreText sets for the whole font when it has COLR, as applying to every glyph, so SKFont.GetGlyphPath gives no path for any glyph of the font (neverRequestPath in SkScalerContext_Mac). SkiaFont.BuildGlyphRun took each of them for a colour glyph and rasterized it with RasterizeColorGlyph, whose default SKPaint is black. DirectWrite and FreeType outline the plain glyphs, so other platforms were unaffected. The Skia renderer draws text through SKCanvas, so its text drew correctly.

Fix: on Apple, for a font whose colour glyphs come from COLR alone (no sbix, CBDT or SVG ), SkiaFontFace now builds a SkiaColrOutlineSource the first time a glyph outline is asked for:

  • the glyphs that COLR colours, read from its v0 base glyph records and v1 base glyph list. Those still go to RasterizeColorGlyph as before;
  • a copy of the font without COLR, CPAL and DSIG, built in memory and loaded as an SKTypeface at the original's variation position (except opsz, which CoreText sets from the text size). SkiaFont takes the outlines of all other glyphs from it, so they fill with the text's brush.

If the COLR table is malformed or of an unknown version, or the copy doesn't load as a font without COLR (for example if CoreText resolves it back to an installed font), there is no source and the font draws as before.

Cost: on Apple, per font face with COLR alone (a face is a font file at one weight, stretch and style): the copy (about the size of the font, in native memory) and an 8 KB glyph bitset, built once on first use, plus one extra SKFont per size that draws such a font. Other platforms and fonts are unchanged.

Tests (runtime tests, Skia):

  • Given_SkiaColrOutlineSource runs on every Skia platform with a small self-made test font (colr-mixed-glyphs.ttf, 1.2 KB, made with fontTools (script below): two plain glyphs, a COLR v0 and a COLR v1 colour glyph, each colour glyph with a monochrome fallback outline). It checks the colour glyphs read from COLR and the outlines of the copy.
  • Given_Geometry.ColrFont_PlainGlyph_Outlines_And_ColorGlyph_Rasterizes_To_Image checks that BuildGlyphRun gives an outline for a plain glyph of the test font and an image for a colour glyph. Without the fix it fails on Apple platforms only.

Validation:

  • Skia desktop on Windows: the new tests pass, as do the rest of Given_Geometry, Given_IFont_AlternativeBackend and Given_GlyphRunRenderer. The Given_SkiaColrOutlineSource tests fail when v0 or v1 glyphs aren't read, or when the copy keeps COLR.
  • iOS: iOS 27 simulator, WebGPU renderer, a small app showing the test font's glyphs in white, yellow and cyan. Without the fix, the plain glyphs draw black in all three; with it they take the foreground, and the COLR glyphs stay in colour. In the same app with the fix, the original typeface gave no outline for any glyph, SkiaColrOutlineSource read colour glyphs 3 and 4, and the copy's outlines had the bounds the tests expect. The runtime tests themselves were not run on iOS. An app build with the fix also draws an icon font with COLR glyphs correctly on an iPhone. These iOS checks ran before the last review changes (an early return for an empty COLR v1 base glyph list, a spec-correct head checksum in the copy, comments). Both were checked on Windows against the same code: the empty list now gives colour glyphs instead of no source, and fontTools accepts the copy's checksums.
Test font generator (Python, fontTools)
# Generates colr-mixed-glyphs.ttf: a tiny TrueType font with plain outline glyphs and COLR colour glyphs.
# Its COLR table is version 1 with a v0 BaseGlyphRecord (badge) and a v1 BaseGlyphList entry (gradientBadge), so a
# reader of both parts is exercised. Each glyph has distinct bounds, so an outline can be told apart by them.
#
# Glyph ids (font units, unitsPerEm 1000):
#   0 .notdef                  empty
#   1 square         U+E000    plain: square (100,0)-(700,600)
#   2 triangle       U+E001    plain: triangle, bounds (100,0)-(500,400)
#   3 badge          U+E002    COLR v0 base glyph (layers 5 red, 6 blue); own glyf outline: monochrome fallback
#                              diamond, bounds (100,0)-(700,700)
#   4 gradientBadge  U+E003    COLR v1 base glyph (glyph 5 filled with a red-to-blue linear gradient); own glyf outline:
#                              monochrome fallback diamond, bounds (100,0)-(700,700)
#   5 badgeBack      no cmap   COLR layer: square (100,0)-(700,700)
#   6 badgeFront     no cmap   COLR layer: square (250,150)-(550,450)
#
# Usage: python make_colr_test_font.py <output.ttf>

import sys
from fontTools.fontBuilder import FontBuilder
from fontTools.pens.ttGlyphPen import TTGlyphPen
from fontTools.colorLib.builder import buildCOLR, buildCPAL
from fontTools.ttLib.tables.otTables import PaintFormat


def poly(points):
    pen = TTGlyphPen(None)
    pen.moveTo(points[0])
    for p in points[1:]:
        pen.lineTo(p)
    pen.closePath()
    return pen.glyph()


def empty():
    return TTGlyphPen(None).glyph()


def main(out):
    order = [".notdef", "square", "triangle", "badge", "gradientBadge", "badgeBack", "badgeFront"]
    fb = FontBuilder(1000, isTTF=True)
    fb.setupGlyphOrder(order)
    fb.setupCharacterMap({0xE000: "square", 0xE001: "triangle", 0xE002: "badge", 0xE003: "gradientBadge"})
    diamond = [(400, 0), (100, 350), (400, 700), (700, 350)]
    fb.setupGlyf({
        ".notdef": empty(),
        "square": poly([(100, 0), (100, 600), (700, 600), (700, 0)]),
        "triangle": poly([(100, 0), (300, 400), (500, 0)]),
        "badge": poly(diamond),
        "gradientBadge": poly(diamond),
        "badgeBack": poly([(100, 0), (100, 700), (700, 700), (700, 0)]),
        "badgeFront": poly([(250, 150), (250, 450), (550, 450), (550, 150)]),
    })
    # The left side bearings match the outlines' xMin, as rasterizers place a glyph by its side bearing.
    glyf = fb.font["glyf"]
    fb.setupHorizontalMetrics({name: (800, getattr(glyf[name], "xMin", 0)) for name in order})
    fb.setupHorizontalHeader(ascent=800, descent=-200)
    fb.setupNameTable({
        "familyName": "COLR Mixed Glyphs",
        "styleName": "Regular",
        "fullName": "COLR Mixed Glyphs Regular",
        "psName": "COLRMixedGlyphs-Regular",
    })
    fb.setupOS2(sTypoAscender=800, sTypoDescender=-200, usWinAscent=800, usWinDescent=200)
    fb.setupPost()
    gradient = {
        "Format": PaintFormat.PaintGlyph,
        "Glyph": "badgeBack",
        "Paint": {
            "Format": PaintFormat.PaintLinearGradient,
            "ColorLine": {"ColorStop": [(0.0, 0), (1.0, 1)]},
            "x0": 100, "y0": 0, "x1": 700, "y1": 700, "x2": 100, "y2": 700,
        },
    }
    fb.font["COLR"] = buildCOLR(
        {"badge": [("badgeBack", 0), ("badgeFront", 1)], "gradientBadge": gradient},
        glyphMap=fb.font.getReverseGlyphMap())
    fb.font["CPAL"] = buildCPAL([[(1.0, 0.0, 0.0, 1.0), (0.0, 0.0, 1.0, 1.0)]])
    fb.save(out)


if __name__ == "__main__":
    main(sys.argv[1])

PR Checklist ✅

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@mergify

mergify Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

mikernet added a commit to Singulink/uno that referenced this pull request Nov 23, 2026
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.

[iOS] WebGPU renderer draws the plain glyphs of a COLR font black

1 participant