|
@@ -2249,13 +2249,14 @@ ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels,
|
|
|
}
|
|
|
|
|
|
// NB: Transfer ownership of 'ttf_data' to ImFontAtlas, unless font_cfg_template->FontDataOwnedByAtlas == false. Owned TTF buffer will be deleted after Build().
|
|
|
-ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* ttf_data, int ttf_size, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges)
|
|
|
+ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* font_data, int font_data_size, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges)
|
|
|
{
|
|
|
IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas between NewFrame() and EndFrame/Render()!");
|
|
|
ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig();
|
|
|
IM_ASSERT(font_cfg.FontData == NULL);
|
|
|
- font_cfg.FontData = ttf_data;
|
|
|
- font_cfg.FontDataSize = ttf_size;
|
|
|
+ IM_ASSERT(font_data_size > 100 && "Incorrect value for font_data_size!"); // Heuristic to prevent accidentally passing a wrong value to font_data_size.
|
|
|
+ font_cfg.FontData = font_data;
|
|
|
+ font_cfg.FontDataSize = font_data_size;
|
|
|
font_cfg.SizePixels = size_pixels > 0.0f ? size_pixels : font_cfg.SizePixels;
|
|
|
if (glyph_ranges)
|
|
|
font_cfg.GlyphRanges = glyph_ranges;
|
|
@@ -2470,7 +2471,10 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
|
|
|
const int font_offset = stbtt_GetFontOffsetForIndex((unsigned char*)cfg.FontData, cfg.FontNo);
|
|
|
IM_ASSERT(font_offset >= 0 && "FontData is incorrect, or FontNo cannot be found.");
|
|
|
if (!stbtt_InitFont(&src_tmp.FontInfo, (unsigned char*)cfg.FontData, font_offset))
|
|
|
+ {
|
|
|
+ IM_ASSERT(0 && "stbtt_InitFont(): failed to parse FontData. It is correct and complete? Check FontDataSize.");
|
|
|
return false;
|
|
|
+ }
|
|
|
|
|
|
// Measure highest codepoints
|
|
|
ImFontBuildDstData& dst_tmp = dst_tmp_array[src_tmp.DstIndex];
|