diff --git a/code/graphics/paths/NanoVGRenderer.cpp b/code/graphics/paths/NanoVGRenderer.cpp index da82ec97bf..bfc1a55237 100644 --- a/code/graphics/paths/NanoVGRenderer.cpp +++ b/code/graphics/paths/NanoVGRenderer.cpp @@ -21,6 +21,22 @@ #include "NanoVGRenderer.h" #include "tracing/tracing.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// That is a wrapper function for log prints to be availiable for nanovg components. For now it is stb_truetype.h +// Planted by ksotar with blessing from asarium +void nvgOldCPrintf(const char *message, ...) { + nprintf(("General", message)); +} + +#ifdef __cplusplus +} +#endif + + namespace { using namespace graphics::paths; diff --git a/code/graphics/paths/nanovg/CHANGES.txt b/code/graphics/paths/nanovg/CHANGES.txt index a4aeb3ff94..b4c9071d7a 100644 --- a/code/graphics/paths/nanovg/CHANGES.txt +++ b/code/graphics/paths/nanovg/CHANGES.txt @@ -6,3 +6,6 @@ Changes to fontstash.h - Increased memory size for newer stb_truetype version - Removed pixel snapping from fons__getQuad - Include as malloc and free weren't found for some reason + +Changes to stb_truetype.h + - Added extern function to print in log. Made Assert on missed glyph a bit more friendly diff --git a/code/graphics/paths/nanovg/stb_truetype.h b/code/graphics/paths/nanovg/stb_truetype.h index 94d6f5ff61..5754778a3a 100644 --- a/code/graphics/paths/nanovg/stb_truetype.h +++ b/code/graphics/paths/nanovg/stb_truetype.h @@ -431,6 +431,9 @@ typedef signed int stbtt_int32; typedef char stbtt__check_size32[sizeof(stbtt_int32) == 4 ? 1 : -1]; typedef char stbtt__check_size16[sizeof(stbtt_int16) == 2 ? 1 : -1]; +// Function from NanoVGRenderer.cpp to provide log printing capabilities here. +extern void nvgOldCPrintf(const char *string, ...); + // e.g. #define your own STBTT_ifloor/STBTT_iceil() to avoid math.h #ifndef STBTT_ifloor #include @@ -1501,7 +1504,12 @@ STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codep stbtt_uint16 offset, start; stbtt_uint16 item = (stbtt_uint16)((search - endCount) >> 1); - STBTT_assert(unicode_codepoint <= ttUSHORT(data + endCount + 2 * item)); + if (unicode_codepoint > ttUSHORT(data + endCount + 2 * item)) { + nvgOldCPrintf("WARNING: Probably font character is missing. Unicode decimal index is %d.\n", unicode_codepoint); + } + STBTT_assert((unicode_codepoint <= ttUSHORT(data + endCount + 2 * item)) && + " \ + Looks like the font file you're using misses a character. Look into log for 'WARNING: Probably font' to know its code."); start = ttUSHORT(data + index_map + 14 + segcount * 2 + 2 + 2 * item); if (unicode_codepoint < start) return 0;