Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass file object into TTCollection and close when done #378

Merged
merged 3 commits into from
Feb 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions kiva/fonttools/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,9 @@ def createFontList(fontfiles, fontext='ttf'):
fontlist = []
# Add fonts from list of known font files.
seen = {}

font_entry_err_msg = "Could not covert font to FontEntry for file %s"

for fpath in fontfiles:
logger.debug("createFontDict %s", fpath)
fname = os.path.split(fpath)[1]
Expand All @@ -712,28 +715,24 @@ def createFontList(fontfiles, fontext='ttf'):
try:
prop = afmFontProperty(fpath, font)
except Exception:
logger.error(
"Could not covert font to FontEntry for file %s", fpath,
exc_info=True
)
logger.error(font_entry_err_msg, fpath, exc_info=True)
continue
else:
_, ext = os.path.splitext(fpath)
try:
if ext.lower() == ".ttc":
collection = TTCollection(six.text_type(fpath))
try:
props = []
for font in collection.fonts:
props.append(ttfFontProperty(fpath, font))
fontlist.extend(props)
continue
except Exception:
logger.error(
"Could not covert font to FontEntry for file %s",
fpath, exc_info=True
)
continue
with open(fpath, "rb") as f:
collection = TTCollection(f)
try:
props = []
for font in collection.fonts:
props.append(ttfFontProperty(fpath, font))
fontlist.extend(props)
continue
except Exception:
logger.error(
font_entry_err_msg, fpath, exc_info=True)
continue
else:
font = TTFont(six.text_type(fpath))
except (RuntimeError, TTLibError):
Expand All @@ -748,10 +747,7 @@ def createFontList(fontfiles, fontext='ttf'):
try:
prop = ttfFontProperty(fpath, font)
except Exception:
logger.error(
"Could not covert font to FontEntry for file %s", fpath,
exc_info=True
)
logger.error(font_entry_err_msg, fpath, exc_info=True)
continue

fontlist.append(prop)
Expand Down