Skip to content

Commit

Permalink
[font] expose LoadHeadTable
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitkugler committed Apr 30, 2024
1 parent d330710 commit 535ab83
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
13 changes: 7 additions & 6 deletions font/font.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion font/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions font/opentype/tables/head_src.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion font/variations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit 535ab83

Please sign in to comment.