Skip to content

DrawString doesn't work on maccatalyst #4993

@BharanikhumarSR

Description

@BharanikhumarSR

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

  • Create a new Maui Application
  • Add GraphicsView to the content page.
  • Create a new class and extend the class from IDrawable
  • Draw a text using DrawString using ICanvas.
  • Bind the drawable to the GraphicsView drawable property.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-drawingShapes, Borders, Shadows, Graphics, BoxView, custom drawingplatform/ioss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't workingt/desktopThe issue relates to desktop scenarios (MacOS/MacCatalyst/Windows/WinUI/WinAppSDK)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions