Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
temp files for both tx output and sfntedit output instead of
overwriting 'otfPath', and also provides an option to skip
the sfntedit step (so 'otfPath' can be either a .otf file or
a .cff file).
"""
tmp_tx_path = get_temp_file_path()
out_path = get_temp_file_path()
shutil.copyfile(otfPath, out_path, follow_symlinks=True)
if not run_shell_command(['tx', '-cff', '+b', '-std', '-no_opt',
otfPath, tmp_tx_path]):
raise Exception
if do_sfnt:
if not run_shell_command(['sfntedit', '-a',
f'CFF ={tmp_tx_path}', out_path]):
raise Exception
return out_path
else:
return tmp_tx_path
filePath = tempTxtPath
if needsSEACRemoval:
tempSeacPath = fdkutils.get_temp_file_path()
# convert to CFF using 'tx'
if not fdkutils.run_shell_command([
'tx', '-cff', '-Z', '+b', filePath, tempSeacPath]):
raise MakeOTFShellError
filePath = tempSeacPath
psName = get_font_psname(filePath, makeOTFParams.srcIsUFO)
# Now convert to Type 1
# (it's the only font format that makeotfexe can consume)
if not fdkutils.run_shell_command(['tx', '-t1', filePath, fontPath]):
raise MakeOTFShellError
makeOTFParams.tempFontPath = fontPath
else: # convertion is not needed
psName = get_font_psname(filePath)
makeOTFParams.psName = psName
ufotools.validateLayers(font_path)
self.defcon_font = defcon.Font(font_path)
self.ufo_format = self.defcon_font.ufoFormatVersion
if self.ufo_format < 2:
self.ufo_format = 2
self.use_hash_map = use_hash_map
self.ufo_font_hash_data = ufotools.UFOFontData(
font_path, self.use_hash_map,
programName=ufotools.kCheckOutlineName)
self.ufo_font_hash_data.readHashMap()
else:
print("Converting to temp UFO font...")
self.temp_ufo_path = temp_path = get_temp_dir_path('font.ufo')
if not run_shell_command([
'tx', '-ufo', font_path, temp_path]):
raise FocusFontError(
'Failed to convert input font to UFO.')
try:
self.defcon_font = defcon.Font(temp_path)
except UFOLibError:
raise
if self.font_format == 'OTF':
self.font_type = OTF_FONT_TYPE
elif self.font_format == 'CFF':
self.font_type = CFF_FONT_TYPE
else:
self.font_type = TYPE1_FONT_TYPE
if glyphList:
glyphList = ", ".join(glyphList)
print("makeotf [Warning] Font at '%s' contains deprecated "
"SEAC operator. These composite glyphs will be "
"decomposed by makeOTF:\n%s" % (filePath, glyphList))
needsConversion = True
needsSEACRemoval = True
if needsConversion:
fontPath = fdkutils.get_temp_file_path()
if isTextPS:
tempTxtPath = fdkutils.get_temp_file_path()
# convert PS decrypted to PS encrypted with 'type1'
if not fdkutils.run_shell_command([
'type1', filePath, tempTxtPath]):
raise MakeOTFShellError
filePath = tempTxtPath
if needsSEACRemoval:
tempSeacPath = fdkutils.get_temp_file_path()
# convert to CFF using 'tx'
if not fdkutils.run_shell_command([
'tx', '-cff', '-Z', '+b', filePath, tempSeacPath]):
raise MakeOTFShellError
filePath = tempSeacPath
psName = get_font_psname(filePath, makeOTFParams.srcIsUFO)
# Now convert to Type 1
def generalizeCFF(otfPath):
tempFilePath = get_temp_file_path()
if not run_shell_command(['tx', '-cff', '+b', '-std', '-no_opt',
otfPath, tempFilePath]):
raise ShellCommandError
if not run_shell_command(['sfntedit', '-a',
f'CFF ={tempFilePath}', otfPath]):
raise ShellCommandError
fontPath = fdkutils.get_temp_file_path()
if isTextPS:
tempTxtPath = fdkutils.get_temp_file_path()
# convert PS decrypted to PS encrypted with 'type1'
if not fdkutils.run_shell_command([
'type1', filePath, tempTxtPath]):
raise MakeOTFShellError
filePath = tempTxtPath
if needsSEACRemoval:
tempSeacPath = fdkutils.get_temp_file_path()
# convert to CFF using 'tx'
if not fdkutils.run_shell_command([
'tx', '-cff', '-Z', '+b', filePath, tempSeacPath]):
raise MakeOTFShellError
filePath = tempSeacPath
psName = get_font_psname(filePath, makeOTFParams.srcIsUFO)
# Now convert to Type 1
# (it's the only font format that makeotfexe can consume)
if not fdkutils.run_shell_command(['tx', '-t1', filePath, fontPath]):
raise MakeOTFShellError
makeOTFParams.tempFontPath = fontPath
else: # convertion is not needed
psName = get_font_psname(filePath)