gpt4 book ai didi

c++ - 在 ImGui 中嵌入大于字符大小的字体

转载 作者:太空宇宙 更新时间:2023-11-04 12:51:22 25 4
gpt4 key购买 nike

我在使用 ImGui 作为前端的小脚本上开发翻译。我需要扩展的 unicode 字符集以在将要使用的字体中可用。由于此脚本是通过 DLL 注入(inject)的,因此无法使用(我认为是。我完全没有使用 C++ 的经验。):

io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels);

从ttf文件添加字体导致数据== 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 编译字体,但输出太大以至于我得到:

fatal error C1091: compiler limit: string exceeds 65535 bytes in length

但是函数不接受除 char* 之外的任何类型。我正在将字符连接成字符串,然后通过 str() 和 c_str() 重新组装它,但应用程序在注入(inject)后崩溃了。这是从 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)。

最佳答案

我已经找到了这个问题的解决方法。如果你真的需要使用 BASE85,仍然没有答案,但你可以通过转换为 int 类型来增加大小限制(不要将 -base85 放在 binary_to_compressed_c.exe 中)然后将结果表插入头文件并使用 ImGui 提供的说明,如下所示:

头文件:

// File: 'DroidSans.ttf' (190044 bytes)
// Exported using binary_to_compressed_c.cpp
static const unsigned int droid_compressed_size = 134345;
static const unsigned int droid_compressed_data[134348 / 4] =

您的导入/渲染文件:

static const ImWchar ranges[] = { 0x0020, 0x00FF, 0x0100, 0x017F, 0 };
//Because I need extended characters im passing my array to function.

io.Fonts->AddFontFromMemoryCompressedTTF(droid_compressed_data, droid_compressed_size, 16.0f, NULL, ranges);

这就解决了从 string 转换为 char 以及其他与 base85 导入相关的问题。

关于c++ - 在 ImGui 中嵌入大于字符大小的字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48939406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com