MPEGGroup / OpenFontFormat

Official MPEG repository to discuss issues on Open Font Format (ISO/IEC 14496-22)
31 stars 6 forks source link

In COLRv1 current design for linear gradients doesn't work well with transforms #40

Closed PeterCon closed 3 years ago

PeterCon commented 3 years ago

Dominik encountered this issue while working on implementing support in Skia and Freetype:

By defining the semantics for p2 so that line p0p2 indicates the direction in which color changes progress, it means that having p2 in line p0p1 will be a common scenario. But if p2 is colinear with p0p1, then applying transforms to p0, p1 and p2 don't always provide the results you'd expect. For example, a skew in the direction of p0p1 should cause a change in the gradient appearance (that was the intent), but after the transform p2 will still be colinear with p0p1, and so that change won't happen.

To make linear gradients interact with transforms the way we'd want, p2 should be off line p0p1 for all non-degenerate cases. That way, there are two non-parallel vectors p0p1 and p0p2 that will change in relation to one another in the expected way under any transform.

So, to achieve that, the semantics for p2 simply need to be redefined so that it indicates the direction in which each color along line p0p1 is projected away from that line. (In the SVG spec's description of gradients, p0p2 is analogous to the "normal" vector, except that in COLRv1 design it doesn't need to be perpendicular to p0p1.)

PeterConstable commented 3 years ago

The draft in the Google Fonts repo has been updated to address this issue. The following is the main pull request for that change:

vlevantovsky commented 3 years ago

Proposed changes have been incorporated as part of the input contribution m56341.