Batch import SVG glyphs to FontForge and create TTF
Here is a Python script to batch Import SVG glyph files into FontForge and create TTF font automatically. Get FontForge first and install it.
Save this script as import_svg.py in the same folder there you have SVG-files.
On Windows:
- run C:\Program Files (x86)\FontForgeBuilds\fontforge-console.bat
- navigate to the folder with your SVG-files using 'cd <FOLDER_PATH>'
- Run Python script by using "ffpython import_svg.py"
# Batch Import SVG glyph files into FontForge and create TTF
# Get FontForge first and install it..
# On Windows:
# run C:\Program Files (x86)\FontForgeBuilds\fontforge-console.bat
# navigate to the folder using 'cd <FOLDER_PATH>'
# Run Python script by using "ffpython import_svg.py"
import fontforge, os, pathlib
str1=os.getcwd()
str2=str1.split('\\')
n=len(str2)
fontname = (str2[n-1])
uzer = os.getlogin()
font = fontforge.font() # new font
font.encoding = 'UnicodeFull'
font.version = '1.0'
font.weight = 'Regular'
font.fontname = fontname
font.familyname = fontname
font.fullname = fontname
svgFilePaths = pathlib.Path().glob("*.svg")
index = 41
for p in svgFilePaths:
    dec = p.stem.split(" ", 1)[0] 
    print(dec)
    glyph = font.createChar(index, dec)
    glyph.importOutlines(str(p))
    index += 1
font.generate(fontname + ".ttf")
# Extra code to create JSON for Iconion 
# (not neccessary, remove from here if you don't need it):
author = '  "author": "'+ uzer + '",'
link = '    "link"  : "https://sysnimda.blogspot.com/",'
nejm = '    "name"  : "'+ fontname +'"'
fontnejm = '    "font"  : "' + fontname +'.ttf",'
lines = ("{","\n",author,"\n",link,"\n",fontnejm,"\n",nejm,"\n","}")
filename = fontname + ".json"
f= open(filename,"w+")
f.writelines(lines)
f.close() 

I used it and it worked as expected, thanks
ReplyDelete