Skip to content

Commit

Permalink
Improved glyphbuilder script (by Barry Schwartz)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgd committed Jun 10, 2013
1 parent f46190f commit 91a5323
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions tools/glyphbuilder.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
import sys
import importlib
import fontforge


#def componentsByFontname(font, fontname):
# module_name = fontname + "_components"
# module = __import__(module_name)

def composeAccented(glyph):
def composeAccented(glyph, glyphComponents):
"""Compose accented glyphs.
Get the components from the dictionary and build the new glyph
Expand Down Expand Up @@ -52,27 +53,40 @@ def buildAccentedGlyphs(junk,object):
# Call the composing function for every glyph that has an entry
# in the dictionary."""
# componentsByFontname(font, font.fontname)
font_file = os.path.normpath(fontforge.activeFont().path)

font = object if type(object).__name__ == "font" else object.font
font_file = os.path.normpath(font.path)
top_level = os.path.split(os.path.split(font_file)[0])[0]
tool_path = os.path.join(top_level, "tools")
if tool_path not in sys.path:
sys.path.append(tool_path)

import_successful = True
try:
sys.path.append(tool_path)
from glyphcomponents import glyphComponents

if type(object).__name__ == "font":
for glyph in object.selection.byGlyphs:
if glyph.glyphname in glyphComponents.keys():
composeAccented(glyph)
else:
continue
else:
if object.glyphname in glyphComponents.keys():
composeAccented(object)
else:
logWarning('This glyph has no entry in the dictionary')
except ImportError:
glyphcomponents = importlib.import_module("glyphcomponents")
except:
import_successful = False
fontforge.postError("Cannot import Python module glyphcomponents",
"This script is made to work with the SFDs residing in top_level/SFD and the module in top_level/tools.")
"This script is made to work with the SFDs residing in top_level/SFD and the module in top_level/tools.")

if import_successful:
try:
reload(glyphcomponents)
glyphComponents = glyphcomponents.glyphComponents

if type(object).__name__ == "font":
for glyph in object.selection.byGlyphs:
if glyph.glyphname in glyphComponents.keys():
composeAccented(glyph, glyphComponents)
else:
continue
else:
if object.glyphname in glyphComponents.keys():
composeAccented(object, glyphComponents)
else:
logWarning('This glyph has no entry in the dictionary')

except BaseException as e:
fontforge.postError("Building glyphs failed", str(e))

fontforge.registerMenuItem(buildAccentedGlyphs,None,None,("Font","Glyph"),None,"Glyphbuilder");

0 comments on commit 91a5323

Please sign in to comment.