add space recognition

This commit is contained in:
jrkb 2025-01-18 18:21:33 +01:00
parent e69cdc951d
commit 1fbac99bd8
3 changed files with 61 additions and 6 deletions

View file

@ -37,6 +37,8 @@ name_to_glyph_d = {
"space": " ",
}
space_d = {}
known_misspellings = {
# simple misspelling
"excent" : "accent",
@ -74,17 +76,47 @@ def name_to_glyph(name):
else:
return None
def generate_name_to_glyph_d():
def is_space(character):
for name in space_d:
if character == space_d[name][0]:
return space_d[name][1]
return False
def generate_from_file_d(filepath):
print(f"{filepath=}")
d = {}
with open(f"{Path(__file__).parent}/glyphNamesToUnicode.txt") as f:
with open(filepath) as f:
for line in f:
if line[0] == '#':
continue
(name, hexstr) = line.split(' ')
val = chr(int(hexstr, base=16))
d[name] = val
split = line.split(' ')
if len(split) == 2:
(name, hexstr) = line.split(' ')
val = chr(int(hexstr, base=16))
d[name] = val
print(f"{name=} {val=}")
if len(split) == 3:
# we might have a parameter, like for the spaces
(name, hexstr, parameter) = line.split(' ')
parameter_value = float(parameter)
val = chr(int(hexstr, base=16))
d[name] = [val, parameter_value]
print(f"{name=} {val=}, {parameter_value=}, {parameter_value * 2}")
return d
def generate_name_to_glyph_d():
return generate_from_file_d(f"{Path(__file__).parent}/glyphNamesToUnicode.txt")
def generate_space_d():
return generate_from_file_d(f"{Path(__file__).parent}/spacesUnicode.txt")
def init():
global name_to_glyph_d
global space_d
name_to_glyph_d = generate_name_to_glyph_d()
space_d = generate_space_d()
class FontFace:
"""FontFace is a class holding glyphs