diff --git a/kitty/fonts/render.py b/kitty/fonts/render.py index ba03837d6..c739fc7ad 100644 --- a/kitty/fonts/render.py +++ b/kitty/fonts/render.py @@ -3,7 +3,7 @@ # License: GPL v3 Copyright: 2016, Kovid Goyal import ctypes -from math import sin, pi, ceil, floor +from math import sin, pi, ceil, floor, sqrt from kitty.constants import isosx from .box_drawing import render_box_char, is_renderable_box_char @@ -30,16 +30,21 @@ def add_curl(buf, cell_width, position, thickness, cell_height): def clamp_y(y): return max(0, min(int(y), cell_height - 1)) - for x in range(cell_width): - y_exact = yfactor * sin(x * xfactor) + position + def clamp_x(x): + return max(0, min(int(x), cell_width - 1)) + + def add_intensity(x, y, distance): + buf[cell_width * y + x] = min(255, buf[cell_width * y + x] + int(255 * (1 - distance))) + + for x_exact in range(cell_width): + y_exact = yfactor * sin(x_exact * xfactor) + position y_below = clamp_y(floor(y_exact)) y_above = clamp_y(ceil(y_exact)) - if y_below == y_above: - buf[cell_width * y_below + x] = 255 - continue - for y in (y_below, y_above): - intensity = int(255 * (1 - abs(y - y_exact))) - buf[cell_width * y + x] = intensity + x_before, x_after = map(clamp_x, (x_exact - 1, x_exact + 1)) + for x in {x_before, x_exact, x_after}: + for y in {y_below, y_above}: + dist = sqrt((x - x_exact)**2 + (y - y_exact)**2) / 2 + add_intensity(x, y, dist) def render_cell(text=' ', bold=False, italic=False, underline=0, strikethrough=False):