Helper tool to diagnose between text encoding issues and font loading issues. Pass your UTF-8 string and verify that there are correct.
| 18526 | |
| 18527 | // Helper tool to diagnose between text encoding issues and font loading issues. Pass your UTF-8 string and verify that there are correct. |
| 18528 | void ImGui::DebugTextEncoding(const char* str) |
| 18529 | { |
| 18530 | Text("Text: \"%s\"", str); |
| 18531 | if (!BeginTable("list", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit)) |
| 18532 | return; |
| 18533 | TableSetupColumn("Offset"); |
| 18534 | TableSetupColumn("UTF-8"); |
| 18535 | TableSetupColumn("Glyph"); |
| 18536 | TableSetupColumn("Codepoint"); |
| 18537 | TableHeadersRow(); |
| 18538 | for (const char* p = str; *p != 0; ) |
| 18539 | { |
| 18540 | unsigned int c; |
| 18541 | const int c_utf8_len = ImTextCharFromUtf8(&c, p, NULL); |
| 18542 | TableNextColumn(); |
| 18543 | Text("%d", (int)(p - str)); |
| 18544 | TableNextColumn(); |
| 18545 | for (int byte_index = 0; byte_index < c_utf8_len; byte_index++) |
| 18546 | { |
| 18547 | if (byte_index > 0) |
| 18548 | SameLine(); |
| 18549 | Text("0x%02X", (int)(unsigned char)p[byte_index]); |
| 18550 | } |
| 18551 | TableNextColumn(); |
| 18552 | if (GetFont()->FindGlyphNoFallback((ImWchar)c)) |
| 18553 | TextUnformatted(p, p + c_utf8_len); |
| 18554 | else |
| 18555 | TextUnformatted((c == IM_UNICODE_CODEPOINT_INVALID) ? "[invalid]" : "[missing]"); |
| 18556 | TableNextColumn(); |
| 18557 | Text("U+%04X", (int)c); |
| 18558 | p += c_utf8_len; |
| 18559 | } |
| 18560 | EndTable(); |
| 18561 | } |
| 18562 | |
| 18563 | // Avoid naming collision with imgui_demo.cpp's HelpMarker() for unity builds. |
| 18564 | static void MetricsHelpMarker(const char* desc) |
nothing calls this directly
no test coverage detected