mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Display all styles from STAT table
This commit is contained in:
@@ -7,15 +7,21 @@ import (
|
|||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
|
|
||||||
type family_style_data struct {
|
type style_group struct {
|
||||||
|
name string
|
||||||
|
ordering int
|
||||||
styles []string
|
styles []string
|
||||||
|
}
|
||||||
|
|
||||||
|
type family_style_data struct {
|
||||||
|
style_groups []style_group
|
||||||
has_variable_faces bool
|
has_variable_faces bool
|
||||||
has_style_attribute_data bool
|
has_style_attribute_data bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func styles_in_family(family string, fonts []ListedFont) (ans *family_style_data) {
|
func styles_in_family(family string, fonts []ListedFont) (ans *family_style_data) {
|
||||||
_ = family
|
_ = family
|
||||||
ans = &family_style_data{styles: make([]string, 0)}
|
ans = &family_style_data{style_groups: make([]style_group, 0)}
|
||||||
for _, f := range fonts {
|
for _, f := range fonts {
|
||||||
vd := variable_data_for(f)
|
vd := variable_data_for(f)
|
||||||
if len(vd.Design_axes) > 0 {
|
if len(vd.Design_axes) > 0 {
|
||||||
@@ -25,25 +31,53 @@ func styles_in_family(family string, fonts []ListedFont) (ans *family_style_data
|
|||||||
ans.has_variable_faces = true
|
ans.has_variable_faces = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
seen := utils.NewSet[string]()
|
|
||||||
add := func(x string) {
|
|
||||||
if !seen.Has(x) {
|
|
||||||
seen.Add(x)
|
|
||||||
ans.styles = append(ans.styles, x)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ans.has_style_attribute_data {
|
if ans.has_style_attribute_data {
|
||||||
|
groups := make(map[string]*style_group)
|
||||||
|
seen_map := make(map[string]*utils.Set[string])
|
||||||
|
get := func(key string, ordering int) (*style_group, *utils.Set[string]) {
|
||||||
|
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
|
||||||
|
seen = utils.NewSet[string]()
|
||||||
|
seen_map[key] = seen
|
||||||
|
}
|
||||||
|
return sg, seen
|
||||||
|
}
|
||||||
for _, f := range fonts {
|
for _, f := range fonts {
|
||||||
vd := variable_data_for(f)
|
vd := variable_data_for(f)
|
||||||
for _, ax := range vd.Design_axes {
|
for _, ax := range vd.Design_axes {
|
||||||
|
if ax.Name == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
sg, seen := get(ax.Name, ax.Ordering)
|
||||||
for _, v := range ax.Values {
|
for _, v := range ax.Values {
|
||||||
add(v.Name)
|
if v.Name != "" && !seen.Has(v.Name) {
|
||||||
|
seen.Add(v.Name)
|
||||||
|
sg.styles = append(sg.styles, v.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for _, ma := range vd.Multi_axis_styles {
|
||||||
|
sg, seen := get("Styles", 0)
|
||||||
|
if ma.Name != "" && !seen.Has(ma.Name) {
|
||||||
|
seen.Add(ma.Name)
|
||||||
|
sg.styles = append(sg.styles, ma.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
utils.StableSortWithKey(ans.style_groups, func(sg style_group) int { return sg.ordering })
|
||||||
} else {
|
} else {
|
||||||
|
ans.style_groups = append(ans.style_groups, style_group{name: "Styles", styles: make([]string, 0)})
|
||||||
|
sg := &ans.style_groups[0]
|
||||||
|
seen := utils.NewSet[string]()
|
||||||
for _, f := range fonts {
|
for _, f := range fonts {
|
||||||
add(f.Style)
|
if f.Style != "" && !seen.Has(f.Style) {
|
||||||
|
seen.Add(f.Style)
|
||||||
|
sg.styles = append(sg.styles, f.Style)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -89,9 +89,11 @@ func (h *handler) draw_family_summary(start_x int, sz loop.ScreenSize) (err erro
|
|||||||
}
|
}
|
||||||
if has_variable_data_for_font(fonts[0]) {
|
if has_variable_data_for_font(fonts[0]) {
|
||||||
s := styles_in_family(family, fonts)
|
s := styles_in_family(family, fonts)
|
||||||
styles := "Styles: " + strings.Join(s.styles, ", ")
|
for _, sg := range s.style_groups {
|
||||||
|
styles := sg.name + ": " + strings.Join(sg.styles, ", ")
|
||||||
add_line(styles)
|
add_line(styles)
|
||||||
add_line("")
|
add_line("")
|
||||||
|
}
|
||||||
add_line(fmt.Sprintf("Press the %s key to choose this family", h.lp.SprintStyled("fg=yellow", "Enter")))
|
add_line(fmt.Sprintf("Press the %s key to choose this family", h.lp.SprintStyled("fg=yellow", "Enter")))
|
||||||
} else {
|
} else {
|
||||||
lines = append(lines, "Reading font data, please wait…")
|
lines = append(lines, "Reading font data, please wait…")
|
||||||
|
|||||||
Reference in New Issue
Block a user