def github_gfonts_ttFont(ttFont, license): """Get a TTFont object of a font downloaded from Google Fonts git repository. """ if not license: return None from fontbakery.utils import download_file from fontTools.ttLib import TTFont from urllib.request import HTTPError LICENSE_DIRECTORY = { "OFL.txt": "ofl", "UFL.txt": "ufl", "LICENSE.txt": "apache" } filename = os.path.basename(ttFont.reader.file.name) fontname = filename.split('-')[0].lower() url = ("https://github.com/google/fonts/raw/master" "/{}/{}/{}").format(LICENSE_DIRECTORY[license], fontname, filename) try: fontfile = download_file(url) if fontfile: return TTFont(fontfile) except HTTPError: return None
def github_gfonts_ttFont(ttFont, license): """Get a TTFont object of a font downloaded from Google Fonts git repository. """ if not license: return from fontbakery.utils import download_file from fontTools.ttLib import TTFont from urllib.request import HTTPError LICENSE_DIRECTORY = { "OFL.txt": "ofl", "UFL.txt": "ufl", "LICENSE.txt": "apache" } filename = os.path.basename(ttFont.reader.file.name) fontname = filename.split('-')[0].lower() url = ("https://github.com/google/fonts/raw/master" "/{}/{}/{}").format(LICENSE_DIRECTORY[license], fontname, filename) try: fontfile = download_file(url) return TTFont(fontfile) except HTTPError: return None
def download_family_from_Google_Fonts(familyname): """Return a zipfile containing a font family hosted on fonts.google.com""" from zipfile import ZipFile from fontbakery.utils import download_file url_prefix = 'https://fonts.google.com/download?family=' url = '{}{}'.format(url_prefix, familyname.replace(' ', '+')) return ZipFile(download_file(url))
def download_family_from_Google_Fonts(familyname): """Return a zipfile containing a font family hosted on fonts.google.com""" from zipfile import ZipFile from fontbakery.utils import download_file url_prefix = 'https://fonts.google.com/download?family=' url = '{}{}'.format(url_prefix, familyname.replace(' ', '+')) return ZipFile(download_file(url))
def github_gfonts_description(ttFont, license): """Get the contents of the DESCRIPTION.en_us.html file from the google/fonts github repository corresponding to a given ttFont. """ if not license: return None from fontbakery.utils import download_file from urllib.request import HTTPError LICENSE_DIRECTORY = { "OFL.txt": "ofl", "UFL.txt": "ufl", "LICENSE.txt": "apache" } filename = os.path.basename(ttFont.reader.file.name) familyname = filename.split('-')[0].lower() url = ( f"https://github.com/google/fonts/raw/main" f"/{LICENSE_DIRECTORY[license]}/{familyname}/DESCRIPTION.en_us.html") try: descfile = download_file(url) if descfile: return descfile.read().decode('UTF-8') except HTTPError: return None
def main(): git_ofl_prefix = 'http://github.com/google/fonts/raw/master/ofl/' git_ufl_prefix = 'http://github.com/google/fonts/raw/master/ufl/' git_apache_prefix = 'http://github.com/google/fonts/raw/master/apache/' fonts_urls = [ git_ofl_prefix + 'sourceserifpro/SourceSerifPro-Bold.ttf', git_ofl_prefix + 'rosarivo/Rosarivo-Regular.ttf', git_ofl_prefix + 'raleway/Raleway-BlackItalic.ttf', git_ofl_prefix + 'librebaskerville/LibreBaskerville-Bold.ttf', git_ofl_prefix + 'worksans/WorkSans-Regular.ttf', git_ufl_prefix + 'ubuntu/Ubuntu-BoldItalic.ttf', git_ofl_prefix + 'vollkorn/Vollkorn-BlackItalic.ttf', git_ofl_prefix + 'breeserif/BreeSerif-Regular.ttf', git_ofl_prefix + 'carme/Carme-Regular.ttf', git_ofl_prefix + 'creteround/CreteRound-Regular.ttf', git_ofl_prefix + 'eczar/Eczar-Bold.ttf', git_ofl_prefix + 'faunaone/FaunaOne-Regular.ttf', git_ofl_prefix + 'hind/Hind-Light.ttf', git_ufl_prefix + 'ubuntumono/UbuntuMono-Bold.ttf', git_ofl_prefix + 'belgrano/Belgrano-Regular.ttf', git_ofl_prefix + 'trirong/Trirong-Light.ttf', git_ofl_prefix + 'mitr/Mitr-Regular.ttf', git_ofl_prefix + 'overpass/Overpass-Regular.ttf', git_ofl_prefix + 'jura/Jura-Regular.ttf', git_ofl_prefix + 'overpass/Overpass-Black.ttf', git_ofl_prefix + 'montserrat/Montserrat-Regular.ttf', git_ofl_prefix + 'montserrat/Montserrat-Black.ttf', git_ofl_prefix + 'montserrat/Montserrat-Thin.ttf', git_apache_prefix + 'roboto/Roboto-Regular.ttf', ] fonts_data = [] for font_url in fonts_urls: print('Downloading and generating glyph data for {}'.format(font_url)) font_ttf = download_file(font_url) font = TTFont(font_ttf) fonts_data.append(get_font_glyph_data(font)) print('Collating font data into glyph data file') glyph_data = collate_fonts_data(fonts_data) script_path = os.path.dirname(__file__) glyph_data_path = os.path.join( script_path, '..', 'Lib', 'fontbakery', 'desired_glyph_data.json' ) print('Saving to {}'.format(glyph_data_path)) with open(glyph_data_path, 'w') as glyph_file: json.dump(glyph_data, glyph_file, indent=4, cls=JsonSetEncoder) print('done')
def main(): git_ofl_prefix = 'http://github.com/google/fonts/raw/master/ofl/' git_ufl_prefix = 'http://github.com/google/fonts/raw/master/ufl/' git_apache_prefix = 'http://github.com/google/fonts/raw/master/apache/' fonts_urls = [ git_ofl_prefix + 'sourceserifpro/SourceSerifPro-Bold.ttf', git_ofl_prefix + 'rosarivo/Rosarivo-Regular.ttf', git_ofl_prefix + 'raleway/Raleway-BlackItalic.ttf', git_ofl_prefix + 'librebaskerville/LibreBaskerville-Bold.ttf', git_ofl_prefix + 'worksans/WorkSans-Regular.ttf', git_ufl_prefix + 'ubuntu/Ubuntu-BoldItalic.ttf', git_ofl_prefix + 'vollkorn/Vollkorn-BlackItalic.ttf', git_ofl_prefix + 'breeserif/BreeSerif-Regular.ttf', git_ofl_prefix + 'carme/Carme-Regular.ttf', git_ofl_prefix + 'creteround/CreteRound-Regular.ttf', git_ofl_prefix + 'eczar/Eczar-Bold.ttf', git_ofl_prefix + 'faunaone/FaunaOne-Regular.ttf', git_ofl_prefix + 'hind/Hind-Light.ttf', git_ufl_prefix + 'ubuntumono/UbuntuMono-Bold.ttf', git_ofl_prefix + 'belgrano/Belgrano-Regular.ttf', git_ofl_prefix + 'trirong/Trirong-Light.ttf', git_ofl_prefix + 'mitr/Mitr-Regular.ttf', git_ofl_prefix + 'overpass/Overpass-Regular.ttf', git_ofl_prefix + 'jura/Jura-Regular.ttf', git_ofl_prefix + 'overpass/Overpass-Black.ttf', git_ofl_prefix + 'montserrat/Montserrat-Regular.ttf', git_ofl_prefix + 'montserrat/Montserrat-Black.ttf', git_ofl_prefix + 'montserrat/Montserrat-Thin.ttf', git_apache_prefix + 'roboto/Roboto-Regular.ttf', ] fonts_data = [] for font_url in fonts_urls: print('Downloading and generating glyph data for {}'.format(font_url)) font_ttf = download_file(font_url) font = TTFont(font_ttf) fonts_data.append(get_font_glyph_data(font)) print('Collating font data into glyph data file') glyph_data = collate_fonts_data(fonts_data) script_path = os.path.dirname(__file__) glyph_data_path = os.path.join(script_path, '..', 'desired_glyph_data.json') print('Saving to {}'.format(glyph_data_path)) with open(glyph_data_path, 'w') as glyph_file: json.dump(glyph_data, glyph_file, indent=4, cls=JsonSetEncoder) print('done')
def main(): parser = ArgumentParser(description=__doc__) parser.add_argument('family', help='Name of font family') parser.add_argument('-wc', '--web-compare', help='Compare against a web url .zip family') parser.add_argument('-lc', '--local-compare', nargs='+', help='Compare against a set of local ttfs') args = parser.parse_args() google_family_zip = download_family_from_Google_Fonts(args.family) google_family_fonts = [f[1] for f in fonts_from_zip(google_family_zip)] google_family_version = parse_version_head(google_family_fonts) if args.web_compare: if args.web_compare.endswith('.zip'): web_family_zip = download_file(args.web_compare) web_family = fonts_from_zip(web_family_zip) web_family_fonts = [f[1] for f in web_family] web_family_name = set(f[0].split('-')[0] for f in web_family) web_family_version = parse_version_head(web_family_fonts) print('Google Fonts Version of %s is v%s' % (args.family, google_family_version)) print('Web Version of %s is v%s' % (', '.join(web_family_name), web_family_version)) elif args.local_compare: local_family = [TTFont(f) for f in args.local_compare] local_family_version = parse_version_head(local_family) local_fonts_name = set( basename(f.split('-')[0]) for f in args.local_compare) print('Google Fonts Version of %s is v%s' % (args.family, google_family_version)) print('Local Version of %s is v%s' % (','.join(local_fonts_name), local_family_version)) else: print('Google Fonts Version of %s is v%s' % (args.family, google_family_version))