Skip to content

Reading UFO failed if feature.fea saved with BOM mark #3822

@NightFurySL2001

Description

@NightFurySL2001

Originally reported in googlefonts/fontmake#972, but another bug came up.

fontmake: Error: In 'LXGWWenKaiLite-Regular.ufoz': Compiling UFO failed: LXGWWenKaiLite-Regular.ufoz\features.fea:1:1: Unexpected character: '\ufeff'

Changing the features.fea file from UTF-8 with BOM to UTF-8 resolve the issue.

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:\Users\User\AppData\Roaming\Python\Python311\site-packages\ufo2ft\__init__.py", line 117, in compileOTF
    return OTFCompiler(**kwargs).compile(ufo)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\AppData\Roaming\Python\Python311\site-packages\ufo2ft\_compilers\baseCompiler.py", line 65, in compile
    self.compileFeatures(ufo, font, glyphSet=glyphSet)
  File "C:\Users\User\AppData\Roaming\Python\Python311\site-packages\ufo2ft\_compilers\baseCompiler.py", line 145, in compileFeatures
    otFont = featureCompiler.compile()
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\AppData\Roaming\Python\Python311\site-packages\ufo2ft\featureCompiler.py", line 148, in compile
    self.setupFeatures()
  File "C:\Users\User\AppData\Roaming\Python\Python311\site-packages\ufo2ft\featureCompiler.py", line 299, in setupFeatures
    featureFile = parseLayoutFeatures(self.ufo, self.feaIncludeDir)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\AppData\Roaming\Python\Python311\site-packages\ufo2ft\featureCompiler.py", line 59, in parseLayoutFeatures
    parser = Parser(buf, glyphNames, includeDir=includeDir)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\fontTools\feaLib\parser.py", line 76, in __init__
    self.advance_lexer_(comments=True)
  File "C:\Python311\Lib\site-packages\fontTools\feaLib\parser.py", line 2330, in advance_lexer_
    ) = next(self.lexer_)
        ^^^^^^^^^^^^^^^^^
  File "Lib\\fontTools\\feaLib\\lexer.py", line 231, in fontTools.feaLib.lexer.IncludingLexer.__next__
  File "Lib\\fontTools\\feaLib\\lexer.py", line 60, in fontTools.feaLib.lexer.Lexer.__next__
  File "Lib\\fontTools\\feaLib\\lexer.py", line 163, in fontTools.feaLib.lexer.Lexer.next_
fontTools.feaLib.error.FeatureLibError: ChocolateClassicalSans-Regular.ufo\features.fea:1:1: Unexpected character: '\ufeff'

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions