Description
Description
If you try to draw inside a GraphicsView
a rectangle having the size obtained by canvas.GetStringSize(string)
and the actual string
, you'll notice that for some strings the rectangle isn't high and wide enough to fully contain the string.
Here are two examples of strings involved in this behavior.
"HELLO, WORLD!\nCiao mondo row 2\nGuten tag!?àèìòù@"
"Ciaomondorowfdskle"
This problem has been discovered while trying to tackle #18572, where it has been found that a deprecated API was used for the iOS implementation of canvas.GetStringSize()
.
In #18621 the use of the correct API was introduced, but unfortunately it wasn't enough and even though that issue has been closed, the problem I described above keeps to be present. However, to solve this bug the edits carried by that PR have to be used.
A possible reason for this bug is described in #18621 (comment).
Possible related issue: #8486
Steps to Reproduce
- Use the correct API to calculate
canvas.GetStringSize()
as in Fix PlatformStringSizeService on iOS/Catalyst to use correct API #18621 - Create a GraphicsView with a Drawable.
- Define a string StringToVisualize with newlines or long enough, like this one: "HELLO, WORLD!\nCiao mondo row 2\n\nGuten tag!?àèìòù@"
- Choose a FontSize
- Inside the Draw() method, call canvas.GetStringSize(StringToVisualize, Font.Default, FontSize);
- Draw a rectangle with the size returned by the call at point 5.
These are the results.
Link to public reproduction project repository
https://github.com/Riccardo11/MauiIssues/tree/main/MeasureStringWrongBounds
Version with bug
8.0.0-rc.2.9511
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
iOS16, iOS17. Couldn't test other versions
Did you find any workaround?
No
Relevant log output
No response