Skip to content

Commit

Permalink
[fontscan] make test platform independant
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitkugler committed Jan 2, 2025
1 parent 1098eb8 commit 2575211
Showing 1 changed file with 145 additions and 12 deletions.
157 changes: 145 additions & 12 deletions fontscan/fontmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"log"
"os"
"path/filepath"
"runtime"
"testing"
"time"

Expand Down Expand Up @@ -320,21 +319,155 @@ func TestFindSytemFont(t *testing.T) {
tu.Assert(t, !ok) // user provided font are ignored
}

func TestResolveSameScript(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip()
func TestResolve_ScriptBengali(t *testing.T) {
// this sample fontset is build from a "typical linux" system,
// looking for Lohit-Bengali, NimbusSans, and Lohit-Devanagari
// families
bengaliFontSet := fontSet{
{
Location: Location{File: "/usr/share/fonts/opentype/urw-base35/NimbusSans-Bold.otf"},
Family: "nimbussans",
Runes: RuneSet{
{0x0, pageSet{0x0, 0xffffffff, 0xffffffff, 0x7fffffff, 0x0, 0xffffffff, 0xffffffff, 0xffffffff}},
{0x1, pageSet{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x40000, 0x0, 0x0, 0xfc000000}},
{0x2, pageSet{0xf000000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3f0002c0, 0x0}},
{0x3, pageSet{0x0, 0x0, 0x0, 0x0, 0xffffd7f0, 0xfffffffb, 0x627fff, 0x0}},
{0x4, pageSet{0xffffffff, 0xffffffff, 0xffffffff, 0x3c000c, 0x3fcf0000, 0xfcfcc0f, 0x3009801, 0xc30c}},
{0x1e, pageSet{0x0, 0x0, 0x0, 0x0, 0x3f, 0x0, 0x0, 0xc0000}},
{0x20, pageSet{0x7fb80004, 0x560d0047, 0x10, 0x83f10000, 0x0, 0x9098, 0x20000000, 0x0}},
{0x21, pageSet{0x514e8020, 0xe0e145, 0x78000000, 0x0, 0x3ff0000, 0x200100, 0x3f0050, 0x0}},
{0x22, pageSet{0xe6aeabed, 0xb04fa9, 0x120, 0xc37, 0x3e000fc, 0x800003c, 0x0, 0x0}},
{0x23, pageSet{0x10004, 0x603, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}},
{0x25, pageSet{0x11111005, 0x10101010, 0xffff0000, 0x1ffff, 0xf1111, 0x96241c03, 0x3008cd8, 0x40}},
{0x26, pageSet{0x0, 0x1c000000, 0x5, 0xc69, 0x0, 0x0, 0x0, 0x0}},
{0x30, pageSet{0xc000000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}},
{0xef, pageSet{0x0, 0x0, 0x0, 0x0, 0x0, 0x80000000, 0xffffffff, 0xfc001fff}},
{0xfb, pageSet{0x1f, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}},
{0xff, pageSet{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80000000}},
},
Scripts: ScriptSet{0x4379726c, 0x4772656b, 0x4c61746e, 0x5a696e68, 0x5a797979, 0x5a7a7a7a},
Langs: LangSet{0x7e2e743b4227384d, 0x9803d4f39f0115fc, 0x8b176fdad2678cfb, 0xa7b822ffbb0b91f0, 0x418f794, 0x0, 0x0, 0x0},
Aspect: font.Aspect{Style: 0x1, Weight: 700, Stretch: 1},
},
{
Location: Location{File: "/usr/share/fonts/opentype/urw-base35/NimbusSans-BoldItalic.otf"},
Family: "nimbussans",
Runes: RuneSet{
{0x0, pageSet{0x0, 0xffffffff, 0xffffffff, 0x7fffffff, 0x0, 0xffffffff, 0xffffffff, 0xffffffff}},
{0x1, pageSet{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x40000, 0x0, 0x0, 0xfc000000}},
{0x2, pageSet{0xf000000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3f0002c0, 0x0}},
{0x3, pageSet{0x0, 0x0, 0x0, 0x0, 0xffffd7f0, 0xfffffffb, 0x627fff, 0x0}},
{0x4, pageSet{0xffffffff, 0xffffffff, 0xffffffff, 0x3c000c, 0x3fcf0000, 0xfcfcc0f, 0x3009801, 0xc30c}},
{0x1e, pageSet{0x0, 0x0, 0x0, 0x0, 0x3f, 0x0, 0x0, 0xc0000}},
{0x20, pageSet{0x7fb80004, 0x560d0047, 0x10, 0x83f10000, 0x0, 0x9098, 0x20000000, 0x0}},
{0x21, pageSet{0x514e8020, 0xe0e145, 0x78000000, 0x0, 0x3ff0000, 0x200100, 0x3f0050, 0x0}},
{0x22, pageSet{0xe6aeabed, 0xb04fa9, 0x120, 0xc37, 0x3e000fc, 0x800003c, 0x0, 0x0}},
{0x23, pageSet{0x10004, 0x603, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}},
{0x25, pageSet{0x11111005, 0x10101010, 0xffff0000, 0x1ffff, 0xf1111, 0x96241c03, 0x3008cd8, 0x40}},
{0x26, pageSet{0x0, 0x1c000000, 0x5, 0xc69, 0x0, 0x0, 0x0, 0x0}},
{0x30, pageSet{0xc000000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}},
{0xef, pageSet{0x0, 0x0, 0x0, 0x0, 0x0, 0x80000000, 0xffffffff, 0xfc001fff}},
{0xfb, pageSet{0x1f, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}},
{0xff, pageSet{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80000000}},
},
Scripts: ScriptSet{0x4379726c, 0x4772656b, 0x4c61746e, 0x5a696e68, 0x5a797979, 0x5a7a7a7a},
Langs: LangSet{0x7e2e743b4227384d, 0x9803d4f39f0115fc, 0x8b176fdad2678cfb, 0xa7b822ffbb0b91f0, 0x418f794, 0x0, 0x0, 0x0},
Aspect: font.Aspect{Style: 0x2, Weight: 700, Stretch: 1},
},
{
Location: Location{File: "/usr/share/fonts/opentype/urw-base35/NimbusSans-Italic.otf"},
Family: "nimbussans",
Runes: RuneSet{
{0x0, pageSet{0x0, 0xffffffff, 0xffffffff, 0x7fffffff, 0x0, 0xffffffff, 0xffffffff, 0xffffffff}},
{0x1, pageSet{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x40000, 0x0, 0x0, 0xfc000000}},
{0x2, pageSet{0xf000000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3f0002c0, 0x0}},
{0x3, pageSet{0x0, 0x0, 0x0, 0x0, 0xffffd7f0, 0xfffffffb, 0x627fff, 0x0}},
{0x4, pageSet{0xffffffff, 0xffffffff, 0xffffffff, 0x3c000c, 0x3fcf0000, 0xfcfcc0f, 0x3009801, 0xc30c}},
{0x1e, pageSet{0x0, 0x0, 0x0, 0x0, 0x3f, 0x0, 0x0, 0xc0000}},
{0x20, pageSet{0x7fb80004, 0x560d0047, 0x10, 0x83f10000, 0x0, 0x9098, 0x20000000, 0x0}},
{0x21, pageSet{0x514e8020, 0xe0e145, 0x78000000, 0x0, 0x3ff0000, 0x200100, 0x3f0050, 0x0}},
{0x22, pageSet{0xe6aeabed, 0xb04fa9, 0x120, 0xc37, 0x3e000fc, 0x800003c, 0x0, 0x0}},
{0x23, pageSet{0x10004, 0x603, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}},
{0x25, pageSet{0x11111005, 0x10101010, 0xffff0000, 0x1ffff, 0xf1111, 0x96241c03, 0x3008cd8, 0x40}},
{0x26, pageSet{0x0, 0x1c000000, 0x5, 0xc69, 0x0, 0x0, 0x0, 0x0}},
{0x30, pageSet{0xc000000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}},
{0xef, pageSet{0x0, 0x0, 0x0, 0x0, 0x0, 0x80000000, 0xffffffff, 0xfc001fff}},
{0xfb, pageSet{0x1f, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}},
{0xff, pageSet{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80000000}},
},
Scripts: ScriptSet{0x4379726c, 0x4772656b, 0x4c61746e, 0x5a696e68, 0x5a797979, 0x5a7a7a7a},
Langs: LangSet{0x7e2e743b4227384d, 0x9803d4f39f0115fc, 0x8b176fdad2678cfb, 0xa7b822ffbb0b91f0, 0x418f794, 0x0, 0x0, 0x0},
Aspect: font.Aspect{Style: 0x2, Weight: 400, Stretch: 1},
},
{
Location: Location{File: "/usr/share/fonts/opentype/urw-base35/NimbusSans-Regular.otf"},
Family: "nimbussans",
Runes: RuneSet{
{0x0, pageSet{0x0, 0xffffffff, 0xffffffff, 0x7fffffff, 0x0, 0xffffffff, 0xffffffff, 0xffffffff}},
{0x1, pageSet{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x40000, 0x0, 0x0, 0xfc000000}},
{0x2, pageSet{0xf000000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3f0002c0, 0x0}},
{0x3, pageSet{0x0, 0x0, 0x0, 0x0, 0xffffd7f0, 0xfffffffb, 0x627fff, 0x0}},
{0x4, pageSet{0xffffffff, 0xffffffff, 0xffffffff, 0x3c000c, 0x3fcf0000, 0xfcfcc0f, 0x3009801, 0xc30c}},
{0x1e, pageSet{0x0, 0x0, 0x0, 0x0, 0x3f, 0x0, 0x0, 0xc0000}},
{0x20, pageSet{0x7fb80004, 0x560d0047, 0x10, 0x83f10000, 0x0, 0x9098, 0x20000000, 0x0}},
{0x21, pageSet{0x514e8020, 0xe0e145, 0x78000000, 0x0, 0x3ff0000, 0x200100, 0x3f0050, 0x0}},
{0x22, pageSet{0xe6aeabed, 0xb04fa9, 0x120, 0xc37, 0x3e000fc, 0x800003c, 0x0, 0x0}},
{0x23, pageSet{0x10004, 0x603, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}},
{0x25, pageSet{0x11111005, 0x10101010, 0xffff0000, 0x1ffff, 0xf1111, 0x96241c03, 0x3008cd8, 0x40}},
{0x26, pageSet{0x0, 0x1c000000, 0x5, 0xc69, 0x0, 0x0, 0x0, 0x0}},
{0x30, pageSet{0xc000000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}},
{0xef, pageSet{0x0, 0x0, 0x0, 0x0, 0x0, 0x80000000, 0xffffffff, 0xfc001fff}},
{0xfb, pageSet{0x1f, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}},
{0xff, pageSet{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80000000}},
},
Scripts: ScriptSet{0x4379726c, 0x4772656b, 0x4c61746e, 0x5a696e68, 0x5a797979, 0x5a7a7a7a},
Langs: LangSet{0x7e2e743b4227384d, 0x9803d4f39f0115fc, 0x8b176fdad2678cfb, 0xa7b822ffbb0b91f0, 0x418f794, 0x0, 0x0, 0x0},
Aspect: font.Aspect{Style: 0x1, Weight: 400, Stretch: 1},
},
{
Location: Location{File: "/usr/share/fonts/truetype/lohit-bengali/Lohit-Bengali.ttf"},
Family: "lohitbengali",
Runes: RuneSet{
{0x0, pageSet{0x0, 0xffffffff, 0xf8000001, 0x78000001, 0x0, 0x4, 0x800000, 0x800000}},
{0x9, pageSet{0x0, 0x0, 0x0, 0x30, 0xfff99fef, 0xf3fdfdff, 0xb0807f9f, 0xfffffcf}},
{0x20, pageSet{0x3ff83000, 0x40, 0x0, 0x0, 0x0, 0x2000000, 0x0, 0x0}},
{0x22, pageSet{0x40000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}},
{0x25, pageSet{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1000, 0x0}},
{0xff, pageSet{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80000000}},
},
Scripts: ScriptSet{0x42656e67, 0x5a696e68, 0x5a797979, 0x5a7a7a7a},
Langs: LangSet{0x10000200, 0x0, 0x4000000, 0x0, 0x0, 0x0, 0x0, 0x0},
Aspect: font.Aspect{Style: 0x1, Weight: 400, Stretch: 1},
},
{
Location: Location{File: "/usr/share/fonts/truetype/lohit-devanagari/Lohit-Devanagari.ttf"},
Family: "lohitdevanagari",
Runes: RuneSet{
{0x0, pageSet{0x0, 0xffffffff, 0xffffffff, 0x7fffffff, 0x0, 0xffffdffe, 0xffffffff, 0xffffffff}},
{0x1, pageSet{0xcfcff0ff, 0xffffcf8f, 0xcfff31ff, 0x7f0fcc3f, 0x40000, 0x0, 0x0, 0x0}},
{0x2, pageSet{0xf000000, 0x800000, 0x0, 0x0, 0x0, 0x10000000, 0x3f0000c0, 0x0}},
{0x3, pageSet{0x80, 0x40, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0}},
{0x9, pageSet{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x0, 0x0, 0x0, 0x0}},
{0x1c, pageSet{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x600000}},
{0x20, pageSet{0xfff83000, 0x601007f, 0x10, 0x0, 0x1f, 0x2001000, 0x0, 0x0}},
{0x21, pageSet{0x80000, 0x407c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}},
{0x22, pageSet{0x7c07807c, 0x800, 0x100, 0x30, 0x0, 0x0, 0x0, 0x0}},
{0x25, pageSet{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1c00, 0x0}},
{0xa8, pageSet{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3fffffff}},
{0xfb, pageSet{0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}},
{0xff, pageSet{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80000000}},
},
Scripts: ScriptSet{0x44657661, 0x4772656b, 0x4c61746e, 0x5a696e68, 0x5a797979, 0x5a7a7a7a},
Langs: LangSet{0x743c7429c3c430c9, 0x882084e39fe115fc, 0x8b066ff86023ecc8, 0x13b880fb9b021b74, 0x418d794, 0x0, 0x0, 0x0},
Aspect: font.Aspect{Style: 0x1, Weight: 400, Stretch: 1},
},
}
// we assume the system contains at least these fonts :
// lohit-bengali/Lohit-Bengali.ttf
// urw-base35/NimbusSans-Regular.otf
// lohit-devanagari/Lohit-Devanagari.ttf

// make sure the same font is selected for a given script, when possible
text := []rune("হয় না।")
fm := NewFontMap(log.New(io.Discard, "", 0))
err := fm.UseSystemFonts(os.TempDir())
tu.AssertNoErr(t, err)
fm.appendFootprints(bengaliFontSet...)

// make sure the same font is selected for a given script, when possible
text := []rune("হয় না।")
fm.SetQuery(Query{Families: []string{"Nimbus Sans"}})
runs := (&shaping.Segmenter{}).Split(shaping.Input{Text: text, RunEnd: len(text)}, fm)
tu.Assert(t, len(runs) == 1)
Expand Down

0 comments on commit 2575211

Please sign in to comment.