Skip to content

Commit b2d171c

Browse files
committed
ignore font with invalid charset
1 parent 512afb1 commit b2d171c

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pycdxml/cdxml_converter/chemdraw_types.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,16 @@ def from_element(fonttable: ET.Element) -> 'CDXFontTable':
355355
fonts = []
356356

357357
for font in fonttable.iter(tag="font"):
358-
logger.debug(f"Reading font {font.attrib}.")
359-
font_id = int(font.attrib["id"])
360-
if font.attrib["charset"] == "UTF-8":
361-
font.attrib["charset"] = "utf8"
362-
charset = next(key for key, value in Font.CHARSETS.items() if value == font.attrib["charset"])
363-
font_name = font.attrib["name"]
364-
fonts.append(Font(font_id, charset, font_name))
358+
try:
359+
logger.debug(f"Reading font {font.attrib}.")
360+
font_id = int(font.attrib["id"])
361+
if font.attrib["charset"] == "UTF-8":
362+
font.attrib["charset"] = "utf8"
363+
charset = next(key for key, value in Font.CHARSETS.items() if value == font.attrib["charset"])
364+
font_name = font.attrib["name"]
365+
fonts.append(Font(font_id, charset, font_name))
366+
except StopIteration:
367+
logger.warning(f"Ignoring font with invalid charset {font.attrib['charset']}.")
365368

366369
if platform.system() == "Windows":
367370
os_type = CDXFontTable.PLATFORM_WINDOWS

0 commit comments

Comments
 (0)