diff --git a/kitty/fonts/box_drawing.py b/kitty/fonts/box_drawing.py new file mode 100644 index 000000000..c6d1d93e2 --- /dev/null +++ b/kitty/fonts/box_drawing.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +# vim:fileencoding=utf-8 +# License: GPL v3 Copyright: 2017, Kovid Goyal + +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 diff --git a/kitty/fonts/freetype.py b/kitty/fonts/freetype.py index dfa0edc0a..a56c43c73 100644 --- a/kitty/fonts/freetype.py +++ b/kitty/fonts/freetype.py @@ -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