Script to generate kerning strings for MetricsMachine

Ramiro EspinozaRamiro Espinoza Posts: 511
edited January 17 in Technique and Theory
Hi there,

I love using MetricsMachine, but I've never liked the fact I can't use my Fontlab kerning text files. Metrics machine uses 2 different kind of kerning text files: one for single pairs and another one that let you set and compare strings.
Setting strings is key (e.g. when setting the kerning in capitals, when comparing kern symmetry and when kerning quotes), but the problem is making string kerning lists for MM by hand is a pain and tools like Impallari's kerning list maker (http://www.impallari.com/testing/) only let you make the simplest kind of kerning text files.

So I've made a simple Python script to automatically generate string kerning text files. Feel free to use/improve it.
# ReType's Make string kerning lists for MetricsMachine

# Tweak / Comment from line 4 to 7 if you are using a PC.
import sys
sys.dont_write_bytecode = True
f = open(title + '.txt', 'w')
sys.stdout = f

# Set the title
title = 'UC_symmetry'

# Set your own strings
string_1 = 'AVAWATAYAVSVSWSW'
string_2 = 'AOAQAPAFASAYSY'
string_3 = 'OVOWOTOYO'


print '#KPL:W: '+ title

for x in range((len(string_1))-1):
	stringlist = list(string_1)
	stringlist.insert(x+1,' ')
	print ''.join(stringlist)
	
for x in range((len(string_2))-1):
	stringlist = list(string_2)
	stringlist.insert(x+1,' ')
	print ''.join(stringlist)
	
for x in range((len(string_3))-1):
	stringlist = list(string_3)
	stringlist.insert(x+1,' ')
	print ''.join(stringlist) 

Comments

  • Ramiro EspinozaRamiro Espinoza Posts: 511
    edited December 2015
    I've made a more efficient version with a function:
    # ReType's Make string kerning lists for MetricsMachine
    
    # Set the title
    title = 'UC_symmetry'
    
    # Tweak / Comment from line 7 to 10 if you are using a PC.
    import sys
    sys.dont_write_bytecode = True
    f = open(title + '.txt', 'w')
    sys.stdout = f
    
    print '#KPL:W: '+ title
    
    def Make_kerning_list(string):
    	for x in range((len(string))-1):
    		stringlist = list(string)
    		stringlist.insert(x+1,' ')
    		print ''.join(stringlist)
    		
    # Set your own strings
    Make_kerning_list('AVAWATAYAVSVSWSW')
    Make_kerning_list('AOAQAPAFASAYSY')
    Make_kerning_list('OVOWOTOYO')
  • Ramiro EspinozaRamiro Espinoza Posts: 511
    edited January 18
    Hi there,

    I just updated my script so it now can take strings set with slashes (for example: "/one.lf/period/two.lf/period ...etc"
    Now it is way simpler to adapt your Fontlab strings to MetricsMachine

    # ReType's Make string kerning lists for MetricsMachine 3.0
    
    # Set the title
    title = 'MetricMachine_kerning_block'
    
    # Tweak / Comment from line 7 to 10 if you are using a PC.
    import sys
    sys.dont_write_bytecode = True
    f = open(title + '.txt', 'w')
    sys.stdout = f
    
    print '#KPL:W: '+ title
    
    def makeString(string):
    	list = string.split()
    	for x in range(len(list) - 1):
    		list.insert(x + 1, ' ')
    		print ''.join(list)
    		list.pop(x + 1)
    
    #Example: format your string in this way (space separated)
    makeString( '/one.lf /comma /two.lf /comma /three.lf /comma /four.lf /comma /five.lf /comma /six.lf /comma /seven.lf /comma /eight.lf /comma /nine.lf' )
    
    


  • thank you for sharing this! pretty helpful I think! Somehow in my case with RF the saved txt file was empty when I tried your example with /glyphnames. I modified it a bit and now it is working here - also added a fontpath as a variable:

    # ReType's Make string kerning lists for MetricsMachine 3.1 
    import sys
    # Set the title and path for export .txt
    title = 'MetricMachine_kerning_block'
    fontPath = "/Users/yourUserName/Desktop/"
    
    finallist = []
    finallist.append('#KPL:W: '+ title)
    
    def makeString(string):
    	list = string.split()
    	for x in range(len(list) - 1):
    		list.insert(x + 1, ' ')
    		finallist.append(str(''.join(list)))
    		list.pop(x + 1)
    
    def exportFile():
        f = open(fontPath+title + '.txt', 'w')
        f.write('\n'.join(finallist))
        f.close
        
    #Example: format your string in this way (space separated)
    makeString( '/one.lf /comma /two.lf /comma /three.lf /comma /four.lf /comma /five.lf /comma /six.lf /comma /seven.lf /comma /eight.lf /comma /nine.lf' )
    # write the file
    exportFile()<br>
  • Ramiro EspinozaRamiro Espinoza Posts: 511
    edited January 18
    Hi Lukas,

    Thanks for the contribution. I should have said I wasn't running the script from Robofont or Fontlab. It was intended to be run with Terminal (actually, I do it from TextWrangler).
Sign In or Register to comment.