From 0b9a37139e26b294547c21a9c564348955faa81c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 6 Apr 2020 23:00:34 +0530 Subject: [PATCH] Render any flag pair in two cells not just known ones --- gen-wcwidth.py | 18 +----------------- kitty/emoji.h | 32 -------------------------------- kitty/screen.c | 5 ++++- 3 files changed, 5 insertions(+), 50 deletions(-) diff --git a/gen-wcwidth.py b/gen-wcwidth.py index 8a45e4d99..ec4c67ce3 100755 --- a/gen-wcwidth.py +++ b/gen-wcwidth.py @@ -10,7 +10,7 @@ from contextlib import contextmanager from datetime import date from functools import partial from html.entities import html5 -from itertools import groupby, repeat +from itertools import groupby from operator import itemgetter from typing import ( Callable, DefaultDict, Dict, FrozenSet, Generator, Iterable, List, @@ -266,22 +266,6 @@ def gen_emoji() -> None: p('\t}') p('\treturn false;\n}') - p('static inline bool is_flag_pair(char_type a, char_type b) {') - p('static const unsigned char flag_combinations[26][26] = {') - for i in range(26): - q = 0x1F1E6 + i - vals = flags.get(q, []) - arr = list(repeat(0, 26)) - for x in vals: - idx = x - 0x1F1E6 - arr[idx] = 1 - comma = '' if i == 0 else ',' - p(comma, '{', ', '.join(map(str, arr)), '}') - p('};') - p('if (a < 0x1F1E6 || b < 0x1F1E6 || a >= 0x1F1E6 + 26 || b >= 0x1F1E6 + 26) return false;') - p('return flag_combinations[a - 0x1F1E6][b - 0x1F1E6];') - p('};') - def category_test( name: str, diff --git a/kitty/emoji.h b/kitty/emoji.h index 8bb04f521..a3e6f1f97 100644 --- a/kitty/emoji.h +++ b/kitty/emoji.h @@ -781,37 +781,5 @@ is_symbol(char_type code) { } return false; } -static inline bool is_flag_pair(char_type a, char_type b) { -static const unsigned char flag_combinations[26][26] = { - { 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1 } -, { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 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+ 26) return false; -return flag_combinations[a - 0x1F1E6][b - 0x1F1E6]; -}; END_ALLOW_CASE_RANGE diff --git a/kitty/screen.c b/kitty/screen.c index 28ee6824a..c28fe5066 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -14,7 +14,6 @@ #include "fonts.h" #include "lineops.h" #include "screen.h" -#include "emoji.h" #include #include #include @@ -358,6 +357,10 @@ selection_has_screen_line(Selection *s, int y) { return top <= y && y <= bottom; } +static inline bool is_flag_pair(char_type a, char_type b) { + return is_flag_codepoint(a) && is_flag_codepoint(b); +} + static inline bool draw_second_flag_codepoint(Screen *self, char_type ch) { index_type xpos = 0, ypos = 0;