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

Add font fallback support, just like what windows does. #182

Closed
heroboy opened this issue Apr 3, 2015 · 7 comments
Closed

Add font fallback support, just like what windows does. #182

heroboy opened this issue Apr 3, 2015 · 7 comments

Comments

@heroboy
Copy link
Contributor

heroboy commented Apr 3, 2015

When rendering text, if a glyph is not found in current font, try the other fonts.

@ocornut
Copy link
Owner

ocornut commented Apr 3, 2015

That would be useful. Things to take into account:

a) It could be part of the font baking itself, that would be the simplest. Bake glyphs for XXX.ttf, use fallback from YYY.ttf

b) It could be a initialisation pass of creating fall-back glyphs across fonts in a same atlas.
I don't want to add searching and guessing inside the render and size calculation functions because that would slow them down (and their efficiency is critical). It could be as simple as changing the IndexLookup vector to use pointers instead of indices and one font can point to glyph from other fonts. The IndexXAdvance vector needs to be patched accordingly.
The other fonts may be baked using different size so that needs to be taken into account.

I'll have to think about it. What sort of use case are you thinking of? (in term of desired symbols/languages)

@heroboy
Copy link
Contributor Author

heroboy commented Apr 3, 2015

Actually I want this function is because TTF font is blurred and builtin font is clear,so I want use TTF font to render Chinese and builtin font to render English.

I's like to add some methods like ImFont::AddFontXXXX to add/override more glyphs to already exists font.
Or modify ImFontAtlas::AddFontXXXX that can accept multiple glyph_ranges, and each glyph_ranges associate with a ttf filename or ttf data or default font.

@heroboy
Copy link
Contributor Author

heroboy commented Apr 7, 2015

I think don't change the api,you can dynamicly add item to IndexLookup vector when some glyph not be found in current font.

@ocornut
Copy link
Owner

ocornut commented Apr 7, 2015

Will do that at some point, but it's not a high priority.
We also need to improve TTF support, at least maybe super sample the font.

@ocornut
Copy link
Owner

ocornut commented Jul 15, 2015

The AA branch now support this with the new ImFontConfig* settings.
All the AddFontxxx() functions now have a ImFontConfig* pointer. If you pass one you can alter settings.

Merge three fonts:

   io.Fonts->AddFontDefault();

   // Add character ranges and merge into main font
   ImWchar ranges[] = { 0xf000, 0xf3ff, 0 };
   ImFontConfig config;
   config.MergeMode = true;
   io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 16.0f, &config, ranges);
   io.Fonts->AddFontFromFileTTF("myfontfile.ttf", 15.0f, &config, io.Fonts->GetGlyphRangesJapanese());

@ocornut
Copy link
Owner

ocornut commented Jul 15, 2015

This is now merged in master along with the entire new AA-branch. Note that it is a rather big update and you'll need to update your render function to use indexed vertex rendering.

@ocornut ocornut closed this as completed Jul 15, 2015
@heroboy
Copy link
Contributor Author

heroboy commented Jul 16, 2015

Very thanks for your great work.

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