allow replacements (upper/lower)
This commit is contained in:
parent
36c8f25e29
commit
167dea8164
1 changed files with 38 additions and 10 deletions
48
butils.py
48
butils.py
|
@ -674,11 +674,23 @@ def get_glyph_height(glyph_obj):
|
||||||
return abs(c.bound_box[0][1] - c.bound_box[3][1])
|
return abs(c.bound_box[0][1] - c.bound_box[3][1])
|
||||||
return abs(glyph_obj.bound_box[0][1] - glyph_obj.bound_box[3][1])
|
return abs(glyph_obj.bound_box[0][1] - glyph_obj.bound_box[3][1])
|
||||||
|
|
||||||
def prepare_text(font_name, face_name, text):
|
def prepare_text(font_name, face_name, text, allow_replacement=True):
|
||||||
loaded, missing, loadable, files = Font.test_glyphs_availability(
|
loaded, missing, loadable, files = Font.test_glyphs_availability(
|
||||||
font_name,
|
font_name,
|
||||||
face_name,
|
face_name,
|
||||||
text)
|
text)
|
||||||
|
# possibly replace upper and lower case letters with each other
|
||||||
|
if len(missing) > 0 and allow_replacement:
|
||||||
|
replacement_search = ""
|
||||||
|
for m in missing:
|
||||||
|
if m.islower():
|
||||||
|
replacement_search += m.upper()
|
||||||
|
if m.isupper():
|
||||||
|
replacement_search += m.lower()
|
||||||
|
r = Font.test_availability(font_name, face_name, replacement_search)
|
||||||
|
loadable += r["maybe"]
|
||||||
|
# not update (loaded, missing, files), we only use loadable/maybe later
|
||||||
|
|
||||||
if len(loadable) > 0:
|
if len(loadable) > 0:
|
||||||
for filepath in files:
|
for filepath in files:
|
||||||
load_font_from_filepath(filepath, loadable, font_name, face_name)
|
load_font_from_filepath(filepath, loadable, font_name, face_name)
|
||||||
|
@ -770,9 +782,6 @@ def set_text_on_curve(text_properties, reset_timeout_s=0.1, reset_depsgraph_n=4)
|
||||||
if c == '\\':
|
if c == '\\':
|
||||||
is_command = True
|
is_command = True
|
||||||
continue
|
continue
|
||||||
if c == ' ':
|
|
||||||
advance = advance + scalor
|
|
||||||
continue
|
|
||||||
is_newline = False
|
is_newline = False
|
||||||
if is_command:
|
if is_command:
|
||||||
if c == 'n':
|
if c == 'n':
|
||||||
|
@ -787,14 +796,33 @@ def set_text_on_curve(text_properties, reset_timeout_s=0.1, reset_depsgraph_n=4)
|
||||||
is_command = False
|
is_command = False
|
||||||
glyph_id = c
|
glyph_id = c
|
||||||
|
|
||||||
glyph = Font.get_glyph(text_properties.font_name,
|
glyph_tmp = Font.get_glyph(text_properties.font_name,
|
||||||
text_properties.face_name,
|
text_properties.face_name,
|
||||||
glyph_id).original
|
glyph_id)
|
||||||
|
if glyph_tmp == None:
|
||||||
|
space_width = Font.is_space(glyph_id)
|
||||||
|
if space_width != False:
|
||||||
|
advance = advance + space_width * text_properties.font_size
|
||||||
|
continue
|
||||||
|
|
||||||
if glyph == None:
|
message=f"Glyph not found for font_name='{text_properties.font_name}' face_name='{text_properties.face_name}' glyph_id='{glyph_id}'"
|
||||||
# self.report({'ERROR'}, f"Glyph not found for {font_name} {face_name} {glyph_id}")
|
replaced = False
|
||||||
print(f"Glyph not found for {text_properties.font_name} {text_properties.face_name} {glyph_id}")
|
if glyph_id.isupper() or glyph_id.islower():
|
||||||
continue
|
possible_replacement = glyph_id.lower() if glyph_id.isupper() else glyph_id.upper()
|
||||||
|
glyph_tmp = Font.get_glyph(text_properties.font_name,
|
||||||
|
text_properties.face_name,
|
||||||
|
possible_replacement)
|
||||||
|
if glyph_tmp != None:
|
||||||
|
message = message + f" (replaced with '{possible_replacement}')"
|
||||||
|
replaced = True
|
||||||
|
|
||||||
|
ShowMessageBox(title="Glyph replaced" if replaced else "Glyph missing",
|
||||||
|
icon='INFO' if replaced else 'ERROR',
|
||||||
|
message=message,
|
||||||
|
prevent_repeat=True)
|
||||||
|
if replaced == False:
|
||||||
|
continue
|
||||||
|
glyph = glyph_tmp.original
|
||||||
|
|
||||||
ob = None
|
ob = None
|
||||||
obg = None
|
obg = None
|
||||||
|
|
Loading…
Reference in a new issue