dotnet / dotnet/maui

Can't consume a custom font in GraphicsView

Open
#9,252 32 comments 13 reactions 0 assignees View on GitHub
area-drawing p/2 platform/android s/triaged s/verified t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 14h
Merged PRs (30d)
296

Description

### Description

Assuming a font registered globally with:
```cs
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp()
.ConfigureFonts(fonts =>
{
fonts.AddFont("MyFont.ttf", "MyFont");
});
return builder.Build();
}
```

In the Drawable implementation of a GraphicsView when I try to use that font:

```cs
using Font = Microsoft.Maui.Graphics.Font;
public void Draw(ICanvas canvas, RectF dirtyRect)
{
canvas.Font = new Font("MyFont");
....
}
```

the canvas ignore that font.
And this is a big problem because we are porting an app from Xamarin (we was using SkiaSharp) to MAUI and we made a diffuse use of this kind of object.
I'm wrong with some thing or this is a bug?
thanks in advice

### Steps to Reproduce

1. Create a new .Net MAUI project
2. Register a custom font in CreateMauiApp() -> MauiProgram.cs
3. Use that font in a canvas (in the Draw() function of a IDrawable interface implementation of a GraphicsView)

### Version with bug

6.0.400

### Last version that worked well

Unknown/Other

### Affected platforms

Android

### Affected platform versions

Android 7 and Up

### Did you find any workaround?

no

### Relevant log output

```shell
no log
```

Contributor guide

Open the contributing guide

Research direction

Start with the custom-font registration in MauiProgram.cs and the IDrawable.Draw implementation used by GraphicsView. Reproduce the issue on Android 7 or later using the reported MyFont.ttf and inspect how canvas.Font resolves the registered name. Done means the custom font renders in the GraphicsView canvas.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, csharp
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.