Skip to content

Commit

Permalink
[font_parser] Always close the BufferedReader
Browse files Browse the repository at this point in the history
  • Loading branch information
moi15moi committed May 3, 2024
1 parent 542fd35 commit b47574e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions font_collector/font/font_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,10 @@ def get_font_italic_bold_property_with_freetype(
Returns:
is_italic, is_glyphs_emboldened, weight
"""
font = Face(font_path.open("rb"), font_index)
is_italic = bool(font.style_flags & FT_STYLE_FLAGS["FT_STYLE_FLAG_ITALIC"])
is_glyphs_emboldened = bool(font.style_flags & FT_STYLE_FLAGS["FT_STYLE_FLAG_BOLD"])
with font_path.open("rb") as f:
face = Face(f, font_index)
is_italic = bool(face.style_flags & FT_STYLE_FLAGS["FT_STYLE_FLAG_ITALIC"])
is_glyphs_emboldened = bool(face.style_flags & FT_STYLE_FLAGS["FT_STYLE_FLAG_BOLD"])
weight = 700 if is_glyphs_emboldened else 400

return is_italic, is_glyphs_emboldened, weight
Expand Down

0 comments on commit b47574e

Please sign in to comment.