ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
61.53k stars 10.35k forks source link

FreeType and about Fonts #3611

Open N1ceL opened 4 years ago

N1ceL commented 4 years ago
  1. With FreeType you can use only same flags on every font. I think better to delete "extra_flags" from here https://github.com/ocornut/imgui/blob/master/misc/freetype/imgui_freetype.cpp#L651-L673 and here https://github.com/ocornut/imgui/blob/master/misc/freetype/imgui_freetype.cpp#L323 And change: if (!font_face.InitFont(ft_library, cfg, extra_flags)) to if (!font_face.InitFont(ft_library, cfg, cfg.RasterizerFlags)) here https://github.com/ocornut/imgui/blob/master/misc/freetype/imgui_freetype.cpp#L362

  2. FreeType and IsDirty(). FreeType fonts conflicts with IsDirty() here (imgui with shadows): https://github.com/ocornut/imgui/blob/features/shadows/imgui_draw.cpp#L2635 https://github.com/ocornut/imgui/blob/features/shadows/imgui_draw.cpp#L2656 Removing these functions from the checks helps.

  3. Error in fonts. I think better to delete error here https://github.com/ocornut/imgui/blob/master/imgui_draw.cpp#L1903 Because its better to go the way of installing a different font if the first one is not found.

  4. It would be good to add one more variable to ImFontConfig struct. char FontPath[256]; //// memcpy(font_cfg.FontPath, filename+ '\x0', strlen(filename) + 1); This struct has all the data needed to rebuild the font except FontPath.

  5. Somthings to ImFontConfig.

    void ImFontConfig::ClearOutputData()
    {
    ImGui::MemFree(FontData);
    FontDataSize = 0;
    FontDataOwnedByAtlas = true;
    FontNo = 0;
    SizePixels = 0.0f;
    OversampleH = 3; 
    OversampleV = 1;
    PixelSnapH = false;
    GlyphExtraSpacing = ImVec2(0.0f, 0.0f);
    GlyphOffset = ImVec2(0.0f, 0.0f);
    GlyphRanges = NULL;
    GlyphMinAdvanceX = 0.0f;
    GlyphMaxAdvanceX = FLT_MAX;
    MergeMode = false;
    RasterizerFlags = 0x00;
    RasterizerMultiply = 1.0f;
    EllipsisChar = (ImWchar)-1;
    memset(Name, 0, sizeof(Name));
    memset(FontPath, 0, sizeof(FontPath));
    ImGui::MemFree(DstFont);
    }

    This can be used for font rebuilding (because rebuilded FontData saves repeatedly and after a certain number of rebuild program eats 1.5 GB of RAM, originally it was 40 MB)

I hope I was able to help a little with something. https://i.imgur.com/qdBhvqQ.mp4

ocornut commented 3 years ago

Hello,

With FreeType you can use only same flags on every font. I think better to delete "extra_flags" ... And change: if (!font_face.InitFont(ft_library, cfg, extra_flags)) to if (!font_face.InitFont(ft_library, cfg, cfg.RasterizerFlags))

I don't think that's correct, InitFont() already does: UserFlags = cfg.RasterizerFlags | extra_user_flags;

So if you leave extra_user_flags to zero so you can configure flags for each font separately.

  1. FreeType and IsDirty().

You are referring to a wip/experimental branch commits those are not supported as this point, I don't think shadows rebuilt have been tested with FreeType yet, we were focused with designing the back-end side protocol. We'll look at this part eventually.

  1. Error in fonts. I think better to delete error here https://github.com/ocornut/imgui/blob/master/imgui_draw.cpp#L1903

I don't know what this line is referring to (best to copy the code line) but I assume you mean the IM_ASSERT_USER_ERROR(0, "Could not load font file!"); error. I agree and think we could add a config flags to disable this assert. However your app can still test for file existence if it wants to dynamically select font.

  1. It would be good to add one more variable to ImFontConfig struct.

Yes-ish, when we support dynamic rebuild I think we'll prefer to keep font data in memory so that shouldn't be a real issue.

Will look at all those in details later, thanks for the feedback!