Skip to content

Commit 240a51a

Browse files
erkkahhajimehoshi
authored andcommitted
font/sfnt: support early version 0 OS/2 tables
Version 0 OS/2 tables can be as small as 68 bytes. See https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6OS2.html. This works is taken over from https://go.dev/cl/510055 by Erik Agsjö. Fixes golang/go#41658 Change-Id: If6fb961943b5563ed21fe5148252005743c17168 Reviewed-on: https://go-review.googlesource.com/c/image/+/533495 Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Nigel Tao <nigeltao@golang.org> Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com>
1 parent c20bbc3 commit 240a51a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

font/sfnt/sfnt.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ func (f *Font) initialize(offset int, isDfont bool) error {
745745
f.cached.xHeight = xHeight
746746

747747
if !hasXHeightCapHeight {
748-
xh, ch, err := f.initOS2Version1()
748+
xh, ch, err := f.initOS2VersionBelow2()
749749
if err != nil {
750750
return err
751751
}
@@ -1201,7 +1201,7 @@ func (f *Font) glyphTopOS2(b *Buffer, ppem fixed.Int26_6, r rune) (int32, error)
12011201
return int32(min), nil
12021202
}
12031203

1204-
func (f *Font) initOS2Version1() (xHeight, capHeight int32, err error) {
1204+
func (f *Font) initOS2VersionBelow2() (xHeight, capHeight int32, err error) {
12051205
ppem := fixed.Int26_6(f.UnitsPerEm())
12061206
var b Buffer
12071207

@@ -1235,12 +1235,14 @@ func (f *Font) parseOS2(buf []byte) (buf1 []byte, hasXHeightCapHeight bool, xHei
12351235
if err != nil {
12361236
return nil, false, 0, 0, err
12371237
}
1238-
if vers <= 1 {
1239-
const headerSize = 86
1238+
if vers < 2 {
1239+
// "The original TrueType specification had this table at 68 bytes long."
1240+
// https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6OS2.html
1241+
const headerSize = 68
12401242
if f.os2.length < headerSize {
12411243
return nil, false, 0, 0, errInvalidOS2Table
12421244
}
1243-
// Will resolve xHeight and capHeight later, see initOS2Version1.
1245+
// Will resolve xHeight and capHeight later, see initOS2VersionBelow2.
12441246
return buf, false, 0, 0, nil
12451247
}
12461248
const headerSize = 96

0 commit comments

Comments
 (0)