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

Get assert while enable bitmap mode for freetype #4145

Closed
xyc19970716 opened this issue May 16, 2021 · 8 comments
Closed

Get assert while enable bitmap mode for freetype #4145

xyc19970716 opened this issue May 16, 2021 · 8 comments

Comments

@xyc19970716
Copy link

xyc19970716 commented May 16, 2021

Version/Branch of Dear ImGui:

Version: 1.83 WIP
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_opengl3.cpp + imgui_impl_glfw.cpp
Compiler: mingw64 gcc8.1.0
Operating System: windows 10 x64

My Issue/Question:

I use the clion to program my project. When i see the imgui_freetype.h/.cpp, it can enable bitmap mode. I want to use this function, but i get assert like next screenshot after i set like this pull 3879.

Screenshots/Video
image

Standalone, minimal, complete and verifiable example: (see #2261)

ImFontConfig font_config;
font_config.SizePixels = 13.0f;
font_config.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_Bitmap;
io.Fonts->AddFontFromFileTTF("c:\\windows\\fonts\\msgothic.ttc", 13.0f, &font_config, io.Fonts->GetGlyphRangesJapanese());
@ocornut
Copy link
Owner

ocornut commented May 16, 2021

Hello,

If I try your code with my copy of msgothic.ttc (8780 KB) it works and I don't hit this assert.

Could you make those changes:

  1. Replace the IM_ASSERT() with:
const FT_Bitmap* ft_bitmap = src_tmp.Font.RenderGlyphAndGetInfo(&src_glyph.Info);
if (ft_bitmap == NULL)
{
    printf("RenderGlyphAndGetInfo() failed for codepoint %04X\n", src_glyph.Codepoint);
    continue;
}
  1. In RenderGlyphAndGetInfo() replace the error handling with:
if (error != 0)
{
    printf("RenderGlyphAndGetInfo() failed: %X \"%s\"\n", error, FT_Error_String(error));
    return NULL;
}

And then report on the glyphs (which glyphs are failing and why). Thank you!

@xyc19970716
Copy link
Author

Thank you for your reply!
I test your code, and get many prints like this.
image

@ocornut
Copy link
Owner

ocornut commented May 18, 2021

0x13 in freetype is:

  FT_ERRORDEF_( Cannot_Render_Glyph,                         0x13,
                "cannot render this glyph format" )

What happen if you load this font AS A SECOND FONT (so first font work).

Then open Demo>Tools>Style Editor>Fonts> then Open your font
And look at the glyphes:

image

@xyc19970716
Copy link
Author

Thank you! But what means AS A SECOND FONT? I just load this font.

@ocornut
Copy link
Owner

ocornut commented May 19, 2021 via email

@xyc19970716
Copy link
Author

xyc19970716 commented May 19, 2021

Well, for your proposal, i get so few glyphs seeing on the editor.
image
Is my system font file broken, or the code version of FreeType wrong? But when no bitmap for FreeType, its font works well.

@ocornut
Copy link
Owner

ocornut commented May 19, 2021 via email

@xyc19970716
Copy link
Author

xyc19970716 commented May 20, 2021

Thanks a lot! I use FreeType by the implementation of vcpkg, that bitmap mode works well. But my project use cmake to install freetype, maybe i get mistake and i would fix it future.
I think this issue can be closed. Very thanks!

ocornut added a commit that referenced this issue Aug 23, 2021
AnClark pushed a commit to AnClark/imgui-vst-mod that referenced this issue Aug 30, 2021
AnClark pushed a commit to AnClark/imgui-vst-mod that referenced this issue Aug 30, 2021
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