From a508161265f7bff22f7cc4f6c5e42fbca0811a61 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 2 Sep 2020 22:00:58 +0530 Subject: [PATCH] Add smooth mosaic chars to box drawing --- kitty/fonts.c | 4 +- kitty/fonts/box_drawing.py | 75 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/kitty/fonts.c b/kitty/fonts.c index 5a772444c..f4738e41d 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -600,7 +600,7 @@ START_ALLOW_CASE_RANGE case 0xe0ba: //  case 0xe0bc: //  case 0xe0be: //  - case 0x1fb00 ... 0x1fb3b: // sextants + case 0x1fb00 ... 0x1fb67: // symbols for legacy computing return BOX_FONT; default: ans = in_symbol_maps(fg, cpu_cell->ch); @@ -638,7 +638,7 @@ START_ALLOW_CASE_RANGE return ch - 0x2500; // IDs from 0x00 to 0x9f case 0xe0b0 ... 0xe0d4: return 0xa0 + ch - 0xe0b0; // IDs from 0xa0 to 0xc4 - case 0x1fb00 ... 0x1fb3b: + case 0x1fb00 ... 0x1fb67: return 0xc5 + ch - 0x1fb00; default: return 0xffff; diff --git a/kitty/fonts/box_drawing.py b/kitty/fonts/box_drawing.py index 7d6c4c097..856bbe177 100644 --- a/kitty/fonts/box_drawing.py +++ b/kitty/fonts/box_drawing.py @@ -611,6 +611,29 @@ def sextant(buf: BufType, width: int, height: int, level: int = 1, which: int = add_row(which // 16, 2) +@supersampled() +def smooth_mosaic( + buf: BufType, width: int, height: int, level: int = 1, + lower: bool = True, a: Tuple[float, float] = (0, 0), b: Tuple[float, float] = (0, 0) +) -> None: + ax, ay = int(a[0] * (width - 1)), int(a[1] * (height - 1)) + bx, by = int(b[0] * (width - 1)), int(b[1] * (height - 1)) + line = line_equation(ax, ay, bx, by) + + def lower_condition(x: int, y: int) -> bool: + return y >= line(x) + + def upper_condition(x: int, y: int) -> bool: + return y <= line(x) + + condition = lower_condition if lower else upper_condition + for y in range(height): + offset = width * y + for x in range(width): + if condition(x, y): + buf[offset + x] = 255 + + box_chars: Dict[str, List[Callable]] = { '─': [hline], '━': [p(hline, level=3)], @@ -710,6 +733,58 @@ box_chars: Dict[str, List[Callable]] = { '▝': [p(quad, x=1)], '▞': [p(quad, x=1), p(quad, y=1)], '▟': [p(quad, x=1), p(quad, y=1), p(quad, x=1, y=1)], + + '🬼': [p(smooth_mosaic, a=(0, 0.75), b=(0.5, 1))], + '🬽': [p(smooth_mosaic, a=(0, 0.75), b=(1, 1))], + '🬾': [p(smooth_mosaic, a=(0, 0.5), b=(0.5, 1))], + '🬿': [p(smooth_mosaic, a=(0, 0.5), b=(1, 1))], + '🭀': [p(smooth_mosaic, a=(0, 0), b=(0.5, 1))], + + '🭁': [p(smooth_mosaic, a=(0, 0.25), b=(0.5, 0))], + '🭂': [p(smooth_mosaic, a=(0, 0.25), b=(1, 0))], + '🭃': [p(smooth_mosaic, a=(0, 0.75), b=(0.5, 0))], + '🭄': [p(smooth_mosaic, a=(0, 0.75), b=(1, 0))], + '🭅': [p(smooth_mosaic, a=(0, 1), b=(0.5, 0))], + '🭆': [p(smooth_mosaic, a=(0, 0.75), b=(1, 0.25))], + + '🭇': [p(smooth_mosaic, a=(0.5, 1), b=(1, 0.75))], + '🭈': [p(smooth_mosaic, a=(0, 1), b=(1, 0.75))], + '🭉': [p(smooth_mosaic, a=(0.5, 1), b=(1, 0.25))], + '🭊': [p(smooth_mosaic, a=(0, 1), b=(1, 0.25))], + '🭋': [p(smooth_mosaic, a=(0.5, 1), b=(1, 0))], + + '🭌': [p(smooth_mosaic, a=(0.5, 0), b=(1, 0.25))], + '🭍': [p(smooth_mosaic, a=(0, 0), b=(1, 0.25))], + '🭎': [p(smooth_mosaic, a=(0.5, 0), b=(1, 0.75))], + '🭏': [p(smooth_mosaic, a=(0, 0), b=(1, 0.75))], + '🭐': [p(smooth_mosaic, a=(0.5, 0), b=(1, 1))], + '🭑': [p(smooth_mosaic, a=(0, 0.25), b=(1, 0.75))], + + '🭒': [p(smooth_mosaic, lower=False, a=(0, 0.75), b=(0.5, 1))], + '🭓': [p(smooth_mosaic, lower=False, a=(0, 0.75), b=(1, 1))], + '🭔': [p(smooth_mosaic, lower=False, a=(0, 0.25), b=(0.5, 1))], + '🭕': [p(smooth_mosaic, lower=False, a=(0, 0.25), b=(1, 1))], + '🭖': [p(smooth_mosaic, lower=False, a=(0, 0), b=(0.5, 1))], + + '🭗': [p(smooth_mosaic, lower=False, a=(0, 0.25), b=(0.5, 0))], + '🭘': [p(smooth_mosaic, lower=False, a=(0, 0.25), b=(1, 0))], + '🭙': [p(smooth_mosaic, lower=False, a=(0, 0.75), b=(0.5, 0))], + '🭚': [p(smooth_mosaic, lower=False, a=(0, 0.75), b=(1, 0))], + '🭛': [p(smooth_mosaic, lower=False, a=(0, 1), b=(0.5, 0))], + + '🭜': [p(smooth_mosaic, lower=False, a=(0, 0.75), b=(1, 0.25))], + '🭝': [p(smooth_mosaic, lower=False, a=(0.5, 1), b=(1, 0.75))], + '🭞': [p(smooth_mosaic, lower=False, a=(0, 1), b=(1, 0.75))], + '🭟': [p(smooth_mosaic, lower=False, a=(0.5, 1), b=(1, 0.25))], + '🭠': [p(smooth_mosaic, lower=False, a=(0, 1), b=(1, 0.25))], + '🭡': [p(smooth_mosaic, lower=False, a=(0.5, 1), b=(1, 0))], + + '🭢': [p(smooth_mosaic, lower=False, a=(0.5, 0), b=(1, 0.25))], + '🭣': [p(smooth_mosaic, lower=False, a=(0, 0), b=(1, 0.25))], + '🭤': [p(smooth_mosaic, lower=False, a=(0.5, 0), b=(1, 0.75))], + '🭥': [p(smooth_mosaic, lower=False, a=(0, 0), b=(1, 0.75))], + '🭦': [p(smooth_mosaic, lower=False, a=(0.5, 0), b=(1, 1))], + '🭧': [p(smooth_mosaic, lower=False, a=(0, 0.25), b=(1, 0.75))], } t, f = 1, 3