Helper tool to diagnose between text encoding issues and font loading issues. Pass your UTF-8 string and verify that there are correct.
| 16318 | |
| 16319 | // Helper tool to diagnose between text encoding issues and font loading issues. Pass your UTF-8 string and verify that there are correct. |
| 16320 | void ImGui::DebugTextEncoding(const char* str) |
| 16321 | { |
| 16322 | Text("Text: \"%s\"", str); |
| 16323 | if (!BeginTable("##DebugTextEncoding", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable)) |
| 16324 | return; |
| 16325 | TableSetupColumn("Offset"); |
| 16326 | TableSetupColumn("UTF-8"); |
| 16327 | TableSetupColumn("Glyph"); |
| 16328 | TableSetupColumn("Codepoint"); |
| 16329 | TableHeadersRow(); |
| 16330 | const char* str_end = str + strlen(str); // As we may receive malformed UTF-8, pass an explicit end instead of relying on ImTextCharFromUtf8() assuming enough space. |
| 16331 | for (const char* p = str; *p != 0; ) |
| 16332 | { |
| 16333 | unsigned int c; |
| 16334 | const int c_utf8_len = ImTextCharFromUtf8(&c, p, str_end); |
| 16335 | TableNextColumn(); |
| 16336 | Text("%d", (int)(p - str)); |
| 16337 | TableNextColumn(); |
| 16338 | for (int byte_index = 0; byte_index < c_utf8_len; byte_index++) |
| 16339 | { |
| 16340 | if (byte_index > 0) |
| 16341 | SameLine(); |
| 16342 | Text("0x%02X", (int)(unsigned char)p[byte_index]); |
| 16343 | } |
| 16344 | TableNextColumn(); |
| 16345 | TextUnformatted(p, p + c_utf8_len); |
| 16346 | if (!GetFont()->IsGlyphInFont((ImWchar)c)) |
| 16347 | { |
| 16348 | SameLine(); |
| 16349 | TextUnformatted("[missing]"); |
| 16350 | } |
| 16351 | TableNextColumn(); |
| 16352 | Text("U+%04X", (int)c); |
| 16353 | p += c_utf8_len; |
| 16354 | } |
| 16355 | EndTable(); |
| 16356 | } |
| 16357 | |
| 16358 | static void DebugFlashStyleColorStop() |
| 16359 | { |
nothing calls this directly
no test coverage detected