Skip to content

Instantly share code, notes, and snippets.

@lilydjwg
Last active July 12, 2023 14:27
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save lilydjwg/8877450 to your computer and use it in GitHub Desktop.
Save lilydjwg/8877450 to your computer and use it in GitHub Desktop.
Convert .ttc to several .ttf files into the current directory
#!/usr/bin/env python3
import sys
import fontforge
def main(file):
for font in fontforge.fontsInFile(file):
f = fontforge.open(u'%s(%s)' % (file, font))
f.generate('%s.ttf' % font)
if __name__ == '__main__':
if len(sys.argv) != 2:
sys.exit('one ttc file one time.')
main(sys.argv[1])
@billyromano
Copy link

billyromano commented Apr 27, 2017

I can't get this to work on Mac OS X El Capitan. I've installed XQuartz, Fontforge and Python 3.5 to try and run the script. Doesn't work. Here's the error I get:

Traceback (most recent call last):
  File "./ttc2ttf", line 4, in <module>
    import fontforge
ImportError: No module named 'fontforge'

Any instruction or idea of what to do?

@lilydjwg
Copy link
Author

@billyromano your fontforge doesn't install a Python module. I don't know why. Maybe you need to build fontforge with some custom flags.
PS: there was no notifications for Gist comments :-(

@erikogan
Copy link

erikogan commented May 8, 2018

@billyromano A year late, but I came across this gist and it worked for me with fontforge installed via Homebrew once I changed the shebang to use python2.7 instead of python3.

@prantlf
Copy link

prantlf commented Jul 19, 2018

As the others wrote, the script works, if:

  1. Fontforge is installed and python bindings for it too.
  2. If installed via Homebrew or from Ubuntu repository, the python version in the shebang has to be 2.

How to install Fontforge on Ubuntu:

sudo apt-get install fontforge python-fontforge 

@acbetter
Copy link

For macOS user, you may need the brew install fontforge and use system python2 (/usr/local/bin/python2.7).

@c02y
Copy link

c02y commented Jan 25, 2021

Thanks, it works here on Manjaro, I only need to install fontforge first.

Sad thing is, it removed a lot of info in the ttc font, such as the font name is empty, font version becomes 1.0, no Copyright, no Designer, no Layout Features.

And most importantly, the name of the font is blank in my Kobo eReader, and it doesn't work at all after I select the font.

@lilydjwg
Copy link
Author

@c02y Is your .ttc file a TrueType font collection or an OpenType font collection? Generating ttf from an OpenType font will result in information loss (and you may try to generate a .otf instead). The file command can tell you which type your file is.

@c02y
Copy link

c02y commented Jan 26, 2021

@lilydjwg Yes, it is "OpenType font collection", actually I already tried Fontforge to convert the ttc to ttf months ago, it was the same result, since the script is using fontforge, so I guess they are the same things.

I already found a better solution: https://github.com/DavidBarts/getfonts and successfully extract the ttc to multiple ttfs, they are working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment