Add rendering functions for dotted and dashed underline.
Dashed underline looks pretty good regardless of conditions, but the dotted underline only looks good/correct on certain font-sizes. This is due to the underline being rendered on a per cell/glyph basis (so one can not place a dot directly between two letters, say. Could be remedied by pulling the rendering of the underlines into the shader, but that is more work.
This commit is contained in:
parent
a2c4f830b3
commit
e86c7d668c
@ -279,6 +279,21 @@ def add_curl(buf: CBufType, cell_width: int, position: int, thickness: int, cell
|
|||||||
add_intensity(x, y1 + t, 255)
|
add_intensity(x, y1 + t, 255)
|
||||||
|
|
||||||
|
|
||||||
|
def add_dots(buf: CBufType, cell_width: int, position: int, thickness: int, cell_height: int) -> None:
|
||||||
|
y = 1 + position - thickness // 2
|
||||||
|
for i in range(y, min(y + thickness, cell_height)):
|
||||||
|
for j in range(0, cell_width, 2 * thickness):
|
||||||
|
buf[cell_width * i + j:cell_width * i + min(j + thickness, cell_width)] = [255] * min(thickness, cell_width - j)
|
||||||
|
|
||||||
|
|
||||||
|
def add_dashes(buf: CBufType, cell_width: int, position: int, thickness: int, cell_height: int) -> None:
|
||||||
|
halfspace_width = cell_width // 4
|
||||||
|
y = 1 + position - thickness // 2
|
||||||
|
for i in range(y, min(y + thickness, cell_height)):
|
||||||
|
buf[cell_width * i:cell_width * i + (cell_width - 3 * halfspace_width)] = [255] * (cell_width - 3 * halfspace_width)
|
||||||
|
buf[cell_width * i + 3 * halfspace_width:cell_width * (i + 1)] = [255] * (cell_width - 3 * halfspace_width)
|
||||||
|
|
||||||
|
|
||||||
def render_special(
|
def render_special(
|
||||||
underline: int = 0,
|
underline: int = 0,
|
||||||
strikethrough: bool = False,
|
strikethrough: bool = False,
|
||||||
@ -313,7 +328,7 @@ def render_special(
|
|||||||
t = underline_thickness
|
t = underline_thickness
|
||||||
if underline > 1:
|
if underline > 1:
|
||||||
t = max(1, min(cell_height - underline_position - 1, t))
|
t = max(1, min(cell_height - underline_position - 1, t))
|
||||||
dl([add_line, add_line, add_dline, add_curl, add_line, add_curl][underline], underline_position, t, cell_height)
|
dl([add_line, add_line, add_dline, add_curl, add_dots, add_dashes][underline], underline_position, t, cell_height)
|
||||||
if strikethrough:
|
if strikethrough:
|
||||||
dl(add_line, strikethrough_position, strikethrough_thickness, cell_height)
|
dl(add_line, strikethrough_position, strikethrough_thickness, cell_height)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user