Skip to content

Commit

Permalink
port varfont_info.py script into a gftools subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
felipesanches committed Nov 2, 2017
1 parent 99b3da4 commit 630e2bb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 38 deletions.
62 changes: 62 additions & 0 deletions bin/gftools-varfont-info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python2
# Copyright 2017 The Google Font Tools Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""
Lists which variable font axes and named-instances are
declared in the 'fvar' table of a given TTF file.
"""
import contextlib
import sys
from fontTools import ttLib

def _ResolveName(ttf, name_id):
if name_id == 0xFFFF:
return '[anonymous]'
names = [n for n in ttf['name'].names if n.nameID == name_id]
if not names:
return '[?nameID=%d?]' % name_id
unicode_names = [n for n in names if n.isUnicode()]
if unicode_names:
return unicode_names[0].toUnicode()
return names[0].toUnicode()


def main(argv):
if len(argv) < 2:
sys.exit(("{}\n"
"usage:\n"
" gftools varfont-info fontfile.ttf").format(__doc__))

for filename in argv[1:]:
with contextlib.closing(ttLib.TTFont(filename)) as ttf:
print (filename)
if 'fvar' not in ttf:
print ("This font file lacks an 'fvar' table.")
else:
fvar = ttf['fvar']
print (' axes')
axes = [(a.axisTag, a.minValue, a.defaultValue, a.maxValue)
for a in fvar.axes]
for tag, minv, defv, maxv in axes:
print (" '%s' %d-%d, default %d" % (tag, minv, maxv, defv))

if fvar.instances:
print (' named-instances')
for inst in fvar.instances:
print (' %s %s' % (_ResolveName(ttf, inst.postscriptNameID),
inst.coordinates))

if __name__ == '__main__':
main(sys.argv)
38 changes: 0 additions & 38 deletions varfont_info.py

This file was deleted.

0 comments on commit 630e2bb

Please sign in to comment.