Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-08-21 14:39:02 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-08-21 14:39:02 +0400
commit9a776daca8fa0aa9bfa22c0c4dd9b6e649acdb84 (patch)
treec8a7687986c108a138dd6144b87f2701074fbc93
parent671e3df070c7868d8a5a445ebab5f819718270c4 (diff)
code cleanup: vfont's used confusing and over complicated method of storing memory for loaded fonts, not store as a temp var in the fonts.
-rw-r--r--intern/guardedalloc/MEM_guardedalloc.h2
-rw-r--r--intern/guardedalloc/intern/mallocn.c4
-rw-r--r--source/blender/blenkernel/BKE_font.h4
-rw-r--r--source/blender/blenkernel/BKE_packedFile.h1
-rw-r--r--source/blender/blenkernel/intern/font.c104
-rw-r--r--source/blender/blenkernel/intern/packedFile.c12
-rw-r--r--source/blender/blenlib/BLI_vfontdata.h12
-rw-r--r--source/blender/blenlib/intern/freetypefont.c13
-rw-r--r--source/blender/blenloader/intern/readfile.c1
-rw-r--r--source/blender/makesdna/DNA_vfont_types.h4
-rw-r--r--source/blender/windowmanager/intern/wm_files.c6
-rw-r--r--source/blender/windowmanager/intern/wm_init_exit.c2
12 files changed, 42 insertions, 123 deletions
diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h
index 149483e719f..6973c19dea9 100644
--- a/intern/guardedalloc/MEM_guardedalloc.h
+++ b/intern/guardedalloc/MEM_guardedalloc.h
@@ -92,7 +92,7 @@ extern "C" {
/**
* Duplicates a block of memory, and returns a pointer to the
* newly allocated block. */
- void *MEM_dupallocN(void *vmemh)
+ void *MEM_dupallocN(const void *vmemh)
#if MEM_GNU_ATTRIBUTES
__attribute__((warn_unused_result))
#endif
diff --git a/intern/guardedalloc/intern/mallocn.c b/intern/guardedalloc/intern/mallocn.c
index df6f4d59c7f..a65871f4410 100644
--- a/intern/guardedalloc/intern/mallocn.c
+++ b/intern/guardedalloc/intern/mallocn.c
@@ -248,12 +248,12 @@ size_t MEM_allocN_len(const void *vmemh)
}
}
-void *MEM_dupallocN(void *vmemh)
+void *MEM_dupallocN(const void *vmemh)
{
void *newp = NULL;
if (vmemh) {
- MemHead *memh = vmemh;
+ const MemHead *memh = vmemh;
memh--;
#ifndef DEBUG_MEMDUPLINAME
diff --git a/source/blender/blenkernel/BKE_font.h b/source/blender/blenkernel/BKE_font.h
index 938a13483d5..cd52dd75f26 100644
--- a/source/blender/blenkernel/BKE_font.h
+++ b/source/blender/blenkernel/BKE_font.h
@@ -76,13 +76,9 @@ 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_free_global_ttf(void);
struct VFont *BKE_vfont_builtin_get(void);
struct VFont *BKE_vfont_load(struct Main *bmain, const char *name);
-struct TmpFont *BKE_vfont_tmpfont_find(struct VFont *vfont);
-void BKE_vfont_tmpfont_remove(struct VFont *vfont);
-
struct CharTrans *BKE_vfont_to_curve(struct Main *bmain, struct Scene *scene, struct Object *ob, int mode);
int BKE_vfont_select_get(struct Object *ob, int *start, int *end);
diff --git a/source/blender/blenkernel/BKE_packedFile.h b/source/blender/blenkernel/BKE_packedFile.h
index 1891840f497..ecbd2e7536b 100644
--- a/source/blender/blenkernel/BKE_packedFile.h
+++ b/source/blender/blenkernel/BKE_packedFile.h
@@ -43,6 +43,7 @@ struct ReportList;
struct VFont;
/* pack */
+struct PackedFile *dupPackedFileMemory(const struct PackedFile *pf_src);
struct PackedFile *newPackedFile(struct ReportList *reports, const char *filename, const char *relabase);
struct PackedFile *newPackedFileMemory(void *mem, int memlen);
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index 49c3d77a527..8689d6648a9 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -60,10 +60,9 @@
#include "BKE_curve.h"
#include "BKE_displist.h"
-static ListBase ttfdata = {NULL, NULL};
+//static ListBase ttfdata = {NULL, NULL};
/* The vfont code */
-
void BKE_vfont_free_data(struct VFont *vfont)
{
if (vfont->data) {
@@ -83,7 +82,10 @@ void BKE_vfont_free_data(struct VFont *vfont)
vfont->data = NULL;
}
- BKE_vfont_tmpfont_remove(vfont);
+ if (vfont->temp_pf) {
+ freePackedFile(vfont->temp_pf); /* NULL when the font file can't be found on disk */
+ vfont->temp_pf = NULL;
+ }
}
void BKE_vfont_free(struct VFont *vf)
@@ -91,7 +93,7 @@ void BKE_vfont_free(struct VFont *vf)
if (vf == NULL) return;
BKE_vfont_free_data(vf);
-
+
if (vf->packedfile) {
freePackedFile(vf->packedfile);
vf->packedfile = NULL;
@@ -128,63 +130,11 @@ static PackedFile *get_builtin_packedfile(void)
}
}
-static void vfont_tmpfont_free(struct TmpFont *tf)
-{
- if (tf->pf) {
- freePackedFile(tf->pf); /* NULL when the font file can't be found on disk */
- }
- MEM_freeN(tf);
-}
-
-void BKE_vfont_free_global_ttf(void)
-{
- struct TmpFont *tf, *tf_next;
-
- for (tf = ttfdata.first; tf; tf = tf_next) {
- tf_next = tf->next;
- vfont_tmpfont_free(tf);
- }
- ttfdata.first = ttfdata.last = NULL;
-}
-
-struct TmpFont *BKE_vfont_tmpfont_find(VFont *vfont)
-{
- struct TmpFont *tmpfnt = NULL;
-
- if (vfont == NULL) return NULL;
-
- /* Try finding the font from font list */
- for (tmpfnt = ttfdata.first; tmpfnt; tmpfnt = tmpfnt->next) {
- if (tmpfnt->vfont == vfont) {
- break;
- }
- }
-
- return tmpfnt;
-}
-
-/* assumes a VFont's tmpfont can't be in the database more then once */
-void BKE_vfont_tmpfont_remove(VFont *vfont)
-{
- struct TmpFont *tmpfnt;
-
- tmpfnt = BKE_vfont_tmpfont_find(vfont);
-
- if (tmpfnt) {
- vfont_tmpfont_free(tmpfnt);
- BLI_remlink(&ttfdata, tmpfnt);
- }
-}
-
static VFontData *vfont_get_data(Main *bmain, VFont *vfont)
{
- struct TmpFont *tmpfnt = NULL;
- PackedFile *tpf;
-
- if (vfont == NULL) return NULL;
-
- /* Try finding the font from font list */
- tmpfnt = BKE_vfont_tmpfont_find(vfont);
+ if (vfont == NULL) {
+ return NULL;
+ }
/* And then set the data */
if (!vfont->data) {
@@ -198,30 +148,15 @@ static VFontData *vfont_get_data(Main *bmain, VFont *vfont)
pf = vfont->packedfile;
/* We need to copy a tmp font to memory unless it is already there */
- if (!tmpfnt) {
- tpf = MEM_callocN(sizeof(*tpf), "PackedFile");
- tpf->data = MEM_mallocN(pf->size, "packFile");
- tpf->size = pf->size;
- memcpy(tpf->data, pf->data, pf->size);
-
- /* Add temporary packed file to globals */
- tmpfnt = (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font");
- tmpfnt->pf = tpf;
- tmpfnt->vfont = vfont;
- BLI_addtail(&ttfdata, tmpfnt);
+ if (vfont->temp_pf == NULL) {
+ vfont->temp_pf = dupPackedFileMemory(pf);
}
}
else {
pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));
- if (!tmpfnt) {
- tpf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));
-
- /* Add temporary packed file to globals */
- tmpfnt = (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font");
- tmpfnt->pf = tpf;
- tmpfnt->vfont = vfont;
- BLI_addtail(&ttfdata, tmpfnt);
+ if (vfont->temp_pf == NULL) {
+ vfont->temp_pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));
}
}
if (!pf) {
@@ -252,9 +187,8 @@ VFont *BKE_vfont_load(Main *bmain, const char *name)
char filename[FILE_MAXFILE];
VFont *vfont = NULL;
PackedFile *pf;
- PackedFile *tpf = NULL;
+ PackedFile *temp_pf = NULL;
int is_builtin;
- struct TmpFont *tmpfnt;
if (strcmp(name, FO_BUILTIN_NAME) == 0) {
BLI_strncpy(filename, name, sizeof(filename));
@@ -269,7 +203,7 @@ VFont *BKE_vfont_load(Main *bmain, const char *name)
BLI_splitdirstring(dir, filename);
pf = newPackedFile(NULL, name, bmain->name);
- tpf = newPackedFile(NULL, name, bmain->name);
+ temp_pf = newPackedFile(NULL, name, bmain->name);
is_builtin = FALSE;
}
@@ -295,10 +229,7 @@ VFont *BKE_vfont_load(Main *bmain, const char *name)
/* Do not add FO_BUILTIN_NAME to temporary listbase */
if (strcmp(filename, FO_BUILTIN_NAME)) {
- tmpfnt = (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font");
- tmpfnt->pf = tpf;
- tmpfnt->vfont = vfont;
- BLI_addtail(&ttfdata, tmpfnt);
+ vfont->temp_pf = temp_pf;
}
}
@@ -324,7 +255,7 @@ static VFont *which_vfont(Curve *cu, CharInfo *info)
if (cu->vfontbi) return(cu->vfontbi); else return(cu->vfont);
default:
return(cu->vfont);
- }
+ }
}
VFont *BKE_vfont_builtin_get(void)
@@ -344,6 +275,7 @@ static VChar *find_vfont_char(VFontData *vfd, intptr_t character)
{
VChar *che = NULL;
+ /* TODO: use ghash */
for (che = vfd->characters.first; che; che = che->next) {
if (che->index == character)
break;
diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c
index f115a41d419..ed2f4af0c51 100644
--- a/source/blender/blenkernel/intern/packedFile.c
+++ b/source/blender/blenkernel/intern/packedFile.c
@@ -158,7 +158,17 @@ void freePackedFile(PackedFile *pf)
else
printf("freePackedFile: Trying to free a NULL pointer\n");
}
-
+
+PackedFile *dupPackedFileMemory(const PackedFile *pf_src)
+{
+ PackedFile *pf_dst;
+
+ pf_dst = MEM_dupallocN(pf_src);
+ pf_dst->data = MEM_dupallocN(pf_src->data);
+
+ return pf_dst;
+}
+
PackedFile *newPackedFileMemory(void *mem, int memlen)
{
PackedFile *pf = MEM_callocN(sizeof(*pf), "PackedFile");
diff --git a/source/blender/blenlib/BLI_vfontdata.h b/source/blender/blenlib/BLI_vfontdata.h
index a63ec8e9f61..ed7d10ab257 100644
--- a/source/blender/blenlib/BLI_vfontdata.h
+++ b/source/blender/blenlib/BLI_vfontdata.h
@@ -39,14 +39,8 @@
struct PackedFile;
struct VFont;
-#define MAX_VF_CHARS 256
-
typedef struct VFontData {
ListBase characters;
- // ListBase nurbsbase[MAX_VF_CHARS];
- // float resol[MAX_VF_CHARS];
- // float width[MAX_VF_CHARS];
- // float *points[MAX_VF_CHARS];
char name[128];
} VFontData;
@@ -59,12 +53,6 @@ typedef struct VChar {
float *points;
} VChar;
-struct TmpFont {
- struct TmpFont *next, *prev;
- struct PackedFile *pf;
- struct VFont *vfont;
-};
-
/**
* Construct a new VFontData structure from
* Freetype font data in a PackedFile.
diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c
index 60999e76c47..597a645eb9c 100644
--- a/source/blender/blenlib/intern/freetypefont.c
+++ b/source/blender/blenlib/intern/freetypefont.c
@@ -293,19 +293,12 @@ static int objchr_to_ftvfontdata(VFont *vfont, FT_ULong charcode)
{
/* Freetype2 */
FT_Face face;
- struct TmpFont *tf;
-
- /* Find the correct FreeType font */
- tf = BKE_vfont_tmpfont_find(vfont);
-
- /* What, no font found. Something strange here */
- if (!tf) return FALSE;
/* Load the font to memory */
- if (tf->pf) {
+ if (vfont->temp_pf) {
err = FT_New_Memory_Face(library,
- tf->pf->data,
- tf->pf->size,
+ vfont->temp_pf->data,
+ vfont->temp_pf->size,
0,
&face);
if (err) return FALSE;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index eb22b9a2e2e..719081e378d 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2913,6 +2913,7 @@ static void lib_link_vfont(FileData *UNUSED(fd), Main *main)
static void direct_link_vfont(FileData *fd, VFont *vf)
{
vf->data = NULL;
+ vf->temp_pf = NULL;
vf->packedfile = direct_link_packedfile(fd, vf->packedfile);
}
diff --git a/source/blender/makesdna/DNA_vfont_types.h b/source/blender/makesdna/DNA_vfont_types.h
index 3cccfe6a19f..7aaeaf23db2 100644
--- a/source/blender/makesdna/DNA_vfont_types.h
+++ b/source/blender/makesdna/DNA_vfont_types.h
@@ -46,6 +46,10 @@ typedef struct VFont {
struct VFontData *data;
struct PackedFile *packedfile;
+
+ /* runtime only, holds memory for freetype to read from
+ * TODO, replace this with blf_font_new() style loading */
+ struct PackedFile *temp_pf;
} VFont;
/* *************** FONT ****************** */
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 660117de9f7..48b552acf26 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -380,8 +380,6 @@ void WM_file_read(bContext *C, const char *filepath, ReportList *reports)
/* assume automated tasks with background, don't write recent file list */
const int do_history = (G.background == FALSE) && (CTX_wm_manager(C)->op_undo_depth == 0);
- BKE_vfont_free_global_ttf();
-
/* put aside screens to match with persistent windows later */
/* also exit screens and editors */
wm_window_match_init(C, &wmbase);
@@ -490,9 +488,7 @@ int WM_homefile_read(bContext *C, ReportList *UNUSED(reports), short from_memory
ListBase wmbase;
char tstr[FILE_MAX];
int success = 0;
-
- BKE_vfont_free_global_ttf();
-
+
G.relbase_valid = 0;
if (!from_memory) {
char *cfgdir = BLI_get_folder(BLENDER_USER_CONFIG, NULL);
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index af24ea81fe6..8c2272e4707 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -399,8 +399,6 @@ void WM_exit_ext(bContext *C, const short do_python)
// BIF_GlobalReebFree();
// BIF_freeRetarget();
BIF_freeTemplates(C);
-
- BKE_vfont_free_global_ttf(); /* bke_font.h */
free_openrecent();