From a2c4f830b3e7ed7d6ab94df1ee677a908e3c5fb3 Mon Sep 17 00:00:00 2001 From: Joseph Adams Date: Thu, 13 Jan 2022 17:27:02 +0100 Subject: [PATCH] Enable use of higher options for underlining text. In `Colored and styled underlines` it's proposed that the SGR codes \e[4:4m and \e[4:5m are used to add a dotted or dashed underline to the rendering context respectively. This commit prepares the necessary changes to add the two additional underline style, while still rendering them as a normal underline and curly underline. --- kitty/cell_vertex.glsl | 4 ++-- kitty/cursor.c | 4 ++-- kitty/data-types.h | 2 +- kitty/fonts/render.py | 4 ++-- kitty/shaders.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/kitty/cell_vertex.glsl b/kitty/cell_vertex.glsl index e44c57053..af772a0c5 100644 --- a/kitty/cell_vertex.glsl +++ b/kitty/cell_vertex.glsl @@ -79,8 +79,8 @@ const uint COLOR_MASK = uint(0x4000); const uint ZERO = uint(0); const uint ONE = uint(1); const uint TWO = uint(2); -const uint THREE = uint(3); const uint FOUR = uint(4); +const uint SEVEN = uint(7); vec3 color_to_vec(uint c) { uint r, g, b; @@ -193,7 +193,7 @@ void main() { foreground = choose_color(float(is_selected & ONE), selection_color, foreground); decoration_fg = choose_color(float(is_selected & ONE), selection_color, decoration_fg); // Underline and strike through (rendered via sprites) - underline_pos = choose_color(in_url, to_sprite_pos(pos, url_style, ZERO, ZERO), to_sprite_pos(pos, (text_attrs >> DECORATION_SHIFT) & THREE, ZERO, ZERO)); + underline_pos = choose_color(in_url, to_sprite_pos(pos, url_style, ZERO, ZERO), to_sprite_pos(pos, (text_attrs >> DECORATION_SHIFT) & SEVEN, ZERO, ZERO)); strike_pos = to_sprite_pos(pos, ((text_attrs >> STRIKE_SHIFT) & ONE) * FOUR, ZERO, ZERO); // Cursor diff --git a/kitty/cursor.c b/kitty/cursor.c index f129c438b..8c1aee84e 100644 --- a/kitty/cursor.c +++ b/kitty/cursor.c @@ -90,7 +90,7 @@ START_ALLOW_CASE_RANGE case 3: self->italic = true; break; case 4: - if (i < count) { self->decoration = MIN(3, params[i]); i++; } + if (i < count) { self->decoration = MIN(5, params[i]); i++; } else self->decoration = 1; break; case 7: @@ -161,7 +161,7 @@ apply_sgr_to_cells(GPUCell *first_cell, unsigned int cell_count, int *params, un S(italic, true); case 4: { uint8_t val = 1; - if (i < count) { val = MIN(3, params[i]); i++; } + if (i < count) { val = MIN(5, params[i]); i++; } S(decoration, val); } case 7: diff --git a/kitty/data-types.h b/kitty/data-types.h index 42287b00e..b04cb75c2 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -142,7 +142,7 @@ typedef struct { typedef union CellAttrs { struct { uint16_t width : 2; - uint16_t decoration : 2; + uint16_t decoration : 3; uint16_t bold : 1; uint16_t italic : 1; uint16_t reverse : 1; diff --git a/kitty/fonts/render.py b/kitty/fonts/render.py index 989497ab9..2c34de2b3 100644 --- a/kitty/fonts/render.py +++ b/kitty/fonts/render.py @@ -313,7 +313,7 @@ def render_special( t = underline_thickness if underline > 1: t = max(1, min(cell_height - underline_position - 1, t)) - dl([add_line, add_line, add_dline, add_curl][underline], underline_position, t, cell_height) + dl([add_line, add_line, add_dline, add_curl, add_line, add_curl][underline], underline_position, t, cell_height) if strikethrough: dl(add_line, strikethrough_position, strikethrough_thickness, cell_height) @@ -384,7 +384,7 @@ def prerender_function( render_cursor, cursor_beam_thickness=cursor_beam_thickness, cursor_underline_thickness=cursor_underline_thickness, cell_width=cell_width, cell_height=cell_height, dpi_x=dpi_x, dpi_y=dpi_y) - cells = f(1), f(2), f(3), f(0, True), f(missing=True), c(1), c(2), c(3) + cells = f(1), f(2), f(3), f(4), f(5), f(0, True), f(missing=True), c(1), c(2), c(3) return tuple(map(ctypes.addressof, cells)), cells diff --git a/kitty/shaders.c b/kitty/shaders.c index f448c8f0d..d99166ff0 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -314,7 +314,7 @@ cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, c } rd->use_cell_for_selection_bg = IS_SPECIAL_COLOR(highlight_bg) ? 1. : 0.; // Cursor position - enum { BLOCK_IDX = 0, BEAM_IDX = 6, UNDERLINE_IDX = 7, UNFOCUSED_IDX = 8 }; + enum { BLOCK_IDX = 0, BEAM_IDX = 8, UNDERLINE_IDX = 9, UNFOCUSED_IDX = 10 }; if (cursor->is_visible) { rd->cursor_x = screen->cursor->x, rd->cursor_y = screen->cursor->y; if (cursor->is_focused) {