choose-fonts: Show styles in axis value order

styles_in_family sorted every style group alphabetically, discarding the
axis value order computed by styles_with_attribute_data, so weights were
listed as, for example, Bold, Light, Regular instead of Light, Regular,
Bold. Only sort by name when falling back to the style names of the fonts.
This commit is contained in:
Kovid Goyal 2026-10-23 19:11:29 +05:30
parent 2df0dcc5e5
commit 3867ffa92b
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 12 additions and 2 deletions

View file

@ -115,8 +115,7 @@ func styles_in_family_from_variable_data(fonts []ListedFont, vds []VariableData)
sg.styles = append(sg.styles, f.Style)
}
}
}
for _, sg := range ans.style_groups {
// styles_with_attribute_data has already sorted by axis value, only sort by name here
slices.Sort(sg.styles)
}
return

View file

@ -65,4 +65,15 @@ func TestStylesInFamily(t *testing.T) {
// Without style attribute data, the de-duplicated style names of the fonts are used
fonts := []ListedFont{{Style: "Regular"}, {Style: "Bold"}, {Style: ""}, {Style: "Bold"}, {Style: "Italic"}}
check([]group_result{{"Styles", []string{"Bold", "Italic", "Regular"}}}, fonts, make([]VariableData, len(fonts)))
// With style attribute data, styles are sorted by axis value, not by name
vd := 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}}},
}}
}
fonts = []ListedFont{{Style: "Bold"}, {Style: "Regular"}, {Style: "Light"}}
check([]group_result{{"Weight", []string{"Light", "Regular", "Bold"}}, {"Italic", []string{"Upright", "Italic"}}},
fonts, []VariableData{vd("Bold", 700, "Italic", 1), vd("Regular", 400, "Upright", 0), vd("Light", 300, "Upright", 0)})
}