question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does TTX merge have an upper limit of complexity? Failing to merge large COLR table into a variable font.

See original GitHub issue

I am currently working on a color font project in which I generate a pretty large COLR table in TTX/XML format, then merge it into a variable font, along with a CPAL table. To be a little more specific, the base font has nearly 3000 glyphs, but then scripts are generating glyph layers, and alt glyphs, for a total of about 26K glyphs in the final font. The COLR TTX file, then, has 106K lines.

When I use ttx -m to attempt to merge the COLR ttx into a TTF, if fails with the traceback shown below.

The thing is, I was previously able to do this merge operation successfully – when using slightly fewer alternate glyphs in the font and a COLR TTX file of 90K lines. I’ve just done this again to confirm. It seems that the added alternates & added COLR/CPAL complexity are the only things really changing, here.

If this is a matter of exceeding a complexity limit, is there some way to work around that limitation?

$  ttx -m variable-font.ttf COLR-patch.ttx                                                                         
Compiling "COLR-patch.ttx" to "variable-font.ttf"...
Parsing 'COLR' table...
ERROR: Unhandled exception has occurred
Traceback (most recent call last):
  File "/Users/stephennixon/color-font-project/venv/lib/python3.9/site-packages/fontTools/ttx.py", line 401, in main
    process(jobs, options)
  File "/Users/stephennixon/color-font-project/venv/lib/python3.9/site-packages/fontTools/ttx.py", line 374, in process
    action(input, output, options)
  File "/Users/stephennixon/color-font-project/venv/lib/python3.9/site-packages/fontTools/misc/loggingTools.py", line 372, in wrapper
    return func(*args, **kwds)
  File "/Users/stephennixon/color-font-project/venv/lib/python3.9/site-packages/fontTools/ttx.py", line 292, in ttCompile
    ttf.save(output)
  File "/Users/stephennixon/color-font-project/venv/lib/python3.9/site-packages/fontTools/ttLib/ttFont.py", line 172, in save
    writer_reordersTables = self._save(tmp)
  File "/Users/stephennixon/color-font-project/venv/lib/python3.9/site-packages/fontTools/ttLib/ttFont.py", line 212, in _save
    self._writeTable(tag, writer, done, tableCache)
  File "/Users/stephennixon/color-font-project/venv/lib/python3.9/site-packages/fontTools/ttLib/ttFont.py", line 634, in _writeTable
    tabledata = self.getTableData(tag)
  File "/Users/stephennixon/color-font-project/venv/lib/python3.9/site-packages/fontTools/ttLib/ttFont.py", line 652, in getTableData
    return self.tables[tag].compile(self)
  File "/Users/stephennixon/color-font-project/venv/lib/python3.9/site-packages/fontTools/ttLib/tables/C_O_L_R_.py", line 82, in compile
    table.compile(writer, ttFont)
  File "/Users/stephennixon/color-font-project/venv/lib/python3.9/site-packages/fontTools/ttLib/tables/otBase.py", line 771, in compile
    conv.write(writer, font, table, value)
  File "/Users/stephennixon/color-font-project/venv/lib/python3.9/site-packages/fontTools/ttLib/tables/otConverters.py", line 613, in write
    value.compile(subWriter, font)
  File "/Users/stephennixon/color-font-project/venv/lib/python3.9/site-packages/fontTools/ttLib/tables/otBase.py", line 735, in compile
    conv.writeArray(writer, font, table, value)
  File "/Users/stephennixon/color-font-project/venv/lib/python3.9/site-packages/fontTools/ttLib/tables/otConverters.py", line 197, in writeArray
    self.write(writer, font, tableDict, value, i)
  File "/Users/stephennixon/color-font-project/venv/lib/python3.9/site-packages/fontTools/ttLib/tables/otConverters.py", line 492, in write
    value.compile(writer, font)
  File "/Users/stephennixon/color-font-project/venv/lib/python3.9/site-packages/fontTools/ttLib/tables/otBase.py", line 771, in compile
    conv.write(writer, font, table, value)
  File "/Users/stephennixon/color-font-project/venv/lib/python3.9/site-packages/fontTools/ttLib/tables/otConverters.py", line 278, in write
    writer.writeUShort(value)
  File "/Users/stephennixon/color-font-project/venv/lib/python3.9/site-packages/fontTools/ttLib/tables/otBase.py", line 465, in writeUShort
    assert 0 <= value < 0x10000, value
AssertionError: (65536, 'int', 16384, 'BaseGlyphRecord[]', 'BaseGlyphRecordArray')

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
anthrotypecommented, Jul 15, 2021

FWIW, in the proposed COLR version 1 table, the LayerList can contain up to 4,294,967,296 unique layers since the numLayers field is a 32-bit unsigned integer.

In theory color glyphs can point to overlapping sets of layers…

Indeed, that’s true for both COLR v0 and v1 (via PaintColrLayers paint format, which defines slices of layers to be taken from the global LayerList). In FontTools, when compiling COLRv1 we try to reuse overlapping layers (see fontTools.colorLib.builder.LayerListBuilder); we should see if we can use the same (or adapted) code for COLRv0 as well

1reaction
justvanrossumcommented, Jul 15, 2021

(I haven’t run into this particular 16-bit limitation before, and tbh I was not aware of it until today.)

there isn’t some clever way to expand or exceed that limit?

I don’t think so. In theory color glyphs can point to overlapping sets of layers, but that doens’t appear a very practical thing to me. Eg. if you have layers A, B, C, D, E, F, glyph 1 could use layers A, B, C, D, E and glyph 2 could use B, C, D, E, F. I can’t think of a design in which that can be useful, though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with Font Variations - FontLab VI Help
To add a new font master:​​ Open the Font Info dialog File > Font Info . Click on the + button at the...
Read more >
Scripting functions — FontForge 20220308 documentation
This will set the current font to have a design size of 10 points, this font will then be used in preference to...
Read more >
nanDECK Manual
nanDECK is a program capable of creating graphic elements from scripts: every line of a script contains a command,.
Read more >
Stata Reporting Reference Manual
Introduction. Stata's commands for exporting estimation results, summary statistics, and graphs deliver neatly formatted reports in Word, ...
Read more >
ReportLab - PDF Library User Guide
This document is an introduction to the ReportLab PDF library. ... Work in high-level markup rather than constructing graphs of Python ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found