Skip to content

Commit

Permalink
Updated the fontforge script with glyphAdvanceWidths + reading actual…
Browse files Browse the repository at this point in the history
… EM height instead of assuming 1000. (#183)
  • Loading branch information
erikronstrom authored Mar 16, 2021
1 parent c288cba commit 57b34e9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions scripts/fontforge/generate_font_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def validateGlyph( glyph ):
sys.exit (1)

fontName = os.path.splitext( os.path.basename(fontFileName) )[0]
staffSpace = (font.em/4.)

log = open( outDir+fontName.lower()+'.log', 'w+' )
print >> log, ("\n# # # %s: checking data & generating metadata... # # #" % (fontFileName) )
Expand Down Expand Up @@ -160,6 +161,7 @@ def validateGlyph( glyph ):
print >> log
glyphBBoxes = dict()
glyphsWithAnchors = dict()
glyphAdvanceWidths = dict()
count = 0
undefCount = 0
started = False
Expand All @@ -169,19 +171,21 @@ def validateGlyph( glyph ):
count += 1
validateGlyph( g )
g.addExtrema();
bbox = [round(bb/250., 4) for bb in g.boundingBox()];
bbox = [round(bb/staffSpace, 4) for bb in g.boundingBox()];
bBoxSW = (bbox[0], bbox[1])
bBoxNE = (bbox[2], bbox[3])
glyphBBoxes[g.glyphname] = {'bBoxNE':bBoxNE, 'bBoxSW':bBoxSW}
if len( g.anchorPoints ) > 0:
anchors = dict()
for item in g.anchorPoints:
anchors[item[0]] = ( round(item[2]/250., 4), round(item[3]/250., 4) )
anchors[item[0]] = ( round(item[2]/staffSpace, 4), round(item[3]/staffSpace, 4) )
glyphsWithAnchors[g.glyphname] = anchors
glyphAdvanceWidths[g.glyphname] = round(g.width/staffSpace, 4)
else:
undefCount += 1
metadata["glyphBBoxes"] = glyphBBoxes
metadata["glyphsWithAnchors"] = glyphsWithAnchors
metadata["glyphAdvanceWidths"] = glyphAdvanceWidths
font.close()
print >> log, ( "\n%d defined glyphs processed (there are %d undefined glyphs)" % (count, undefCount-31) )
log.close()
Expand Down

0 comments on commit 57b34e9

Please sign in to comment.