Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def saveOTF(font, destFile, glyphOrder, truetype=False):
"""Save a RoboFab font as an OTF binary using ufo2fdk."""
if truetype:
otf = compileTTF(font, featureCompilerClass=RobotoFeatureCompiler,
kernWriter=RobotoKernWriter, glyphOrder=glyphOrder,
convertCubics=False,
useProductionNames=False)
else:
otf = compileOTF(font, featureCompilerClass=RobotoFeatureCompiler,
kernWriter=RobotoKernWriter, glyphOrder=glyphOrder,
useProductionNames=False)
otf.save(destFile)
def export(self, path, format="otf", compression=None, **kwargs):
if format == "otf":
func = compileOTF
elif format == "ttf":
func = compileTTF
else:
raise ValueError("unknown format: %s" % format)
if compression is not None:
invalid = compression - {"none", "woff", "woff2"}
if invalid:
raise ValueError(f"unknown compression format: {invalid}")
# info attrs
missingAttrs = []
for attr in (
"familyName",
"styleName",
"unitsPerEm",
"ascender",
"descender",
"xHeight",
"capHeight",
def _iter_compile(self, ufos, ttf=False, debugFeatureFile=None, **kwargs):
# generator function that calls ufo2ft compiler for each ufo and
# yields ttFont instances
options = dict(kwargs)
if ttf:
for key in ("optimizeCFF", "roundTolerance"):
options.pop(key, None)
compile_func, fmt = ufo2ft.compileTTF, "TTF"
else:
for key in ("cubicConversionError", "reverseDirection"):
options.pop(key, None)
compile_func, fmt = ufo2ft.compileOTF, "OTF"
writeFontName = len(ufos) > 1
for ufo in ufos:
name = self._font_name(ufo)
logger.info(f"Building {fmt} for {name}")
if debugFeatureFile and writeFontName:
debugFeatureFile.write(f"\n### {name} ###\n")
yield compile_func(ufo, debugFeatureFile=debugFeatureFile, **options)
def compile(ufo, out_filename):
ext = os.path.splitext(out_filename)[1]
if ext == '.ufo':
return ufo
otf = None
if ext == '.ttf':
otf = compileTTF(ufo)
elif ext == '.otf':
otf = compileOTF(ufo)
elif ext == '.woff':
otf = compileOTF(ufo, optimizeCFF=False)
otf.flavor = 'woff'
elif ext == '.woff2':
otf = compileOTF(ufo, optimizeCFF=False)
otf.flavor = 'woff2'
else:
raise RuntimeError('Unknown output file type: %s' % ext)
return otf
def QuadraticTTFontFactory(font, useProductionNames=False):
ttf = compileTTF(font, useProductionNames=useProductionNames)
return ttf
def loadFont(fname):
if fname.lower().endswith(".ufo"):
ufo = Font(fname)
f = compileTTF(ufo)
else:
f = ttLib.TTFont(fname)
return f