Fontlab 5: How to 'Update [kern] feature' in all open fonts?

Hi there,

Does anyone know a Python command to 'Update [kern] feature' in all open fonts?

Thanks in advance.

Comments

  • <div>from FL import Feature, fl
    
    # loop through open fonts
    for ifont in range(len(fl)):
    	font = fl[ifont]
    
    	# generate 'kern' feature value
    	kern_feature_value = font.MakeKernFeature().value
    	# create 'kern' FontLab feature
    	kern_feature = Feature('kern', kern_feature_value)
    
    	# check for 'kern' feature index in current font if it already exists
    	kern_feature_i = None
    	for i, feature in enumerate(font.features):
    		if feature.tag == 'kern':
    			kern_feature_i = i
    			break
    
    	# delete current 'kern' feature if it exists
    	if kern_feature_i:
    		del font.features[kern_feature_i]
    
    	# add 'kern' feature to font features
    	font.features.append(kern_feature)
    
    	fl.UpdateFont(ifont)<br></div>
    This should work.
  • If you are updating, saving and closing vfb files you can use this call command but you will need to click OK in the dialog for each font.
    for i in range(len(fl)-1,-1,-1):<br>&nbsp;&nbsp;&nbsp; fl.CallCommand(33934)<br>&nbsp;&nbsp;&nbsp; fl.Save(fl.font.file_name)<br>&nbsp;&nbsp;&nbsp; fl.Close(fl.ifont)<br><br>
    Else you can do this which is similar to Jameson's above but works backwards through the list of opened fonts as each is saved and closed.
    <div>for ifont in range(len(fl)-1,-1,-1):<br>&nbsp;&nbsp;&nbsp; f = fl[ifont]<br>&nbsp;&nbsp;&nbsp; print f.full_name + "\n"<br><br>&nbsp;&nbsp;&nbsp; for i in range(len(f.features)-1,-1,-1):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if f.features[i].tag == 'kern':<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; del f.features[i]<br><br>&nbsp;&nbsp;&nbsp; f.features.append(Feature('kern', f.MakeKernFeature().value))<br><br>&nbsp;&nbsp;&nbsp; fl.UpdateFont(ifont)<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; fl.Save(f.file_name)<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; fl.Close(ifont)<br><br></div><br>

  • Thanks!