removeOverlaps: print glyph name when pathops.simplify fails

Sometimes skia-pathops simplify may fail (for unknown reasons which I'm still trying to debug).
It's a good idea to know the name of the offending glyph
https://github.com/google/fonts/issues/3365
This commit is contained in:
Cosimo Lupo 2021-05-04 17:08:59 +01:00
parent 2100a96e77
commit e13b781526

View File

@ -18,6 +18,10 @@ import pathops
__all__ = ["removeOverlaps"] __all__ = ["removeOverlaps"]
class RemoveOverlapsError(Exception):
pass
log = logging.getLogger("fontTools.ttLib.removeOverlaps") log = logging.getLogger("fontTools.ttLib.removeOverlaps")
_TTGlyphMapping = Mapping[str, ttFont._TTGlyph] _TTGlyphMapping = Mapping[str, ttFont._TTGlyph]
@ -93,7 +97,12 @@ def removeTTGlyphOverlaps(
path = skPathFromGlyph(glyphName, glyphSet) path = skPathFromGlyph(glyphName, glyphSet)
# remove overlaps # remove overlaps
path2 = pathops.simplify(path, clockwise=path.clockwise) try:
path2 = pathops.simplify(path, clockwise=path.clockwise)
except pathops.PathOpsError as e:
raise RemoveOverlapsError(
f"Failed to remove overlaps from glyph {glyphName!r}"
) from e
# replace TTGlyph if simplified path is different (ignoring contour order) # replace TTGlyph if simplified path is different (ignoring contour order)
if {tuple(c) for c in path.contours} != {tuple(c) for c in path2.contours}: if {tuple(c) for c in path.contours} != {tuple(c) for c in path2.contours}: