(EDITED) Fixed typos.
Hello,
I've been looking at the font system lately (planning a long awaited refactor that may happen soonish).
Going to use this thread to ask questions/feedback, in particular trying to find users who use certain features to get details about their usage. I am aware I may not get enough feedback as the fields/features mentioned of those are rarely used, but let's try.
Q1. Have you ever used ImFontConfig::GlyphExtraSpacing ? If so, why and how? (which fonts, etc.)
This was added in 1.43. While removing the extraneous spacing in ProggyClean, I added this field as a I thought it would be useful. I am highly enclined to obsolete it now.
Q2. Have you ever used ImFontAtlas::AddCustomRectFontGlyph() ? If so, why and how?
This was primarily designed in 1.52 to be able to map color icons into codepoints of a font (by registering rectangles and copying graphics into them after packing). I suspect no-one has been using it (I added it to fullfil a specific private request but I don't think the team requesting it ended up using it). My problem is that in order to support a system for more naturally resizing fonts (e.g. 1 ImFont can map to different sizes transparently) this will need to be redesigned somehow.
Q3. Have you ever altered the ImFontConfig::GlyphOffset or ImFont::DisplayOffset field? If so why, for which fonts at which size? Are you using non-integer values for any of them?
This is much easier to answer, I'm pretty sure lots of people are altering DisplayOffset.y but I'd be interested in getting specific examples (font/size). In #1619 stfx said "[...] used ImFontConfig.GlyphOffset.y to fix vertical font alignment when merging multiple fonts", that's one legit use case.
(Edit) Likewise, the reason I am interested in this is because this field is often used a manual adjustment which may not scale linearly/properly. If we want to support a font-size cache how this field is handled needs to be addressed.
Thanks!
Q4. Are you creating ImFontAtlas instance yourself?
e.g. to share a font atlas between 2 imgui context, or another reason, please provide details!
Q5. Are you using ImFont::SetFallbackChar()?
This function was added in 1.35 but never advertised. I would like to move this information to ImFontConfig and have it be immutable.
No to all your specific questions, but I was recently looking for a way to add a simple raster font for using extracted old-school 8-bit home computer fonts without having to go through TTF, basically just a pre-baked font atlas texture, and an array of simplified glyph infos (only texture coords, or similar).
Totally low-prio though :)
I was recently looking for a way to add a simple raster font for using extracted old-school 8-bit home computer fonts without having to go through TTF,
Was about to send this paragraph:
It is close to be possible or maybe already possible probably by twisting some code (or just bypassing Build/ImFontAtlasBuildWithStbTruetype, calling the ImFontAtlasBuild** helpers yourself and font->AddGlyph) but probably messy. This is probably should I could keep in the corner of my mind as I refactor the system, I agree if would be healthy.
Then I realized, it is already possible if you do the following:
Awkward but doable. That itself is a vote of confidence for AddCustomRectFontGlyph() :)
I've been looking at AddCustomRectFontGlyph for colorful icons just recently but haven't used it yet. The plan already was to use .svg icons so that they would work regardless of DPI scaling. Support for custom and colorful iconography is definitely something I would use.
We're not using / doing any of the things in questions 1-5.
However, we do use ImFontAtlas::TexGlyphPadding to facilitate a hack we have that adds an outline to the glyphs in the font texture. We do this to allow us to have windows with very translucent backgrounds (to avoid obscuring the game behind), while keeping the text legible regardless of what's going on in the background.
The degree to which either of these use cases is advisable is certainly debatable (and something I'd like to revisit one day when I have time), but I bring it up as an information point since it seems relevant to the topic. :)
I use tiny vertical positive/negative adjustments for GlyphOffset.y to align GoogleMaterialIcons with my main high-dpi fonts (for example, m-plus medium 18pt)
Q4. Are you creating ImFontAtlas instance yourself?
e.g. to share a font atlas between 2 imgui context, or another reason, please provide details!
Yes, in a video/security app the main window creates an ImFontAtlas which is then shared with any Video Windows that may later be created. The font atlas itself is the Roboto-Medium loaded with 11 different point sizes, for the various sizes of overlay text in our video/security app.
No to all the other questions, though we have been thinking about using custom rect for colourful icons/emoji support.
Q4. Are you creating ImFontAtlas instance yourself?
e.g. to share a font atlas between 2 imgui context, or another reason, please provide details!
I'll need to double-check, but I'm fairly sure the Segross Unreal 4 plugin shares a font atlas between PIE clients, where multiple game clients, each with their own ImGui context are started within the same process.
If you're looking at doing some font refactoring, it'd be great if we could have a more dynamic atlas that only fills in glyphs that are needed in the sizes rendered. We're looking to add support for more script types to our project, and some of the Asian languages include an awful lot of glyphs; multiplied by a couple of fonts (with some size, bold and italic variants), it's going to overflow a 4kx4k atlas quite easily. I expect the additional usage tracking would have a detrimental effect on the performance of CalcTextSize though.
As a new user of ImGui:
The only one that applies to me:
Q3. Have you ever altered the
ImFontConfig::GlyphOffsetorImFont::DisplayOffsetfield? If so why, for which fonts at which size? Are you using non-integer values for any of them?
I've used ImFontConfig::GlyphOffset (using floats for fine tuned alignment) to align an in-house custom icon font (generated by IcoMoon) and a general typography font (Sintony from Google) merged at a size of 16.
Also of note, I used the following general config to allow me to have different font sizes:
FontConf->RasterizeMultiply = 2
FontConf->OversampleH = 2
FontConf->OversampleV = 2
I can use ImGui::SetWindowFontScale() to size my fonts and give me different sizes depending on need. But the GlyphOffset was key in getting these two fonts to play nice together.
Most helpful comment
I've been looking at AddCustomRectFontGlyph for colorful icons just recently but haven't used it yet. The plan already was to use .svg icons so that they would work regardless of DPI scaling. Support for custom and colorful iconography is definitely something I would use.