|
| 1 | +#!/usr/bin/env python2 |
| 2 | + |
| 3 | +import sys |
| 4 | +import psMat |
| 5 | +import re |
| 6 | +import os.path |
| 7 | + |
| 8 | +try: |
| 9 | + #Load the module |
| 10 | + import fontforge |
| 11 | + |
| 12 | +except ImportError: |
| 13 | + sys.stderr.write("FontForge module could not be loaded. Try installing fontforge python bindings\n") |
| 14 | + sys.exit(1) |
| 15 | + |
| 16 | +print "using fontforge package version: " + str(fontforge.__version__) |
| 17 | + |
| 18 | +sourceFont = fontforge.open(sys.argv[1]) |
| 19 | + |
| 20 | +# rename font |
| 21 | +fontname, style = re.match("^([^-]*)(?:(-.*))?$", sourceFont.fontname).groups() |
| 22 | +sourceFont.familyname = sourceFont.familyname + " Plus Nerd File Types" |
| 23 | +sourceFont.fullname = sourceFont.fullname + " Plus Nerd File Types" |
| 24 | +sourceFont.fontname = fontname + 'PlusNerdFileTypes' |
| 25 | +sourceFont.appendSFNTName('English (US)', 'Preferred Family', sourceFont.familyname) |
| 26 | +sourceFont.appendSFNTName('English (US)', 'Compatible Full', sourceFont.fullname) |
| 27 | + |
| 28 | +# glyph font |
| 29 | + |
| 30 | +sourceFont_em_original = sourceFont.em |
| 31 | + |
| 32 | +# glyph fonts |
| 33 | + |
| 34 | +#Open a font |
| 35 | +glyphFont1=fontforge.open("glyph-source-fonts/original-source.otf") |
| 36 | + |
| 37 | +#select unicodes: |
| 38 | +glyphFont1.selection.select(("ranges","unicode"),0xE500,0xE51D) |
| 39 | +#Copy those glyphs into the clipboard: |
| 40 | +glyphFont1.copy() |
| 41 | + |
| 42 | +#select unicodes: |
| 43 | +sourceFont.selection.select(("ranges","unicode"),0xE600,0xE61D) |
| 44 | +#paste the glyphs above in: |
| 45 | +sourceFont.paste() |
| 46 | + |
| 47 | +### even more glyphs |
| 48 | + |
| 49 | +##Open a font |
| 50 | +glyphFont2=fontforge.open("glyph-source-fonts/devicons.ttf") |
| 51 | +## @todo improve/fix |
| 52 | +sourceFont.em = glyphFont2.em |
| 53 | +##select unicodes: |
| 54 | +glyphFont2.selection.select(("ranges","unicode"),0xE600,0xE6A4) |
| 55 | +##Copy those glyphs into the clipboard |
| 56 | +glyphFont2.copy() |
| 57 | +# |
| 58 | +# |
| 59 | +## #select unicodes |
| 60 | +sourceFont.selection.select(("ranges","unicode"),0xE700,0xE7A4) |
| 61 | +##paste the glyphs above in: |
| 62 | +sourceFont.paste() |
| 63 | + |
| 64 | +# fix scaling of glyphs |
| 65 | +sourceFont.em = sourceFont_em_original |
| 66 | + |
| 67 | +extension = os.path.splitext(sourceFont.path)[1] |
| 68 | + |
| 69 | +# @todo later add option to generate the sfd? |
| 70 | +#sourceFont.save(sourceFont.fullname + ".sfd") |
| 71 | + |
| 72 | +sourceFont.generate(sourceFont.fullname + extension) |
| 73 | + |
| 74 | +print "Generated" |
| 75 | +print sourceFont.fullname |
| 76 | +print sourceFont.fontname |
| 77 | + |
0 commit comments