diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-10-06 11:40:15 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-10-06 11:44:02 +0300 |
commit | 9f15bcb218ef32d5f15e1e13235d2d7fa667e04a (patch) | |
tree | 58669c2b15dad9fb28ca08e122f146318f23b768 /source/blender/blenkernel/intern/font.c | |
parent | 65bd2a6e6ae72a64dd2d3822fe79b44736b82264 (diff) |
RNA: Add check_existing arg to other load() funcs
Note: movieclip was doing this already by default,
now split into 2 functions, matching image behavior.
Diffstat (limited to 'source/blender/blenkernel/intern/font.c')
-rw-r--r-- | source/blender/blenkernel/intern/font.c | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 23261b63486..e3ebb7f908c 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -203,7 +203,7 @@ static VFontData *vfont_get_data(Main *bmain, VFont *vfont) return vfont->data; } -VFont *BKE_vfont_load(Main *bmain, const char *name) +VFont *BKE_vfont_load(Main *bmain, const char *filepath) { char filename[FILE_MAXFILE]; VFont *vfont = NULL; @@ -211,16 +211,16 @@ VFont *BKE_vfont_load(Main *bmain, const char *name) PackedFile *temp_pf = NULL; bool is_builtin; - if (STREQ(name, FO_BUILTIN_NAME)) { - BLI_strncpy(filename, name, sizeof(filename)); + if (STREQ(filepath, FO_BUILTIN_NAME)) { + BLI_strncpy(filename, filepath, sizeof(filename)); pf = get_builtin_packedfile(); is_builtin = true; } else { - BLI_split_file_part(name, filename, sizeof(filename)); - pf = newPackedFile(NULL, name, bmain->name); - temp_pf = newPackedFile(NULL, name, bmain->name); + BLI_split_file_part(filepath, filename, sizeof(filename)); + pf = newPackedFile(NULL, filepath, bmain->name); + temp_pf = newPackedFile(NULL, filepath, bmain->name); is_builtin = false; } @@ -237,7 +237,7 @@ VFont *BKE_vfont_load(Main *bmain, const char *name) if (vfd->name[0] != '\0') { BLI_strncpy(vfont->id.name + 2, vfd->name, sizeof(vfont->id.name) - 2); } - BLI_strncpy(vfont->name, name, sizeof(vfont->name)); + BLI_strncpy(vfont->name, filepath, sizeof(vfont->name)); /* if autopack is on store the packedfile in de font structure */ if (!is_builtin && (G.fileflags & G_AUTOPACK)) { @@ -259,6 +259,37 @@ VFont *BKE_vfont_load(Main *bmain, const char *name) return vfont; } +VFont *BKE_vfont_load_exists_ex(struct Main *bmain, const char *filepath, bool *r_exists) +{ + VFont *vfont; + char str[FILE_MAX], strtest[FILE_MAX]; + + BLI_strncpy(str, filepath, sizeof(str)); + BLI_path_abs(str, bmain->name); + + /* first search an identical filepath */ + for (vfont = bmain->vfont.first; vfont; vfont = vfont->id.next) { + BLI_strncpy(strtest, vfont->name, sizeof(vfont->name)); + BLI_path_abs(strtest, ID_BLEND_PATH(bmain, &vfont->id)); + + if (BLI_path_cmp(strtest, str) == 0) { + vfont->id.us++; /* officially should not, it doesn't link here! */ + if (r_exists) + *r_exists = true; + return vfont; + } + } + + if (r_exists) + *r_exists = false; + return BKE_vfont_load(bmain, filepath); +} + +VFont *BKE_vfont_load_exists(struct Main *bmain, const char *filepath) +{ + return BKE_vfont_load_exists_ex(bmain, filepath, NULL); +} + static VFont *which_vfont(Curve *cu, CharInfo *info) { switch (info->flag & (CU_CHINFO_BOLD | CU_CHINFO_ITALIC)) { |