You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hi,
i want use fonttools to subbset our chinese truetype fonts, but i found it is so slowly for realtime web request.
the flavor are woff and woff2 for webpage。some code snippets as below:
from fontTools.subset import Options, Subsetter
from fontTools.ttLib import TTFont
import io
drop_tables_extra = ['GSUB', 'prep', 'vhea', 'vmtx', 'FFTM', 'GDEF', 'GPOS', 'kern', 'hdmx', 'VDMX', 'LTSH', 'DSIG', 'EBLC', 'EBDT', 'morx', 'mort']
from enum import Enum
class TTFormat(str, Enum):
woff = "woff"
woff2 = "woff2"
ttf = "ttf"
fontDir='/tmp'
def subset_font(fontFamily: str, text : str, format : TTFormat):
fontPath = f"{fontDir}/{fontFamily}.ttf"
options = Options()
options.flavor = format
#options.desubroutinize = True
options.hinting = False
options.drop_tables += drop_tables_extra
try:
font = TTFont(fontPath, recalcTimestamp=False, lazy=False)
subset_font = font
if format ==TTFormat.woff or format == TTFormat.woff2:
subset_font.flavor = format
subsetter = Subsetter(options = options)
subsetter.populate(text = text)
subsetter.subset(subset_font)
return subset_font
except FileNotFoundError:
pass
except AssertionError:
pass
return None
if __name__ == '__main__' :
font = subset_font('fangzheng_ktjt', 'Javatest', 'woff2')
if font:
buf = io.BytesIO()
font.save(buf)
buf.seek(0)
print(buf)
font.close()
I would suggest to try hb-subset instead (part of the HarfBuzz project). (I haven't used it myself, and I'm assuming it has similar functionality, yet it's written in C++, so should be a lot faster.)
hi,
i want use fonttools to subbset our chinese truetype fonts, but i found it is so slowly for realtime web request.
the flavor are woff and woff2 for webpage。some code snippets as below:
so i use cProfile to find the problem.
you can see some truetype check use most of the time.
anyone know how to optimze it? thanks.
fangzheng_ktjt.ttf.zip
.
The text was updated successfully, but these errors were encountered: