autoremove text_objects and newline

This commit is contained in:
jrkb 2024-07-02 12:22:24 +02:00
parent 62e6c63a61
commit 8bcb252087
2 changed files with 46 additions and 73 deletions

View file

@ -41,6 +41,21 @@ def get_curve_length(curve_obj, resolution = -1):
return total_length
def get_curve_line_lengths(curve_obj, resolution = -1):
output = []
for spline in curve_obj.data.splines:
output.append(spline.calc_length(resolution=resolution))
return output
def get_next_line_advance(curve_obj, current_advance, previous_glyph_advance, resolution = -1):
curve_line_lengths = get_curve_line_lengths(curve_obj, resolution)
total_length = 0
for cll in curve_line_lengths:
total_length += cll
if current_advance - previous_glyph_advance < total_length:
return total_length
return current_advance
def calc_point_on_bezier(bezier_point_1, bezier_point_2, t):
p1 = bezier_point_1.co
h1 = bezier_point_1.handle_right
@ -364,6 +379,8 @@ def set_text_on_curve(text_properties):
context_override["selected_objects"] = list(glyph_objects)
with bpy.context.temp_override(**context_override):
bpy.ops.object.delete()
for g in glyph_objects:
bpy.data.objects.remove(g, do_unlink=True)
# bpy.ops.object.delete({"selected_objects": glyph_objects})
text_properties.glyphs.clear()
@ -374,7 +391,21 @@ def set_text_on_curve(text_properties):
curve_length = get_curve_length(mom)
advance = 0
glyph_advance = 0
is_command = False
for i, c in enumerate(text_properties.text):
print(f"trying letter ({c})")
if c == '\\':
is_command = True
continue
if is_command:
if c == 'n':
next_line_advance = get_next_line_advance(mom, advance, glyph_advance)
if advance == next_line_advance:
self.report({'INFO'}, f"would like to add new line for {text_properties.text} please")
advance = next_line_advance
continue
is_command = False
glyph_id = c
glyph = Font.get_glyph(text_properties.font_name,
text_properties.font_face,
@ -385,6 +416,7 @@ def set_text_on_curve(text_properties):
continue
ob = bpy.data.objects.new(f"{glyph_id}", glyph.data)
ob['linked_textobject'] = text_properties.text_index
distribution_type = 'CALCULATE'
if distribution_type == 'FOLLOW_PATH':