mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-17 13:42:49 +00:00
choose-fonts: Fix missing styles when a family has several font files
This commit is contained in:
parent
e615009378
commit
6ee17085ab
2 changed files with 35 additions and 12 deletions
|
|
@ -23,20 +23,16 @@ type family_style_data struct {
|
|||
}
|
||||
|
||||
func styles_with_attribute_data(ans *family_style_data, items ...VariableData) {
|
||||
groups := make(map[string]*style_group)
|
||||
seen_map := make(map[string]map[string]string)
|
||||
// Store indices, not pointers, as appending to ans.style_groups can reallocate it
|
||||
groups := make(map[string]int)
|
||||
get := func(key string, ordering int) *style_group {
|
||||
sg := groups[key]
|
||||
seen := seen_map[key]
|
||||
if sg == nil {
|
||||
ans.style_groups = append(ans.style_groups, style_group{name: key, ordering: ordering, styles: make([]string, 0)})
|
||||
sg = &ans.style_groups[len(ans.style_groups)-1]
|
||||
groups[key] = sg
|
||||
sg.style_sort_map = make(map[string]string)
|
||||
seen = make(map[string]string)
|
||||
seen_map[key] = seen
|
||||
idx, found := groups[key]
|
||||
if !found {
|
||||
idx = len(ans.style_groups)
|
||||
ans.style_groups = append(ans.style_groups, style_group{name: key, ordering: ordering, styles: make([]string, 0), style_sort_map: make(map[string]string)})
|
||||
groups[key] = idx
|
||||
}
|
||||
return sg
|
||||
return &ans.style_groups[idx]
|
||||
}
|
||||
has := func(n string, m map[string]string) bool {
|
||||
_, found := m[n]
|
||||
|
|
|
|||
27
kittens/choose_fonts/styles_test.go
Normal file
27
kittens/choose_fonts/styles_test.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// License: GPLv3 Copyright: 2026, kitty contributors
|
||||
|
||||
package choose_fonts
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
func TestStylesWithAttributeData(t *testing.T) {
|
||||
face := func(weight string, weight_value float64, italic string, italic_value float64) VariableData {
|
||||
return VariableData{Design_axes: []DesignAxis{
|
||||
{Name: "Weight", Ordering: 0, Values: []DesignAxisValue{{Name: weight, Value: weight_value}}},
|
||||
{Name: "Italic", Ordering: 1, Values: []DesignAxisValue{{Name: italic, Value: italic_value}}},
|
||||
}}
|
||||
}
|
||||
ans := &family_style_data{}
|
||||
styles_with_attribute_data(ans, face("Regular", 400, "Upright", 0), face("Bold", 700, "Italic", 1))
|
||||
actual := map[string][]string{}
|
||||
for _, sg := range ans.style_groups {
|
||||
actual[sg.name] = sg.styles
|
||||
}
|
||||
if diff := cmp.Diff(map[string][]string{"Weight": {"Regular", "Bold"}, "Italic": {"Upright", "Italic"}}, actual); diff != "" {
|
||||
t.Fatalf("Unexpected styles:\n%s", diff)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue