Rename the font file with PostScript name based file name
This CL also adds lint rules for matching the file name and PostScript name. Bug: 179952916 Test: m fontchain_lint Change-Id: I829840299b5d138cfec8924ce8f77e1371524a70
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -33,7 +33,7 @@ namespace {
|
|||||||
|
|
||||||
constexpr char kRobotoVariable[] = "/system/fonts/Roboto-Regular.ttf";
|
constexpr char kRobotoVariable[] = "/system/fonts/Roboto-Regular.ttf";
|
||||||
|
|
||||||
constexpr char kRegularFont[] = "/system/fonts/NotoSerif-Regular.ttf";
|
constexpr char kRegularFont[] = "/system/fonts/NotoSerif.ttf";
|
||||||
constexpr char kBoldFont[] = "/system/fonts/NotoSerif-Bold.ttf";
|
constexpr char kBoldFont[] = "/system/fonts/NotoSerif-Bold.ttf";
|
||||||
constexpr char kItalicFont[] = "/system/fonts/NotoSerif-Italic.ttf";
|
constexpr char kItalicFont[] = "/system/fonts/NotoSerif-Italic.ttf";
|
||||||
constexpr char kBoldItalicFont[] = "/system/fonts/NotoSerif-BoldItalic.ttf";
|
constexpr char kBoldItalicFont[] = "/system/fonts/NotoSerif-BoldItalic.ttf";
|
||||||
|
|||||||
@@ -11,6 +11,12 @@ from fontTools import ttLib
|
|||||||
|
|
||||||
EMOJI_VS = 0xFE0F
|
EMOJI_VS = 0xFE0F
|
||||||
|
|
||||||
|
#TODO(179952916): Rename CutiveMono and DancingScript
|
||||||
|
CANONICAL_NAME_EXCEPTION_LIST = [
|
||||||
|
'CutiveMono.ttf',
|
||||||
|
'DancingScript-Regular.ttf',
|
||||||
|
]
|
||||||
|
|
||||||
LANG_TO_SCRIPT = {
|
LANG_TO_SCRIPT = {
|
||||||
'as': 'Beng',
|
'as': 'Beng',
|
||||||
'be': 'Cyrl',
|
'be': 'Cyrl',
|
||||||
@@ -665,6 +671,53 @@ def check_cjk_punctuation():
|
|||||||
assert_font_supports_none_of_chars(record.font, cjk_punctuation, name)
|
assert_font_supports_none_of_chars(record.font, cjk_punctuation, name)
|
||||||
|
|
||||||
|
|
||||||
|
def getPostScriptName(font):
|
||||||
|
ttf = open_font(font)
|
||||||
|
nameTable = ttf['name']
|
||||||
|
for name in nameTable.names:
|
||||||
|
if name.nameID == 6 and name.platformID == 3 and name.platEncID == 1 and name.langID == 0x0409:
|
||||||
|
return str(name)
|
||||||
|
|
||||||
|
|
||||||
|
def getSuffix(font):
|
||||||
|
file_path, index = font
|
||||||
|
with open(path.join(_fonts_dir, file_path), 'rb') as f:
|
||||||
|
tag = f.read(4)
|
||||||
|
isCollection = tag == b'ttcf'
|
||||||
|
|
||||||
|
ttf = open_font(font)
|
||||||
|
isType1 = ('CFF ' in ttf or 'CFF2' in ttf)
|
||||||
|
|
||||||
|
if isType1:
|
||||||
|
if isCollection:
|
||||||
|
return '.otc'
|
||||||
|
else:
|
||||||
|
return '.otf'
|
||||||
|
else:
|
||||||
|
if isCollection:
|
||||||
|
return '.ttc'
|
||||||
|
else:
|
||||||
|
return '.ttf'
|
||||||
|
|
||||||
|
|
||||||
|
def check_canonical_name():
|
||||||
|
for record in _all_fonts:
|
||||||
|
file_name, index = record.font
|
||||||
|
if file_name in CANONICAL_NAME_EXCEPTION_LIST:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if index and index != 0:
|
||||||
|
continue
|
||||||
|
|
||||||
|
psName = getPostScriptName(record.font)
|
||||||
|
assert psName, 'PostScript must be defined'
|
||||||
|
|
||||||
|
suffix = getSuffix(record.font)
|
||||||
|
canonicalName = '%s%s' % (psName, suffix)
|
||||||
|
|
||||||
|
assert file_name == canonicalName, (
|
||||||
|
'%s is not a canonical name. Must be %s' % (file_name, canonicalName))
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global _fonts_dir
|
global _fonts_dir
|
||||||
target_out = sys.argv[1]
|
target_out = sys.argv[1]
|
||||||
@@ -682,6 +735,8 @@ def main():
|
|||||||
|
|
||||||
check_cjk_punctuation()
|
check_cjk_punctuation()
|
||||||
|
|
||||||
|
check_canonical_name()
|
||||||
|
|
||||||
check_emoji = sys.argv[2]
|
check_emoji = sys.argv[2]
|
||||||
if check_emoji == 'true':
|
if check_emoji == 'true':
|
||||||
ucd_path = sys.argv[3]
|
ucd_path = sys.argv[3]
|
||||||
|
|||||||
Reference in New Issue
Block a user