-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathverify_fonts.py
executable file
·172 lines (131 loc) · 7.02 KB
/
verify_fonts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env python3
import sys
# Inspired by https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/bin/scripts/test-fonts.sh
RESET_COLOR = '\033[0m'
BG_COLOR_BORDER = '\033[48;5;8m'
EMOJI_TESTSET = sorted([
'😀', '😁', '😂', '😃', '😅', '😆', '😉', '😊', '😋', '😎', '😍', '😘', '😗', '😙', '😚', '🙂',
'🤩', '🥳', '😇', '🤠', '🤡', '🤥', '🤫', '🤭', '🧐', '🤓', '😈', '👿', '👹', '👺', '💀', '👻',
'👽', '👾', '🤖', '💩', '😺', '😸', '😹', '😻', '😼', '😽', '🙀', '😿', '😾', '🙈', '🙉', '🙊',
'💋', '💌', '💘', '💝', '💖', '💗', '💓', '💞', '💕', '💟', '💔', '🧡', '💛', '💚', '💙', '💜',
'🤎', '🖤', '🤍', '💯', '💢', '💥', '💫', '💦', '💨', '💣', '💬', '💭',
'💤', '🤗', '🤔', '😐', '😑', '😶', '🙄', '😏', '😣', '😥', '😮', '🤐', '😯', '😪', '😫', '😴',
'😌', '😛', '😜', '😝', '🤤', '😒', '😓', '😔', '😕', '🙃', '🤑', '😲', '🙁', '😖', '😞', '😟',
'😤', '😢', '😭', '😦', '😧', '😨', '😩', '🤯', '😬', '😰', '😱', '😳', '🤪', '😵', '😡', '😠',
'🤬', '😷', '🤒', '🤕', '🤢', '🤮', '🤧'
], key=ord)
NF_EXAMPLAR_TESTSET = ['', '', '', '', '', '', '', '', '', '', '', '']
NF_CHESS_TESTSET = ['♚', '♛', '♜', '♝', '♞', '♟', '♔', '♕', '♖', '♗', '♘', '♙']
CELL_WIDTH = 6
HALF_BAR = '═' * (int)(CELL_WIDTH / 2)
def print_top_line(length):
top_line_start = f'{BG_COLOR_BORDER}╔{HALF_BAR}'
top_line_middle = f'{HALF_BAR}╦{HALF_BAR}'
top_line_end = f'{HALF_BAR}╗{RESET_COLOR}'
print(top_line_start + (top_line_middle * (length - 1)) + top_line_end)
def print_bottom_line(length):
bottom_line_start = f'{BG_COLOR_BORDER}╚{HALF_BAR}'
bottom_line_middle = f'{HALF_BAR}╩{HALF_BAR}'
bottom_line_end = f'{HALF_BAR}╝{RESET_COLOR}'
print(bottom_line_start + (bottom_line_middle * (length - 1)) + bottom_line_end)
def print_middle_line(length, next_line_length):
line_start = f'{BG_COLOR_BORDER}╠{HALF_BAR}'
line_middle = f'{HALF_BAR}╬{HALF_BAR}'
line_end = f'{HALF_BAR}╣{RESET_COLOR}'
bottom_line_middle = f'{HALF_BAR}╩{HALF_BAR}'
bottom_line_end = f'{HALF_BAR}╝{RESET_COLOR}'
if next_line_length == length:
print(line_start + (line_middle * (length - 1)) + line_end)
else:
print(line_start + (line_middle * next_line_length), end='')
print((bottom_line_middle * (length - next_line_length - 1)) + bottom_line_end)
def print_codes_line(code_color, char_color, chunk, line_length):
vertical_bar = f'{BG_COLOR_BORDER}║{RESET_COLOR}'
underline = '\033[4m'
header_line = [(f'{n:x}', chr(n)) for n in chunk]
# add fillers to array to maintain table:
header_line.extend([('', ' ')] * (line_length - len(chunk)))
all_codes = vertical_bar
all_chars = vertical_bar
for (code, char) in header_line:
leftpad_code = (int)((CELL_WIDTH - len(code)) / 2)
rightpad_code = CELL_WIDTH - len(code) - leftpad_code
# Emoji characters print with variable width in different fonts,
# but generally it works to treat them as double-wide.
char_width = 2 if char in EMOJI_TESTSET else 1
leftpad_char = (int)((CELL_WIDTH - char_width) / 2)
rightpad_char = CELL_WIDTH - char_width - leftpad_char
all_codes += f'{code_color}{" " * (leftpad_code)}{underline}{code}{RESET_COLOR}{code_color}{" " * rightpad_code}{vertical_bar}'
all_chars += f'{char_color}{" " * leftpad_char}{char}{" " * rightpad_char}{vertical_bar}'
print(f'{all_codes}\n{all_chars}')
# Given a range of numbers print all unicode code-points.
def print_unicode_range(seq, wrap_at=16):
# Use alternating colors to see which symbols extend outside the bounding boxes.
bg_color_code_alt = '\033[48;5;246m'
bg_color_code = '\033[48;5;240m'
bg_color_char_alt = '\033[48;5;66m'
bg_color_char = '\033[48;5;60m'
sequence = []
sequence.extend(seq)
chunked_sequences = [sequence[i * wrap_at:(i + 1) * wrap_at]
for i in range((len(sequence) + wrap_at - 1) // wrap_at)]
# If there's only one line, then let the table display narrower
line_length = len(chunked_sequences[0])
print_top_line(line_length)
color_code = bg_color_code_alt
color_char = bg_color_char_alt
first = True
for chunk in chunked_sequences:
if first:
first = False
else:
print_middle_line(line_length, len(chunk))
if color_code == bg_color_code_alt:
color_code = bg_color_code
color_char = bg_color_char
else:
color_code = bg_color_code_alt
color_char = bg_color_char_alt
print_codes_line(color_code, color_char, chunk, len(chunk))
print_bottom_line(len(chunked_sequences[-1]))
def list_to_ranges(lst):
if len(lst) % 2 != 0:
raise ValueError('This is expected to be an even number of items')
ranges = []
for previous, current in zip(lst[::2], lst[1::2]):
ranges.extend([i for i in range(previous, current)])
return ranges
def convert_symbols_to_ranges(symbols):
filtered_symbols = [c for c in symbols if len(c) == 1]
if len(filtered_symbols) != len(symbols):
print(f'Warning: {len(symbols) - len(filtered_symbols)} symbols were filtered out')
print(f'Filtered out symbols: {", ".join([c for c in symbols if len(c) != 1])}')
return list(sum([(ord(c), ord(c)+1) for c in filtered_symbols], ()))
def main():
categories = {
# 'ASCII control codes': [0, 32, 127, 128],
'ASCII': [32, 127],
'Emoji': convert_symbols_to_ranges(EMOJI_TESTSET),
'Nerd Fonts - Pomicons': [0xe000, 0xe00a],
'Nerd Fonts - Powerline + Extras': [0xe0a0, 0xE0A4, 0xE0B0, 0xE0C0, 0xE0C0, 0xE0C9, 0xE0CC, 0xE0D0, 0xE0D0, 0xE0D3, 0xE0D4, 0xe0d5, 0xE0D6, 0xE0D8],
'Nerd Fonts - Symbols original': [0xe5fa, 0xe62c],
# 198 icons
'Nerd Fonts - Devicons': [0xe700, (0xe700 + 198)],
'Nerd Fonts - Font awesome': [0xf000, 0xf2e1],
'Nerd Fonts - Font awesome extension': [0xe200, 0xe2aa],
'Nerd Fonts - Octicons': [0xf400, 0xf4a9, 0x2665, 0x2666, 0x26A1, 0x26A2, 0xf27c, 0xf27d],
'Nerd Fonts - Font Logos': [0xf300, 0xf330],
'Nerd Fonts - Font Power Symbols': [0x23fb, 0x23ff, 0x2b58, 0x2b59],
'Nerd Fonts - Material Design Icons (first few)': [0xf0001, 0xf0031],
# 228 icons
'Nerd Fonts - Weather Icons': [0xe300, (0xe300 + 228)],
'Nerd Fonts - Chess Icons': [0xed5f, 0xed67, 0xe29c, 0xe29d, 0xe25f, 0xe264, 0xf0857, 0xf085d],
'Nerd Fonts - ZSH Prompt Icons': convert_symbols_to_ranges(NF_EXAMPLAR_TESTSET)
}
for name, range_list in categories.items():
print(name)
print_unicode_range(list_to_ranges(range_list))
print()
return 0
if __name__ == "__main__":
sys.exit(main())