forked from googlefonts/gftools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
port varfont_info.py script into a gftools subcommand
(issue googlefonts#3)
- Loading branch information
1 parent
99b3da4
commit 630e2bb
Showing
2 changed files
with
62 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file was deleted.
Oops, something went wrong.