Skip to content

Instantly share code, notes, and snippets.

@shuymn
Last active December 5, 2020 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shuymn/46a2ffc4b17cf25ac9a8ce55c1fc79e3 to your computer and use it in GitHub Desktop.
Save shuymn/46a2ffc4b17cf25ac9a8ce55c1fc79e3 to your computer and use it in GitHub Desktop.
import fontforge
import argparse
KATAKANA_LOWER_BOUND = 0x30A0
KATAKANA_UPPER_BOUND = 0x30FF
def remove_katakana_glyphs(input: str, output: str):
font = fontforge.open(input)
for glyph in font.glyphs():
point: int = glyph.unicode
if KATAKANA_LOWER_BOUND <= point <= KATAKANA_UPPER_BOUND:
font.removeGlyph(glyph)
font.fontname += '-Without-Katakana'
font.fullname += ' Without Katakana'
font.generate(output)
font.close()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('input', nargs=1, help='path to input font file')
parser.add_argument('output', nargs=1, help='path to output font file')
args = parser.parse_args()
input_file_path = args.input[0]
output_file_path = args.output[0]
remove_katakana_glyphs(input_file_path, output_file_path)
@shuymn
Copy link
Author

shuymn commented Dec 5, 2020

Example usage

 for file in *.otf; do python3 remove-katakana-glyphs.py ${file} modified/${file%.*}-Without-Katakana.otf &; done

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