Skip to content

[iOS] canvas.GetStringSize() is not consistent with actual string size in GraphicsView #18679

Open
@riccardominato

Description

@riccardominato

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

  1. Use the correct API to calculate canvas.GetStringSize() as in Fix PlatformStringSizeService on iOS/Catalyst to use correct API #18621
  2. Create a GraphicsView with a Drawable.
  3. Define a string StringToVisualize with newlines or long enough, like this one: "HELLO, WORLD!\nCiao mondo row 2\n\nGuten tag!?àèìòù@"
  4. Choose a FontSize
  5. Inside the Draw() method, call canvas.GetStringSize(StringToVisualize, Font.Default, FontSize);
  6. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-drawingShapes, Borders, Shadows, Graphics, BoxView, custom drawingplatform/iOS 🍎s/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions