googlefonts / nanoemoji

A wee tool to build color fonts.
Apache License 2.0
238 stars 20 forks source link

maximum_color v0.14.2 still fails with some fonts with colored .notdef glyph #429

Closed anthrotype closed 2 years ago

anthrotype commented 2 years ago

428 was meant to address issues with incorrect reordering of the .notdef glyph following maximum_color, which occurred when .notdef was itself a color glyph.

While that worked for BungeeSpice, it still fails for Nabla with the following error:

$ maximum_color --build_dir /tmp/nabla2 --output_file 'Nabla[EDPT,EHLT].ttf' ofl/nabla/Nabla\[EDPT\,EHLT\].ttf
I0901 13:51:21.023385 4311631232 maximum_color.py:449] Generating build.ninja
I0901 13:51:21.158877 4311631232 ninja.py:113] ninja -C /private/tmp/nabla2
ninja: Entering directory `/private/tmp/nabla2'
[1/2] /Users/clupo/Github/fonts/.vebv/bin/python -m nanoemoji.glue_toget....ttf --output_file 'Nabla[EDPT,EHLT].keep_glyph_names.added_picosvg.ttf'
FAILED: Nabla[EDPT,EHLT].keep_glyph_names.added_picosvg.ttf
/Users/clupo/Github/fonts/.vebv/bin/python -m nanoemoji.glue_together -v 0 --color_table SVG --target_font Nabla[EDPT,EHLT].keep_glyph_names.ttf --donor_font MergeSource.picosvg.ttf --output_file 'Nabla[EDPT,EHLT].keep_glyph_names.added_picosvg.ttf'
Traceback (most recent call last):
  File "/Users/clupo/.pyenv/versions/3.10.2/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/clupo/.pyenv/versions/3.10.2/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/clupo/Github/nanoemoji/src/nanoemoji/glue_together.py", line 214, in <module>
    app.run(main)
  File "/Users/clupo/Github/fonts/.vebv/lib/python3.10/site-packages/absl/app.py", line 308, in run
    _run_main(main, args)
  File "/Users/clupo/Github/fonts/.vebv/lib/python3.10/site-packages/absl/app.py", line 254, in _run_main
    sys.exit(main(argv))
  File "/Users/clupo/Github/nanoemoji/src/nanoemoji/glue_together.py", line 205, in main
    target.save(FLAGS.output_file)
  File "/Users/clupo/Github/fonts/.vebv/lib/python3.10/site-packages/fontTools/ttLib/ttFont.py", line 189, in save
    writer_reordersTables = self._save(tmp)
  File "/Users/clupo/Github/fonts/.vebv/lib/python3.10/site-packages/fontTools/ttLib/ttFont.py", line 229, in _save
    self._writeTable(tag, writer, done, tableCache)
  File "/Users/clupo/Github/fonts/.vebv/lib/python3.10/site-packages/fontTools/ttLib/ttFont.py", line 650, in _writeTable
    self._writeTable(masterTable, writer, done, tableCache)
  File "/Users/clupo/Github/fonts/.vebv/lib/python3.10/site-packages/fontTools/ttLib/ttFont.py", line 654, in _writeTable
    tabledata = self.getTableData(tag)
  File "/Users/clupo/Github/fonts/.vebv/lib/python3.10/site-packages/fontTools/ttLib/ttFont.py", line 676, in getTableData
    return self.tables[tag].compile(self)
  File "/Users/clupo/Github/fonts/.vebv/lib/python3.10/site-packages/fontTools/ttLib/tables/_m_a_x_p.py", line 43, in compile
    self.recalc(ttFont)
  File "/Users/clupo/Github/fonts/.vebv/lib/python3.10/site-packages/fontTools/ttLib/tables/_m_a_x_p.py", line 62, in recalc
    self.numGlyphs = len(glyfTable)
  File "/Users/clupo/Github/fonts/.vebv/lib/python3.10/site-packages/fontTools/ttLib/tables/_g_l_y_f.py", line 311, in __len__
    assert len(self.glyphOrder) == len(self.glyphs)

I think the issue is in the case of Nabla, unlike for Bungee, the .notdef glyph shapes are being reused by subsequent color glyphs and the latter ends up in a reuse group with others while also been added in the first, standalone, group, thus ends up being encoded twice in the SVG table...

I'm working on a fix.