def reorderFontTables(inFile, outFile, tableOrder=None, checkChecksums=False): """Rewrite a font file, ordering the tables as recommended by the OpenType specification 1.4. """ from fontTools.ttLib.sfnt import SFNTReader, SFNTWriter 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()
def _save(self, file, tableCache=None): """Internal function, to be shared by save() and TTCollection.save()""" if self.recalcTimestamp and 'head' in self: self['head'] # make sure 'head' is loaded so the recalculation is actually done tags = list(self.keys()) if "GlyphOrder" in tags: tags.remove("GlyphOrder") numTables = len(tags) # write to a temporary stream to allow saving to unseekable streams writer = SFNTWriter(file, numTables, self.sfntVersion, self.flavor, self.flavorData) done = [] for tag in tags: self._writeTable(tag, writer, done, tableCache) writer.close() return writer.reordersTables()