Skip to content

Commit

Permalink
Merge pull request #453 from justvanrossum/fix-ufo2ft
Browse files Browse the repository at this point in the history
Adapt to latest ufo2ft
  • Loading branch information
justvanrossum authored Dec 19, 2024
2 parents 8b16596 + 9d208b3 commit 4a88050
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
38 changes: 27 additions & 11 deletions Lib/fontgoggles/compile/ufoCompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ def compileUFOToPath(ufoPath, ttPath):
ttFont.save(ttPath, reorderTables=False)


_tagGLIFPattern = re.compile(rb'(<\s*(advance|anchor|unicode)\s+([^>]+)>)')
_ufo2AnchorPattern = re.compile(rb"<contour>\s+(<point\s+[^>]+move[^>]+name[^>]+>)\s+</contour>")
_unicodeAttributeGLIFPattern = re.compile(rb'hex\s*=\s*\"([0-9A-Fa-f]+)\"')
_widthAttributeGLIFPattern = re.compile(rb'width\s*=\s*\"([0-9A-Fa-f]+)\"')
_tagGLIFPattern = re.compile(rb"(<\s*(advance|anchor|unicode)\s+([^>]+)>)")
_ufo2AnchorPattern = re.compile(
rb"<contour>\s+(<point\s+[^>]+move[^>]+name[^>]+>)\s+</contour>"
)
_unicodeAttributeGLIFPattern = re.compile(rb"hex\s*=\s*\"([0-9A-Fa-f]+)\"")
_widthAttributeGLIFPattern = re.compile(rb"width\s*=\s*\"([0-9A-Fa-f]+)\"")


def fetchGlyphInfo(glyphSet, ufoPath, glyphNames=None, ufo2=False):
Expand Down Expand Up @@ -131,11 +133,16 @@ def fetchGlyphInfo(glyphSet, ufoPath, glyphNames=None, ufo2=False):
revCmap[glyphName] = uniqueUnicodes

if duplicateUnicodes:
dupMessage = "; ".join(f"U+{codePoint:04X}:{','.join(glyphNames)}"
for codePoint, glyphNames in sorted(duplicateUnicodes.items()))
dupMessage = "; ".join(
f"U+{codePoint:04X}:{','.join(glyphNames)}"
for codePoint, glyphNames in sorted(duplicateUnicodes.items())
)
logger = logging.getLogger("fontgoggles.font.ufoFont")
logger.warning("Some code points in '%s' are assigned to multiple glyphs: %s",
ufoPath, dupMessage)
logger.warning(
"Some code points in '%s' are assigned to multiple glyphs: %s",
ufoPath,
dupMessage,
)
return widths, cmap, revCmap, anchors


Expand All @@ -159,7 +166,12 @@ def _parseNumber(s):


def _parseAnchorAttrs(attrs):
return attrs.get("name"), _parseNumber(attrs.get("x")), _parseNumber(attrs.get("y"))
return (
attrs.get("name"),
_parseNumber(attrs.get("x")),
_parseNumber(attrs.get("y")),
attrs.get("identifier"),
)


class FetchUnicodesAndAnchorsParser(BaseGlifParser):
Expand Down Expand Up @@ -241,7 +253,10 @@ def __init__(self, name, width, unicodes, anchors):
self.name = name
self.width = width
self.unicodes = unicodes
self.anchors = [MinimalAnchorObject(name, x, y) for name, x, y in anchors]
self.anchors = [
MinimalAnchorObject(name, x, y, identifier)
for name, x, y, identifier in anchors
]

@property
def unicode(self):
Expand All @@ -250,10 +265,11 @@ def unicode(self):

class MinimalAnchorObject:

def __init__(self, name, x, y):
def __init__(self, name, x, y, identifier):
self.name = name
self.x = x
self.y = y
self.identifier = identifier


class MinimalFeaturesObject:
Expand Down
12 changes: 6 additions & 6 deletions Tests/test_ufoCompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def test_ufoCharacterMapping():
# tag, that must not be parsed, as well as a commented-out <anchor>.
assert 0x1234 not in cmap
assert anchors == {
"A": [("top", 645, 815)],
"E": [("top", 582.5, 815)],
"macroncmb": [("_top", 0, 815)],
"asteriskabovecmb": [("_top", 153, 808)],
"asteriskbelowcmb": [("_top", 153, 808)],
"A": [("top", 645, 815, None)],
"E": [("top", 582.5, 815, None)],
"macroncmb": [("_top", 0, 815, None)],
"asteriskabovecmb": [("_top", 153, 808, None)],
"asteriskbelowcmb": [("_top", 153, 808, None)],
}


Expand All @@ -33,7 +33,7 @@ def test_ufoCharacterMapping_glyphNames():
widths, cmap, revCmap, anchors = fetchGlyphInfo(reader.getGlyphSet(), ufoPath, ["A"])
assert cmap[0x0041] == "A"
assert revCmap["A"] == [0x0041]
assert anchors == {"A": [("top", 645, 815)]}
assert anchors == {"A": [("top", 645, 815, None)]}


@pytest.mark.asyncio
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fonttools[woff,lxml,unicode,ufo,type1]==4.53.1
uharfbuzz==0.42.0
python-bidi==0.4.2 # pin for now
jundo==0.1.2
ufo2ft==3.2.8
ufo2ft==3.3.1
numpy==2.1.1
unicodedata2==15.1.0
git+https://github.com/BlackFoundryCom/rcjk-tools/
Expand Down

0 comments on commit 4a88050

Please sign in to comment.