Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[font] expose LoadHeadTable #163

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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