Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
## Step 1: Cross-family tests
## * Validates consistency of data throughout all TTF files
## in a given family
## * The list of TTF files in infered from the METADATA.pb file
## * We avoid testing the same family twice by deduplicating the
## list of METADATA.pb files first
###########################################################################
metadata_to_check = []
for target in fonts_to_check:
metadata = os.path.join(family_dir, "METADATA.pb")
if not os.path.exists(metadata):
logging.error("'{}' is missing"
" a METADATA.pb file!".format(target))
else:
family = get_FamilyProto_Message(metadata)
if family is None:
logging.warning("Could not load data from METADATA.pb.")
elif family not in metadata_to_check:
metadata_to_check.append([family_dir, family])
for dirname, family in metadata_to_check:
ttf = {}
for f in family.fonts:
if not os.path.exists(os.path.join(dirname, f.filename)):
logging.warning(("METADATA.pb references a TTF file"
" that is missing: "
"'{}'").format(os.path.join(dirname, f.filename)))
continue
if font_key(f) in ttf.keys():
# I think this will likely never happen. But just in case...
checks.check_that_glyph_names_do_not_exceed_max_length(fb, font)
##########################################################
## Metadata related checks:
##########################################################
skip_gfonts = False
is_listed_in_GFD = False
metadata = os.path.join(family_dir, "METADATA.pb")
if not os.path.exists(metadata):
logging.warning(("{} is missing a METADATA.pb file!"
" This will disable all Google-Fonts-specific checks."
" Please considering adding a METADATA.pb file to the"
" same folder as the font files.").format(filename))
skip_gfonts = True
else:
family = get_FamilyProto_Message(metadata)
if family is None:
logging.warning("Could not load data from METADATA.pb.")
skip_gfonts = True
break
fb.default_target = metadata
checks.check_METADATA_Ensure_all_TTF_references_are_valid(fb, family)
checks.check_METADATA_Ensure_designer_simple_short_name(fb, family)
is_listed_in_GFD = checks.check_family_is_listed_in_GFDirectory(fb,
family)
checks.check_METADATA_Designer_exists_in_GWF_profiles_csv(fb, family)
checks.check_METADATA_has_unique_full_name_values(fb, family)
checks.check_METADATA_check_style_weight_pairs_are_unique(fb, family)
checks.check_METADATA_license_is_APACHE2_UFL_or_OFL(fb, family)
checks.check_METADATA_contains_at_least_menu_and_latin_subsets(fb,
## Step 1: Cross-family tests
## * Validates consistency of data throughout all TTF files
## in a given family
## * The list of TTF files in infered from the METADATA.pb file
## * We avoid testing the same family twice by deduplicating the
## list of METADATA.pb files first
###########################################################################
metadata_to_check = []
for target in fonts_to_check:
metadata = os.path.join(family_dir, "METADATA.pb")
if not os.path.exists(metadata):
logging.error("'{}' is missing"
" a METADATA.pb file!".format(target))
else:
family = get_FamilyProto_Message(metadata)
if family is None:
logging.warning("Could not load data from METADATA.pb.")
elif family not in metadata_to_check:
metadata_to_check.append([family_dir, family])
for dirname, family in metadata_to_check:
ttf = {}
for f in family.fonts:
if font_key(f) in ttf.keys():
# I think this will likely never happen. But just in case...
logging.error("This is a fontbakery bug."
" We need to figure out a better hash-function"
" for the font ProtocolBuffer message."
" Please file an issue on"
" https://github.com/googlefonts"
"/fontbakery/issues/new")
monospace_detected)
##########################################################
## Metadata related checks:
##########################################################
skip_gfonts = False
is_listed_in_GFD = False
metadata = os.path.join(family_dir, "METADATA.pb")
if not os.path.exists(metadata):
logging.warning(("{} is missing a METADATA.pb file!"
" This will disable all Google-Fonts-specific checks."
" Please considering adding a METADATA.pb file to the"
" same folder as the font files.").format(filename))
skip_gfonts = True
else:
family = get_FamilyProto_Message(metadata)
if family is None:
logging.warning("Could not load data from METADATA.pb.")
skip_gfonts = True
break
fb.default_target = metadata
checks.check_METADATA_Ensure_designer_simple_short_name(fb, family)
is_listed_in_GFD = checks.check_family_is_listed_in_GFDirectory(fb,
family)
checks.check_METADATA_Designer_exists_in_GWF_profiles_csv(fb, family)
checks.check_METADATA_has_unique_full_name_values(fb, family)
checks.check_METADATA_check_style_weight_pairs_are_unique(fb, family)
checks.check_METADATA_license_is_APACHE2_UFL_or_OFL(fb, family)
checks.check_METADATA_contains_at_least_menu_and_latin_subsets(fb,
family)
def family_metadata(family_directory):
from google.protobuf import text_format
from fontbakery.utils import get_FamilyProto_Message
if family_directory:
try:
pb_file = os.path.join(family_directory, "METADATA.pb")
if os.path.exists(pb_file):
return get_FamilyProto_Message(pb_file)
except text_format.ParseError:
return None
def family_metadata(family_directory):
from fontbakery.utils import get_FamilyProto_Message
if family_directory:
pb_file = os.path.join(family_directory, "METADATA.pb")
if os.path.exists(pb_file):
return get_FamilyProto_Message(pb_file)