[Bf-blender-cvs] [0698e892c75] id_copy_refactor: Add VFont copying.

Bastien Montagne noreply at git.blender.org
Tue Jul 11 15:57:57 CEST 2017


Commit: 0698e892c751fea4d2f250c8938d32cf0a3f9675
Author: Bastien Montagne
Date:   Mon Jul 10 13:57:05 2017 +0200
Branches: id_copy_refactor
https://developer.blender.org/rB0698e892c751fea4d2f250c8938d32cf0a3f9675

Add VFont copying.

Not much happy, have to include BKE_curve in BLI_freetypefont to copy
nurbs... Not sure why fonts are in BLI tbh. We are already replicating
quite a bit of nurbs logic there. :(

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

M	source/blender/blenkernel/BKE_font.h
M	source/blender/blenkernel/intern/font.c
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenlib/BLI_vfontdata.h
M	source/blender/blenlib/intern/freetypefont.c

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

diff --git a/source/blender/blenkernel/BKE_font.h b/source/blender/blenkernel/BKE_font.h
index e7ae0f606e7..60ad061bf77 100644
--- a/source/blender/blenkernel/BKE_font.h
+++ b/source/blender/blenkernel/BKE_font.h
@@ -78,6 +78,7 @@ 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);
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index 401fed74c52..5892c8aeeb7 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -106,6 +106,23 @@ void BKE_vfont_free(struct VFont *vf)
 	}
 }
 
+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_COPY_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 = dupPackedFile(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;
 
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 4249e690826..2c28501eb11 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -527,7 +527,8 @@ static int id_copy_libmanagement_cb(void *user_data, ID *id_self, ID **id_pointe
 bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, const bool test)
 {
 #define LIB_ID_TYPES_NOCOPY ID_LI, ID_SCR, ID_WM,  /* Not supported */ \
-                            ID_IP  /* Deprecated */
+                            ID_IP,  /* Deprecated */ \
+                            ID_SCE  /* Temp, TODO */
 
 	if (ELEM(GS(id->name), LIB_ID_TYPES_NOCOPY)) {
 		return false;
@@ -622,8 +623,10 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
 		case ID_SO:
 			if (!test) BKE_sound_copy_data(bmain, (bSound *)*r_newid, (bSound *)id, flag);
 			break;
-		case ID_SCE:
 		case ID_VF:
+			if (!test) BKE_vfont_copy_data(bmain, (VFont *)*r_newid, (VFont *)id, flag);
+			break;
+		case ID_SCE:
 			return false;  /* not implemented */
 		case ID_LI:
 		case ID_SCR:
diff --git a/source/blender/blenlib/BLI_vfontdata.h b/source/blender/blenlib/BLI_vfontdata.h
index 8a7079b6c5f..0cd50319a33 100644
--- a/source/blender/blenlib/BLI_vfontdata.h
+++ b/source/blender/blenlib/BLI_vfontdata.h
@@ -52,8 +52,10 @@ typedef struct VChar {
 } VChar;
 
 VFontData *BLI_vfontdata_from_freetypefont(struct PackedFile *pf);
+VFontData *BLI_vfontdata_copy(const VFontData *vfont_src, const int flag);
 
 VChar *BLI_vfontchar_from_freetypefont(struct VFont *vfont, unsigned long character);
+VChar *BLI_vfontchar_copy(const VChar *vchar_src, const int flag);
 
 #endif
 
diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c
index 8719c92a2a6..b97e41402d7 100644
--- a/source/blender/blenlib/intern/freetypefont.c
+++ b/source/blender/blenlib/intern/freetypefont.c
@@ -481,6 +481,21 @@ VFontData *BLI_vfontdata_from_freetypefont(PackedFile *pf)
 	return vfd;
 }
 
+static void *vfontdata_copy_characters_value_cb(const void *src) {
+	return BLI_vfontchar_copy(src, 0);
+}
+
+VFontData *BLI_vfontdata_copy(const VFontData *vfont_src, const int UNUSED(flag))
+{
+	VFontData *vfont_dst = MEM_dupallocN(vfont_src);
+
+	if (vfont_src->characters != NULL) {
+		vfont_dst->characters = BLI_ghash_copy(vfont_src->characters, NULL, vfontdata_copy_characters_value_cb);
+	}
+
+	return vfont_dst;
+}
+
 VChar *BLI_vfontchar_from_freetypefont(VFont *vfont, unsigned long character)
 {
 	VChar *che = NULL;
@@ -503,6 +518,20 @@ VChar *BLI_vfontchar_from_freetypefont(VFont *vfont, unsigned long character)
 	return che;
 }
 
+/* Yeah, this is very bad... But why is this in BLI in the first place, since it uses Nurb data?
+ * Anyway, do not feel like duplicating whole Nurb copy code here, so unless someone has a better idea... */
+#include "../../blenkernel/BKE_curve.h"
+
+VChar *BLI_vfontchar_copy(const VChar *vchar_src, const int UNUSED(flag))
+{
+	VChar *vchar_dst = MEM_dupallocN(vchar_src);
+
+	BLI_listbase_clear(&vchar_dst->nurbsbase);
+	BKE_nurbList_duplicate(&vchar_dst->nurbsbase, &vchar_src->nurbsbase);
+
+	return vchar_dst;
+}
+
 #if 0
 
 /* Freetype2 Outline struct */




More information about the Bf-blender-cvs mailing list