From 57f95946354c6441d16299a913af9288c608c723 Mon Sep 17 00:00:00 2001 From: Benoit KUGLER Date: Sun, 3 Nov 2024 19:02:08 +0100 Subject: [PATCH 1/2] [font] properly decode names for Windows fonts (related to #172) --- font/metadata_test.go | 11 +++++++++++ font/opentype/tables/name_src.go | 5 +++-- font/opentype/tables/name_test.go | 9 +++++++++ go.mod | 2 +- go.sum | 4 ++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/font/metadata_test.go b/font/metadata_test.go index aff3e360..c2b9e8b3 100644 --- a/font/metadata_test.go +++ b/font/metadata_test.go @@ -118,3 +118,14 @@ func TestAspectFromOS2(t *testing.T) { inferred.inferFromStyle(fd.additionalStyle()) tu.Assert(t, inferred.Weight == 380) } + +func TestFamily(t *testing.T) { + f, err := td.Files.ReadFile("collections/msgothic.ttc") + tu.AssertNoErr(t, err) + + faces, err := ParseTTC(bytes.NewReader(f)) + tu.AssertNoErr(t, err) + + tu.Assert(t, len(faces) == 3) + tu.Assert(t, faces[0].Describe().Family == "MS Gothic") +} diff --git a/font/opentype/tables/name_src.go b/font/opentype/tables/name_src.go index 3a14443d..15e54f76 100644 --- a/font/opentype/tables/name_src.go +++ b/font/opentype/tables/name_src.go @@ -140,8 +140,9 @@ func (names Name) decodeRecord(n nameRecord) string { } value := names.stringData[n.stringOffset:end] - if n.platformID == PlatformUnicode || (n.platformID == PlatformMicrosoft && - n.encodingID == PEMicrosoftUnicodeCs) { + if n.platformID == PlatformUnicode || + (n.platformID == PlatformMicrosoft && + (n.encodingID == PEMicrosoftUnicodeCs || n.encodingID == PEMicrosoftUcs4 || n.encodingID == PEMicrosoftSymbolCs)) { return decodeUtf16(value) } diff --git a/font/opentype/tables/name_test.go b/font/opentype/tables/name_test.go index f06edaac..067c9b12 100644 --- a/font/opentype/tables/name_test.go +++ b/font/opentype/tables/name_test.go @@ -95,6 +95,15 @@ func TestFamilyNames(t *testing.T) { tu.AssertNoErr(t, err) // NameFontFamily tu.Assert(t, names.Name(1) == "Roboto") + + // Windows font + f, err = td.Files.ReadFile("collections/msgothic.ttc") + tu.AssertNoErr(t, err) + fonts, err = ot.NewLoaders(bytes.NewReader(f)) + tu.AssertNoErr(t, err) + names, _, err = ParseName(readTable(t, fonts[0], "name")) + tu.AssertNoErr(t, err) + tu.Assert(t, names.Name(1) == "MS Gothic") } func TestNames(t *testing.T) { diff --git a/go.mod b/go.mod index db6d2128..b201a48a 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/go-text/typesetting go 1.17 require ( - github.com/go-text/typesetting-utils v0.0.0-20240317173224-1986cbe96c66 + github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066 golang.org/x/image v0.3.0 golang.org/x/text v0.9.0 ) diff --git a/go.sum b/go.sum index 4534de20..6912f6ae 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,10 @@ github.com/go-text/typesetting-utils v0.0.0-20231211103740-d9332ae51f04 h1:zBx+p github.com/go-text/typesetting-utils v0.0.0-20231211103740-d9332ae51f04/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o= github.com/go-text/typesetting-utils v0.0.0-20240317173224-1986cbe96c66 h1:GUrm65PQPlhFSKjLPGOZNPNxLCybjzjYBzjfoBGaDUY= github.com/go-text/typesetting-utils v0.0.0-20240317173224-1986cbe96c66/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o= +github.com/go-text/typesetting-utils v0.0.0-20240329101916-eee87fb235a3 h1:levTnuLLUmpavLGbJYLJA7fQnKeS7P1eCdAlM+vReXk= +github.com/go-text/typesetting-utils v0.0.0-20240329101916-eee87fb235a3/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o= +github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066 h1:qCuYC+94v2xrb1PoS4NIDe7DGYtLnU2wWiQe9a1B1c0= +github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= From 0702fe7a2d836652efa1b05a1d4d1f0c1c84452a Mon Sep 17 00:00:00 2001 From: Benoit KUGLER Date: Sun, 3 Nov 2024 19:03:39 +0100 Subject: [PATCH 2/2] [fontscan] bump cache version --- fontscan/serialize.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fontscan/serialize.go b/fontscan/serialize.go index 2e823833..3e118e94 100644 --- a/fontscan/serialize.go +++ b/fontscan/serialize.go @@ -185,7 +185,7 @@ func (ff *fileFootprints) deserializeFrom(src []byte) error { return nil } -const cacheFormatVersion = 4 +const cacheFormatVersion = 5 func max(i, j int) int { if i > j {