From 1fbdbca41a95f4efde9b00be511ebdd1f93dc45a Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Sun, 3 May 2015 16:46:58 +0100 Subject: [PATCH] [OS/2] update fsFirstCharIndex and fsLastCharIndex upon compile; add comment to XML output; use all unicode cmap subtables, but set 0xFFFF as max value for USHORT --- Lib/fontTools/ttLib/tables/O_S_2f_2.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Lib/fontTools/ttLib/tables/O_S_2f_2.py b/Lib/fontTools/ttLib/tables/O_S_2f_2.py index 523e77f31..b1b2c164a 100644 --- a/Lib/fontTools/ttLib/tables/O_S_2f_2.py +++ b/Lib/fontTools/ttLib/tables/O_S_2f_2.py @@ -121,6 +121,7 @@ class table_O_S_2f_2(DefaultTable.DefaultTable): self.panose = sstruct.unpack(panoseFormat, self.panose, Panose()) def compile(self, ttFont): + self.updateFirstAndLastCharIndex(ttFont) panose = self.panose self.panose = sstruct.pack(panoseFormat, self.panose) if self.version == 0: @@ -141,6 +142,10 @@ class table_O_S_2f_2(DefaultTable.DefaultTable): return data def toXML(self, writer, ttFont): + writer.comment( + "The fields 'fsFirstCharIndex' and 'fsLastCharIndex'\n" + "will be recalculated by the compiler") + writer.newline() if self.version == 1: format = OS2_format_1 elif self.version in (2, 3, 4): @@ -185,3 +190,15 @@ class table_O_S_2f_2(DefaultTable.DefaultTable): setattr(self, name, safeEval("'''" + attrs["value"] + "'''")) else: setattr(self, name, safeEval(attrs["value"])) + + def updateFirstAndLastCharIndex(self, ttFont): + codes = set() + for table in ttFont['cmap'].tables: + if table.isUnicode(): + codes.update(table.cmap.keys()) + if codes: + minCode = min(codes) + maxCode = max(codes) + # USHORT cannot hold codepoints greater than 0xFFFF + self.fsFirstCharIndex = 0xFFFF if minCode > 0xFFFF else minCode + self.fsLastCharIndex = 0xFFFF if maxCode > 0xFFFF else maxCode