rougier / freetype-py

Python binding for the freetype library
Other
300 stars 87 forks source link

glyph-vector/glyph-vector-2 examples do not look at the 3rd order bezier curve bit #58

Open HinTak opened 7 years ago

HinTak commented 7 years ago

The examples ignore the 3rd order bezier curve bit and always intepolate between off-curve points. This is strictly speaking only correct for truetype fonts (which only use 2nd order bezier curves). The difference is small but may be important for some glyphs.

Also I think they assume the first point is always on curve. First point being off is less common, but valid.

I'm not going to fix these, but would push a couple of coments in the relevant places. I just think the examples should do the right thing if somebody want to use a different font or a different glyph, or documented not to do so quite correctly...

(cairo don't have 2nd order curves - it is either line or 3rd order; but a 2nd order curve is just a 3rd order with duplicated off points).

rougier commented 7 years ago

How do you get first point off curve for a cubic Bézier considering the explicit form? You mean given first point doesn't correspond to t=0, right?

HinTak commented 7 years ago

A while ago there was a discussion on the Opentype list about this sort of thing. It is legal for a curve to consist of entirely off-curve points. Say 4, at the corner of a square. The rasterizer interpolates them. That was the answer from Microsoft people.

So an implied on-curve point is between the first and the last.

I think it can be even more extreme - a contour can be made from 3 off-curve points. Font designers rarely do it, that's all.

rougier commented 7 years ago

Didn't know that. Do you have a pointer to some documentation such that we can add it in the relevant example (where I'm asking to rephrase). It's not the example is not optimal but it is more a partial implementation.

HinTak commented 7 years ago

http://stackoverflow.com/questions/20733790/truetype-fonts-glyph-are-made-of-quadratic-bezier-why-do-more-than-one-consecu

rougier commented 7 years ago

But freetype outline takes care of normalizing the output, no? See https://www.freetype.org/freetype2/docs/glyphs/glyphs-6.html)

rougier commented 7 years ago

Ok, no it doesn't, we have to take care of point tags.

HinTak commented 7 years ago

You do interpolate most of the time - just afaic, not the first point; and also always split a 3-order curve into two, with an interpolation in the middle. Difference small but for some glyph, might be visible.

rougier commented 7 years ago

So we better implement the full method.

HinTak commented 7 years ago

3rd curves only on postscript fonts. 2nd order is sufficient for truetype.

HinTak commented 7 years ago

I hope this is shown side by side - left interpolated 2nd order, right true-3rd order:

glyph-vector-2-cairo-interpolated glyph-vector-2-cairo-real

and again, with the control points,, which make it clearer:

glyph-vector-cairo-s--interpoloated-minionpro-regular otf glyph-vector-cairo-real

correct answer from ftgrid: screenshot from 2017-05-02 22-57-41

These are using MinionPro-Regular.otf from adobe acrobat reader.

HinTak commented 7 years ago

Hmm, my 'g' is a bit off in the horizonal direction for the MinionPro-Regular.otf

HinTak commented 7 years ago

These are the g's from MinionPro-Regular.otf and MinionPro-It.otf, correctly aligned in the horizontal. from the top of https://github.com/rougier/freetype-py/issues/55 .

glyph-vector-2-cairo-it glyph-vector-2-cairo