add space recognition
This commit is contained in:
parent
e69cdc951d
commit
1fbac99bd8
3 changed files with 61 additions and 6 deletions
|
@ -1589,7 +1589,7 @@ def register():
|
||||||
|
|
||||||
# bpy.ops.abc3d.load_installed_fonts()
|
# bpy.ops.abc3d.load_installed_fonts()
|
||||||
|
|
||||||
Font.name_to_glyph_d = Font.generate_name_to_glyph_d()
|
Font.init()
|
||||||
|
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
|
|
|
@ -37,6 +37,8 @@ name_to_glyph_d = {
|
||||||
"space": " ",
|
"space": " ",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
space_d = {}
|
||||||
|
|
||||||
known_misspellings = {
|
known_misspellings = {
|
||||||
# simple misspelling
|
# simple misspelling
|
||||||
"excent" : "accent",
|
"excent" : "accent",
|
||||||
|
@ -74,17 +76,47 @@ def name_to_glyph(name):
|
||||||
else:
|
else:
|
||||||
return None
|
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 = {}
|
d = {}
|
||||||
with open(f"{Path(__file__).parent}/glyphNamesToUnicode.txt") as f:
|
with open(filepath) as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
if line[0] == '#':
|
if line[0] == '#':
|
||||||
continue
|
continue
|
||||||
(name, hexstr) = line.split(' ')
|
split = line.split(' ')
|
||||||
val = chr(int(hexstr, base=16))
|
if len(split) == 2:
|
||||||
d[name] = val
|
(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
|
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:
|
class FontFace:
|
||||||
"""FontFace is a class holding glyphs
|
"""FontFace is a class holding glyphs
|
||||||
|
|
23
common/spacesUnicode.txt
Normal file
23
common/spacesUnicode.txt
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# The space value derives from The Elements of Typographic Style
|
||||||
|
# same for en-/em values. Rest are rough guesses.
|
||||||
|
space 0020 0.25
|
||||||
|
nbspace 00A0 0.25
|
||||||
|
# ethi:wordspace 1361 # NOTE: has shape
|
||||||
|
enquad 2000 0.5
|
||||||
|
emquad 2001 1
|
||||||
|
enspace 2002 0.5
|
||||||
|
emspace 2003 1
|
||||||
|
threeperemspace 2004 3
|
||||||
|
fourperemspace 2005 4
|
||||||
|
sixperemspace 2006 6
|
||||||
|
figurespace 2007 1
|
||||||
|
punctuationspace 2008 1
|
||||||
|
thinspace 2009 0.1
|
||||||
|
hairspace 200A 0.05
|
||||||
|
zerowidthspace 200B 0
|
||||||
|
narrownobreakspace 202F 0.1
|
||||||
|
mediummathematicalspace 205F 1
|
||||||
|
cntr:space 2420 0.25
|
||||||
|
ideographicspace 3000 1
|
||||||
|
# ideographichalffillspace 303F # NOTE: has shape
|
||||||
|
zerowidthnobreakspace FEFF 0
|
Loading…
Reference in a new issue