mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-06 01:05:48 +02:00
Work on getting styles from STAT table data
This commit is contained in:
@@ -25,6 +25,9 @@ def create_family_groups(monospaced: bool = True) -> Dict[str, List[ListedFont]]
|
||||
def as_json(indent: Optional[int] = None) -> str:
|
||||
import json
|
||||
groups = create_family_groups()
|
||||
for v in groups.values():
|
||||
for f in v:
|
||||
f['variable_data'] = get_variable_data_for_descriptor(f['descriptor']) # type: ignore
|
||||
return json.dumps(groups, indent=indent)
|
||||
|
||||
|
||||
|
||||
@@ -63,13 +63,14 @@ const (
|
||||
MARK_AFTER = "\033[39m"
|
||||
)
|
||||
|
||||
func apply_search(families []string, expression string, marks ...string) []string {
|
||||
func apply_search(families []string, expression string, marks ...string) (matched_families []string, display_strings []string) {
|
||||
mark_before, mark_after := MARK_BEFORE, MARK_AFTER
|
||||
if len(marks) == 2 {
|
||||
mark_before, mark_after = marks[0], marks[1]
|
||||
}
|
||||
results := utils.Filter(match(expression, families), func(x *subseq.Match) bool { return x.Score > 0 })
|
||||
ans := make([]string, 0, len(results))
|
||||
matched_families = make([]string, 0, len(results))
|
||||
display_strings = make([]string, 0, len(results))
|
||||
for _, m := range results {
|
||||
text := m.Text
|
||||
positions := m.Positions
|
||||
@@ -77,15 +78,17 @@ func apply_search(families []string, expression string, marks ...string) []strin
|
||||
p := positions[i]
|
||||
text = text[:p] + mark_before + text[p:p+1] + mark_after + text[p+1:]
|
||||
}
|
||||
ans = append(ans, text)
|
||||
display_strings = append(display_strings, text)
|
||||
matched_families = append(matched_families, m.Text)
|
||||
}
|
||||
return ans
|
||||
return
|
||||
}
|
||||
|
||||
func (self *FamilyList) UpdateFamilies(families []string) {
|
||||
self.families, self.all_families = families, families
|
||||
if self.current_search != "" {
|
||||
self.display_strings = utils.Map(limit_lengths, apply_search(self.all_families, self.current_search))
|
||||
self.families, self.display_strings = apply_search(self.all_families, self.current_search)
|
||||
self.display_strings = utils.Map(limit_lengths, self.display_strings)
|
||||
} else {
|
||||
self.display_strings = utils.Map(limit_lengths, families)
|
||||
}
|
||||
|
||||
@@ -7,29 +7,44 @@ import (
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
func styles_in_family(family string, fonts []ListedFont) (ans []string, is_variable bool) {
|
||||
has_style_attribute_data := false
|
||||
type family_style_data struct {
|
||||
styles []string
|
||||
has_variable_faces bool
|
||||
has_style_attribute_data bool
|
||||
}
|
||||
|
||||
func styles_in_family(family string, fonts []ListedFont) (ans *family_style_data) {
|
||||
_ = family
|
||||
ans = &family_style_data{styles: make([]string, 0)}
|
||||
for _, f := range fonts {
|
||||
vd := variable_data_for(f)
|
||||
if len(vd.Design_axes) > 0 {
|
||||
has_style_attribute_data = true
|
||||
break
|
||||
ans.has_style_attribute_data = true
|
||||
}
|
||||
if len(vd.Axes) > 0 {
|
||||
ans.has_variable_faces = true
|
||||
}
|
||||
}
|
||||
ans = make([]string, 0)
|
||||
seen := utils.NewSet[string]()
|
||||
add := func(x string) {
|
||||
if !seen.Has(x) {
|
||||
seen.Add(x)
|
||||
ans = append(ans, x)
|
||||
ans.styles = append(ans.styles, x)
|
||||
}
|
||||
}
|
||||
if has_style_attribute_data {
|
||||
if ans.has_style_attribute_data {
|
||||
for _, f := range fonts {
|
||||
vd := variable_data_for(f)
|
||||
for _, ax := range vd.Design_axes {
|
||||
for _, v := range ax.Values {
|
||||
add(v.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, f := range fonts {
|
||||
add(f.Style)
|
||||
}
|
||||
}
|
||||
debugprintln(111111111, family, has_style_attribute_data, ans)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ type NamedStyle struct {
|
||||
Postscript_name string `json:"psname"`
|
||||
}
|
||||
|
||||
type DesignAxis struct {
|
||||
type DesignAxisValue struct {
|
||||
Format int `json:"format"`
|
||||
Flags int `json:"flags"`
|
||||
Name string `json:"name"`
|
||||
@@ -32,6 +32,13 @@ type DesignAxis struct {
|
||||
Linked_value float64 `json:"linked_value"`
|
||||
}
|
||||
|
||||
type DesignAxis struct {
|
||||
Tag string `json:"tag"`
|
||||
Name string `json:"name"`
|
||||
Ordering int `json:"ordering"`
|
||||
Values []DesignAxisValue `json:"values"`
|
||||
}
|
||||
|
||||
type AxisValue struct {
|
||||
Design_index int `json:"design_index"`
|
||||
Value float64 `json:"value"`
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"kitty/tools/tui/loop"
|
||||
"kitty/tools/tui/readline"
|
||||
"kitty/tools/utils"
|
||||
"kitty/tools/utils/style"
|
||||
"kitty/tools/wcswidth"
|
||||
|
||||
"golang.org/x/exp/maps"
|
||||
@@ -78,12 +79,20 @@ func (h *handler) draw_family_summary(start_x int, sz loop.ScreenSize) (err erro
|
||||
h.lp.SprintStyled("fg=green bold", center_string(family, int(sz.WidthCells)-start_x)),
|
||||
"",
|
||||
}
|
||||
width := int(sz.WidthCells) - start_x - 1
|
||||
add_line := func(x string) {
|
||||
lines = append(lines, style.WrapTextAsLines(x, width, style.WrapOptions{})...)
|
||||
}
|
||||
fonts := h.fonts[family]
|
||||
if len(fonts) == 0 {
|
||||
return fmt.Errorf("The family: %s has no fonts", family)
|
||||
}
|
||||
if has_variable_data_for_font(fonts[0]) {
|
||||
styles_in_family(family, fonts)
|
||||
s := styles_in_family(family, fonts)
|
||||
styles := "Styles: " + strings.Join(s.styles, ", ")
|
||||
add_line(styles)
|
||||
add_line("")
|
||||
add_line(fmt.Sprintf("Press the %s key to choose this family", h.lp.SprintStyled("fg=yellow", "Enter")))
|
||||
} else {
|
||||
lines = append(lines, "Reading font data, please wait…")
|
||||
key := fonts[0].cache_key()
|
||||
|
||||
Reference in New Issue
Block a user