我正在开发使用 ImGui 作为前端的小脚本的翻译。我需要扩展的 unicode 字符集才能在将要使用的字体中使用。由于这个脚本是通过 DLL 注入的,所以没有办法(我想是的。我根本没有使用 c++ 的经验。)使用:
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels);
从 ttf 文件添加字体导致 data == NULL;
void* data = ImFileLoadToMemory(filename, "rb", &data_size, 0);
if (!data)
{
IM_ASSERT(0); // Could not load file.
return NULL;
}
我也尝试使用 io.Fonts->AddFontFromMemoryCompressedBase85TTF 并通过包含 binary_to_compressed_c 编译字体,但输出太大了,我得到:
致命错误 C1091:编译器限制:字符串长度超过 65535 个字节
但函数不接受除 char* 之外的任何类型。我将字符连接成字符串,然后通过 str() 和 c_str() 重新组装它,但应用程序在注入后崩溃。这是从 ImGui 处理 base85 转换的函数:
ImFont* ImFontAtlas::AddFontFromMemoryCompressedBase85TTF(const char* compressed_ttf_data_base85, float size_pixels, const ImFontConfig* font_cfg, const ImWchar* glyph_ranges)
{
int compressed_ttf_size = (((int)strlen(compressed_ttf_data_base85) + 4) / 5) * 4;
void* compressed_ttf = ImGui::MemAlloc((size_t)compressed_ttf_size);
Decode85((const unsigned char*)compressed_ttf_data_base85, (unsigned char*)compressed_ttf);
ImFont* font = AddFontFromMemoryCompressedTTF(compressed_ttf, compressed_ttf_size, size_pixels, font_cfg, glyph_ranges);
ImGui::MemFree(compressed_ttf);
return font;
}
我该如何解决这个问题?我已经尝试了一切,但没有任何效果。只有将较小的字符传递给编译函数才有效(尝试使用捆绑的 Cousine_Regular.ttf)。