Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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')
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(f'Downloading and generating glyph data for {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(f'Saving to {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 download_family_from_Google_Fonts(family_name):
"""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, family_name.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))