From 8f3d58aad0c068ca0f546927c8d9694f1601a4aa Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Sun, 25 May 2025 22:00:54 +0200 Subject: [PATCH] transfer glyph transforms on duplication --- __init__.py | 24 +++++++++++++----------- butils.py | 44 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/__init__.py b/__init__.py index 2d8ac95..358b99b 100644 --- a/__init__.py +++ b/__init__.py @@ -284,17 +284,19 @@ class ABC3D_data(bpy.types.PropertyGroup): def active_text_index_update(self, context): if self.active_text_index != -1: - o = self.available_texts[self.active_text_index].text_object - # active_text_index changed. so let's update the selection - # check if it is already selected - # or perhaps one of the glyphs - if ( - not o.select_get() - and not len([c for c in o.children if c.select_get()]) > 0 - ): - bpy.ops.object.select_all(action="DESELECT") - o.select_set(True) - bpy.context.view_layer.objects.active = o + text_properties = butils.get_text_properties(self.active_text_index, context.scene) + if text_properties is not None: + o = text_properties.text_object + # active_text_index changed. so let's update the selection + # check if it is already selected + # or perhaps one of the glyphs + if (o is not None + and not o.select_get() + and not len([c for c in o.children if c.select_get()]) > 0 + ): + bpy.ops.object.select_all(action="DESELECT") + o.select_set(True) + context.view_layer.objects.active = o # else: # print("already selected") diff --git a/butils.py b/butils.py index 57dea5b..b74a618 100644 --- a/butils.py +++ b/butils.py @@ -772,6 +772,15 @@ def prepare_text(font_name, face_name, text, allow_replacement=True): load_font_from_filepath(filepath, loadable, font_name, face_name) return True +def predict_actual_text(text_properties): + availability = Font.test_availability(text_properties.font_name, text_properties.face_name, text_properties.text) + AVAILABILITY = Font.test_availability(text_properties.font_name, text_properties.face_name, text_properties.text.swapcase()) + t_text = text_properties.text + for c in availability["missing"]: + t_text = t_text.replace(c, "") + for c in AVAILABILITY["missing"]: + t_text = t_text.replace(c, "") + return t_text def is_bezier(curve): if curve.type != "CURVE": @@ -936,6 +945,25 @@ def get_text_properties(text_id, scene = None): return t return None +def duplicate(obj, data=True, actions=True, add_to_collection=True, collection=None, recursive=True): + obj_copy = obj.copy() + if add_to_collection: + if collection: + collection.objects.link(obj_copy) + elif len(obj.users_collection) > 0: + obj.users_collection[0].objects.link(obj_copy) + if data and obj.data: + obj_copy.data = obj.data.copy() + if actions and obj.animation_data: + obj_copy.animation_data.action = obj.animation_data.action.copy() + if recursive and hasattr(obj, "children"): + for child in obj.children: + child_copy = duplicate(child) + child_copy.parent_type = child.parent_type + child_copy.parent = obj_copy + # child_copy.matrix_parent_inverse = obj_copy.matrix_world.inverted() + return obj_copy + def transfer_text_object_to_text_properties(text_object, text_properties, id_from_text_properties=True): print("TRANSFER:: BEGIN") print(f" {text_properties['text_id']=}") @@ -957,9 +985,18 @@ def transfer_text_object_to_text_properties(text_object, text_properties, id_fro print(f" {text_properties['offset']=}") if len(text_object.children) == 0: - print("could be duplicate?") + print("ccccccccccccccccccccccccccccccccc ccccc ccccc c c c c ccould be duplicate?") if possible_brother_text_id != text_properties["text_id"] and possible_brother_text_id != "": - pass + possible_brother_properties = get_text_properties(possible_brother_text_id) + possible_brother_object = possible_brother_properties.text_object + if possible_brother_object is not None: + for child in possible_brother_object.children: + if is_glyph_object(child): + child_copy = duplicate(child) + child_copy.parent_type = child.parent_type + child_copy.parent = text_object + parent_to_curve(child_copy, text_object) + # child_copy.matrix_parent_inverse = text_object.matrix_world.inverted() found_reconstructable_glyphs = False glyph_objects_with_indices = [] @@ -1155,7 +1192,8 @@ def transfer_glyph_object_to_glyph_properties(glyph_object, glyph_properties): import inspect def would_regenerate(text_properties): print("REGENERATE?") - if len(text_properties.actual_text) != len(text_properties.glyphs): + predicted_text = predict_actual_text(text_properties) + if text_properties.actual_text != predicted_text: print(inspect.currentframe().f_lineno) return True if len(text_properties.glyphs) == 0: