mirror of
https://github.com/google/fonts.git
synced 2024-12-25 09:45:01 +03:00
namelist.py: rewrite with fontTools
This commit is contained in:
parent
4fa312b5c9
commit
ac2d40351b
@ -1,6 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
# Copyright 2010, Google Inc.
|
||||
# Author: Raph Levien (<firstname.lastname>@gmail.com)
|
||||
#!/usr/bin/env python
|
||||
# Copyright 2015, Google Inc.
|
||||
# Author: Dave Crossland (dave@understandinglimited.com)
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -15,16 +14,25 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# namelist.py: A FontForge python script for generating namelist files.
|
||||
# namelist.py: A fontTools python script for generating namelist files
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# $ namelist.py Font.ttf NameList.nam
|
||||
import fontforge, sys
|
||||
def main(fontFile, namFile):
|
||||
font = fontforge.open(fontFile)
|
||||
font.saveNamelist(namFile)
|
||||
# $ namelist.py Font.ttf > NameList.nam
|
||||
import sys
|
||||
from fontTools.ttLib import TTFont
|
||||
from fontTools.unicode import Unicode
|
||||
|
||||
def main(file_name):
|
||||
excluded_chars = ["????", "SPACE", "NO-BREAK SPACE"]
|
||||
font = TTFont(file_name)
|
||||
for cmap in font["cmap"].tables:
|
||||
char_list = sorted(cmap.cmap.items())
|
||||
for item in char_list:
|
||||
item_description = Unicode[item[0]]
|
||||
if item_description not in excluded_chars:
|
||||
print hex(item[0]), item_description
|
||||
font.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
print "Font: " + sys.argv[1]
|
||||
print "Namelist: " + sys.argv[2]
|
||||
main(sys.argv[1], sys.argv[2])
|
||||
main(sys.argv[1])
|
||||
|
Loading…
Reference in New Issue
Block a user