DOnt be lazy about typing font features

This commit is contained in:
Kovid Goyal
2021-05-25 09:29:47 +05:30
parent b169831810
commit ba821cb02f
5 changed files with 16 additions and 9 deletions

View File

@@ -11,9 +11,13 @@ class ListedFont(TypedDict):
is_monospace: bool
class FontFeature(str):
class FontFeature:
def __new__(cls, name: str, parsed: bytes) -> 'FontFeature':
ans: FontFeature = str.__new__(cls, name)
ans.parsed = parsed # type: ignore
return ans
__slots__ = 'name', 'parsed'
def __init__(self, name: str, parsed: bytes):
self.name = name
self.parsed = parsed
def __repr__(self) -> str:
return repr(self.name)

View File

@@ -6,6 +6,7 @@ import re
from typing import Dict, Generator, Iterable, List, Optional, Tuple
from kitty.fast_data_types import coretext_all_fonts
from kitty.fonts import FontFeature
from kitty.options_stub import Options
from kitty.typing import CoreTextFont
from kitty.utils import log_error
@@ -50,7 +51,7 @@ def list_fonts() -> Generator[ListedFont, None, None]:
yield {'family': f, 'full_name': fn, 'postscript_name': fd['postscript_name'] or '', 'is_monospace': is_mono}
def find_font_features(postscript_name: str) -> Tuple[str, ...]:
def find_font_features(postscript_name: str) -> Tuple[FontFeature, ...]:
"""Not Implemented"""
return ()

View File

@@ -71,7 +71,7 @@ def fc_match(family: str, bold: bool, italic: bool, spacing: int = FC_MONO) -> F
return fc_match_impl(family, bold, italic, spacing)
def find_font_features(postscript_name: str) -> Tuple[str, ...]:
def find_font_features(postscript_name: str) -> Tuple[FontFeature, ...]:
pat = fc_match_postscript_name(postscript_name)
if pat.get('postscript_name') != postscript_name or 'fontfeatures' not in pat: