font/sfnt: ignore version 1 kern tables.
The format is relatively complicated but rarely seen. It doesn't seem worth the effort. Ignoring it is what Microsoft Windows and FreeType do. Change-Id: I4415bd591c832650066de1d4e035b20a7230a4da Reviewed-on: https://go-review.googlesource.com/38273 Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
parent
6847effb9b
commit
88e2d806a0
|
@ -103,6 +103,14 @@ func TestProprietaryAppleAppleSymbols(t *testing.T) {
|
|||
testProprietary(t, "apple", "Apple Symbols.ttf", 4600, -1)
|
||||
}
|
||||
|
||||
func TestProprietaryAppleGeezaPro0(t *testing.T) {
|
||||
testProprietary(t, "apple", "GeezaPro.ttc?0", 1700, -1)
|
||||
}
|
||||
|
||||
func TestProprietaryAppleGeezaPro1(t *testing.T) {
|
||||
testProprietary(t, "apple", "GeezaPro.ttc?1", 1700, -1)
|
||||
}
|
||||
|
||||
func TestProprietaryAppleHiragino0(t *testing.T) {
|
||||
testProprietary(t, "apple", "ヒラギノ角ゴシック W0.ttc?0", 9000, 6)
|
||||
}
|
||||
|
@ -320,6 +328,8 @@ var proprietaryVersions = map[string]string{
|
|||
"adobe/SourceSansPro-Regular.ttf": "Version 2.020;PS 2.000;hotconv 1.0.86;makeotf.lib2.5.63406",
|
||||
|
||||
"apple/Apple Symbols.ttf": "12.0d3e10",
|
||||
"apple/GeezaPro.ttc?0": "12.0d1e3",
|
||||
"apple/GeezaPro.ttc?1": "12.0d1e3",
|
||||
"apple/ヒラギノ角ゴシック W0.ttc?0": "11.0d7e1",
|
||||
"apple/ヒラギノ角ゴシック W0.ttc?1": "11.0d7e1",
|
||||
|
||||
|
@ -340,6 +350,8 @@ var proprietaryFullNames = map[string]string{
|
|||
"adobe/SourceSansPro-Regular.ttf": "Source Sans Pro",
|
||||
|
||||
"apple/Apple Symbols.ttf": "Apple Symbols",
|
||||
"apple/GeezaPro.ttc?0": "Geeza Pro Regular",
|
||||
"apple/GeezaPro.ttc?1": "Geeza Pro Bold",
|
||||
"apple/ヒラギノ角ゴシック W0.ttc?0": "Hiragino Sans W0",
|
||||
"apple/ヒラギノ角ゴシック W0.ttc?1": ".Hiragino Kaku Gothic Interface W0",
|
||||
|
||||
|
|
|
@ -693,10 +693,20 @@ func (f *Font) parseKern(buf []byte) (buf1 []byte, kernNumPairs, kernOffset int3
|
|||
}
|
||||
return f.parseKernVersion0(buf, offset, length)
|
||||
case 1:
|
||||
// TODO: find such a (proprietary?) font, and support it. Both of
|
||||
// https://www.microsoft.com/typography/otspec/kern.htm
|
||||
if buf[2] != 0 || buf[3] != 0 {
|
||||
return nil, 0, 0, errUnsupportedKernTable
|
||||
}
|
||||
// Microsoft's https://www.microsoft.com/typography/otspec/kern.htm
|
||||
// says that "Apple has extended the definition of the 'kern' table to
|
||||
// provide additional functionality. The Apple extensions are not
|
||||
// supported on Windows."
|
||||
//
|
||||
// The format is relatively complicated, including encoding a state
|
||||
// machine, but rarely seen. We follow Microsoft's and FreeType's
|
||||
// behavior and simply ignore it. Theoretically, we could follow
|
||||
// https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6kern.html
|
||||
// say that such fonts work on Mac OS but not on Windows.
|
||||
// but it doesn't seem worth the effort.
|
||||
return buf, 0, 0, nil
|
||||
}
|
||||
return nil, 0, 0, errUnsupportedKernTable
|
||||
}
|
||||
|
@ -729,7 +739,9 @@ func (f *Font) parseKernVersion0(buf []byte, offset, length int) (buf1 []byte, k
|
|||
case 0:
|
||||
return f.parseKernFormat0(buf, offset, subtableLength)
|
||||
case 2:
|
||||
// TODO: find such a (proprietary?) font, and support it.
|
||||
// If we could find such a font, we could write code to support it, but
|
||||
// a comment in the equivalent FreeType code (sfnt/ttkern.c) says that
|
||||
// they've never seen such a font.
|
||||
}
|
||||
return nil, 0, 0, errUnsupportedKernTable
|
||||
}
|
||||
|
@ -982,9 +994,9 @@ func (f *Font) Kern(b *Buffer, x0, x1 GlyphIndex, ppem fixed.Int26_6, h font.Hin
|
|||
if n := f.NumGlyphs(); int(x0) >= n || int(x1) >= n {
|
||||
return 0, ErrNotFound
|
||||
}
|
||||
// Not every font has a kern table. If it doesn't, there's no need to
|
||||
// allocate a Buffer.
|
||||
if f.kern.length == 0 {
|
||||
// Not every font has a kern table. If it doesn't, or if that table is
|
||||
// ignored, there's no need to allocate a Buffer.
|
||||
if f.cached.kernNumPairs == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
if b == nil {
|
||||
|
|
Loading…
Reference in New Issue
Block a user