Skip to content

[iOS] canvas.GetStringSize() not considering newlines #18572

@riccardominato

Description

@riccardominato

Description

In iOS canvas.GetStringSize() seems not to handle correctly newlines. It creates a Size wide as the longest row and high as a single row.

You can verify this by running the project in repro and setting NEWLINE_IOS global variable (if not already set) in MyDrawable.cs.

In my opinion this issue could be linked to #8486.

Steps to Reproduce

  1. Create a GraphicsView with a Drawable.
  2. Define a string StringToVisualize with newlines, like this one: "HELLO, WORLD!\nCiao mondo row 2\n\nGuten tag!?àèìòù@"
  3. Choose a FontSize
  4. Inside the Draw() method, call canvas.GetStringSize(StringToVisualize, Font.Default, FontSize);
  5. Draw a rectangle with the size returned by the call at point 4.

Expected Result (Android)
Screenshot_1699369953

Actual Result (iOS)
Simulator Screenshot - iPhone 15 - 2023-11-07 at 16 15 15

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?

Calculating string size by hand.

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-drawingShapes, Borders, Shadows, Graphics, BoxView, custom drawingfixed-in-8.0.6Look for this fix in 8.0.6 SR1!platform/iost/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions