mirror of
https://github.com/ocornut/imgui.git
synced 2026-10-16 22:40:48 +00:00
Request for ImFontBaked::FindGlyphByGlyphId #9559
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 milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#9559
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?
Version/Branch of Dear ImGui:
Version v1.92.9b
Back-ends:
n/a
Compiler, OS:
all
Full config/build information:
No response
Details:
I'm writing a program that uses ImGui as the main UI, and then reuses the ImGui font atlas to render text in some canvas. It works great, but now I'm doing some low level stuff with the fonts, and I need to access some glyphs in my TTF that don't have a char mapped (think of alternative shapes, custom ligatures and the like).
For normal characters I just call
ImFontBaked::FindGlyph(ImWchar c), but for these weird glyphs I would need aImFontBaked::FindGlyphByGlyphId(uint32_t glyph_id)and that it bypass the char->glyph_id mapping.Naturally I can use
AddCustomRect()but that forces me to do the render of the font myself, and the code for that is already there inside ImGui...I reckon this is a niche need, and that it may break some assumptions in the code (everything is indexed by codepoint). But I was thinking that if instead one function
ImFontLoader::FontBakedLoadGlyph(ImWchar codepoint, ...)we had two:uint32_t ImFontLoader::FontSrcMapCodepointToGlyphId(ImWchar codepoint)and thenImFontLoader::FontBakedLoadGlyph(uint32_t glyphId, ...). Then I could just subclass the standard ImFontLoader, and add my desired glyph_ids to the private unicode block....What do you refer to as glyph_id, is the glyph index in a given font?
It is this?
stb_truetype:
FreeType:
Are they glyphs that are not accessible via a codepoint?
I recall https://github.com/ocornut/imgui/issues/5647#issuecomment-1238127411 mentioned this.
Yes, here it is called
glyph_index, just the index in the glyph table. 0 is reserved for ".notdef".Indeed. TTF fonts store glyphs in an array, the glyph id is just the index in that array. Then there is the
cmaptable that maps character codes (usually Unicode codepoints) to glyph_index. But that is the short story, TTF fonts support also:æhave the own codepoint, and popular ones such asfi,fl,ffido have one too. But the TTF author can define whatever ligatures they want. For example my Palatino version hasQu,Th,ct,ft.We can see the unmapped glyphs of a font using FontForge and setting the option "View / Label glyph by / Unicode". The unmapped glyphs show a "?". For example, my Palatino font has these:

Understood. I think I can make this change.