diff options
Diffstat (limited to 'source/blender/blenkernel/intern/font.c')
-rw-r--r-- | source/blender/blenkernel/intern/font.c | 67 |
1 files changed, 59 insertions, 8 deletions
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 2adf8ebc615..b12e16d9502 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -203,7 +203,27 @@ static VFontData *vfont_get_data(Main *bmain, VFont *vfont) return vfont->data; } -VFont *BKE_vfont_load(Main *bmain, const char *name) +/* 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 */ + freePackedFile(pf); + } +} + +VFont *BKE_vfont_load(Main *bmain, const char *filepath) { char filename[FILE_MAXFILE]; VFont *vfont = NULL; @@ -211,16 +231,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 +257,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 +279,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)) { @@ -777,7 +828,7 @@ makebreak: if ((tb_scale.h != 0.0f) && (cu->totbox > (curbox + 1)) && - ((-(yof - tb_scale.y)) > (tb_scale.h - (linedist * cu->fsize)) - yof_scale)) + ((-(yof - tb_scale.y)) > (tb_scale.h - linedist) - yof_scale)) { maxlen = 0; curbox++; |