Skip to content

Instantly share code, notes, and snippets.

@fdiary
Created September 19, 2019 17:59
Show Gist options
  • Save fdiary/384c37f2265ff2bdca87c974b099793e to your computer and use it in GitHub Desktop.
Save fdiary/384c37f2265ff2bdca87c974b099793e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#
# Usage:
# fontforge -script generate_comic_font.py gothic.ttf mincho.ttf
import fontforge
import os
import sys
gothic_font_path = sys.argv[1]
mincho_font_path = sys.argv[2]
ff = fontforge.open(gothic_font_path)
mincho_ff = fontforge.open(mincho_font_path)
new_sfnt_names = tuple(
(i[0], i[1], 'Comic ' + i[2] if i[1] in ('Family', 'Fullname', 'Preferred Family', 'Trademark', 'UniqueID') else i[2])
for i in ff.sfnt_names
)
ff.sfnt_names = new_sfnt_names
ff.fontname = 'Comic-' + ff.fontname
ff.familyname = 'Comic ' + ff.familyname
ff.fullname = 'Comic ' + ff.fullname
for range_start, range_end in (
(0x3040, 0x309f), # Hiragana
(0x30a0, 0x30ff), # Katakana
(0x31f0, 0x31ff), # Katakana Phonetic Extensions
):
mincho_ff.selection.select(('ranges', 'unicode'), range_start, range_end)
mincho_ff.copy()
ff.selection.select(('ranges', 'unicode'), range_start, range_end)
ff.paste()
ff.generate('Comic-' + os.path.splitext(os.path.basename(gothic_font_path))[0] + '.ttf')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment