[Internal] Display details for a single font, called by ShowStyleEditor().
| 5797 | |
| 5798 | // [Internal] Display details for a single font, called by ShowStyleEditor(). |
| 5799 | static void NodeFont(ImFont* font) |
| 5800 | { |
| 5801 | ImGuiIO& io = ImGui::GetIO(); |
| 5802 | ImGuiStyle& style = ImGui::GetStyle(); |
| 5803 | bool font_details_opened = ImGui::TreeNode(font, "Font: \"%s\"\n%.2f px, %d glyphs, %d file(s)", |
| 5804 | font->ConfigData ? font->ConfigData[0].Name : "", font->FontSize, font->Glyphs.Size, font->ConfigDataCount); |
| 5805 | ImGui::SameLine(); if (ImGui::SmallButton("Set as default")) { io.FontDefault = font; } |
| 5806 | if (!font_details_opened) |
| 5807 | return; |
| 5808 | |
| 5809 | ImGui::PushFont(font); |
| 5810 | ImGui::Text("The quick brown fox jumps over the lazy dog"); |
| 5811 | ImGui::PopFont(); |
| 5812 | ImGui::DragFloat("Font scale", &font->Scale, 0.005f, 0.3f, 2.0f, "%.1f"); // Scale only this font |
| 5813 | ImGui::SameLine(); HelpMarker( |
| 5814 | "Note than the default embedded font is NOT meant to be scaled.\n\n" |
| 5815 | "Font are currently rendered into bitmaps at a given size at the time of building the atlas. " |
| 5816 | "You may oversample them to get some flexibility with scaling. " |
| 5817 | "You can also render at multiple sizes and select which one to use at runtime.\n\n" |
| 5818 | "(Glimmer of hope: the atlas system will be rewritten in the future to make scaling more flexible.)"); |
| 5819 | ImGui::Text("Ascent: %f, Descent: %f, Height: %f", font->Ascent, font->Descent, font->Ascent - font->Descent); |
| 5820 | ImGui::Text("Fallback character: '%c' (U+%04X)", font->FallbackChar, font->FallbackChar); |
| 5821 | ImGui::Text("Ellipsis character: '%c' (U+%04X)", font->EllipsisChar, font->EllipsisChar); |
| 5822 | const int surface_sqrt = (int)sqrtf((float)font->MetricsTotalSurface); |
| 5823 | ImGui::Text("Texture Area: about %d px ~%dx%d px", font->MetricsTotalSurface, surface_sqrt, surface_sqrt); |
| 5824 | for (int config_i = 0; config_i < font->ConfigDataCount; config_i++) |
| 5825 | if (font->ConfigData) |
| 5826 | if (const ImFontConfig* cfg = &font->ConfigData[config_i]) |
| 5827 | ImGui::BulletText("Input %d: \'%s\', Oversample: (%d,%d), PixelSnapH: %d, Offset: (%.1f,%.1f)", |
| 5828 | config_i, cfg->Name, cfg->OversampleH, cfg->OversampleV, cfg->PixelSnapH, cfg->GlyphOffset.x, cfg->GlyphOffset.y); |
| 5829 | if (ImGui::TreeNode("Glyphs", "Glyphs (%d)", font->Glyphs.Size)) |
| 5830 | { |
| 5831 | // Display all glyphs of the fonts in separate pages of 256 characters |
| 5832 | const ImU32 glyph_col = ImGui::GetColorU32(ImGuiCol_Text); |
| 5833 | for (unsigned int base = 0; base <= IM_UNICODE_CODEPOINT_MAX; base += 256) |
| 5834 | { |
| 5835 | // Skip ahead if a large bunch of glyphs are not present in the font (test in chunks of 4k) |
| 5836 | // This is only a small optimization to reduce the number of iterations when IM_UNICODE_MAX_CODEPOINT |
| 5837 | // is large // (if ImWchar==ImWchar32 we will do at least about 272 queries here) |
| 5838 | if (!(base & 4095) && font->IsGlyphRangeUnused(base, base + 4095)) |
| 5839 | { |
| 5840 | base += 4096 - 256; |
| 5841 | continue; |
| 5842 | } |
| 5843 | |
| 5844 | int count = 0; |
| 5845 | for (unsigned int n = 0; n < 256; n++) |
| 5846 | if (font->FindGlyphNoFallback((ImWchar)(base + n))) |
| 5847 | count++; |
| 5848 | if (count <= 0) |
| 5849 | continue; |
| 5850 | if (!ImGui::TreeNode((void*)(intptr_t)base, "U+%04X..U+%04X (%d %s)", base, base + 255, count, count > 1 ? "glyphs" : "glyph")) |
| 5851 | continue; |
| 5852 | float cell_size = font->FontSize * 1; |
| 5853 | float cell_spacing = style.ItemSpacing.y; |
| 5854 | ImVec2 base_pos = ImGui::GetCursorScreenPos(); |
| 5855 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); |
| 5856 | for (unsigned int n = 0; n < 256; n++) |
no test coverage detected