Skip to content

Instantly share code, notes, and snippets.

@flozz
Created May 12, 2017 07:28
Show Gist options
  • Save flozz/0454806fdbf760e290329dda24c45fd2 to your computer and use it in GitHub Desktop.
Save flozz/0454806fdbf760e290329dda24c45fd2 to your computer and use it in GitHub Desktop.
Converts fonts using FontForge
#!/usr/bin/env python
## To allow this script to work, you must install FontForge with its Python
## extention. On Debian / Ubuntu, this can be done with the following command:
##
## apt install fontforge python-fontforge
## usage: font-convertor.py [-h] input_file output_file
##
## Converts fonts using FontForge
##
## positional arguments:
## input_file input font file
## output_file output file name. The format is determined using the file's
## extension.
##
## optional arguments:
## -h, --help show this help message and exit
## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
## Version 2, December 2004
##
## Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
##
## Everyone is permitted to copy and distribute verbatim or modified
## copies of this license document, and changing it is allowed as long
## as the name is changed.
##
## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
## TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
##
## 0. You just DO WHAT THE FUCK YOU WANT TO.
import argparse
import fontforge
def convert(input_file, output_file):
font = fontforge.open(input_file)
font.generate(output_file)
def cli():
parser = argparse.ArgumentParser(
description="Converts fonts using FontForge")
parser.add_argument("input",
help="input font file",
metavar = "input_file",
type=str)
parser.add_argument("output",
help="output file name. The format is determined using the file's extension.",
metavar = "output_file",
type=str)
args = parser.parse_args()
convert(args.input, args.output)
if __name__ == "__main__":
cli()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment