Helper tool to diagnose between text encoding issues and font loading issues. Pass your UTF-8 string and verify that there are correct.
| 13178 | |
| 13179 | // Helper tool to diagnose between text encoding issues and font loading issues. Pass your UTF-8 string and verify that there are correct. |
| 13180 | void ImGui::DebugTextEncoding(const char* str) |
| 13181 | { |
| 13182 | Text("Text: \"%s\"", str); |
| 13183 | if (!BeginTable("list", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit)) |
| 13184 | return; |
| 13185 | TableSetupColumn("Offset"); |
| 13186 | TableSetupColumn("UTF-8"); |
| 13187 | TableSetupColumn("Glyph"); |
| 13188 | TableSetupColumn("Codepoint"); |
| 13189 | TableHeadersRow(); |
| 13190 | for (const char* p = str; *p != 0; ) |
| 13191 | { |
| 13192 | unsigned int c; |
| 13193 | const int c_utf8_len = ImTextCharFromUtf8(&c, p, NULL); |
| 13194 | TableNextColumn(); |
| 13195 | Text("%d", (int)(p - str)); |
| 13196 | TableNextColumn(); |
| 13197 | for (int byte_index = 0; byte_index < c_utf8_len; byte_index++) |
| 13198 | { |
| 13199 | if (byte_index > 0) |
| 13200 | SameLine(); |
| 13201 | Text("0x%02X", (int)(unsigned char)p[byte_index]); |
| 13202 | } |
| 13203 | TableNextColumn(); |
| 13204 | if (GetFont()->FindGlyphNoFallback((ImWchar)c)) |
| 13205 | TextUnformatted(p, p + c_utf8_len); |
| 13206 | else |
| 13207 | TextUnformatted((c == IM_UNICODE_CODEPOINT_INVALID) ? "[invalid]" : "[missing]"); |
| 13208 | TableNextColumn(); |
| 13209 | Text("U+%04X", (int)c); |
| 13210 | p += c_utf8_len; |
| 13211 | } |
| 13212 | EndTable(); |
| 13213 | } |
| 13214 | |
| 13215 | // Avoid naming collision with imgui_demo.cpp's HelpMarker() for unity builds. |
| 13216 | static void MetricsHelpMarker(const char* desc) |
nothing calls this directly
no test coverage detected