Work on listing available styles for a family

This commit is contained in:
Kovid Goyal
2024-05-03 19:57:02 +05:30
parent 198aec84c2
commit 8a0b562f4f
6 changed files with 41 additions and 4 deletions

View File

@@ -0,0 +1,35 @@
package list_fonts
import (
"fmt"
"kitty/tools/utils"
)
var _ = fmt.Print
func styles_in_family(family string, fonts []ListedFont) (ans []string, is_variable bool) {
has_style_attribute_data := false
for _, f := range fonts {
vd := variable_data_for(f)
if len(vd.Design_axes) > 0 {
has_style_attribute_data = true
break
}
}
ans = make([]string, 0)
seen := utils.NewSet[string]()
add := func(x string) {
if !seen.Has(x) {
seen.Add(x)
ans = append(ans, x)
}
}
if has_style_attribute_data {
} else {
for _, f := range fonts {
add(f.Style)
}
}
debugprintln(111111111, family, has_style_attribute_data, ans)
return
}

View File

@@ -45,6 +45,7 @@ type MultiAxisStyle struct {
type ListedFont struct {
Family string `json:"family"`
Style string `json:"style"`
Fullname string `json:"full_name"`
Postscript_name string `json:"postscript_name"`
Is_monospace bool `json:"is_monospace"`

View File

@@ -83,6 +83,7 @@ func (h *handler) draw_family_summary(start_x int, sz loop.ScreenSize) (err erro
return fmt.Errorf("The family: %s has no fonts", family)
}
if has_variable_data_for_font(fonts[0]) {
styles_in_family(family, fonts)
} else {
lines = append(lines, "Reading font data, please wait…")
key := fonts[0].cache_key()
@@ -261,11 +262,9 @@ func (h *handler) on_wakeup() (err error) {
case SCANNING_FAMILIES:
h.state = LISTING_FAMILIES
h.family_list.UpdateFamilies(utils.StableSortWithKey(maps.Keys(h.fonts), strings.ToLower))
return h.draw_screen()
case LISTING_FAMILIES:
return h.draw_screen()
}
return
return h.draw_screen()
}
func (h *handler) on_key_event(event *loop.KeyEvent) (err error) {