dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.26k stars 1.76k forks source link

DrawString doesn't work on maccatalyst #4993

Open BharanikhumarSR opened 2 years ago

BharanikhumarSR commented 2 years ago

Description

I am using canvas DrawString method to render a text in my application. But after updating preview 13 I have faced breaking issues on setting font properties. But when I tried to set the font properties using font class, text is not visible. For android and windows, the text is rendered but the alignment is not same for the platforms.

XAML

<ContentPage.Resources>
        <ResourceDictionary>
            <local:GraphicsDrawable x:Key="GraphicsDrawable" />
        </ResourceDictionary>
</ContentPage.Resources>

 <ContentPage.Content>
      <StackLayout>
           <GraphicsView
                HeightRequest="500"
               WidthRequest="500"
               Drawable="{StaticResource GraphicsDrawable}"></GraphicsView>
     </StackLayout>
 </ContentPage.Content>

C#

public class GraphicsDrawable : IDrawable
{
    public void Draw(ICanvas canvas, RectF dirtyRect)
    {
      canvas.FontColor = Colors.Black;
      canvas.FontSize = 14;
      canvas.DrawString("Hello world", 10, 10, HorizontalAlignment.Center);
    }
}

Steps to Reproduce

Version with bug

Preview 13 (current)

Last version that worked well

Preview 12

Affected platforms

iOS, macOS

Affected platform versions

iOS15

Did you find any workaround?

Yes, for ios I have fixed by mapping the text to NSString in the native platform.

Relevant log output

No response

XamlTest commented 2 years ago

Verified on Visual Studio Enterprise 2022 main 17.2.0 Preview 2.0 [32223.438.main]. Not render text in iOS platform. Repro Project: 4993.zip iOS: image

Android: image

Windows: image

XamlTest commented 2 years ago

If replace "canvas.DrawString("Hello world", 10, 10, HorizontalAlignment.Center);" with "canvas.DrawString("Hello world", 10, 10, 380, 100, HorizontalAlignment.Center, VerticalAlignment.Top);", iOS and Android will work as expected.

JuQiang commented 2 years ago

Same issue in VS for Mac 17.3.1(build 411)

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

homeyf commented 1 year ago

Verified this issue with Visual Studio Enterprise 17.6.0 Preview 2.0. Not render text in iOS platform and android. Windows: image