Skip to content

Fix COLRv1 sweeps modulo and paint clipping - #241

Merged
justvanrossum merged 6 commits into
fontra:mainfrom
hybridherbst:feature/better-colorv1-sweeps-and-clip
May 18, 2026
Merged

Fix COLRv1 sweeps modulo and paint clipping#241
justvanrossum merged 6 commits into
fontra:mainfrom
hybridherbst:feature/better-colorv1-sweeps-and-clip

Conversation

@hybridherbst

Copy link
Copy Markdown
Contributor

Fixes #240 and some related bugs with glyphs from the test font.

@justvanrossum justvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, looks great!

I left one question inline.

@justvanrossum

Copy link
Copy Markdown
Member

Out of scope for this issue, but I've noticed that rendering many adjacent triangles gives some artifacts, and causes some pixels "between" triangles to be more transparent, resulting in a lighter color:

(Top Chrome, bottom Fontgoggles)

image

This is unlikely something that you have introduced, but I'm curious what your thoughts are about this.

@hybridherbst

Copy link
Copy Markdown
Contributor Author

Turns out there's a coregraphics API, CGContextDrawConicGradient, that can render these gradients with less of the triangle line artifacts.
I added a small test font with two glyphs for testing as well, because there was no coverage for "transparent sweep gradients that overlap each other" – so that should be covered now as well.

Can you check if that fixes the transparency issue you see in FontGoggles? I wasn't able to reproduce that.

@justvanrossum

Copy link
Copy Markdown
Member

CGContextDrawConicGradient

Great find, thanks!

This probably means that the fallback _drawPathSweepGradientWithPatches() is no longer tested, right?

Can you check if that fixes the transparency issue you see in FontGoggles? I wasn't able to reproduce that.

It's just perfect now:

image

Thanks!

@hybridherbst

Copy link
Copy Markdown
Contributor Author

Great to hear!

The fallback would to the best of my understanding still be needed for MacOS < 14; if that's not an intended target anymore then it can go. (for reference, https://en.wikipedia.org/wiki/MacOS_Ventura, https://developer.apple.com/documentation/coregraphics/cgcontextdrawconicgradient(_:_:_:_:))

@justvanrossum

Copy link
Copy Markdown
Member

If I disable the "CGContextDrawConicGradient" codepath, there is still some transparency:

image

But I'm not sure it's worth fixing, given that even 10.14 (when CGContextDrawConicGradient was introduced) is pretty rare these day, let alone 10.13, which would be the only macOS where this problem exists.

@justvanrossum

Copy link
Copy Markdown
Member

FontGoggles requires macOS >= 10.13.

It's good to keep the fallback around, I'll try to think how we could make it be part of the tests. Shouldn't be a blocker.

@justvanrossum justvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great work again, thanks!

@justvanrossum
justvanrossum merged commit 9abd659 into fontra:main May 18, 2026
3 checks passed
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.

More sweep gradient issues

2 participants