Returns the exact height of rendered text string in pixels.
Takes text (string to measure, any UTF-8 text), font (font handle from b2dLoadFont, positive integer).
Returns the exact height of rendered text string in pixels.
2D Overlay
Parameters & Returns
Parameters
textString
fontInt
Returns
Int
Quick Summary
Returns the exact height of rendered text string in pixels.
Takes text (string to measure, any UTF-8 text), font (font handle from b2dLoadFont, positive integer).
Returns the exact height of rendered text string in pixels.
Technical Exegesis...
Returns the exact height of rendered text string in pixels. Takes text (string to measure, any UTF-8 text), font (font handle from b2dLoadFont, positive integer). Returns integer height (vertical space required for text in pixels, 0 if invalid font). Calculates precise rendering height based on actual characters in string (considers ascenders and descenders).
Returns the exact height of rendered text string in pixels. Takes text (string to measure, any UTF-8 text), font (font handle from b2dLoadFont, positive integer). Returns integer height (vertical space required for text in pixels, 0 if invalid font). Calculates precise rendering height based on actual characters in string (considers ascenders and descenders).
Height calculation: examines actual characters in string (not font maximum), includes ascenders (tall characters like 'b', 'd', 'h'), includes descenders (hanging characters like 'g', 'j', 'p', 'q', 'y'), tighter than font line height (excludes line spacing), varies by content (lowercase-only shorter than mixed-case).
Use cases: (1) Vertical text centering (calculate precise vertical offset), (2) Text box sizing (size UI elements to fit text exactly), (3) Multi-line layout (calculate total height for text blocks), (4) Collision detection (bounds checking for text elements).
Common patterns: center vertically = y=(panelHeight-b2dGetStringHeight(text, font))/2: b2dDrawText(text, x, y, 0, font); text box height = height=b2dGetStringHeight(text, font)+padding*2; multi-line height = totalHeight=lineCount*b2dGetFontHeight(font) (for uniform spacing) or sum individual line heights (for tight fit).
Content dependency: "abc" shorter than "Abc" (no ascenders vs capital), "abc" shorter than "abp" (no descenders vs descender), "HELLO" taller than "hello" (capitals taller), empty string returns 0 (no characters to measure).
Performance: fast calculation (~0.001ms for typical strings), linear with string length (each character examined), cached font metrics (no file I/O), suitable for per-frame calls.
Related: b2dGetStringWidth measures text width, b2dGetFontHeight queries font line height (includes spacing), b2dGetFontWidth queries average character width, b2dDrawText renders text with same height.