aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/golang/freetype/truetype/truetype.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/golang/freetype/truetype/truetype.go')
-rw-r--r--vendor/github.com/golang/freetype/truetype/truetype.go30
1 files changed, 20 insertions, 10 deletions
diff --git a/vendor/github.com/golang/freetype/truetype/truetype.go b/vendor/github.com/golang/freetype/truetype/truetype.go
index 613fc17..7270bbf 100644
--- a/vendor/github.com/golang/freetype/truetype/truetype.go
+++ b/vendor/github.com/golang/freetype/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
@@ -323,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))
- }
- offset += 2
+ if n == 0 {
+ return UnsupportedError("kern nTables: 0")
+ }
+ // 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 {
@@ -550,8 +560,7 @@ func parse(ttf []byte, offset int) (font *Font, err error) {
return
}
ttcVersion, offset := u32(ttf, offset), offset+4
- if ttcVersion != 0x00010000 {
- // TODO: support TTC version 2.0, once I have such a .ttc file to test with.
+ if ttcVersion != 0x00010000 && ttcVersion != 0x00020000 {
err = FormatError("bad TTC version")
return
}
@@ -578,14 +587,15 @@ func parse(ttf []byte, offset int) (font *Font, err error) {
return
}
n, offset := int(u16(ttf, offset)), offset+2
- if len(ttf) < 16*n+12 {
+ offset += 6 // Skip the searchRange, entrySelector and rangeShift.
+ if len(ttf) < 16*n+offset {
err = FormatError("TTF data is too short")
return
}
f := new(Font)
// Assign the table slices.
for i := 0; i < n; i++ {
- x := 16*i + 12
+ x := 16*i + offset
switch string(ttf[x : x+4]) {
case "cmap":
f.cmap, err = readTable(ttf, ttf[x+8:x+16])