Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example python script for glyph names #16

Open
davelab6 opened this issue Aug 5, 2013 · 3 comments
Open

Add example python script for glyph names #16

davelab6 opened this issue Aug 5, 2013 · 3 comments

Comments

@davelab6
Copy link
Member

davelab6 commented Aug 5, 2013

This python script was made by me an Andrew Miller [A.J.Miller@bcs.org.uk] and could be a nice example of python scripting; it renames all glyphs to the "AGL without afii" namelist:

import fontforge
font = fontforge.open("Font.sfd")
for glyph in font:
  if font[glyph].unicode != -1:
    font[glyph].glyphname = fontforge.nameFromUnicode (font[glyph].unicode, "AGL without afii")
@Welshmilla
Copy link

I've expanded the above into a generic cleanup script that loads a font and does some basic maintenance.

Andrew Miller

cleanup.py:

#! /usr/bin/env python
import fontforge
import sys

fontfile = sys.argv[1]

try:
    font = fontforge.open (fontfile)
except EnvironmentError:
    sys.exit (1)

font.selection.all ()
font.removeOverlap ()
font.simplify ()
font.correctDirection ()
font.round ()

for glyph in font:
    if font[glyph].unicode != -1:
        font[glyph].glyphname = fontforge.nameFromUnicode (font[glyph].unicode, "AGL without afii")

font.save (fontfile)

@davelab6
Copy link
Member Author

davelab6 commented Aug 8, 2013

Nice! :) Would be great to have some print() methods in there (or logging() etc) to tell the user what glyphs change in each step...

@mrmartin
Copy link

mrmartin commented Apr 6, 2018

Convenient script. Just watch out for removing overlaps before correcting the direction. This causes the removal of inpainted regions before they get a chance to be fixed.

Do this instead:

font.selection.all ()
font.correctDirection ()
font.removeOverlap ()
font.simplify ()
font.round ()

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

No branches or pull requests

3 participants