Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FreeType and about Fonts #3611

Closed
N1ceL opened this issue Nov 23, 2020 · 2 comments
Closed

FreeType and about Fonts #3611

N1ceL opened this issue Nov 23, 2020 · 2 comments

Comments

@N1ceL
Copy link

N1ceL commented Nov 23, 2020

  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
Copy link
Owner

ocornut commented Jan 12, 2021

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!

@ocornut
Copy link
Owner

ocornut commented Mar 5, 2025

Closing as this is all handled by WIP work on dynamic_fonts for 1.92 (#8465).

Specifically for (3) I have added a ImFontFlags_NoLoadError flag.
Font flags are currently stored in ImFontConfig::Flags and not particularly documented.
As I go forward with revamping the AddFontXXX() functions, the new entry points will likely accept ImFontFlags as a parameter.

(4) is not necessary anymore.

@ocornut ocornut closed this as completed Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants