From b12e98108289d6367ecd1a819deee597b2c3fa57 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Thu, 20 Apr 2017 11:23:31 +1000 Subject: [PATCH] Support Unicode Full Repertoire cmap tables. For example, "Apple Color Emoji.ttc" has such a cmap. After this commit, we can render its glyph for "U+0001F1E6 REGIONAL INDICATOR SYMBOL LETTER A", which is clearly outside the Unicode BMP. Note that this only lets us render black-and-white glyphs for out-of-BMP runes. Rendering color glyphs (i.e. emoji) remains TODO. Updates #45 --- truetype/truetype.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/truetype/truetype.go b/truetype/truetype.go index 2eb0c90..7a17d8e 100644 --- a/truetype/truetype.go +++ b/truetype/truetype.go @@ -57,7 +57,8 @@ const ( // A 32-bit encoding consists of a most-significant 16-bit Platform ID and a // least-significant 16-bit Platform Specific ID. The magic numbers are // specified at https://www.microsoft.com/typography/otspec/name.htm - unicodeEncoding = 0x00000003 // PID = 0 (Unicode), PSID = 3 (Unicode 2.0) + unicodeEncodingBMPOnly = 0x00000003 // PID = 0 (Unicode), PSID = 3 (Unicode 2.0 BMP Only) + unicodeEncodingFull = 0x00000004 // PID = 0 (Unicode), PSID = 4 (Unicode 2.0 Full Repertoire) microsoftSymbolEncoding = 0x00030000 // PID = 3 (Microsoft), PSID = 0 (Symbol) microsoftUCS2Encoding = 0x00030001 // PID = 3 (Microsoft), PSID = 1 (UCS-2) microsoftUCS4Encoding = 0x0003000a // PID = 3 (Microsoft), PSID = 10 (UCS-4) @@ -142,7 +143,7 @@ func parseSubtables(table []byte, name string, offset, size int, pred func([]byt pidPsid := u32(table, offset) // We prefer the Unicode cmap encoding. Failing to find that, we fall // back onto the Microsoft cmap encoding. - if pidPsid == unicodeEncoding { + if pidPsid == unicodeEncodingBMPOnly || pidPsid == unicodeEncodingFull { bestOffset, bestPID, ok = offset, pidPsid>>16, true break