Skip to content

Fonts: optional ImFont::KerningFn pair-adjust hook - #9516

Open
GitBruno wants to merge 1 commit into
ocornut:dockingfrom
GitBruno:features/font-kerning-fn
Open

Fonts: optional ImFont::KerningFn pair-adjust hook#9516
GitBruno wants to merge 1 commit into
ocornut:dockingfrom
GitBruno:features/font-kerning-fn

Conversation

@GitBruno

Copy link
Copy Markdown

Summary

  • Add ImFont::KerningFn / KerningUserData: optional extra advance (pixels at size) between consecutive codepoints.
  • Applied in RenderText and ImFontCalcTextSizeEx so layout matches draw.
  • NULL keeps the current advance-only path (one null check per glyph). No atlas / loader changes.

Why

ImGui places glyphs by AdvanceX only. Hosts that already have pair data (legacy kern, HarfBuzz GPOS, or a custom table) cannot feed it into chrome/ImGui::Text without 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

  • Default (KerningFn == NULL): demo / examples look identical.
  • Set a callback that returns a known extra for A+V; ImGui::Text(AV) and CalcTextSize(AV) both pick it up.
  • Newlines reset the previous codepoint (no pair across lines).

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants