Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when parsing anchor names ending with underscore-number #1104

Open
NightFurySL2001 opened this issue Jul 1, 2024 · 0 comments
Open

Comments

@NightFurySL2001
Copy link
Contributor

Anchors generated by FontLab when reading binary font files usually end with underscore-number, e.g. _t.uni3001_1. When passing these names generated by FontLab into fontmake, the builder fails as the anchor name with underscore-number are identified as the index of ligature component to attach to.

Traceback (most recent call last):
  File "C:\Python311\Lib\site-packages\fontmake\font_project.py", line 519, in _iter_compile
    yield compile_func(ufo, debugFeatureFile=debugFeatureFile, **options)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\ufo2ft\__init__.py", line 117, in compileOTF
    return OTFCompiler(**kwargs).compile(ufo)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\ufo2ft\_compilers\baseCompiler.py", line 65, in compile
    self.compileFeatures(ufo, font, glyphSet=glyphSet)
  File "C:\Python311\Lib\site-packages\ufo2ft\_compilers\baseCompiler.py", line 145, in compileFeatures
    otFont = featureCompiler.compile()
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\ufo2ft\featureCompiler.py", line 148, in compile
    self.setupFeatures()
  File "C:\Python311\Lib\site-packages\ufo2ft\featureCompiler.py", line 315, in setupFeatures
    writer.write(self.ufo, featureFile, compiler=self)
  File "C:\Python311\Lib\site-packages\ufo2ft\featureWriters\baseFeatureWriter.py", line 151, in write
    self.setContext(font, feaFile, compiler=compiler)
  File "C:\Python311\Lib\site-packages\ufo2ft\featureWriters\markFeatureWriter.py", line 325, in setContext
    ctx.anchorLists = self._getAnchorLists()
                      ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\ufo2ft\featureWriters\markFeatureWriter.py", line 360, in _getAnchorLists
    a = self.NamedAnchor(name=anchorName, x=x, y=y)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\ufo2ft\featureWriters\markFeatureWriter.py", line 177, in __init__
    isMark, key, number = parseAnchorName(
                          ^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\ufo2ft\featureWriters\markFeatureWriter.py", line 151, in parseAnchorName
    raise ValueError("mark anchor cannot be numbered: %r" % anchorName)
ValueError: mark anchor cannot be numbered: '_t.uni0308_2'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Python311\Lib\site-packages\fontmake\__main__.py", line 746, in main
    project.run_from_ufos(
  File "C:\Python311\Lib\site-packages\fontmake\font_project.py", line 1374, in run_from_ufos
    self.build_otfs(ufos, cff_version=cff_version, inplace=inplace, **kwargs)
  File "C:\Python311\Lib\site-packages\fontmake\font_project.py", line 315, in build_otfs
    self.save_otfs(ufos, **kwargs)
  File "C:\Python311\Lib\site-packages\fontTools\misc\loggingTools.py", line 375, in wrapper
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\fontmake\font_project.py", line 682, in save_otfs
    for font, ufo in zip(fonts, ufos):
  File "C:\Python311\Lib\site-packages\fontmake\font_project.py", line 521, in _iter_compile
    raise FontmakeError("Compiling UFO failed", ufo.path) from e
fontmake.errors.FontmakeError: In 'orig-pearl-tangyuan-v2.ufo': Compiling UFO failed: mark anchor cannot be numbered: '_t.uni0308_2'

This convention is not noted anywhere in any formalised standards, and is only noted in parseAnchorName() function description of ufo2ft:

Parse anchor name and return a tuple that specifies:
1) whether the anchor is a "mark" anchor (bool);
2) the "key" name of the anchor, i.e. the name after stripping all the
prefixes and suffixes, which identifies the class it belongs to (str);
3) An optional number (int), starting from 1, which identifies that index
of the ligature component the anchor refers to.

The 'ignoreRE' argument is an optional regex pattern (str) identifying
sub-strings in the anchor name that should be ignored when parsing the
three elements above.

It is not mentioned in UFO specification:

name: An arbitrary name for the anchor. This attribute is optional. It must be at least one character long. There is no maximum name length. A name must not contain control characters.

and

Anchor naming conventions
The following are agreed upon standard naming conventions for special uses of the name attribute.

Ligature Carets
Anchors with a name starting with caret_ or vcaret_ indicate horizontal or vertical caret positions for ligature glyphs. Example usage would be to compile the OpenType GDEF Ligature Caret List table.

Anchor names starting with caret_ provide the x value for a ligature caret position, and the y value is ignored. Likewise, anchor names starting with vcaret_ provide the y value for a ligature caret position, and the x value is ignored.

Both names may be followed arbitrary text (caret_1, caret_blah, etc) for designers or applications to have unique caret position names.

There must be exactly N-1 caret positions for N ligature components.

Or in AFDKO FEA syntax:

The anchor name follows the same rules as are used to form glyph names. For example:

anchorDef 300 0 ANCHOR_1;
anchorDef 120 -20 contourpoint 5 ANCHOR_2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant