1
0
mirror of https://github.com/google/fonts.git synced 2025-01-02 05:56:46 +03:00

Update tools. Most notably allow lower threshold for detecting -ext subsets.

This commit is contained in:
Rod Sheeter 2016-02-04 13:31:02 -08:00
parent 81f1b67e72
commit 472bda4848
6 changed files with 29 additions and 5 deletions

15
tools/add_font.py Executable file → Normal file
View File

@ -9,9 +9,19 @@ import time
import fonts_public_pb2 as fonts_pb2
from google.protobuf import text_format
from google.apputils import app
import gflags as flags
from util import google_fonts as fonts
FLAGS = flags.FLAGS
flags.DEFINE_integer('min_pct', 50,
'What percentage of subset codepoints have to be supported'
' for a non-ext subset.')
flags.DEFINE_integer('min_pct_ext', 10,
'What percentage of subset codepoints have to be supported'
' for a -ext subset.')
def _FileFamilyStyleWeights(fontdir):
@ -59,7 +69,9 @@ def _MakeMetadata(fontdir):
file_family_style_weights = _FileFamilyStyleWeights(fontdir)
first_file = file_family_style_weights[0].file
subsets = ['menu'] + [s[0] for s in fonts.SubsetsInFont(first_file, 50)]
subsets = ['menu'] + [s[0] for s in fonts.SubsetsInFont(first_file,
FLAGS.min_pct,
FLAGS.min_pct_ext)]
font_license = fonts.LicenseFromPath(fontdir)
@ -69,6 +81,7 @@ def _MakeMetadata(fontdir):
metadata.designer = 'Unknown'
metadata.category = 'SANS_SERIF'
metadata.license = font_license
subsets = sorted(subsets)
for subset in subsets:
metadata.subsets.append(subset)
metadata.date_added = time.strftime('%Y-%m-%d')

0
tools/compare_font.py Executable file → Normal file
View File

0
tools/sanity_check.py Executable file → Normal file
View File

0
tools/space_check.py Executable file → Normal file
View File

View File

@ -286,13 +286,16 @@ def CodepointFiles(subset):
return map(CodepointFileForSubset, files)
def SubsetsInFont(file_path, min_pct):
def SubsetsInFont(file_path, min_pct, ext_min_pct=None):
"""Finds all subsets for which we support > min_pct of codepoints.
Args:
file_path: A file_path to a font file.
min_pct: Min percent coverage to report a subset. 0 means at least 1 glyph.
25 means 25%.
ext_min_pct: The minimum percent coverage to report a -ext
subset supported. Used to admit extended subsets with a lower percent. Same
interpretation as min_pct. If None same as min_pct.
Returns:
A list of 3-tuples of (subset name, #supported, #in subset).
"""
@ -310,7 +313,11 @@ def SubsetsInFont(file_path, min_pct):
overlap = all_cps & subset_cps
if 100.0 * len(overlap) / len(subset_cps) > min_pct:
target_pct = min_pct
if ext_min_pct is not None and subset.endswith('-ext'):
target_pct = ext_min_pct
if 100.0 * len(overlap) / len(subset_cps) > target_pct:
results.append((subset, len(overlap), len(subset_cps)))
return results

8
tools/what_subsets.py Executable file → Normal file
View File

@ -12,12 +12,16 @@ FLAGS = flags.FLAGS
flags.DEFINE_integer('min_pct', 0,
'What percentage of subset codepoints have to be supported'
' to print.')
' for a non-ext subset.')
flags.DEFINE_integer('min_pct_ext', 0,
'What percentage of subset codepoints have to be supported'
' for a -ext subset.')
def main(argv):
for arg in argv[1:]:
for (subset, available, total) in fonts.SubsetsInFont(arg, FLAGS.min_pct):
subsets = fonts.SubsetsInFont(arg, FLAGS.min_pct, FLAGS.min_pct_ext)
for (subset, available, total) in subsets:
print '%s %s %d/%d' % (os.path.basename(arg), subset, available, total)