Skip to main content

estimate_text_width

Function estimate_text_width 

Source
pub fn estimate_text_width(text: &str, style: &TextStyle) -> f64
Expand description

Estimates the width of a text string for a given TextStyle.

This uses a heuristic based on average character width ratios for common proportional fonts. The estimate is char_count * size * 0.6 for normal weight and char_count * size * 0.65 for bold, which provides reasonable approximations when the Canvas2D measureText API is not available (e.g., during testing or server-side pre-layout).