Skip to content

Commit

Permalink
Merge pull request #546 from googlefonts/black
Browse files Browse the repository at this point in the history
Updated and ran black
  • Loading branch information
rsheeter authored Sep 8, 2021
2 parents 86ab5bb + 0eaa3fa commit 801cdc0
Show file tree
Hide file tree
Showing 33 changed files with 606 additions and 556 deletions.
72 changes: 36 additions & 36 deletions nototools/android_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@
def patch_hyphen(srcdir, dstdir, copy_unchanged=True):
"""Add hyphen-minus glyphs to fonts that need it.
This is to enable languages to be hyphenated properly,
since Minikin's itemizer currently shows tofus if an
automatically hyphenated word is displated in a font
that has neither HYPHEN nor HYPHEN-MINUS.
This is to enable languages to be hyphenated properly,
since Minikin's itemizer currently shows tofus if an
automatically hyphenated word is displated in a font
that has neither HYPHEN nor HYPHEN-MINUS.
The list of font names comes from LANG_TO_SCRIPT in
tools/font/fontchain_lint.py.
The list of font names comes from LANG_TO_SCRIPT in
tools/font/fontchain_lint.py.
(In practice only U+002D HYPHEN-MINUS is added, since Noto LGC fonts
don't have U+2010 HYPHEN.)
(In practice only U+002D HYPHEN-MINUS is added, since Noto LGC fonts
don't have U+2010 HYPHEN.)
Bug: 21570828"""
Bug: 21570828"""

# Names of fonts for which Android requires a hyphen.
# This list omits Japanese and Korean.
Expand Down Expand Up @@ -106,15 +106,15 @@ def patch_hyphen(srcdir, dstdir, copy_unchanged=True):

def _remove_cjk_emoji(cjk_font_names, srcdir, dstdir):
"""
Remove default emoji characters from CJK fonts.
Remove default emoji characters from CJK fonts.
Twenty-six characters that Unicode Technical Report #51 "Unicode
Emoji" defines as defaulting to emoji styles used to be displayed as
black and white ("text" style) before this. This patch removes those
characters from Noto CJK fonts, so they get displayed as color.
Twenty-six characters that Unicode Technical Report #51 "Unicode
Emoji" defines as defaulting to emoji styles used to be displayed as
black and white ("text" style) before this. This patch removes those
characters from Noto CJK fonts, so they get displayed as color.
(1c4749e20391a4)
"""
(1c4749e20391a4)
"""

# Since subsetting changes tables in a way that would prevent a compact
# .ttc file, this simply removes entries from the cmap table. This
Expand Down Expand Up @@ -190,7 +190,7 @@ def _remove_from_cmap(infile, outfile, exclude=[]):

def patch_cjk_ttc(ttc_srcfile, ttc_dstfile):
"""Take the source ttc, break it apart, remove the cjk emoji
from each file, then repackage them into a new ttc."""
from each file, then repackage them into a new ttc."""

tmp_dir = tempfile.mkdtemp()
font_names = ttc_utils.ttcfile_extract(ttc_srcfile, tmp_dir)
Expand All @@ -205,7 +205,7 @@ def patch_cjk_ttc(ttc_srcfile, ttc_dstfile):

def patch_cjk_ttcs(srcdir, dstdir):
"""Call patch_cjk_ttc for each ttc file in srcdir, writing the
result to dstdir using the same name."""
result to dstdir using the same name."""

if not path.isdir(srcdir):
print("%s is not a directory" % srcdir)
Expand Down Expand Up @@ -349,30 +349,30 @@ def _format_set(char_set, name, filename):
def subset_symbols(srcdir, dstdir):
"""Subset Noto Sans Symbols in a curated way.
Noto Sans Symbols is now subsetted in a curated way. Changes include:
Noto Sans Symbols is now subsetted in a curated way. Changes include:
* Currency symbols now included in Roboto are removed.
* Currency symbols now included in Roboto are removed.
* All combining marks for symbols (except for combining keycap) are
added, to combine with other symbols if needed.
* All combining marks for symbols (except for combining keycap) are
added, to combine with other symbols if needed.
* Characters in symbol blocks that are also covered by Noto CJK fonts
are added, for better harmony with the rest of the fonts in non-CJK
settings. The dentistry characters at U+23BE..23CC are not added,
since they appear to be Japan-only and full-width.
* Characters in symbol blocks that are also covered by Noto CJK fonts
are added, for better harmony with the rest of the fonts in non-CJK
settings. The dentistry characters at U+23BE..23CC are not added,
since they appear to be Japan-only and full-width.
* Characters that UTR #51 defines as default text are added, although
they may also exist in the color emoji font, to make sure they get
a default text style.
* Characters that UTR #51 defines as default text are added, although
they may also exist in the color emoji font, to make sure they get
a default text style.
* Characters that UTR #51 defines as default emoji are removed, to
make sure they don't block the fallback to the color emoji font.
* Characters that UTR #51 defines as default emoji are removed, to
make sure they don't block the fallback to the color emoji font.
* A few math symbols that are currently included in Roboto are added,
to prepare for potentially removing them from Roboto when they are
lower-quality in Roboto.
* A few math symbols that are currently included in Roboto are added,
to prepare for potentially removing them from Roboto when they are
lower-quality in Roboto.
Based on subset_noto_sans_symbols.py from AOSP external/noto-fonts."""
Based on subset_noto_sans_symbols.py from AOSP external/noto-fonts."""

# TODO see if we need to change this subset based on Noto Serif coverage
# (so the serif fallback chain would support them)
Expand Down Expand Up @@ -429,7 +429,7 @@ def patch_post_table(srcdir, dstdir):

def patch_fonts(srcdir, dstdir):
"""Remove dstdir and repopulate with patched contents of srcdir (and
its 'cjk' subdirectory if it exists)."""
its 'cjk' subdirectory if it exists)."""

srcdir = tool_utils.resolve_path(srcdir)
dstdir = tool_utils.resolve_path(dstdir)
Expand Down
36 changes: 18 additions & 18 deletions nototools/autofix_for_phase3.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def _check_version(version):

def _check_version_info(version_info):
"""ensure version info looks reasonable, for example:
'GOOG;noto-fonts:20170220:a8a215d2e889'. Raise an exception
if it does not."""
'GOOG;noto-fonts:20170220:a8a215d2e889'. Raise an exception
if it does not."""
m = _version_info_re.match(version_info)
if not m:
raise Exception(
Expand Down Expand Up @@ -89,7 +89,7 @@ def _check_version_info(version_info):

def _get_version_info(fonts):
"""If fonts are all from noto-fonts, use information from the current
state of the repo to build a version string. Otherwise return None."""
state of the repo to build a version string. Otherwise return None."""

# add '/' to distinguish between noto-fonts/ and noto-fonts-alpha/
for repo_tag in ["[fonts]", "[fonts_alpha]", "[source]"]:
Expand Down Expand Up @@ -137,7 +137,7 @@ def _check_autohint(script):

def _expand_font_names(font_names, result=None):
"""font names can include names of files containing a list of names, open
those recursively and add to the set."""
those recursively and add to the set."""

def strip_comment(line):
ix = line.find("#")
Expand Down Expand Up @@ -240,14 +240,14 @@ def _mm_to_version_str(mm):

def get_new_version(font, relfont, nversion):
"""Return a new version number. font is the font we're updating,
relfont is the released version of this font if it exists, or None,
and nversion is the new version, 'keep', or None. If a new version is
passed to us, use it unless it is lower than either existing version,
in which case we raise an exception. If the version is 'keep' and
there is an existing release version, keep that. Otherwise bump the
release version, if it exists, or convert the old version to a 2.0 version
as appropriate. If the old version is a 2.0 version (e.g. Armenian was
was '2.30' in phase 2), that value is mapped to 2.40."""
relfont is the released version of this font if it exists, or None,
and nversion is the new version, 'keep', or None. If a new version is
passed to us, use it unless it is lower than either existing version,
in which case we raise an exception. If the version is 'keep' and
there is an existing release version, keep that. Otherwise bump the
release version, if it exists, or convert the old version to a 2.0 version
as appropriate. If the old version is a 2.0 version (e.g. Armenian was
was '2.30' in phase 2), that value is mapped to 2.40."""

version = _extract_version(font)
rversion = _extract_version(relfont) if relfont else None
Expand Down Expand Up @@ -311,8 +311,8 @@ def _is_ui_metrics(f):

def _autohint_code(f, script):
"""Return 'not-hinted' if we don't hint this, else return the ttfautohint
code, which might be None if ttfautohint doesn't support the script.
Note that LGC and MONO return None."""
code, which might be None if ttfautohint doesn't support the script.
Note that LGC and MONO return None."""

if script == "no-script":
return script
Expand Down Expand Up @@ -364,7 +364,7 @@ def _alert(val_name, cur_val, new_val):

def _alert_and_check(val_name, cur_val, expected_val, max_diff):
"""if max_diff >= 0, curval must be <= expected_val + maxdiff,
else curval must be >= expected_val + maxdiff"""
else curval must be >= expected_val + maxdiff"""
_alert(val_name, cur_val, expected_val)
if max_diff >= 0:
err = cur_val > expected_val + max_diff
Expand All @@ -376,9 +376,9 @@ def _alert_and_check(val_name, cur_val, expected_val, max_diff):

def _get_release_fontpath(f, rel_dir):
"""If rel_dir is not None, look for a font under 'hinted' or 'unhinted'
depending on which of these is in the path f. If neither is in f,
look under rel_dir, and then rel_dir/unhinted. If a match is found,
return the path."""
depending on which of these is in the path f. If neither is in f,
look under rel_dir, and then rel_dir/unhinted. If a match is found,
return the path."""

if rel_dir is None:
return None
Expand Down
14 changes: 7 additions & 7 deletions nototools/check_familyname_and_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@

def _get_stylenames(styles):
"""Returns the list of style names for the encoded styles. These are the
(master-ish) style names encoded as weights / widths / italic, where each
field is one of the above key values.
If there's not an italic then the italic is omitted, if there's only
regular width and no italic then widths are omitted."""
(master-ish) style names encoded as weights / widths / italic, where each
field is one of the above key values.
If there's not an italic then the italic is omitted, if there's only
regular width and no italic then widths are omitted."""
m = _extended_style_re.match(styles)
if not m:
raise ValueError('could not match style "%s"' % styles)
Expand Down Expand Up @@ -99,15 +99,15 @@ def check_familyname(name, styles):

def generate_family_filenames(name, styles):
"""Name is the family name portion of a Noto filename. Styles is the
encoding of the styles, see _get_stylenames."""
encoding of the styles, see _get_stylenames."""
stylenames = _get_stylenames(styles)
return [name + "-" + s + ".ttf" for s in stylenames]


def _for_all_familynames(namefile, fn):
"""Call fn passing the family name and style descriptor for
all families in namefile. '#' is a comment to eol, blank lines are
ignored."""
all families in namefile. '#' is a comment to eol, blank lines are
ignored."""
styles = None
with open(namefile, "r") as f:
for name in f:
Expand Down
6 changes: 3 additions & 3 deletions nototools/cldr_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def get_exemplar_and_source(loc_tag):

def loc_tag_to_lsrv(loc_tag):
"""Convert a locale tag to a tuple of lang, script, region, and variant.
Supplies likely script if missing."""
Supplies likely script if missing."""
m = LSRV_RE.match(loc_tag)
if not m:
if _DEBUG:
Expand Down Expand Up @@ -732,8 +732,8 @@ def _init_lang_scr_to_lit_pops():

def get_lang_scr_to_lit_pops():
"""Return a mapping from lang_scr to a list of tuples of region and
population sorted in descending order by population.
"""
population sorted in descending order by population.
"""
if not _lang_scr_to_lit_pops:
_init_lang_scr_to_lit_pops()
return _lang_scr_to_lit_pops
Expand Down
32 changes: 19 additions & 13 deletions nototools/cmap_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

def _prettify(root, indent=""):
"""Pretty-print the root element if it has no text and children
by adding to the root text and each child's tail."""
by adding to the root text and each child's tail."""
if not root.text and len(root):
indent += " "
sfx = "\n" + indent
Expand Down Expand Up @@ -163,9 +163,9 @@ def create_metadata(program, args=None, date=datetime.date.today()):

def create_table(header, rows):
"""Create a TableData object from the header and rows. Header
is a string, rows is a list of strings. In each, columns are
separated by ',' which cannot otherwise appear in the text.
Each row must have the same number of columns as the header does."""
is a string, rows is a list of strings. In each, columns are
separated by ',' which cannot otherwise appear in the text.
Each row must have the same number of columns as the header does."""
header = [t.strip() for t in header.split(",")]
RowData = collections.namedtuple("RowData", header)
rowdatas = []
Expand All @@ -182,14 +182,14 @@ def create_table(header, rows):

def create_table_from_map(script_to_cmap):
"""Create a table from a map from script to cmaps. Outputs
the script code, script name, count of code points, the
codepoint ranges in hex separated by space, the count of
excluded/fallback code points, and their ranges separated by
space. script_to_cmap can have values either of cmap or of
a tuple of cmap, xcmap; in the first case xcmap is assumed
None. xcmaps that are None are marked as having an xcount of -1.
This makes it possible to distinguish an empty xcmap from one
that doesn't exist."""
the script code, script name, count of code points, the
codepoint ranges in hex separated by space, the count of
excluded/fallback code points, and their ranges separated by
space. script_to_cmap can have values either of cmap or of
a tuple of cmap, xcmap; in the first case xcmap is assumed
None. xcmaps that are None are marked as having an xcount of -1.
This makes it possible to distinguish an empty xcmap from one
that doesn't exist."""

table_header = "script,name,count,ranges,xcount,xranges".split(",")
RowData = collections.namedtuple("RowData", table_header)
Expand Down Expand Up @@ -224,7 +224,13 @@ def create_map_from_table(table):

def _test():
meta = create_metadata("test", [("this", 5), ("that", 12.3)])
table = create_table("foo,bar", ["1,5.3", "2,6.4",])
table = create_table(
"foo,bar",
[
"1,5.3",
"2,6.4",
],
)
cmapdata = CmapData(meta, table)
print(cmapdata)
xml_text = write_cmap_data(cmapdata)
Expand Down
4 changes: 2 additions & 2 deletions nototools/collect_cldr_punct.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def _get_cldr_files(cldr_dirs):

def _collect_script_to_punct(files):
"""Builds script to punct from provided cldr files. Builds 'LGC'
data from component scripts. Adds ASCII single and double quotes if
corresponding quotes are in the punct."""
data from component scripts. Adds ASCII single and double quotes if
corresponding quotes are in the punct."""

script_to_punct = collections.defaultdict(set)
curly_quotes_to_standard = [
Expand Down
10 changes: 5 additions & 5 deletions nototools/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
def character_set(font):
"""Returns the character coverage of a font.
Args:
font: The input font's file name, or a TTFont.
Args:
font: The input font's file name, or a TTFont.
Returns:
A frozenset listing the characters supported in the font.
"""
Returns:
A frozenset listing the characters supported in the font.
"""
if isinstance(font, str):
font = ttLib.TTFont(font, fontNumber=0)
cmap_table = font["cmap"]
Expand Down
8 changes: 4 additions & 4 deletions nototools/create_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@

def setup_fonts_conf():
"""We first look for fonts.conf under the root nototools, and if we don't
find it we write it. The fontconfig cache also goes there. This of course
requires nototools to be writable."""
find it we write it. The fontconfig cache also goes there. This of course
requires nototools to be writable."""

# We require notoconfig because we don't know where this code is located,
# nor whether the font directories might be relative to it.
Expand Down Expand Up @@ -129,7 +129,7 @@ def __repr__(self):

def make_drawparams(**kwargs):
"""Create a DrawParams from kwargs, but converting weight, style, and stretch
from values from string to the pango value types if needed."""
from values from string to the pango value types if needed."""
dp = DrawParams(**kwargs)
dp.weight = _get_weight(kwargs.get("weight", "normal"))
dp.style = _get_style(kwargs.get("style", "normal"))
Expand Down Expand Up @@ -291,7 +291,7 @@ def create_png(text, output_path, **kwargs):

def create_img(text, output_path, **kwargs):
"""Creates a PNG or SVG image based on the output_path extension,
from the given text"""
from the given text"""
ext = (path.splitext(output_path)[1]).lower()
if ext == ".png":
create_png(text, output_path, **kwargs)
Expand Down
8 changes: 6 additions & 2 deletions nototools/dump_otl.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ def printable_glyph_list(glyph_list, quote=False):

def dump_lang_sys(script, lang, lang_sys):
"""Dumps a language system."""
print("%s %s:" % (script, lang),)
print(
"%s %s:" % (script, lang),
)
assert lang_sys.LookupOrder is None
if lang_sys.ReqFeatureIndex != 65535:
print("<%s>" % lang_sys.ReqFeatureIndex,)
print(
"<%s>" % lang_sys.ReqFeatureIndex,
)
print(lang_sys.FeatureIndex)


Expand Down
Loading

0 comments on commit 801cdc0

Please sign in to comment.