allow replacements (upper/lower)

This commit is contained in:
jrkb 2025-01-19 14:19:59 +01:00
parent 36c8f25e29
commit 167dea8164

View file

@ -674,11 +674,23 @@ def get_glyph_height(glyph_obj):
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])
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(
font_name,
face_name,
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:
for filepath in files:
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 == '\\':
is_command = True
continue
if c == ' ':
advance = advance + scalor
continue
is_newline = False
if is_command:
if c == 'n':
@ -787,15 +796,34 @@ def set_text_on_curve(text_properties, reset_timeout_s=0.1, reset_depsgraph_n=4)
is_command = False
glyph_id = c
glyph = Font.get_glyph(text_properties.font_name,
glyph_tmp = Font.get_glyph(text_properties.font_name,
text_properties.face_name,
glyph_id).original
if glyph == None:
# self.report({'ERROR'}, f"Glyph not found for {font_name} {face_name} {glyph_id}")
print(f"Glyph not found for {text_properties.font_name} {text_properties.face_name} {glyph_id}")
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
message=f"Glyph not found for font_name='{text_properties.font_name}' face_name='{text_properties.face_name}' glyph_id='{glyph_id}'"
replaced = False
if glyph_id.isupper() or glyph_id.islower():
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
obg = None
if regenerate: