I have a font that gets this error message in Font Validator: "table 'cmap' precedes table 'name'", but the ttx dump shows 'name' coming before 'cmap.' What am I missing? George
I think the error message is a statement of how things should be, not of how they are in the file. In the table directory, the entry for 'cmap' should precede the entry for 'name'.
So there are a couple of different things to bear in mind with regard to table order in sfnt (TT and OT) fonts. One is the actual order in which the tables are stored in the binary, and the other is the order in which the tables are recorded in the Table Directory in the font header. The latter is a case-sensitive alphabetical sort (so Apple all-caps tables precede Microsoft and other all-lowercase tables) with offset and length records for each table. But the actual order in which the tables are stored in the binary is technically arbitrary but there are processing benefits to storing at least some of the table before others. Microsoft used to make available a command line tool called fastfont that sorted the tables in the optimum order for processing, and using this tool supressed the kind of FontValidator warning (not error) you report. With the speed of today’s CPUs, I expect this kind of optimised table order, like many other processing speed optimisations, is moot.
def reorderFontTables(inFile, outFile, tableOrder=None, checkChecksums=False):
"""Rewrite a font file, ordering the tables as recommended by the
OpenType specification 1.4.
"""
inFile.seek(0)
outFile.seek(0)
reader = SFNTReader(inFile, checkChecksums=checkChecksums)
writer = SFNTWriter(outFile, len(reader.tables), reader.sfntVersion, reader.flavor, reader.flavorData)
tables = list(reader.keys())
for tag in sortedTagList(tables, tableOrder):
writer[tag] = reader[tag]
writer.close()
Comments
Maybe if you rebuild the font with TTX it will reorder the tables too, but I can't find traces in the code and have nothing to test it.