From 19e6f70655cc092746fa2483607157009e030440 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 12 Jan 2022 23:18:18 +0530 Subject: [PATCH] Draw the dots for braille characters more evenly spaced at all font sizes Fixes #4499 --- docs/changelog.rst | 2 ++ kitty/fonts/box_drawing.py | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index faa0de8f7..f34e9603c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -91,6 +91,8 @@ Detailed list of changes - macOS: Fix hiding via :kbd:`cmd+h` not working on macOS 10.15.7 (:iss:`4472`) +- Draw the dots for braille characters more evenly spaced at all font sizes (:iss:`4499`) + 0.24.1 [2022-01-06] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/fonts/box_drawing.py b/kitty/fonts/box_drawing.py index 7ccc3e2e2..146664e77 100644 --- a/kitty/fonts/box_drawing.py +++ b/kitty/fonts/box_drawing.py @@ -754,13 +754,25 @@ def eight_block(buf: BufType, width: int, height: int, level: int = 1, which: Tu eight_bar(buf, width, height, level, x, horizontal) +def distribute_dots(available_space: int, num_of_dots: int, i: int) -> Tuple[int, int]: + dot_size = max(1, available_space // (2 * num_of_dots)) + extra = available_space - 2 * num_of_dots * dot_size + gaps = list(repeat(dot_size, num_of_dots)) + if extra > 0: + idx = 0 + while extra > 0: + gaps[idx] += 1 + idx = (idx + 1) % len(gaps) + extra -= 1 + gaps[0] //= 2 + margin = sum(gaps[:i + 1]) + start = margin + (i * dot_size) + return start, dot_size + + def braille_dot(buf: BufType, width: int, height: int, col: int, row: int) -> None: - dot_height = max(1, height // 8) - dot_width = max(1, width // 4) - top_margin = (height - 7 * dot_height) // 2 - left_margin = (width - 3 * dot_width) // 2 - x_start = left_margin + (col * 2 * dot_width) - y_start = top_margin + (row * 2 * dot_height) + x_start, dot_width = distribute_dots(width, 2, col) + y_start, dot_height = distribute_dots(height, 4, row) if y_start < height and x_start < width: for y in range(y_start, min(height, y_start + dot_height)): offset = y * width