mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-14 19:04:44 +00:00
Merge overlapping font ranges #1671
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#1671
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
So, I am running into this fun issue today. I am loading some fonts and including Font Awesome in them by using the
MergeModeoption when loading fonts. This works, generally. However, FA has multiple font files for different styles now, so they have a separate ttf file for solid & brand icons.Loading them separately when merging in the current version of Imgui will cause it to discard many icons because they've already been added from the first range (since the ranges of brands & solid icons overlap).
As an attempt to fix this in a quick way, I've modified
ImFontAtlasBuildWithStbTruetypeto not include glyphs in the font that don't advance a character, like this:I don't know if this is the right approach, but it seems to work fine for me and there are no weird artefacts or missing characters as far as I can tell, and still allows me to merge overlapping ranges from 2 separate fonts.
Perhaps this would be nice as a setting? (Or maybe the check is safe enough?)
Related: https://github.com/juliettef/IconFontCppHeaders/pull/5
It looks like we could indeed add flags for that purpose and/or glyph with no advance could be treated differently (overwrite by default, etc.). I'll look into it.
I had a quick look, I don't think the AdvanceX == 0.0f check is correct but it'll work in that case FontAwesome5.
There's an issue with the font code we don't properly handle glyphs that are missing from the font. One of the inner stb_truetype.h call is leading us to pack and rasterize the first glyph of the font as many times as they are missing glyphs. Likewise with the truetype path. It's fixable but it's not a 1 hour fix unfortunately so I don't yet know when I'll be able to do it.
Your local workaround should be fine until then.
Sounds good, thanks for checking. Will be using this workaround for the time being.
Yup same issue here. After I updated to latest master merged font awesome seem not to work anymore. Removing this line that you added also works for me. Though I doubt its ok to do that.
@codecat @volcoma This should be fixed in master now, could you let me know if it works for you?
I submitted my modification to nothings/stb, I'm not sure it'll be merged as is (perhaps as an option to the packer) but either way I'll follow on it and hopefully the next version of stb_truetype will match our mod.
Great, thank you! Is there any set up necessary for this fix? Some setting? Or do I just use it as-is and load both fonts?
You can load both fonts. Currently if a character already exist it doesn't overwrite it, may add the option later. It should matter for FA5 Solid + FA5 Brand. If you want FA5 Regular showing when available and fallback to FA5 Solid, you want to merge Regular first then Solid.
Perfect, thanks!
I don't exactly know if this is related to this issue at all, but it also involves FontAwesome in my case so I'll just post it here.
I'm storing a font awesome font (that's not using merging in this case) somewhere in my initialization:
Then, in my rendering, I try to render an icon from the font:
But there is nothing getting drawn. I've also had some stranger issues besides it not drawing, like in
ImDrawList::AddTextit would crash onfont->ContainerAtlasbeing null. Any other font works fine. Is merging required for fonts like FontAwesome?Edit: Oh, this happens because
Glyphsis empty..Edit 2: Okay, I traced it down back to me not providing a glyph range.. surprised that a font without any glyphs doesn't trigger a failed assertion..
Font merging isn’t required. Use the font browser inside the style editor to figure out if fonts are loaded as expected, if you have a crash/assert a more detailed explanation + repro would be useful too.
@codecat
The code fallback on the default ASCII range:
Closing this now, yeah!
(The way AddFontXXX/ImFontConfig are designed is a prime candidate for minor refactors perhaps for 1.70. May may ImFontConfig mandatory and take a copy/ownership of the font range then.)