From 27eece6d495ee99bc317087f1e980e1592c19d71 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 11 Dec 2024 17:25:53 +1100 Subject: [PATCH] Cleanup: reduce repitition in curve font access --- source/blender/editors/object/object_add.cc | 29 +++++++-------- .../editors/object/object_relations.cc | 36 +++++++++---------- 2 files changed, 29 insertions(+), 36 deletions(-) diff --git a/source/blender/editors/object/object_add.cc b/source/blender/editors/object/object_add.cc index 06798859e57..f4f99f2b80d 100644 --- a/source/blender/editors/object/object_add.cc +++ b/source/blender/editors/object/object_add.cc @@ -3362,22 +3362,19 @@ static Object *convert_font_to_curves_legacy(Base &base, newob->type = OB_CURVES_LEGACY; cu->type = OB_CURVES_LEGACY; - if (cu->vfont) { - id_us_min(&cu->vfont->id); - cu->vfont = nullptr; - } - if (cu->vfontb) { - id_us_min(&cu->vfontb->id); - cu->vfontb = nullptr; - } - if (cu->vfonti) { - id_us_min(&cu->vfonti->id); - cu->vfonti = nullptr; - } - if (cu->vfontbi) { - id_us_min(&cu->vfontbi->id); - cu->vfontbi = nullptr; - } +#define CURVE_VFONT_CLEAR(vfont_member) \ + if (cu->vfont_member) { \ + id_us_min(&cu->vfont_member->id); \ + cu->vfont_member = nullptr; \ + } \ + ((void)0) + + CURVE_VFONT_CLEAR(vfont); + CURVE_VFONT_CLEAR(vfontb); + CURVE_VFONT_CLEAR(vfonti); + CURVE_VFONT_CLEAR(vfontbi); + +#undef CURVE_VFONT_CLEAR if (!info.keep_original) { /* other users */ diff --git a/source/blender/editors/object/object_relations.cc b/source/blender/editors/object/object_relations.cc index ef70b997360..93234299e85 100644 --- a/source/blender/editors/object/object_relations.cc +++ b/source/blender/editors/object/object_relations.cc @@ -1567,26 +1567,22 @@ static int make_links_data_exec(bContext *C, wmOperator *op) break; } - if (cu_dst->vfont) { - id_us_min(&cu_dst->vfont->id); - } - cu_dst->vfont = cu_src->vfont; - id_us_plus((ID *)cu_dst->vfont); - if (cu_dst->vfontb) { - id_us_min(&cu_dst->vfontb->id); - } - cu_dst->vfontb = cu_src->vfontb; - id_us_plus((ID *)cu_dst->vfontb); - if (cu_dst->vfonti) { - id_us_min(&cu_dst->vfonti->id); - } - cu_dst->vfonti = cu_src->vfonti; - id_us_plus((ID *)cu_dst->vfonti); - if (cu_dst->vfontbi) { - id_us_min(&cu_dst->vfontbi->id); - } - cu_dst->vfontbi = cu_src->vfontbi; - id_us_plus((ID *)cu_dst->vfontbi); +#define CURVE_VFONT_SET(vfont_member) \ + { \ + if (cu_dst->vfont_member) { \ + id_us_min(&cu_dst->vfont_member->id); \ + } \ + cu_dst->vfont_member = cu_src->vfont_member; \ + id_us_plus((ID *)cu_dst->vfont_member); \ + } \ + ((void)0) + + CURVE_VFONT_SET(vfont); + CURVE_VFONT_SET(vfontb); + CURVE_VFONT_SET(vfonti); + CURVE_VFONT_SET(vfontbi); + +#undef CURVE_VFONT_SET DEG_id_tag_update(&ob_dst->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION);