Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def open(self, use_hash_map):
font_path = self.font_path
if self.font_format == 'UFO':
self.font_type = UFO_FONT_TYPE
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]):
normalizeUFO(instancePath, outputPath=None, onlyModified=True,
writeModTimes=False)
if options.doAutoHint or options.doOverlapRemoval:
logger.info("Applying post-processing...")
# Apply autohint and checkoutlines, if requested.
for instancePath in newInstancesList:
# make new instance font.
updateInstance(instancePath, options)
# checkoutlinesufo does ufotools.validateLayers()
if not options.doOverlapRemoval:
for instancePath in newInstancesList:
# make sure that there are no old glyphs left in the
# processed glyphs folder
validateLayers(instancePath)
# The defcon library renames glyphs. Need to fix them again
if options.doOverlapRemoval or options.doAutoHint:
for instancePath in newInstancesList:
if options.doNormalize:
normalizeUFO(instancePath, outputPath=None, onlyModified=False,
writeModTimes=False)
# Restore the contents of the instances' 'features.fea' files
for fea_pth, fea_cntnts in features_store.items():
with open(fea_pth, 'w') as fp:
fp.write(fea_cntnts)
for contour in fixed_glyph:
for point in contour:
point.x = int(round(point.x))
point.y = int(round(point.y))
restore_contour_order(fixed_glyph, original_contours)
# The following is needed when the script is called from another
# script with Popen():
sys.stdout.flush()
# update layer plist: the hash check call may have deleted processed layer
# glyphs because the default layer glyph is newer.
# At this point, we may have deleted glyphs in the
# processed layer.writer.getGlyphSet()
# will fail unless we update the contents.plist file to match.
if options.allow_changes:
ufotools.validateLayers(font_path, False)
if not font_changed:
# Even if the program didn't change any glyphs,
# we should still save updates to the src glyph hash file.
font_file.close()
else:
font_file.save()
if processed_glyph_count != seen_glyph_count:
print("Skipped %s of %s glyphs." %
(seen_glyph_count - processed_glyph_count, seen_glyph_count))
if not options.quiet_mode:
print("Done with font")