Allow testing of rendering combined glyphs
This commit is contained in:
parent
e6f758b986
commit
692bdd3ad5
@ -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
|
||||||
opts = defaults._replace(font_family=family, font_size=sz)
|
from kitty.fast_data_types import glfw_init, glfw_terminate
|
||||||
set_font_family(opts)
|
if not glfw_init():
|
||||||
display_bitmap(*render_string(text))
|
raise SystemExit('Failed to initialize glfw')
|
||||||
|
try:
|
||||||
|
opts = defaults._replace(font_family=family, font_size=sz)
|
||||||
|
set_font_family(opts)
|
||||||
|
display_bitmap(*render_string(text, underline=underline, strikethrough=strikethrough))
|
||||||
|
finally:
|
||||||
|
glfw_terminate()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user