Skip to content

Commit

Permalink
[__main__] Don't try to convert a VariableFontFace to a NormalFontFac…
Browse files Browse the repository at this point in the history
…e twice

Move the conversion of variable font to ttc font in the same loop as where we request font to FontCollection

This allow the converted font (.ttc file) to be added into the FontCollection, so it doesn't collect the VariableFontFace twice. First, it collects the VariableFontFace that we convert to a NormalFontFace, so when we request the same variable font twice, it won't try to convert it to a ttc file twice.
  • Loading branch information
moi15moi committed Jan 19, 2025
1 parent d61d1b1 commit b13b74e
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions font_collector/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def main() -> None:
_logger.info(f"{Path.cwd()}>{' '.join(argv)}")

try:
font_results: list[FontResult] = []
fonts_file_found: set[FontFile] = set()
additional_fonts = FontLoader.load_additional_fonts(additional_fonts_path)
additional_fonts.extend(FontLoader.load_additional_fonts(additional_fonts_recursive_path, True))
font_collection = FontCollection(use_system_font=use_system_font, additional_fonts=additional_fonts)
Expand All @@ -64,8 +64,6 @@ def main() -> None:
_logger.error(f"Could not find font '{style.fontname}'")
_logger.error(f"Used on lines: {' '.join(str(line) for line in usage_data.ordered_lines)}")
else:
font_results.append(font_result)

if font_result.need_faux_bold:
_logger.warning(f"Faux bold used for '{style.fontname}'.")
elif font_result.mismatch_bold:
Expand All @@ -81,24 +79,22 @@ def main() -> None:
if len(missing_glyphs) > 0:
_logger.warning(f"'{style.fontname}' is missing the following glyphs used: {missing_glyphs}")

if nbr_font_not_found == 0:
_logger.info(f"All fonts found")
else:
_logger.info(f"{nbr_font_not_found} fonts could not be found.")

fonts_file_found: set[FontFile] = set()
if font_result.font_face.font_file is None:
raise ValueError(f"This font_face \"{font_result.font_face}\" isn't linked to any FontFile.")

for font_result in font_results:
if font_result.font_face.font_file is None:
raise ValueError(f"This font_face \"{font_result.font_face}\" isn't linked to any FontFile.")
if convert_variable_to_collection and isinstance(font_result.font_face, VariableFontFace):
font_name = font_result.font_face.get_best_family_prefix_from_lang().value
font_filename = output_directory.joinpath(f"{font_name}.ttc")
generated_font_file = font_result.font_face.variable_font_to_collection(font_filename)
fonts_file_found.add(generated_font_file)
else:
fonts_file_found.add(font_result.font_face.font_file)

if convert_variable_to_collection and isinstance(font_result.font_face, VariableFontFace):
font_name = font_result.font_face.get_best_family_prefix_from_lang().value
font_filename = output_directory.joinpath(f"{font_name}.ttc")
generated_font_file = font_result.font_face.variable_font_to_collection(font_filename)
fonts_file_found.add(generated_font_file)
if nbr_font_not_found == 0:
_logger.info(f"All fonts found")
else:
fonts_file_found.add(font_result.font_face.font_file)
_logger.info(f"{nbr_font_not_found} fonts could not be found.")

if mkv_path is not None:
if delete_fonts:
Expand Down

0 comments on commit b13b74e

Please sign in to comment.