@@ -745,7 +745,7 @@ func (f *Font) initialize(offset int, isDfont bool) error {
745
745
f .cached .xHeight = xHeight
746
746
747
747
if ! hasXHeightCapHeight {
748
- xh , ch , err := f .initOS2Version1 ()
748
+ xh , ch , err := f .initOS2VersionBelow2 ()
749
749
if err != nil {
750
750
return err
751
751
}
@@ -1201,7 +1201,7 @@ func (f *Font) glyphTopOS2(b *Buffer, ppem fixed.Int26_6, r rune) (int32, error)
1201
1201
return int32 (min ), nil
1202
1202
}
1203
1203
1204
- func (f * Font ) initOS2Version1 () (xHeight , capHeight int32 , err error ) {
1204
+ func (f * Font ) initOS2VersionBelow2 () (xHeight , capHeight int32 , err error ) {
1205
1205
ppem := fixed .Int26_6 (f .UnitsPerEm ())
1206
1206
var b Buffer
1207
1207
@@ -1235,12 +1235,14 @@ func (f *Font) parseOS2(buf []byte) (buf1 []byte, hasXHeightCapHeight bool, xHei
1235
1235
if err != nil {
1236
1236
return nil , false , 0 , 0 , err
1237
1237
}
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
1240
1242
if f .os2 .length < headerSize {
1241
1243
return nil , false , 0 , 0 , errInvalidOS2Table
1242
1244
}
1243
- // Will resolve xHeight and capHeight later, see initOS2Version1 .
1245
+ // Will resolve xHeight and capHeight later, see initOS2VersionBelow2 .
1244
1246
return buf , false , 0 , 0 , nil
1245
1247
}
1246
1248
const headerSize = 96
0 commit comments