Skip to content

Fixed Maui.Graphics GetStringSize Inverts Width and Height #29574

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 6 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 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 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 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.

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 Work that we can't release without label May 20, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

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 p/0 Work that we can't release without partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows 🪟
Projects
Status: Ready To Review
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