Skip to content

Commit

Permalink
raise InvalidFontData with multiple unicode mappings, add errors module
Browse files Browse the repository at this point in the history
  • Loading branch information
anthrotype committed May 14, 2018
1 parent d935472 commit 25c82fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
9 changes: 9 additions & 0 deletions Lib/ufo2ft/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

class Error(Exception):
"""Base exception class for all ufo2ft errors."""
pass


class InvalidFontData(Error):
"""Raised when input font contains invalid data."""
pass
12 changes: 6 additions & 6 deletions Lib/ufo2ft/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ def newGlyph(name):
def makeUnicodeToGlyphNameMapping(font, glyphOrder=None):
""" Make a unicode: glyph name mapping for this glyph set (dict or Font).
If multiple glyphs are mapped to the same unicode codepoint, we take
the first one that appears in the font's glyphOrder, and skip any other
duplicate mappings with a warning message.
Raises InvalidFontData exception if multiple glyphs are mapped to the
same unicode codepoint.
"""
if glyphOrder is None:
glyphOrder = makeOfficialGlyphOrder(font)
Expand All @@ -91,9 +90,10 @@ def makeUnicodeToGlyphNameMapping(font, glyphOrder=None):
if uni not in mapping:
mapping[uni] = glyphName
else:
logger.warning("U+%04X is already mapped to '%s'; "
"skipped duplicate mapping for '%s'"
% (uni, mapping[uni], glyphName))
from ufo2ft.errors import InvalidFontData
InvalidFontData(
"cannot map '%s' to U+%04X; already mapped to '%s'"
% (glyphName, uni, mapping[uni]))
return mapping


Expand Down

0 comments on commit 25c82fd

Please sign in to comment.