From bcfeb16b74e8aea9e2fe043406f2ef74b1cb0759 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sat, 29 Apr 2017 10:42:25 +1000 Subject: [PATCH] Allow multiple kern subtables. We still only use the first subtable, but we no longer fail if there's more than one subtable. Updates fogleman/gg#7 --- truetype/truetype.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/truetype/truetype.go b/truetype/truetype.go index 7a17d8e..7270bbf 100644 --- a/truetype/truetype.go +++ b/truetype/truetype.go @@ -324,11 +324,20 @@ func (f *Font) parseKern() error { if version != 0 { return UnsupportedError(fmt.Sprintf("kern version: %d", version)) } + n, offset := u16(f.kern, offset), offset+2 - if n != 1 { - return UnsupportedError(fmt.Sprintf("kern nTables: %d", n)) + if n == 0 { + return UnsupportedError("kern nTables: 0") } - offset += 2 + // TODO: support multiple subtables. In practice, almost all .ttf files + // have only one subtable, if they have a kern table at all. But it's not + // impossible. Xolonium Regular (https://fontlibrary.org/en/font/xolonium) + // has 3 subtables. Those subtables appear to be disjoint, rather than + // being the same kerning pairs encoded in three different ways. + // + // For now, we'll use only the first subtable. + + offset += 2 // Skip the version. length, offset := int(u16(f.kern, offset)), offset+2 coverage, offset := u16(f.kern, offset), offset+2 if coverage != 0x0001 {