Is there a way to decompose components of a glyph in a TTF?
See original GitHub issueI am attempting to decompose components in glyphs within a TTF, but having trouble.
Is there a way to do this?
It seems that there is nothing direct, and that I may need to use pens. I am pretty new to pens, and not sure I understand them completely.
I think I would need to find a way to record points of each component to a pen
object, and then draw those points into the ttGlyph with the .drawPoints()
method. However, it doesn’t seem that the decomposingRecordingPen works with TTFont objects. I also can’t figure out whether I am using the ttGlyphPen correctly (can it even record points, or is it just a way to store points to later draw?).
def decomposeGlyph(font, glyphName):
components = (font['glyf'][glyphName].getComponentNames(font['glyf']))
## BASIC IDEA (not yet working)
# for component in glyph
# record tt points of component base
# draw points to glyph
glyphset = font.getGlyphSet()
for comp in components:
glyph = glyphset[comp]
pen = ttGlyphPen.TTGlyphPen(glyph)
# font['glyf'][glyphName].drawPoints(pen, font['glyf'])
font['glyf'][glyphName].draw(pen, font['glyf'])
It may or may not be a related goal, but I am also hoping to remove overlap in the glyphs in a TTF. If this is easy to point out, I would love to get a head start on it, but if it’s a totally separate thing, feel free to skip this part and I will look into it separately.
Thank you so much for any tips or insights!
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (3 by maintainers)
Top GitHub Comments
This snippet works:
The way ufo2ft uses pathops.union() function will not work with a TTGlyph object as these don’t have
getPen()
method (unlike defcon or ufoLib2 Glyph). I have already updated Just’s script to remove overlaps using skia-pathops (via Path.simplify() which is the underlying method called upon by pathops.union). Just use that.