font creation
improve font creation operator offer fixing common misspellings use glyphNamesToUnicode.txt table to generate name_to_glyph_d fix typos in code more consistent naming font_face -> face_name
This commit is contained in:
parent
6f71a8f4c4
commit
7c72dd54dc
4 changed files with 12374 additions and 23 deletions
|
@ -1,8 +1,11 @@
|
|||
from typing import TypedDict
|
||||
from typing import Dict
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
# convenience dictionary for translating names to glyph ids
|
||||
# note: overwritten/extended by the content of "glypNamesToUnicode.txt"
|
||||
# when addon is registered in __init__.py
|
||||
name_to_glyph_d = {
|
||||
"zero": "0",
|
||||
"one": "1",
|
||||
|
@ -34,6 +37,55 @@ name_to_glyph_d = {
|
|||
"space": " ",
|
||||
}
|
||||
|
||||
known_misspellings = {
|
||||
# simple misspelling
|
||||
"excent" : "accent",
|
||||
"overdot" : "dotaccent",
|
||||
"diaresis": "dieresis",
|
||||
"diaeresis": "dieresis",
|
||||
# character does not exist.. maybe something else
|
||||
"Odoubleacute": "Ohungarumlaut",
|
||||
"Udoubleacute": "Uhungarumlaut",
|
||||
"Wcaron": "Wcircumflex",
|
||||
"Neng": "Nlongrightleg",
|
||||
"Lgrave": "Lacute",
|
||||
# currency stuff
|
||||
"doller": "dollar",
|
||||
"euro": "Euro",
|
||||
"yuan": "yen", # https://en.wikipedia.org/wiki/Yen_and_yuan_sign
|
||||
"pound": "sterling",
|
||||
# whoopsie
|
||||
"__": "_",
|
||||
}
|
||||
|
||||
def fix_glyph_name_misspellings(name):
|
||||
for misspelling in known_misspellings:
|
||||
if misspelling in name:
|
||||
return name.replace(misspelling,
|
||||
known_misspellings[misspelling])
|
||||
return name
|
||||
|
||||
|
||||
def name_to_glyph(name):
|
||||
if len(name) == 1:
|
||||
return name
|
||||
if name in name_to_glyph_d:
|
||||
return name_to_glyph_d[name]
|
||||
else:
|
||||
return None
|
||||
|
||||
def generate_name_to_glyph_d():
|
||||
d = {}
|
||||
with open(f"{Path(__file__).parent}/glyphNamesToUnicode.txt") as f:
|
||||
for line in f:
|
||||
if line[0] == '#':
|
||||
continue
|
||||
(name, hexstr) = line.split(' ')
|
||||
val = chr(int(hexstr, base=16))
|
||||
d[name] = val
|
||||
return d
|
||||
|
||||
|
||||
class FontFace:
|
||||
"""FontFace is a class holding glyphs
|
||||
|
||||
|
|
12264
common/glyphNamesToUnicode.txt
Normal file
12264
common/glyphNamesToUnicode.txt
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue