Skip to content

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 Details

The values returned by canvas.GetStringSize has incorrect width and height measurements.

Root Cause

In recent changes, removed CanvasWordWrapping = NoWrap caused incorrect width and height calculations due to unintended word wrapping.

Description of Change

The fix explicitly reinstates the CanvasWordWrapping setting to NoWrap before measuring the text. This ensures that GetStringSize returns correct dimensions for single-line content, resulting in accurate rectangle sizing and proper alignment.

Validated the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Break PR: 29048

Issues Fixed:

Fixes #29562

Screenshots

Before After

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels May 19, 2025
@Dhivya-SF4094 Dhivya-SF4094 marked this pull request as ready for review May 19, 2025 14:13
Copilot AI review requested due to automatic review settings May 19, 2025 14:13
@Dhivya-SF4094 Dhivya-SF4094 requested a review from a team as a code owner May 19, 2025 14:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the incorrect sizing of text in Maui.Graphics by explicitly setting CanvasWordWrapping to NoWrap before measuring the text.

  • The Windows platform implementation now reinstates NoWrap for GetStringSize.
  • New test cases in both TestCases.Shared.Tests and TestCases.HostApp verify that text is rendered as a single line.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/Graphics/src/Graphics/Platforms/Windows/PlatformStringSizeService.cs Fixes GetStringSize by setting WordWrapping to NoWrap
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29562.cs Adds automated test for verifying single-line text rendering
src/Controls/tests/TestCases.HostApp/Issues/Issue29562.cs Provides UI test integration to validate the fix

@sheiksyedm sheiksyedm added area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing platform/windows labels May 19, 2025
@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

public void GraphicsViewShouldNotWrapText()
{
App.WaitForElement("Label");
VerifyScreenshot();
Copy link
Contributor

Choose a reason for hiding this comment

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

Pending snapshots. Running a build.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz Added the Snapshots.

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@PureWeen PureWeen added this to the .NET 9 SR8 milestone May 20, 2025
@PureWeen PureWeen moved this from Todo to Ready To Review in MAUI SDK Ongoing May 20, 2025
@PureWeen PureWeen added the p/0 Current heighest priority issues that we are targeting for a release. label May 20, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@github-project-automation github-project-automation bot moved this from Ready To Review to Approved in MAUI SDK Ongoing May 21, 2025
@PureWeen PureWeen changed the base branch from main to inflight/current May 21, 2025 16:08
@PureWeen PureWeen merged commit 2aea9c9 into dotnet:inflight/current May 21, 2025
130 of 131 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing May 21, 2025
PureWeen pushed a commit that referenced this pull request May 21, 2025
* Fixed incorrect width and height

* Updated test sample

* Updated method name

* Update shared test sample

* Given width and height request for graphicsview in sample

* Added snapshots
github-actions bot pushed a commit that referenced this pull request May 22, 2025
* Fixed incorrect width and height

* Updated test sample

* Updated method name

* Update shared test sample

* Given width and height request for graphicsview in sample

* Added snapshots
github-actions bot pushed a commit that referenced this pull request May 30, 2025
* Fixed incorrect width and height

* Updated test sample

* Updated method name

* Update shared test sample

* Given width and height request for graphicsview in sample

* Added snapshots
github-actions bot pushed a commit that referenced this pull request May 30, 2025
* Fixed incorrect width and height

* Updated test sample

* Updated method name

* Update shared test sample

* Given width and height request for graphicsview in sample

* Added snapshots
@github-actions github-actions bot locked and limited conversation to collaborators Jun 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing community ✨ Community Contribution p/0 Current heighest priority issues that we are targeting for a release. partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Maui.Graphics GetStringSize Inverts Width and Height in version 9.0.70 (Windows only)

4 participants