Modifying CFF Glyph points ( From existing .otf ) #3267
-
I want to modify only the glyph shapes of otf font without modifying the rest of the font. (metadata, kerning, alt glyph, ect.) I've managed to do it with TTF : ttpen = TTGlyphPen( font.getGlyphSet() ) # not sur why I've passed the glyphSet...
# pen beziers ...
ttFont['glyf']['a'] = ttpen.glyph( dropImpliedOnCurves=True ) I didn't managed to do it with the CFF table, it is not working : font = ttLib.TTFont(path("files/1.otf"))
pen = T2CharStringPen(600, None)
# pen beziers ...
font['CFF '].cff[0].CharStrings["a"] = pen.getCharString()
font.save('out.otf')
# error :
# File "C:\Python\Python310\site-packages\fontTools\misc\psCharStrings.py", line 1142, in draw
# self.private.nominalWidthX,
# AttributeError: 'NoneType' object has no attribute 'nominalWidthX' maybe I should use I've tried an other way with a |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I finnally managed to do it with font = ttLib.TTFont("files/1.otf", recalcBBoxes = False )
pen = T2CharStringPen(600, None)
# pen beziers ...
font['CFF '].cff[0].CharStrings["a"] = pen.getCharString()
font.save('out.otf') Someone know why |
Beta Was this translation helpful? Give feedback.
-
For thoses interested there is an even better way to keep a maximum of originals data ecept vectors : char_string = pen.getCharString()
char_string.compile()
font['CFF '].cff.topDictIndex[0].CharStrings[glyph].bytecode = char_string.bytecode |
Beta Was this translation helpful? Give feedback.
For thoses interested there is an even better way to keep a maximum of originals data ecept vectors :
replacing only the compiled glyph bytecode into the CFF table