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

Snippet to alter sidebearings #1656

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Snippet to alter sidebearings
  • Loading branch information
simoncozens committed Jul 1, 2019
commit 6f7f3fcf8243d379514b6461395047ce4d578290
25 changes: 25 additions & 0 deletions Snippets/alter-sidebearings.py
@@ -0,0 +1,25 @@
#! /usr/bin/env python
# Alters the left and right sidebearings of a glyph

from __future__ import print_function, division, absolute_import
from fontTools.ttLib import TTFont

if len(sys.argv) != 5:
print("usage: alter-sidebearings.py in.ttf out.ttf glyphname newLSB newRSB")
sys.exit(1)

font = TTFont(sys.argv[1])
outfile = sys.argv[2]
glyphname = sys.argv[3]
newLSB = sys.argv[4]
newRSB = sys.argv[5]

assert "glyf" in font # OTF only for now.

oldWidth, oldLSB = font["hmtx"].metrics[glyphname]
oldRSB = oldWidth - max([f[0] for f in font["glyf"][glyphname].coordinates])
inkWidth = oldWidth - (oldLSB+oldRSB)
font["hmtx"].metrics[glyphname] = (newLSB+inkWidth+newRSB, newLSB)
font["glyf"][glyphname].coordinates -= (oldLSB-newLSB,0)

font.save(outfile)