From 5525c8cf0064ea5cf96937b2e4f4128ee02f4ba6 Mon Sep 17 00:00:00 2001 From: Benoit KUGLER Date: Sat, 2 Dec 2023 11:30:11 +0100 Subject: [PATCH] [fontscan] specify Location in AddFace, closes #112 --- fontscan/fontmap.go | 4 ++-- fontscan/fontmap_test.go | 2 +- fontscan/footprint.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fontscan/fontmap.go b/fontscan/fontmap.go index 7682975..9a09d9c 100644 --- a/fontscan/fontmap.go +++ b/fontscan/fontmap.go @@ -281,8 +281,8 @@ func (fm *FontMap) AddFont(fontFile font.Resource, fileID, familyName string) er // // The order of calls to [AddFont] and [AddFace] determines relative priority // of manually loaded fonts. See [ResolveFace] for details about when this matters. -func (fm *FontMap) AddFace(face font.Face, md meta.Description) { - fp := newFootprintFromFont(face.Font, md) +func (fm *FontMap) AddFace(face font.Face, location Location, md meta.Description) { + fp := newFootprintFromFont(face.Font, location, md) fm.cache(fp, face) fm.appendFootprints(fp) diff --git a/fontscan/fontmap_test.go b/fontscan/fontmap_test.go index ef6f34e..9ddd7cd 100644 --- a/fontscan/fontmap_test.go +++ b/fontscan/fontmap_test.go @@ -52,7 +52,7 @@ func ExampleFontMap_AddFace() { md := meta.Metadata(ld) f, _ := fontapi.NewFont(ld) // error handling omitted fontMap := NewFontMap(log.Default()) - fontMap.AddFace(&fontapi.Face{Font: f}, md) + fontMap.AddFace(&fontapi.Face{Font: f}, Location{File: fmt.Sprint(md)}, md) // set the font description fontMap.SetQuery(Query{Families: []string{"Arial", "serif"}}) // regular Aspect diff --git a/fontscan/footprint.go b/fontscan/footprint.go index e183565..61a1159 100644 --- a/fontscan/footprint.go +++ b/fontscan/footprint.go @@ -50,12 +50,12 @@ type footprint struct { isUserProvided bool } -func newFootprintFromFont(f font.Font, md meta.Description) (out footprint) { +func newFootprintFromFont(f font.Font, location Location, md meta.Description) (out footprint) { out.Runes, out.scripts, _ = newCoveragesFromCmap(f.Cmap, nil) out.langs = newLangsetFromCoverage(out.Runes) out.Family = meta.NormalizeFamily(md.Family) out.Aspect = md.Aspect - out.Location.File = fmt.Sprintf("%v", md) + out.Location = location out.isUserProvided = true return out }