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: enable colored-glyphs #3369
Conversation
Hello, |
Done. And also please notice that I have upgraded Ubuntu vertion till 20.04. Because Ubuntu 18.04 has only FreeType version 2.6 in a repository. And I wan't able to build it during preparation step because of all dependencies of version 2.10 are outdated too. So it was easier to upgrade Ubuntu version instead of building this all. |
…eased ConfigDataCount. CI: Update Ubuntu 18.04 > 20.04 (motivated by #3369) Fix Freetype warning.
Thanks! Do you have a specific font and test code in mind?
|
Hello, I have tested my solution on the same font and it worked.
|
This doesn't work either. It does set |
I'm using freetype 2.10.2 under Windows. |
Hello, I have found the problem. |
Hello, I suggest make a tag called "Microsoft style". Sometime we can't know what style implemented in the TTF. If you want to use twitter emoji color font with Microsoft Style, |
@ocornut hello, can we expect this PR will be merged soon? I mean, we are using ImGui with this changes, and it would be nice if colored glyphs will appear in master branch. If you see some problems in this PR I can fix them and help this PR to be merged faster. Thx. |
Hello Petr,
I would like to look at this, but don't have resources to follow on every PR in a timely manner unfortunately. Please be patient! Since not all kind of colored glyphes are currently supported by FreeType I hadn't had time to evaluate if/how this may backfire into more support/feature requests and parachute us into a world of growing expectation in terms of unicode features and i18n support. Because next thing looming somebody will ask for emoji skin tone modifiers and other stateful feature. There's a enormous list of things following and I am not sure we can afford to get there. Your patch is technically great and sound, and I appreciate it. But there is an unfortunate widespread misunderstanding with the state of maintaining OSS and the cost of initial code drop vs the cost of further maintenance and support. By accepting a PR, I'm effectively taking on the load to maintain this and its further ramifications forever. So I have to be cautious in order to protect this project, because we have 500+ other things competing for current and future attention. If it is critical for your company ("Estimated annual revenue ~$587.5M") to not carry the burden of maintaining a simple patch for a few months-years, you'd imagine in a fair world they would commit to contribute to the indefinite associated support and maintenance cost of us maintaining the patch. But somehow over time the narrative has been twisted for everyone, so it's really not personal but please appreciate merging a PR is the point where it starts to have a cost for me and I'm not superhuman. One thing comes to mind would be to ensure this will still build with pre-2.10. |
[IMP] : improvement of ImGuiFreetype, customized to take into account the color change of the PR ocornut/imgui#3369. static func copy from ImDraw for avoid modification of Imdraw [FiX] : fix project change notif for some widget, was not take into account [ADD] : add a black screen under the texture, because a colored glyph need to have a tint color of Vec4(1,1,1,1). else on light theme we can see only full ImGuiColText color [IMP] : improvement of FontInfos for create a table who can say which glyph is colored or not. glyphInfos was modified for reflect this change. due to that, each glyphs is rendered differently regarding if colored or not [FIX] : add COLR and partial CMAP parsing/display in fontParser
Hello, i have customized ImGui_FreeType.cpp/.h for avoid modification of current ImDraw.cpp. btw there is an issue when the text must be rendered with a black color or other color than white. i have tested a shader modification like : void main()
{
vec4 tex = texture(Texture, Frag_UV.st), col = Frag_Color;
if (tex.r + tex.g + tex.b < 3.0) col = vec4(1);
Out_Color = col * tex;
} its not perfect because :
So on light theme its an issue. but its not usable for the rest of the ui without modification of ImGui.
if we push the ImGuiCol_Text with vec4(1,1,1,1) before the text, any other idea for avoid ImGui Modification / or without perf impact ? |
That's an interesting issue indeed, particularly as we strive to facilitate both text color changes and merging of icons into main fonts. I think in theory we may want the text render loop to do: ImU32 glyph_col = col;
if (glyph->IgnoreTint)
glyph_col |= ~IM_COL32_A_MASK; It's probably an acceptable overhead, something to consider as we rewrite the text functions. |
indeed it seem acceptable :) if you want i can propose a PR for that |
I've been looking at this PR today.
Tried 2.6.5 and 2.9.1 and with both things compiles and run, Freetype transparently just provide black and white outlines. I'll just add a few comments stating this requires 2.10+ but otherwise there's nothing to do on our side. Will be looking at the tinting issue @aiekick mentioned, it's not a trivial change as we need to pass that information down. |
nice i always using your trick in ImGuiFontStudio and i not see any perf issue. |
I fixed those in my commit already, by orring all the LoadColor flags (shared and per font) and only loading them in that situation.
|
…derFlags_LoadColor (#3369) (squashed 4 commits)
Here's a test with seguiemj imconfig #define IMGUI_USE_WCHAR32
#define IMGUI_ENABLE_FREETYPE In main.cpp io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 16.0f);
{
static ImWchar ranges[] = { 0x1, 0x1FFFF, 0 };
static ImFontConfig cfg;
cfg.OversampleH = cfg.OversampleV = 1;
cfg.MergeMode = true;
cfg.FontBuilderFlags |= ImGuiFreeTypeBuilderFlags_LoadColor;
io.Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\seguiemj.ttf", 16.0f, &cfg, ranges);
} ImGui::Text("\xf0\x9f\x8d\x89 \xf0\x9f\x8d\x8a \xf0\x9f\x8d\x8b"); Shows the fruits above. |
@ocornut: Do you think it's not portable to replace: ImGui::Text("\xf0\x9f\x8d\x89 \xf0\x9f\x8d\x8a \xf0\x9f\x8d\x8b"); with just: ImGui::Text("🍉 🍊 🍋"); if the file encoding is UTF8? P.S. sorry if it's slightly OT. |
It doesn't work with all editors and toolsets. "If the file encoding is UTF8" is already an assumption. In Visual Studio it seems to tries to add the UTF-8 header which would then confuse some more basic text editor. Note of that code is committed anyway, is was just a way to provide that text in a super-portable way. |
Well, I'm on Ubuntu/QtCreator and it just works. But probably you're right... it's not super-safe to share source code like that. |
…see: #61). addons/imguicodeeditor/imguicodeeditor.cpp and addons/imguipanelmanager/imguipanelmanager.cpp: minimal changes to keep code up to date with Dear ImGui upstream repository. examples/addons_examples/fonts/Icons/TwemojiMozilla/...: added this font from https://github.com/mozilla/twemoji-colr (color icons), together with some optional header files to make its use a bit easier in some contexts. Please note that it needs IMGUI_ENABLE_FREETRYPE plus a very recent version of the freetype library. Furthermore: a) it's not used by any examples, b) it does not contain many characters usable for GUI environment and c) composed glyphs (like country flags and many others) are not supported. In short: better stick to monochromatic icon fonts (like FontAwesome) in most cases. examples/addons_examples/html/main.html and main2.html: rebuilt using a more recent version of emscripten. examples/addons_examples/fonts/Icons/TwemojiMozilla/...: did I mention that together with IMGUI_ENABLE_FREETRYPE, the IMGUI_USE_WCHAR32 definition is required as well? Well, better fetch the 'reference link'. Here it is: ocornut#3369
Why?
FreeType supports color-layered glyphs since version 2.10.0. This feature allows render scalable icons. Different emoji, for, example.
Now any can use colored glyphs as icons in ImGui applications.
Screenshot