remove text and allow rudimentary nurbs

This commit is contained in:
jrkb 2024-08-21 16:51:00 +02:00
parent 28e664cd6c
commit 01c116c321
2 changed files with 67 additions and 36 deletions

View file

@ -633,6 +633,11 @@ def prepare_text(font_name, face_name, text):
load_font_from_filepath(filepath, loadable, font_name, face_name)
return True
def is_bezier(curve):
if len(curve.data.splines) < 1:
return False
return curve.data.splines[0].type == 'BEZIER'
def set_text_on_curve(text_properties, recursive=True):
# starttime = time.perf_counter_ns()
mom = text_properties.text_object
@ -660,33 +665,7 @@ def set_text_on_curve(text_properties, recursive=True):
# if we regenerate.... delete objects
if regenerate:
# loaded, missing, maybe, files = Font.test_glyphs_availability(
# text_properties.font_name,
# text_properties.face_name,
# text_properties.text)
# if len(maybe) > 0 and recursive:
# print(f"doing the thing {len(files)} times")
# for filepath in files:
# def loader():
# set_text_on_curve(text_properties, False)
# print(f"loading font from filepath {filepath} {maybe}")
# load_font_from_filepath(filepath, maybe)
# print(f"font: {text_properties.font_name} face: {text_properties.face_name}")
# print("text",text_properties.text)
# text_properties.font_size = text_properties.font_size
# # run_in_main_thread(loader)
# return
completely_delete_objects(glyph_objects)
# context_override = bpy.context.copy()
# context_override["selected_objects"] = list(glyph_objects)
# with bpy.context.temp_override(**context_override):
# bpy.ops.object.delete()
# # remove deleted objects
# # this is necessary
# for g in glyph_objects:
# if type(g) != type(None):
# bpy.data.objects.remove(g, do_unlink=True)
text_properties.glyphs.clear()
@ -733,7 +712,7 @@ def set_text_on_curve(text_properties, recursive=True):
else:
ob = text_properties.glyphs[i].glyph_object
distribution_type = 'CALCULATE'
distribution_type = 'CALCULATE' if is_bezier(mom) else 'FOLLOW_PATH'
if distribution_type == 'FOLLOW_PATH':
ob.constraints.new(type='FOLLOW_PATH')
ob.constraints["Follow Path"].target = mom
@ -776,15 +755,16 @@ def set_text_on_curve(text_properties, recursive=True):
# otherwise letters will be closer together the curvier the bezier is
# this could be done more efficiently, but whatever
curve_compensation = 0
if text_properties.compensate_curvature and glyph_advance > 0:
previous_location = calc_point_on_bezier_curve(mom, advance, False)
new_location = calc_point_on_bezier_curve(mom, advance + glyph_advance, False)
while (previous_location - new_location).length > glyph_advance:
curve_compensation = curve_compensation - glyph_advance * 0.01
new_location = calc_point_on_bezier_curve(mom, advance + glyph_advance + curve_compensation, False)
while (previous_location - new_location).length < glyph_advance:
curve_compensation = curve_compensation + glyph_advance * 0.01
new_location = calc_point_on_bezier_curve(mom, advance + glyph_advance + curve_compensation, False)
if distribution_type == 'CALCULATE':
if text_properties.compensate_curvature and glyph_advance > 0:
previous_location = calc_point_on_bezier_curve(mom, advance, False)
new_location = calc_point_on_bezier_curve(mom, advance + glyph_advance, False)
while (previous_location - new_location).length > glyph_advance:
curve_compensation = curve_compensation - glyph_advance * 0.01
new_location = calc_point_on_bezier_curve(mom, advance + glyph_advance + curve_compensation, False)
while (previous_location - new_location).length < glyph_advance:
curve_compensation = curve_compensation + glyph_advance * 0.01
new_location = calc_point_on_bezier_curve(mom, advance + glyph_advance + curve_compensation, False)
ob.scale = (scalor, scalor, scalor)