Remove box drawing python code

This commit is contained in:
Kovid Goyal
2024-12-23 14:50:53 +05:30
parent 6a18db45f0
commit c67475271f
7 changed files with 766 additions and 1603 deletions

View File

@@ -2678,7 +2678,6 @@ class Boss:
window.refresh()
def apply_new_options(self, opts: Options) -> None:
from .fonts.box_drawing import set_scale
bg_colors_before = {w.id: w.screen.color_profile.default_bg for w in self.all_windows}
# Update options storage
set_options(opts, is_wayland(), self.args.debug_rendering, self.args.debug_font_fallback)
@@ -2686,7 +2685,6 @@ class Boss:
set_layout_options(opts)
set_default_env(opts.env.copy())
# Update font data
set_scale(opts.box_drawing_scale)
from .fonts.render import set_font_family
set_font_family(opts)
for os_window_id, tm in self.os_window_map.items():

View File

@@ -1,5 +1,4 @@
import termios
from ctypes import Array, c_ubyte
from typing import Any, Callable, Dict, Iterator, List, Literal, NewType, Optional, Tuple, TypedDict, Union, overload
from kitty.boss import Boss
@@ -1131,7 +1130,6 @@ def set_send_sprite_to_gpu(
def set_font_data(
box_drawing_func: Callable[[int, int, int, float], Tuple[int, Union[bytearray, bytes, Array[c_ubyte]]]],
descriptor_for_idx: Callable[[int], Tuple[Union[FontObject|str], bool, bool]],
bold: int, italic: int, bold_italic: int, num_symbol_fonts: int,
symbol_maps: Tuple[Tuple[int, int, int], ...], font_sz_in_pts: float,

View File

@@ -769,7 +769,7 @@ START_ALLOW_CASE_RANGE
END_ALLOW_CASE_RANGE
}
static PyObject* box_drawing_function = NULL, *descriptor_for_idx = NULL;
static PyObject *descriptor_for_idx = NULL;
void
render_alpha_mask(const uint8_t *alpha_mask, pixel* dest, const Region *src_rect, const Region *dest_rect, size_t src_stride, size_t dest_stride, pixel color_rgb) {
@@ -1912,12 +1912,12 @@ set_symbol_maps(SymbolMap **maps, size_t *num, const PyObject *sm) {
static PyObject*
set_font_data(PyObject UNUSED *m, PyObject *args) {
PyObject *sm, *ns;
Py_CLEAR(box_drawing_function); Py_CLEAR(descriptor_for_idx);
if (!PyArg_ParseTuple(args, "OOIIIIO!dO!",
&box_drawing_function, &descriptor_for_idx,
Py_CLEAR(descriptor_for_idx);
if (!PyArg_ParseTuple(args, "OIIIIO!dO!",
&descriptor_for_idx,
&descriptor_indices.bold, &descriptor_indices.italic, &descriptor_indices.bi, &descriptor_indices.num_symbol_fonts,
&PyTuple_Type, &sm, &OPT(font_size), &PyTuple_Type, &ns)) return NULL;
Py_INCREF(box_drawing_function); Py_INCREF(descriptor_for_idx);
Py_INCREF(descriptor_for_idx);
free_font_groups();
clear_symbol_maps();
set_symbol_maps(&symbol_maps, &num_symbol_maps, sm);
@@ -2030,7 +2030,6 @@ static void
finalize(void) {
Py_CLEAR(python_send_to_gpu_impl);
clear_symbol_maps();
Py_CLEAR(box_drawing_function);
Py_CLEAR(descriptor_for_idx);
free_font_groups();
free(ligature_types);

File diff suppressed because it is too large Load Diff

View File

@@ -5,7 +5,7 @@ import ctypes
import os
import sys
from collections.abc import Generator
from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, Union, cast
from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, Union
from kitty.constants import fonts_dir, is_macos
from kitty.fast_data_types import (
@@ -22,7 +22,6 @@ from kitty.fast_data_types import (
test_render_line,
test_shape,
)
from kitty.fonts.box_drawing import BufType, render_box_char
from kitty.options.types import Options, defaults
from kitty.options.utils import parse_font_spec
from kitty.types import _T
@@ -205,7 +204,7 @@ def set_font_family(opts: Optional[Options] = None, override_font_size: Optional
ns = create_narrow_symbols(opts)
num_symbol_fonts = len(current_faces) - before
set_font_data(
render_box_drawing, descriptor_for_idx,
descriptor_for_idx,
indices['bold'], indices['italic'], indices['bi'], num_symbol_fonts,
sm, sz, ns
)
@@ -218,15 +217,6 @@ else:
UnderlineCallback = Callable[[CBufType, int, int, int, int], None]
def render_box_drawing(codepoint: int, cell_width: int, cell_height: int, dpi: float) -> tuple[int, CBufType]:
CharTexture = ctypes.c_ubyte * (cell_width * cell_height)
buf = CharTexture()
render_box_char(
chr(codepoint), cast(BufType, buf), cell_width, cell_height, dpi
)
return ctypes.addressof(buf), buf
class setup_for_testing:
xnum = 100000

View File

@@ -45,7 +45,6 @@ from .fast_data_types import (
set_default_window_icon,
set_options,
)
from .fonts.box_drawing import set_scale
from .fonts.render import dump_font_debug, set_font_family
from .options.types import Options
from .options.utils import DELETE_ENV_VAR
@@ -253,7 +252,6 @@ class AppRunner:
self.initial_window_size_func = initial_window_size_func
def __call__(self, opts: Options, args: CLIOptions, bad_lines: Sequence[BadLine] = (), talk_fd: int = -1) -> None:
set_scale(opts.box_drawing_scale)
set_options(opts, is_wayland(), args.debug_rendering, args.debug_font_fallback)
if theme_colors.refresh():
theme_colors.patch_opts(opts, args.debug_rendering)

View File

@@ -6,7 +6,9 @@ import os
import tempfile
import unittest
from functools import lru_cache, partial
from itertools import repeat
from math import ceil
from typing import Iterable
from kitty.constants import is_macos, read_kitty_resource
from kitty.fast_data_types import (
@@ -22,7 +24,6 @@ from kitty.fast_data_types import (
wcwidth,
)
from kitty.fonts import family_name_to_key
from kitty.fonts.box_drawing import box_chars
from kitty.fonts.common import FontSpec, all_fonts_map, face_from_descriptor, get_font_files, get_named_style, spec_for_face
from kitty.fonts.render import coalesce_symbol_maps, render_string, setup_for_testing, shape_string
from kitty.options.types import Options
@@ -430,3 +431,760 @@ class Rendering(FontBaseTest):
q = {(0, 30): 'a', (10, 10): 'b', (11, 11): 'b', (2, 2): 'c', (1, 1): 'c'}
self.ae(coalesce_symbol_maps(q), {
(0, 0): 'a', (1, 2): 'c', (3, 9): 'a', (10, 11): 'b', (12, 30): 'a'})
def test_chars(chars: str = '', sz: int = 128) -> None:
# kitty +runpy "from kitty.fonts.box_drawing import test_chars; test_chars('XXX')"
from kitty.fast_data_types import concat_cells, render_box_char, set_send_sprite_to_gpu
from .render import display_bitmap, setup_for_testing
if not chars:
import sys
chars = sys.argv[-1]
with setup_for_testing('monospace', sz) as (_, width, height):
try:
for ch in chars:
nb = render_box_char(ord(ch), width, height)
rgb_data = concat_cells(width, height, False, (nb,))
display_bitmap(rgb_data, width, height)
print()
finally:
set_send_sprite_to_gpu(None)
def test_drawing(sz: int = 48, family: str = 'monospace', start: int = 0x2500, num_rows: int = 10, num_cols: int = 16) -> None:
from kitty.fast_data_types import concat_cells, render_box_char, set_send_sprite_to_gpu
from .render import display_bitmap, setup_for_testing
with setup_for_testing(family, sz) as (_, width, height):
space = bytearray(width * height)
def join_cells(cells: Iterable[bytes]) -> bytes:
cells = tuple(bytes(x) for x in cells)
return concat_cells(width, height, False, cells)
def render_chr(ch: str) -> bytearray:
if ch in box_chars:
return bytearray(render_box_char(ord(ch), width, height))
return space
pos = start
rows = []
space_row = join_cells(repeat(space, 32))
try:
for r in range(num_rows):
row = []
for i in range(num_cols):
row.append(render_chr(chr(pos)))
row.append(space)
pos += 1
rows.append(join_cells(row))
rows.append(space_row)
rgb_data = b''.join(rows)
width *= 32
height *= len(rows)
assert len(rgb_data) == width * height * 4, f'{len(rgb_data)} != {width * height * 4}'
display_bitmap(rgb_data, width, height)
finally:
set_send_sprite_to_gpu(None)
box_chars = { # {{{
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'\ue0b0',
'\ue0b1',
'\ue0b2',
'\ue0b3',
'\ue0b4',
'\ue0b5',
'\ue0b6',
'\ue0b7',
'\ue0b8',
'\ue0b9',
'\ue0ba',
'\ue0bb',
'\ue0bc',
'\ue0bd',
'\ue0be',
'\ue0bf',
'\ue0d6',
'\ue0d7',
'\uee00',
'\uee01',
'\uee02',
'\uee03',
'\uee04',
'\uee05',
'\uee06',
'\uee07',
'\uee08',
'\uee09',
'\uee0a',
'\uee0b',
'\uf5d0',
'\uf5d1',
'\uf5d2',
'\uf5d3',
'\uf5d4',
'\uf5d5',
'\uf5d6',
'\uf5d7',
'\uf5d8',
'\uf5d9',
'\uf5da',
'\uf5db',
'\uf5dc',
'\uf5dd',
'\uf5de',
'\uf5df',
'\uf5e0',
'\uf5e1',
'\uf5e2',
'\uf5e3',
'\uf5e4',
'\uf5e5',
'\uf5e6',
'\uf5e7',
'\uf5e8',
'\uf5e9',
'\uf5ea',
'\uf5eb',
'\uf5ec',
'\uf5ed',
'\uf5ee',
'\uf5ef',
'\uf5f0',
'\uf5f1',
'\uf5f2',
'\uf5f3',
'\uf5f4',
'\uf5f5',
'\uf5f6',
'\uf5f7',
'\uf5f8',
'\uf5f9',
'\uf5fa',
'\uf5fb',
'\uf5fc',
'\uf5fd',
'\uf5fe',
'\uf5ff',
'\uf600',
'\uf601',
'\uf602',
'\uf603',
'\uf604',
'\uf605',
'\uf606',
'\uf607',
'\uf608',
'\uf609',
'\uf60a',
'\uf60b',
'\uf60c',
'\uf60d',
'🬀',
'🬁',
'🬂',
'🬃',
'🬄',
'🬅',
'🬆',
'🬇',
'🬈',
'🬉',
'🬊',
'🬋',
'🬌',
'🬍',
'🬎',
'🬏',
'🬐',
'🬑',
'🬒',
'🬓',
'🬔',
'🬕',
'🬖',
'🬗',
'🬘',
'🬙',
'🬚',
'🬛',
'🬜',
'🬝',
'🬞',
'🬟',
'🬠',
'🬡',
'🬢',
'🬣',
'🬤',
'🬥',
'🬦',
'🬧',
'🬨',
'🬩',
'🬪',
'🬫',
'🬬',
'🬭',
'🬮',
'🬯',
'🬰',
'🬱',
'🬲',
'🬳',
'🬴',
'🬵',
'🬶',
'🬷',
'🬸',
'🬹',
'🬺',
'🬻',
'🬼',
'🬽',
'🬾',
'🬿',
'🭀',
'🭁',
'🭂',
'🭃',
'🭄',
'🭅',
'🭆',
'🭇',
'🭈',
'🭉',
'🭊',
'🭋',
'🭌',
'🭍',
'🭎',
'🭏',
'🭐',
'🭑',
'🭒',
'🭓',
'🭔',
'🭕',
'🭖',
'🭗',
'🭘',
'🭙',
'🭚',
'🭛',
'🭜',
'🭝',
'🭞',
'🭟',
'🭠',
'🭡',
'🭢',
'🭣',
'🭤',
'🭥',
'🭦',
'🭧',
'🭨',
'🭩',
'🭪',
'🭫',
'🭬',
'🭭',
'🭮',
'🭯',
'🭰',
'🭱',
'🭲',
'🭳',
'🭴',
'🭵',
'🭶',
'🭷',
'🭸',
'🭹',
'🭺',
'🭻',
'🭼',
'🭽',
'🭾',
'🭿',
'🮀',
'🮁',
'🮂',
'🮃',
'🮄',
'🮅',
'🮆',
'🮇',
'🮈',
'🮉',
'🮊',
'🮋',
'🮌',
'🮍',
'🮎',
'🮏',
'🮐',
'🮑',
'🮒',
'\U0001fb93',
'🮔',
'🮕',
'🮖',
'🮗',
'🮘',
'🮙',
'🮚',
'🮛',
'🮜',
'🮝',
'🮞',
'🮟',
'🮠',
'🮡',
'🮢',
'🮣',
'🮤',
'🮥',
'🮦',
'🮧',
'🮨',
'🮩',
'🮪',
'🮫',
'🮬',
'🮭',
'🮮'} # }}}