def scaleFont(source, destination, factor): font = OpenFont(source) factor = float(factor) # Transform metadata font.info.descender = font.info.descender * factor font.info.xHeight = font.info.xHeight * factor font.info.capHeight = font.info.capHeight * factor font.info.ascender = font.info.ascender * factor font.info.postscriptUnderlineThickness = font.info.postscriptUnderlineThickness * factor font.info.postscriptUnderlinePosition = font.info.postscriptUnderlinePosition * factor font.info.postscriptBlueValues = list( map(lambda x: x * factor, font.info.postscriptBlueValues)) # Transform glyphs for glyph in font: glyph.scaleBy(factor, None, True, True) for component in glyph.components: component.scaleBy(1 / factor) # Transform kerning font.kerning.scaleBy(factor) # Round everything and save font.info.round() font.save(destination)
Input: opsz 014 wdth 100 wght 900 lxtra 1.05 Input: opsz 144 wdth 100 wght 400 lxtra 1.20 """ if path == 'Amstelvar-Roman-opsz-min.ufo': m = 0.98 elif path == 'Amstelvar-Roman-wdthmin.ufo': m *= 1.1 elif path == 'Amstelvar-Roman-wdthmax.ufo': m *= 1.5 elif path == 'Amstelvar-Roman-wghtmax.ufo': m *= 1.4 elif path == 'Amstelvar-Roman-wghtmin.ufo': m *= 1.05 elif path == 'Amstelvar-Roman-opsz-max.ufo': m *= 1.20 print('|', path, '|', m, '|', xtraValue, '|') f.groups.clear() f.kerning.clear() for groupName, groupGlyphs in default.groups.items(): f.groups[groupName] = groupGlyphs f.kerning.update(default.kerning.asDict()) for pair in f.kerning: value = f.kerning[pair] f.kerning[pair] = int(round(value * m)) f.save() print('done')
print("Processing OpszMin") for ufo in set([m.path for m in doc.sources]): newUfo = ufo.replace('.ufo', '-OpszMin.ufo') shutil.copytree(ufo, newUfo) source = SourceDescriptor() source.path = newUfo source.familyName = familyName if "Light" in newUfo or "Thin" in newUfo: lightUfo = newUfo font = OpenFont(newUfo) tweakSpacing(font, adjustments['min']['offset'], adjustments['min']['percentage']) font.save() if adjustments['min']['scaleFactor'] != 1: factor = adjustments['min']['scaleFactor'] print('Scaling %s by %s' % (font.path, factor)) scaleFont(font.path, font.path, factor) source.location = {'Weight': wght['min'], 'Optical size': opsz['min']} source.styleName = "ThinMin" else: blackUfo = newUfo font = OpenFont(newUfo) tweakSpacing(font, adjustments['max']['offset'], adjustments['max']['percentage']) font.save()
slugName, slugInfo = slug slugComponents, slugUnicode = slugInfo setSlug(f, slugName, slugComponents) f[slugName].unicodes = [slugUnicode] if i != 0 and addMissingGlyphsFromDefault: print "Adding missing glyphs in sources from default..." for gname in src.keys(): g = src[gname] if g.name not in f or (g.name in f and not f[g.name].contours and not f[g.name].components): f.insertGlyph(g, name=g.name) f.save() masters2.append('temp/' + master) else: masters2 = masters print masters2 project = FontProject() project.run_from_ufos( masters2, output=("ttf-interpolatable" ), # FIXME this also build master_ttf and should not. remove_overlaps=False, reverse_direction=False, use_production_names=False) finder = lambda s: s.replace(pathReplace, "master_ttf_interpolatable/"