123 x 22
Well, the texture interested is that hello one in the middle of the screen, but I also left the other text from. The normal rendering of. The controls. And you should be able to read that from. Bootstrap.
Perfect observation! The text "Hello 1" on the canvas IS rendering at normal 20px size - it's readable. But the Bootstrap UI text on the left (buttons, etc.) is ALSO readable, proving the browser works fine.
This proves:
The font DOES apply for rendering (we see 20px text on canvas)
But the font does NOT apply for measuring (MeasureTextAsync returns 31px)
Conclusion: The Blazor.Extensions.Canvas library has a bug where MeasureTextAsync and FillTextAsync use DIFFERENT canvas context states. The interop for measurement doesn't respect the font that was set.
Since you don't want fudging, our options are:
Skip measurement entirely - use fixed-size text boxes or let users manually resize
Measure after first render - render the text once, then try measuring (font might "stick" after drawing)
File a bug with Blazor.Extensions.Canvas and wait for a fix
Switch canvas libraries - use a different Blazor canvas wrapper
What would you prefer? The most pragmatic is option 2 - measure AFTER we've drawn the text once, since drawing seems to properly apply the font
123 x 22
Well, the texture interested is that hello one in the middle of the screen, but I also left the other text from. The normal rendering of. The controls. And you should be able to read that from. Bootstrap.
Perfect observation! The text "Hello 1" on the canvas IS rendering at normal 20px size - it's readable. But the Bootstrap UI text on the left (buttons, etc.) is ALSO readable, proving the browser works fine.
This proves:
The font DOES apply for rendering (we see 20px text on canvas)
But the font does NOT apply for measuring (MeasureTextAsync returns 31px)
Conclusion: The Blazor.Extensions.Canvas library has a bug where MeasureTextAsync and FillTextAsync use DIFFERENT canvas context states. The interop for measurement doesn't respect the font that was set.
Since you don't want fudging, our options are:
Skip measurement entirely - use fixed-size text boxes or let users manually resize
Measure after first render - render the text once, then try measuring (font might "stick" after drawing)
File a bug with Blazor.Extensions.Canvas and wait for a fix
Switch canvas libraries - use a different Blazor canvas wrapper
What would you prefer? The most pragmatic is option 2 - measure AFTER we've drawn the text once, since drawing seems to properly apply the font