I’ve been asked to write a tool which performs various transformations to outlines in an OTF, and am now trying to get my head around the various parts of the Python font manipulation ecosystem.
Previously I have written plugins for editors which all come with their own libraries for manipulating Beziers, but this one will be a command line tool using fonttools.
What I’m looking for is an independent library which takes an outline in some format and has functions to add extrema and inflections, rotate, translate, offset, simplify, delete and keep shape, split curve at a point, harmonize, etc. - all the usual operations you want when manipulating curves.
Does such a library exist already? It seems like there should be but I have not found anything in fonttools, robofog, etc. - maybe I’m missing the obvious or maybe the documentation isn’t great.
If not, I think it would be useful to have and I wonder if there would be some value in one which also converted between different Bezier representations (array, NSBezierPath, Glyphs, etc.). I’m happy to write one since I will need it for this project.
0
Comments
There is code available for some...
Basically I am looking for the Python equivalent of https://pomax.github.io/bezierjs/
More functions could be added. Especially simplification and harmonizing could be interesting. Maybe the "SuperCubic" is a good starting point because it already can work across multiple cubic segments.
I could upload it to GitHub if there's any interest.
Let me know if you have any questions or suggestions. A demo script for Glyphs that extracts the SuperCubics from the current layer is included to get you started.
Some functions are provided in a c extension for speed. This is optional, the same functions are available in pure Python from jkFontGeometry.geometry.
However, it also does not contain any solutions for offset or simplify. But in my understanding there are no generic solutions for those problems, therefore you wont find them in a base library.
Here's an example:
What has happened in the top right corner of the offset curves? How come the offset curve handles are showing corners (i.e., not colinear)?
Currently I'm doing that process segment-wise, rather than over the whole path, which is why you were seeing a corner there. It's not hard to change it to collect the samples over the whole path and path-fit to that:
I could probably improve it a bit by adding more samples around areas of high curvature and less around areas of low curvature; that would smooth out parts like the top right and the left-hand side (around (60,130) or so).
Ich second Georg Seifert: The old outlining algorithm seems to have better results at the points with high curvature. Be aware that the outlines may be self-intersecting, when you just interpolate offset sample points. It may be a good idea to examine the curvature along the original path with respect to the stroking radius and then only consider the parts that have a curvature radius >= stroking radius to avoid the self intersection.
Or just remove the self-intersection afterwards (that's what I did).
Ist there a reason, why you make the list of points redundant (the first and the last point are identical)?
and here are the docs:
https://simoncozens.github.io/beziers.py/index.html
The points are deliberately redundant if you ask for the curve as a segment representation, because you want four points in each segment to make a cubic Bézier. If you don’t want that, you can ask for the curve in node list representation.
I'm trying to convert TTF fonts to OTF with FontTools, specifically T2CharStringPen. I noticed that the generated OTF fonts have more point than the TTF sources. This is the code:
Is there a way to simplify the paths using the tidy() method of BezierPath and pass the new path to pathops pen or t2_pen?