[Bf-blender-cvs] [afe6df1487f] master: Cleanup: VFont: Move to IDTypeInfo and remove unused BKE API

Dalai Felinto noreply at git.blender.org
Fri Mar 6 20:07:07 CET 2020


Commit: afe6df1487fd001e18c30bd85660154753ece345
Author: Dalai Felinto
Date:   Fri Mar 6 20:00:42 2020 +0100
Branches: master
https://developer.blender.org/rBafe6df1487fd001e18c30bd85660154753ece345

Cleanup: VFont: Move to IDTypeInfo and remove unused BKE API

This was particularly strange because we had a _free_data() function.
But still the one I replaced was of course the _free() one.

And we should rename the _free_data_ function later to avoid confusions.

===================================================================

M	source/blender/blenkernel/BKE_font.h
M	source/blender/blenkernel/BKE_idtype.h
M	source/blender/blenkernel/intern/font.c
M	source/blender/blenkernel/intern/idtype.c
M	source/blender/blenkernel/intern/lib_id.c
M	source/blender/blenkernel/intern/lib_id_delete.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_font.h b/source/blender/blenkernel/BKE_font.h
index 31938c48529..35f7d8b7d53 100644
--- a/source/blender/blenkernel/BKE_font.h
+++ b/source/blender/blenkernel/BKE_font.h
@@ -71,19 +71,11 @@ bool BKE_vfont_is_builtin(struct VFont *vfont);
 void BKE_vfont_builtin_register(void *mem, int size);
 
 void BKE_vfont_free_data(struct VFont *vfont);
-void BKE_vfont_free(struct VFont *sc);
-void BKE_vfont_init(struct VFont *vfont);
-void BKE_vfont_copy_data(struct Main *bmain,
-                         struct VFont *vfont_dst,
-                         const struct VFont *vfont_src,
-                         const int flag);
 struct VFont *BKE_vfont_builtin_get(void);
 struct VFont *BKE_vfont_load(struct Main *bmain, const char *filepath);
 struct VFont *BKE_vfont_load_exists_ex(struct Main *bmain, const char *filepath, bool *r_exists);
 struct VFont *BKE_vfont_load_exists(struct Main *bmain, const char *filepath);
 
-void BKE_vfont_make_local(struct Main *bmain, struct VFont *vfont, const int flags);
-
 bool BKE_vfont_to_curve_ex(struct Object *ob,
                            struct Curve *cu,
                            int mode,
diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h
index 7289ceb95df..77e9580a9fd 100644
--- a/source/blender/blenkernel/BKE_idtype.h
+++ b/source/blender/blenkernel/BKE_idtype.h
@@ -140,7 +140,7 @@ extern IDTypeInfo IDType_ID_CA;
 extern IDTypeInfo IDType_ID_KE;
 extern IDTypeInfo IDType_ID_WO;
 extern IDTypeInfo IDType_ID_SCR;
-// extern IDTypeInfo IDType_ID_VF;
+extern IDTypeInfo IDType_ID_VF;
 extern IDTypeInfo IDType_ID_TXT;
 // extern IDTypeInfo IDType_ID_SPK;
 // extern IDTypeInfo IDType_ID_SO;
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index 44c59bcb00c..ec6a265ed96 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -41,6 +41,8 @@
 #include "BLI_threads.h"
 #include "BLI_vfontdata.h"
 
+#include "BLT_translation.h"
+
 #include "DNA_packedFile_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_vfont_types.h"
@@ -50,6 +52,7 @@
 #include "BKE_lib_id.h"
 #include "BKE_font.h"
 #include "BKE_global.h"
+#include "BKE_idtype.h"
 #include "BKE_main.h"
 #include "BKE_anim.h"
 #include "BKE_curve.h"
@@ -57,6 +60,84 @@
 static CLG_LogRef LOG = {"bke.data_transfer"};
 static ThreadRWMutex vfont_rwlock = BLI_RWLOCK_INITIALIZER;
 
+/**************************** Prototypes **************************/
+
+static PackedFile *get_builtin_packedfile(void);
+
+/****************************** VFont Datablock ************************/
+
+static void vfont_init_data(ID *id)
+{
+  VFont *vfont = (VFont *)id;
+  PackedFile *pf = get_builtin_packedfile();
+
+  if (pf) {
+    VFontData *vfd;
+
+    vfd = BLI_vfontdata_from_freetypefont(pf);
+    if (vfd) {
+      vfont->data = vfd;
+
+      BLI_strncpy(vfont->name, FO_BUILTIN_NAME, sizeof(vfont->name));
+    }
+
+    /* Free the packed file */
+    BKE_packedfile_free(pf);
+  }
+}
+
+static void vfont_copy_data(Main *UNUSED(bmain),
+                            ID *id_dst,
+                            const ID *UNUSED(id_src),
+                            const int flag)
+{
+  VFont *vfont_dst = (VFont *)id_dst;
+
+  /* We never handle usercount here for own data. */
+  const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
+
+  /* Just to be sure, should not have any value actually after reading time. */
+  vfont_dst->temp_pf = NULL;
+
+  if (vfont_dst->packedfile) {
+    vfont_dst->packedfile = BKE_packedfile_duplicate(vfont_dst->packedfile);
+  }
+
+  if (vfont_dst->data) {
+    vfont_dst->data = BLI_vfontdata_copy(vfont_dst->data, flag_subdata);
+  }
+}
+
+/** Free (or release) any data used by this font (does not free the font itself). */
+static void vfont_free_data(ID *id)
+{
+  VFont *vfont = (VFont *)id;
+  BKE_vfont_free_data(vfont);
+
+  if (vfont->packedfile) {
+    BKE_packedfile_free(vfont->packedfile);
+    vfont->packedfile = NULL;
+  }
+}
+
+IDTypeInfo IDType_ID_VF = {
+    .id_code = ID_VF,
+    .id_filter = FILTER_ID_VF,
+    .main_listbase_index = INDEX_ID_VF,
+    .struct_size = sizeof(VFont),
+    .name = "Font",
+    .name_plural = "fonts",
+    .translation_context = BLT_I18NCONTEXT_ID_VFONT,
+    .flags = 0,
+
+    .init_data = vfont_init_data,
+    .copy_data = vfont_copy_data,
+    .free_data = vfont_free_data,
+    .make_local = NULL,
+};
+
+/***************************** VFont *******************************/
+
 /* The vfont code */
 void BKE_vfont_free_data(struct VFont *vfont)
 {
@@ -90,37 +171,6 @@ void BKE_vfont_free_data(struct VFont *vfont)
   }
 }
 
-/** Free (or release) any data used by this font (does not free the font itself). */
-void BKE_vfont_free(struct VFont *vf)
-{
-  BKE_vfont_free_data(vf);
-
-  if (vf->packedfile) {
-    BKE_packedfile_free(vf->packedfile);
-    vf->packedfile = NULL;
-  }
-}
-
-void BKE_vfont_copy_data(Main *UNUSED(bmain),
-                         VFont *vfont_dst,
-                         const VFont *UNUSED(vfont_src),
-                         const int flag)
-{
-  /* We never handle usercount here for own data. */
-  const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
-
-  /* Just to be sure, should not have any value actually after reading time. */
-  vfont_dst->temp_pf = NULL;
-
-  if (vfont_dst->packedfile) {
-    vfont_dst->packedfile = BKE_packedfile_duplicate(vfont_dst->packedfile);
-  }
-
-  if (vfont_dst->data) {
-    vfont_dst->data = BLI_vfontdata_copy(vfont_dst->data, flag_subdata);
-  }
-}
-
 static void *builtin_font_data = NULL;
 static int builtin_font_size = 0;
 
@@ -218,26 +268,6 @@ static VFontData *vfont_get_data(VFont *vfont)
   return vfont->data;
 }
 
-/* Bad naming actually in this case... */
-void BKE_vfont_init(VFont *vfont)
-{
-  PackedFile *pf = get_builtin_packedfile();
-
-  if (pf) {
-    VFontData *vfd;
-
-    vfd = BLI_vfontdata_from_freetypefont(pf);
-    if (vfd) {
-      vfont->data = vfd;
-
-      BLI_strncpy(vfont->name, FO_BUILTIN_NAME, sizeof(vfont->name));
-    }
-
-    /* Free the packed file */
-    BKE_packedfile_free(pf);
-  }
-}
-
 VFont *BKE_vfont_load(Main *bmain, const char *filepath)
 {
   char filename[FILE_MAXFILE];
@@ -325,11 +355,6 @@ VFont *BKE_vfont_load_exists(struct Main *bmain, const char *filepath)
   return BKE_vfont_load_exists_ex(bmain, filepath, NULL);
 }
 
-void BKE_vfont_make_local(Main *bmain, VFont *vfont, const int flags)
-{
-  BKE_lib_id_make_local_generic(bmain, &vfont->id, flags);
-}
-
 static VFont *which_vfont(Curve *cu, CharInfo *info)
 {
   switch (info->flag & (CU_CHINFO_BOLD | CU_CHINFO_ITALIC)) {
diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c
index 3ff8a1bebd5..222c201a50e 100644
--- a/source/blender/blenkernel/intern/idtype.c
+++ b/source/blender/blenkernel/intern/idtype.c
@@ -67,7 +67,7 @@ static void id_type_init(void)
   INIT_TYPE(ID_KE);
   INIT_TYPE(ID_WO);
   INIT_TYPE(ID_SCR);
-  // INIT_TYPE(ID_VF);
+   INIT_TYPE(ID_VF);
   INIT_TYPE(ID_TXT);
   // INIT_TYPE(ID_SPK);
   // INIT_TYPE(ID_SO);
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index b74bb134dd3..4843bd1bb2b 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -511,9 +511,7 @@ bool BKE_lib_id_make_local(Main *bmain, ID *id, const bool test, const int flags
       BLI_assert(0);
       return true;
     case ID_VF:
-      if (!test) {
-        BKE_vfont_make_local(bmain, (VFont *)id, flags);
-      }
+      BLI_assert(0);
       return true;
     case ID_TXT:
       BLI_assert(0);
@@ -784,7 +782,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag)
         BKE_sound_copy_data(bmain, (bSound *)*r_newid, (bSound *)id, flag);
         break;
       case ID_VF:
-        BKE_vfont_copy_data(bmain, (VFont *)*r_newid, (VFont *)id, flag);
+        BLI_assert(0);
         break;
       case ID_LI:
       case ID_SCR:
@@ -1358,7 +1356,7 @@ void BKE_libblock_init_empty(ID *id)
       /* Nothing to do. */
       break;
     case ID_VF:
-      BKE_vfont_init((VFont *)id);
+      BLI_assert(0);
       break;
     case ID_TXT:
       BLI_assert(0);
diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c
index 634e7c59c08..77323891b45 100644
--- a/source/blender/blenkernel/intern/lib_id_delete.c
+++ b/source/blender/blenkernel/intern/lib_id_delete.c
@@ -184,7 +184,7 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag))
       BLI_assert(0);
       break;
     case ID_VF:
-      BKE_vfont_free((VFont *)id);
+      BLI_assert(0);
       break;
     case ID_TXT:
       BLI_assert(0);



More information about the Bf-blender-cvs mailing list