Returns the average character width of the font in pixels.
Takes font (font handle from b2dLoadFont, positive integer).
Returns the average character width of the font in pixels.
2D Overlay
Parameters & Returns
Parameters
fontInt
Returns
Int
Quick Summary
Returns the average character width of the font in pixels.
Takes font (font handle from b2dLoadFont, positive integer).
Returns the average character width of the font in pixels.
Technical Exegesis...
Returns the average character width of the font in pixels. Takes font (font handle from b2dLoadFont, positive integer). Returns integer average width (horizontal space per character in pixels, 0 if invalid font). Queries font metrics for typical character width, useful for estimating text dimensions.
Returns the average character width of the font in pixels. Takes font (font handle from b2dLoadFont, positive integer). Returns integer average width (horizontal space per character in pixels, 0 if invalid font). Queries font metrics for typical character width, useful for estimating text dimensions.
Width definition: average width across all characters in font (not maximum or specific character), approximation for layout calculations (actual text may vary), proportional fonts have variable width (this returns average), monospace fonts have fixed width (all characters same).
Use cases: (1) Quick text width estimation (approximate before accurate measurement), (2) Text field sizing (estimate capacity without measuring all text), (3) Character-based layout (estimate columns for monospace fonts), (4) UI element sizing (rough text box dimensions).
Common patterns: estimate width = approxWidth=b2dGetFontWidth(font)*strLen(text); monospace check = width=b2dGetFontWidth(font) (if monospace, all chars have this width); text box size = boxWidth=maxChars*b2dGetFontWidth(font)+padding.
Accuracy considerations: approximation only (use b2dGetStringWidth for exact), varies by font design (narrow fonts smaller, wide fonts larger), proportional fonts less accurate (variable character widths), monospace fonts very accurate (all chars same width).
Performance: very fast query (~0.0001ms), simple map lookup and return, no calculation required (pre-loaded from font file).
Related: b2dGetStringWidth measures exact text width, b2dGetFontHeight queries font line height, b2dLoadFont loads font with metrics, b2dGetStringHeight measures exact text height.