Allow testing of rendering combined glyphs

This commit is contained in:
Kovid Goyal 2017-10-25 11:53:25 +05:30
parent e6f758b986
commit 692bdd3ad5
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -106,20 +106,39 @@ def display_bitmap(data, w, h):
img.show() img.show()
def render_string(text='\'Qing👁a⧽'): def render_string(text='\'Qing👁a⧽', underline=2, strikethrough=True):
import unicodedata
cells = [] cells = []
for c in text: current_text = ''
f, s = render_cell(c, underline=2, strikethrough=True)
def render_one(c):
f, s = render_cell(c, underline=underline, strikethrough=strikethrough)
cells.append(f) cells.append(f)
if s is not None: if s is not None:
cells.append(s) cells.append(s)
for c in text:
if unicodedata.combining(c):
current_text += c
else:
if current_text:
render_one(current_text)
current_text = c
if current_text:
render_one(current_text)
cell_width, cell_height = current_cell()[1:3] cell_width, cell_height = current_cell()[1:3]
char_data = join_cells(cell_width, cell_height, *cells) char_data = join_cells(cell_width, cell_height, *cells)
return char_data, cell_width * len(cells), cell_height return char_data, cell_width * len(cells), cell_height
def test_rendering(text='\'Ping👁a⧽', sz=144, family='monospace'): def test_rendering(text='\'Ping👁a⧽', sz=144, family='monospace', underline=2, strikethrough=True):
from kitty.config import defaults from kitty.config import defaults
from kitty.fast_data_types import glfw_init, glfw_terminate
if not glfw_init():
raise SystemExit('Failed to initialize glfw')
try:
opts = defaults._replace(font_family=family, font_size=sz) opts = defaults._replace(font_family=family, font_size=sz)
set_font_family(opts) set_font_family(opts)
display_bitmap(*render_string(text)) display_bitmap(*render_string(text, underline=underline, strikethrough=strikethrough))
finally:
glfw_terminate()