Browse Source

ImFont: comments, minor bits

ocornut 10 years ago
parent
commit
6ae8062ca0
2 changed files with 20 additions and 29 deletions
  1. 4 13
      imgui.cpp
  2. 16 16
      imgui.h

+ 4 - 13
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();
                 }

+ 16 - 16
imgui.h

@@ -1175,27 +1175,27 @@ struct ImFontAtlas
 struct ImFont
 {
     // Members: Settings
-    float               FontSize;           // <user set>      // 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;           // <user set>      // 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<Glyph>     Glyphs;
-    const Glyph*        FallbackGlyph;      // == FindGlyph(FontFallbackChar)
-    float               FallbackXAdvance;   //
-    ImVector<float>     IndexXAdvance;      // Glyphs->XAdvance directly indexable (for CalcTextSize functions which are often bottleneck in large UI)
-    ImVector<int>       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<Glyph>             Glyphs;
+    const Glyph*                FallbackGlyph;      // == FindGlyph(FontFallbackChar)
+    float                       FallbackXAdvance;   //
+    ImVector<float>             IndexXAdvance;      // Sparse. Glyphs->XAdvance directly indexable (for CalcTextSize functions which are often bottleneck in large UI)
+    ImVector<int>               IndexLookup;        // Sparse. Index glyphs by Unicode code-point
 
     // Methods
     IMGUI_API ImFont();