Start work on rendering box drawing characters directly

This commit is contained in:
Kovid Goyal 2017-01-08 16:25:35 +05:30
parent d786d71cab
commit 1b81971464
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,37 @@
#!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
import math
from functools import partial as p
from kitty.utils import get_logical_dpi
def thickness(level=1, horizontal=True):
dpi = get_logical_dpi()[0 if horizontal else 1]
pts = (1, 1, 2, 4)[level]
return int(math.ceil(pts * dpi / 72.0))
def half_hline(buf, width, height, level=1, which='left'):
sz = thickness(level=level, horizontal=True)
start = height // 2 - sz // 2
for y in range(start, start + sz):
for x in (range(0, width // 2) if which == 'left' else range(width // 2, width)):
buf[y * width + x] = 255
box_chars = {
'': [half_hline, p(half_hline, which='right')],
'': [p(half_hline, level=3), p(half_hline, level=3, which='right')],
}
is_renderable_box_char = box_chars.__contains__
def render_box_char(ch, buf, width, height):
for func in box_chars[ch]:
func(buf, width, height)
return buf

View File

@ -11,6 +11,7 @@ from threading import Lock
from kitty.fast_data_types import Face, FT_PIXEL_MODE_GRAY
from .fontconfig import find_font_for_character, get_font_files
from .box_drawing import is_renderable_box_char, render_box_char
from kitty.utils import get_logical_dpi, wcwidth
@ -193,6 +194,8 @@ def render_cell(text=' ', bold=False, italic=False, underline=0, strikethrough=F
# TODO: Handle non-normalizable combining chars. Probably need to use
# harfbuzz for that
text = unicodedata.normalize('NFC', text)[0]
if is_renderable_box_char(text):
return render_box_char(text, CharTexture(), cell_width, cell_height), None
width = wcwidth(text)
bitmap_char = render_char(text, bold, italic, width)
second = None