unified-font-object / ufo-spec

The official Unified Font Object specification source files.
http://unifiedfontobject.org
175 stars 30 forks source link

should a qcurve segment not preceded by any offcurves be interpreted as a straight line? #211

Closed anthrotype closed 2 years ago

anthrotype commented 2 years ago

The current GLIF point types spec currently says about "curve"

https://unifiedfontobject.org/versions/ufo3/glyphs/glif/#point-types

curve

Draw a cubic bezier curve from the last non-offcurve point to this point. The number of offcurve points can be zero, one or two. If the number of offcurve points is zero, a straight line is drawn. If it is one, a quadratic curve is drawn. If it is two, a regular cubic bezier is drawn.

For the "qcurve" quadratic curve segment type, it simply says:

qcurve

Similar to curve, but uses quadratic curves, using the TrueType “implied on-curve points” principle.

It does not explicitly say what to do in the case of zero offcurve points preceding the oncurve point marked as "qcurve".

I think this situation should also be interpreted as a straight line, which it also appears to be what Robofont does.

Maybe the UFO spec should be updated to mention this explicitly if that's the case.

This issue came up in https://github.com/googlefonts/ufo2ft/issues/468#issuecomment-1311657646

anthrotype commented 2 years ago

not sure if relevant here but I noticed that the fontTools BasePen (the mother of all pens!), while it does handle the variable number of off-curves in the curveTo method, it has this assertion in the qCurveTo method that seems to suggest for the quadratic with case zero offcurves are not expected (perhaps intentionally?, if so we should make it explicit)

https://github.com/fonttools/fonttools/blob/35856412485bce4a1e6c08cceb52c7a87c75c4ee/Lib/fontTools/pens/basePen.py#L303-L305

    def qCurveTo(self, *points):
        n = len(points) - 1  # 'n' is the number of control points
        assert n >= 0

/cc @justvanrossum @typemytype @jenskutilek

EDIT: it totally is expected if you understand the difference between > and >= 😅

justvanrossum commented 2 years ago

n seems to be the number of off-curve points, and it's asserted to be zero or greater than zero.

I think this situation should also be interpreted as a straight line

That's for sure the intention.

anthrotype commented 2 years ago

oops sorry... can't even read python code. Ok then, would be nice to get the spec updated accordingly to mention this explicitly