Fix #122808: Better Indication of Missing VFont

For text objects, current code will use another font if you ask for
a character that is not found in the selected font. But what if the
selected font is invalid? This can happen with a saved Blend that uses
a non-packed font that is since deleted. Current behavior will show
nothing. This PR restores earlier behavior where we use the built-in
font in this case.

Pull Request: https://projects.blender.org/blender/blender/pulls/122851
This commit is contained in:
Harley Acheson
2024-07-04 03:26:22 +02:00
committed by Harley Acheson
parent 4806078dbd
commit ff89e24bf5
2 changed files with 16 additions and 1 deletions

View File

@@ -39,6 +39,7 @@
#include "BKE_anim_path.h"
#include "BKE_bpath.hh"
#include "BKE_context.hh"
#include "BKE_curve.hh"
#include "BKE_global.hh"
#include "BKE_idtype.hh"
@@ -46,6 +47,7 @@
#include "BKE_main.hh"
#include "BKE_object_types.hh"
#include "BKE_packedFile.h"
#include "BKE_report.hh"
#include "BKE_vfont.hh"
#include "BKE_vfontdata.hh"
@@ -300,6 +302,16 @@ static VFontData *vfont_get_data(VFont *vfont)
if (!pf) {
CLOG_WARN(&LOG, "Font file doesn't exist: %s", vfont->filepath);
if (!G.background) {
bContext *C_temp = CTX_create();
wmWindowManager *wm = static_cast<wmWindowManager *>(G_MAIN->wm.first);
if (wm) {
CTX_wm_manager_set(C_temp, wm);
BKE_reportf(CTX_wm_reports(C_temp), RPT_ERROR, "Missing font: %s", vfont->filepath);
}
CTX_free(C_temp);
}
/* DON'T DO THIS
* missing file shouldn't modify path! - campbell */
#if 0

View File

@@ -93,7 +93,10 @@ VChar *BKE_vfontdata_char_from_freetypefont(VFont *vfont, ulong character)
}
if (font_id == -1) {
return nullptr;
/* This could happen for a saved file with unpacked local font, later
* removed. Load the default UI font so we can still show _something_. */
font_id = BLF_load_mem(
vfont->data->name, static_cast<const uchar *>(builtin_font_data), builtin_font_size);
}
VChar *che = (VChar *)MEM_callocN(sizeof(VChar), "objfnt_char");