Skip to content

Fixed GetStringSize() is not consistent with actual string size in GraphicsView #30133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Dhivya-SF4094
Copy link
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Issue Detail

When drawing text and its bounding rectangle in GraphicsView using canvas.GetStringSize(string), the measured size is insufficient, causing the text to overflow the rectangle.

Root Cause

String size was calculated inaccurately on iOS and Windows, causing text to overflow the measured rectangle in GraphicsView.

Description of Change

iOS: Replaced NSString.GetBoundingRect with CTFramesetter.SuggestFrameSize, which provides a more accurate and layout-aware measurement of the text using CoreText. This results proper frame size of string text.

Windows: Replaced the previous bounding logic with CanvasTextLayout from Win2D to accurately measure text size. Word wrapping is disabled, and proper horizontal and vertical alignments are applied. The size is taken from LayoutBounds, with a fallback to DrawBounds to ensure the full text is enclosed.

Validated the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed:

Fixes #18679

Screenshots

Before  After 
     

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jun 23, 2025
Copy link
Contributor

Hey there @@Dhivya-SF4094! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Jun 23, 2025
@jsuarezruiz jsuarezruiz added the area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing label Jun 23, 2025
@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test GraphicsViewShouldNotWrapText is failing on iOS and could be related with the changes. Could you take a look?

Snapshot different than baseline: GraphicsViewShouldNotWrapText.png (0.80% difference)

@Dhivya-SF4094
Copy link
Contributor Author

The test GraphicsViewShouldNotWrapText is failing on iOS and could be related with the changes. Could you take a look?

@jsuarezruiz I have resaved the image for the failing GraphicsViewShouldNotWrapText test case. Could you please review once.

@Dhivya-SF4094 Dhivya-SF4094 marked this pull request as ready for review June 25, 2025 09:50
@Dhivya-SF4094 Dhivya-SF4094 requested a review from a team as a code owner June 25, 2025 09:50
@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/rebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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