Copy font infos from one font to another

This example shows how to copy font info data from one open font to another.

# get the source font by namef1=AllFonts().getFontsByStyleName('Regular')[0]# get the destination font by namef2=AllFonts().getFontsByStyleName('Bold')[0]# a list of font.info attributes to copyattributes=['familyName','xHeight','openTypeNameDesigner',]# copy font.info data from f1 to f2forattrinattributes:# get value from source fontvalue=getattr(f1.info,attr)# set value in destination fontsetattr(f2.info,attr,value)

Generate fonts for all UFOs in folder

This script will first open a dialog for selecting a folder; it will then open each UFO file in the folder, without the UI, and generate an OpenType-CFF font for it.

importosfromvanilla.dialogsimportgetFolder# select folderfolder=getFolder('Select a folder with UFOs')[0]# make a subfolder for otfsotfsFolder=os.path.join(folder,'otfs')os.mkdir(otfsFolder)# iterate over all files in folderforfinos.listdir(folder):# if file has .ufo extensionifos.path.splitext(f)[-1]=='.ufo':# get full ufo pathufoPath=os.path.join(folder,f)# open ufo (without UI)font=OpenFont(ufoPath,showUI=False)# RF 1.8# font = OpenFont(ufoPath, showInterface=False) # RF 3.0# make otf pathotfPath=os.path.join(folder,f.replace('.ufo','.otf'))# generate otf fontfont.generate(path=otfPath,format='otf',decompose=True,checkOutlines=True)# close the ufofont.close()

Import a font into layer of current font

This script shows how to import all glyphs of a font into a layer of the current font. Notice how the source font is never opened in the UI: it is just loaded in memory. Note also how the glyphs are copied from one font to the other with a point pen.

# open a font without UIsrcFont=OpenFont(showInterface=False)# get the current fontf=CurrentFont()# create a layer name based on the familyName and styleName of the source fontlayerName="%s %s"%(srcFont.info.familyName,srcFont.info.styleName)# loop over all glyphs in the source fontforginsrcFont:# if the glyph doesn't exist in the current font, create a new glyphifg.namenotinf:f.newGlyph(g.name)# get the layered glyphlayerGlyph=f[g.name].getLayer(layerName)# get the point pen of the layer glyphpen=layerGlyph.getPointPen()# draw the points of the imported glyph into the layered glyphg.drawPoints(pen)# we are done :)print("done")