mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-14 04:24:52 +02:00
Get font selection for the cascadia code variable fonts working
This commit is contained in:
@@ -102,7 +102,7 @@ def find_medium_variant(font: Descriptor) -> Descriptor:
|
||||
vd = get_variable_data_for_descriptor(font)
|
||||
for i, ns in enumerate(vd['named_styles']):
|
||||
if ns['name'] == 'Regular':
|
||||
set_named_style(ns['psname'], font, vd)
|
||||
set_named_style(ns['psname'] or ns['name'], font, vd)
|
||||
return font
|
||||
axis_values = {}
|
||||
for i, ax in enumerate(vd['axes']):
|
||||
|
||||
@@ -7,7 +7,7 @@ from collections import defaultdict
|
||||
from functools import lru_cache
|
||||
from typing import Dict, Generator, Iterable, List, NamedTuple, Optional, Sequence, Tuple
|
||||
|
||||
from kitty.fast_data_types import coretext_all_fonts
|
||||
from kitty.fast_data_types import CTFace, coretext_all_fonts
|
||||
from kitty.fonts import FontSpec, family_name_to_key
|
||||
from kitty.options.types import Options
|
||||
from kitty.typing import CoreTextFont
|
||||
@@ -109,9 +109,9 @@ def weight_range_for_family(family: str) -> WeightRange:
|
||||
bold = w
|
||||
elif s == 'bold' and bold == wr.bold:
|
||||
bold = w
|
||||
elif s == 'medium':
|
||||
elif s == 'regular':
|
||||
medium = w
|
||||
elif s == 'regular' and medium == wr.medium:
|
||||
elif s == 'medium' and medium == wr.medium:
|
||||
medium = w
|
||||
return WeightRange(mini, maxi, medium, bold)
|
||||
|
||||
@@ -148,15 +148,18 @@ class CTScorer(Scorer):
|
||||
families = {x['family'] for x in candidates}
|
||||
if len(families) == 1:
|
||||
wr = weight_range_for_family(next(iter(families)))
|
||||
if wr.is_valid and wr.minimum < 0 and wr.maximum <= 0: # Operator Mono is an example of this craziness
|
||||
if wr.is_valid and wr.medium < 0: # Operator Mono is an example of this craziness
|
||||
self.weight_range = wr
|
||||
candidates = sorted(candidates, key=self.score)
|
||||
if dump:
|
||||
print(self)
|
||||
if self.weight_range:
|
||||
print(self.weight_range)
|
||||
for x in candidates:
|
||||
assert x['descriptor_type'] == 'core_text'
|
||||
print(x['postscript_name'], f'bold={x["bold"]}', f'italic={x["italic"]}', f'weight={x["weight"]:.2f}', f'slant={x["slant"]:.2f}')
|
||||
print(self.score(x))
|
||||
print(CTFace(descriptor=x).postscript_name(),
|
||||
f'bold={x["bold"]}', f'italic={x["italic"]}', f'weight={x["weight"]:.2f}', f'slant={x["slant"]:.2f}')
|
||||
print(' ', self.score(x))
|
||||
print()
|
||||
return candidates
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ from kitty.fast_data_types import (
|
||||
FC_SLANT_ROMAN,
|
||||
FC_WEIGHT_REGULAR,
|
||||
FC_WIDTH_NORMAL,
|
||||
Face,
|
||||
fc_list,
|
||||
)
|
||||
from kitty.fast_data_types import (
|
||||
@@ -117,9 +118,9 @@ def weight_range_for_family(family: str) -> WeightRange:
|
||||
bold = w
|
||||
elif s == 'bold' and bold == wr.bold:
|
||||
bold = w
|
||||
elif s == 'medium':
|
||||
elif s == 'regular':
|
||||
medium = w
|
||||
elif s == 'regular' and medium == wr.medium:
|
||||
elif s == 'medium' and medium == wr.medium:
|
||||
medium = w
|
||||
return WeightRange(mini, maxi, medium, bold)
|
||||
|
||||
@@ -148,15 +149,17 @@ class FCScorer(Scorer):
|
||||
families = {x['family'] for x in candidates}
|
||||
if len(families) == 1:
|
||||
wr = weight_range_for_family(next(iter(families)))
|
||||
if wr.is_valid and wr.maximum < 100: # Operator Mono is an example of this craziness
|
||||
if wr.is_valid and wr.medium < 100: # Operator Mono and Cascadia Code are examples
|
||||
self.weight_range = wr
|
||||
candidates = sorted(candidates, key=self.score)
|
||||
if dump:
|
||||
print(self)
|
||||
if self.weight_range:
|
||||
print(self.weight_range)
|
||||
for x in candidates:
|
||||
assert x['descriptor_type'] == 'fontconfig'
|
||||
print(x['postscript_name'], f'weight={x["weight"]}', f'slant={x["slant"]}')
|
||||
print(self.score(x))
|
||||
print(Face(descriptor=x).postscript_name(), f'weight={x["weight"]}', f'slant={x["slant"]}')
|
||||
print(' ', self.score(x))
|
||||
print()
|
||||
return candidates
|
||||
|
||||
|
||||
Reference in New Issue
Block a user