From 535ab839d6066b8c2c81ca4664a1a63cfb2064b3 Mon Sep 17 00:00:00 2001 From: Benoit KUGLER Date: Tue, 30 Apr 2024 09:27:38 +0200 Subject: [PATCH] [font] expose LoadHeadTable --- font/font.go | 13 +++++++------ font/metadata.go | 2 +- font/opentype/tables/head_src.go | 1 + font/variations_test.go | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/font/font.go b/font/font.go index d4b997a6..93614e9f 100644 --- a/font/font.go +++ b/font/font.go @@ -212,7 +212,7 @@ func NewFont(ld *ot.Loader) (*Font, error) { return nil, err } - out.head, _, err = loadHeadTable(ld, nil) + out.head, _, err = LoadHeadTable(ld, nil) if err != nil { return nil, err } @@ -347,13 +347,14 @@ func NewFont(ld *ot.Loader) (*Font, error) { var bhedTag = ot.MustNewTag("bhed") -// loadHeadTable loads the table corresponding to the 'head' tag. +// LoadHeadTable loads the 'head' or the 'bhed' table. +// // If a 'bhed' Apple table is present, it replaces the 'head' one. // -// 'buffer' may be provided to reduce allocations; the return Head is guaranteed -// not to retain any reference on 'buffer'. -// If 'buffer' is nil or has not enough capacity, a new slice is allocated (and returned). -func loadHeadTable(ld *ot.Loader, buffer []byte) (tables.Head, []byte, error) { +// [buffer] may be provided to reduce allocations; the returned [tables.Head] is guaranteed +// not to retain any reference on [buffer]. +// If [buffer] is nil or has not enough capacity, a new slice is allocated (and returned). +func LoadHeadTable(ld *ot.Loader, buffer []byte) (tables.Head, []byte, error) { var err error // check 'bhed' first if ld.HasTable(bhedTag) { diff --git a/font/metadata.go b/font/metadata.go index 198b121b..ed538362 100644 --- a/font/metadata.go +++ b/font/metadata.go @@ -334,7 +334,7 @@ func newFontDescriptor(ld *ot.Loader, buffer []byte) (fontDescriptor, []byte) { desc.os2 = newOS2Desc(os2) } - desc.head, buffer, _ = loadHeadTable(ld, buffer) + desc.head, buffer, _ = LoadHeadTable(ld, buffer) buffer, _ = ld.RawTableTo(ot.MustNewTag("name"), buffer) desc.names, _, _ = tables.ParseName(buffer) diff --git a/font/opentype/tables/head_src.go b/font/opentype/tables/head_src.go index 681502b9..b84df294 100644 --- a/font/opentype/tables/head_src.go +++ b/font/opentype/tables/head_src.go @@ -5,6 +5,7 @@ package tables // TableHead contains critical information about the rest of the font. // https://learn.microsoft.com/en-us/typography/opentype/spec/head // https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6head.html +// https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6bhed.html type Head struct { majorVersion uint16 minorVersion uint16 diff --git a/font/variations_test.go b/font/variations_test.go index 2f60d94d..4e865a47 100644 --- a/font/variations_test.go +++ b/font/variations_test.go @@ -179,7 +179,7 @@ func TestInvalidGVAR(t *testing.T) { ld, err := ot.NewLoader(f) tu.AssertNoErr(t, err) - head, _, _ := loadHeadTable(ld, nil) + head, _, _ := LoadHeadTable(ld, nil) raw, _ := ld.RawTable(ot.MustNewTag("maxp")) maxp, _, _ := tables.ParseMaxp(raw) raw, _ = ld.RawTable(ot.MustNewTag("glyf"))