Returns the rendered width of text at font_size using the window’s
current text style. Used for layout calculations that need to reserve
space for labels before the scale ranges are fixed.
Truncate text with a trailing ellipsis so it fits within max_width at
font_size. Returns text unchanged when it already fits; returns just
the ellipsis when not even one character fits. max_width <= 0 is treated
as “no budget” and returns text unchanged (the caller has no room to
reason about).