mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-10 22:24:24 +02:00
Work on listing available styles for a family
This commit is contained in:
35
tools/cmd/list_fonts/styles.go
Normal file
35
tools/cmd/list_fonts/styles.go
Normal 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
|
||||
}
|
||||
@@ -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"`
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user