Fonts: optional ImFont::KerningFn pair-adjust hook - #9516
Open
GitBruno wants to merge 1 commit into
Open
Conversation
RenderText and CalcTextSize apply extra advance when set. NULL stays the current advance-only path so default text cost is unchanged. Lets hosts supply TTF kern or GPOS without baking pairs into the atlas.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ImFont::KerningFn/KerningUserData: optional extra advance (pixels atsize) between consecutive codepoints.RenderTextandImFontCalcTextSizeExso layout matches draw.NULLkeeps the current advance-only path (one null check per glyph). No atlas / loader changes.Why
ImGui places glyphs by
AdvanceXonly. Hosts that already have pair data (legacykern, HarfBuzz GPOS, or a custom table) cannot feed it into chrome/ImGui::Textwithout wrapping every call. This hook is the smallest seam: the atlas stays a glyph cache; the host owns shaping.Omar noted in #618 that kerning would be nice as an optional per-font path because text-size calc is a bottleneck. This is that option: default cost is unchanged.
Word-wrap (
CalcWordWrapPosition) is not adjusted yet; wrap points can be off by the pair extras on a line. Happy to add that if this shape is acceptable.Test plan
KerningFn == NULL): demo / examples look identical.A+V;ImGui::Text(AV)andCalcTextSize(AV)both pick it up.