From 6ae8062ca0a9e3ecd2dba8150ebac453c468c4ce Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 14 Jul 2015 15:51:19 -0600 Subject: [PATCH] ImFont: comments, minor bits --- imgui.cpp | 17 ++++------------- imgui.h | 32 ++++++++++++++++---------------- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index d2c71c71e..f22a152d9 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9762,8 +9762,7 @@ ImFont* ImFontAtlas::AddFontDefault() unsigned int ttf_compressed_size; const void* ttf_compressed; GetDefaultCompressedFontDataTTF(&ttf_compressed, &ttf_compressed_size); - ImFont* font = AddFontFromMemoryCompressedTTF(ttf_compressed, ttf_compressed_size, 13.0f, GetGlyphRangesDefault(), 0); - return font; + return AddFontFromMemoryCompressedTTF(ttf_compressed, ttf_compressed_size, 13.0f, GetGlyphRangesDefault(), 0); } ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, const ImWchar* glyph_ranges, int font_no) @@ -9775,9 +9774,7 @@ ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, IM_ASSERT(0); // Could not load file. return NULL; } - - ImFont* font = AddFontFromMemoryTTF(data, data_size, size_pixels, glyph_ranges, font_no); - return font; + return AddFontFromMemoryTTF(data, data_size, size_pixels, glyph_ranges, font_no); } // Transfer ownership of 'ttf_data' to ImFontAtlas, will be deleted after Build() @@ -9808,14 +9805,10 @@ ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* ttf_data, int ttf_size, float si ImFont* ImFontAtlas::AddFontFromMemoryCompressedTTF(const void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, const ImWchar* glyph_ranges, int font_no) { - // Decompress const unsigned int buf_decompressed_size = stb_decompress_length((unsigned char*)compressed_ttf_data); unsigned char* buf_decompressed_data = (unsigned char *)ImGui::MemAlloc(buf_decompressed_size); stb_decompress(buf_decompressed_data, (unsigned char*)compressed_ttf_data, (unsigned int)compressed_ttf_size); - - // Add - ImFont* font = AddFontFromMemoryTTF(buf_decompressed_data, (int)buf_decompressed_size, size_pixels, glyph_ranges, font_no); - return font; + return AddFontFromMemoryTTF(buf_decompressed_data, (int)buf_decompressed_size, size_pixels, glyph_ranges, font_no); } bool ImFontAtlas::Build() @@ -9983,8 +9976,6 @@ bool ImFontAtlas::Build() // Cleanup temporaries ImGui::MemFree(buf_packedchars); ImGui::MemFree(buf_ranges); - buf_packedchars = NULL; - buf_ranges = NULL; // Render into our custom data block RenderCustomTexData(1, &extra_rects); @@ -11185,7 +11176,7 @@ void ImGui::ShowTestWindow(bool* opened) if (ImGui::TreeNode("Details")) { ImGui::DragFloat("font scale", &font->Scale, 0.005f, 0.3f, 2.0f, "%.1f"); // scale only this font - ImGui::Text("Ascent: %f, Descent: %f", font->Ascent, font->Descent); + ImGui::Text("Ascent: %f, Descent: %f, Height: %f", font->Ascent, font->Descent, font->Ascent - font->Descent); ImGui::Text("Fallback character: '%c' (%d)", font->FallbackChar, font->FallbackChar); ImGui::TreePop(); } diff --git a/imgui.h b/imgui.h index 705900451..f94eb9dec 100644 --- a/imgui.h +++ b/imgui.h @@ -1175,27 +1175,27 @@ struct ImFontAtlas struct ImFont { // Members: Settings - float FontSize; // // Height of characters, set during loading (don't change after loading) - float Scale; // = 1.0f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale() - ImVec2 DisplayOffset; // = (0.0f,0.0f) // Offset font rendering by xx pixels - ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar() + float FontSize; // // Height of characters, set during loading (don't change after loading) + float Scale; // = 1.0f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale() + ImVec2 DisplayOffset; // = (0.0f,0.0f) // Offset font rendering by xx pixels + ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar() // Members: Runtime data struct Glyph { - ImWchar Codepoint; - float XAdvance; - float X0, Y0, X1, Y1; - float U0, V0, U1, V1; // Texture coordinates + ImWchar Codepoint; + float XAdvance; + float X0, Y0, X1, Y1; + float U0, V0, U1, V1; // Texture coordinates }; - float Ascent; // Distance from top to bottom of e.g. 'A' [0..FontSize] - float Descent; // - ImFontAtlas* ContainerAtlas; // What we has been loaded into - ImVector Glyphs; - const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar) - float FallbackXAdvance; // - ImVector IndexXAdvance; // Glyphs->XAdvance directly indexable (for CalcTextSize functions which are often bottleneck in large UI) - ImVector IndexLookup; // Index glyphs by Unicode code-point + float Ascent; // Distance from top to bottom of e.g. 'A' [0..FontSize] + float Descent; // + ImFontAtlas* ContainerAtlas; // What we has been loaded into + ImVector Glyphs; + const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar) + float FallbackXAdvance; // + ImVector IndexXAdvance; // Sparse. Glyphs->XAdvance directly indexable (for CalcTextSize functions which are often bottleneck in large UI) + ImVector IndexLookup; // Sparse. Index glyphs by Unicode code-point // Methods IMGUI_API ImFont();