toptensoftware / RichTextKit

Rich text rendering for SkiaSharp
Other
366 stars 73 forks source link

Create a default Typeface when the current is not found. #6

Closed Clancey closed 4 years ago

Clancey commented 4 years ago

If a font is not found, you get a null reference exception. This will create a default font to prevent crashes!

mattleibow commented 4 years ago

I will also investigate this in SkiaSharp to see if it is a bug to return null. Somehow, I recall that this method is not supposed to ever do that. I may be getting this mixed up.

toptensoftware commented 4 years ago

Thanks guys. I was going to wait till @mattleibow checks SkiaSharp, but the change is tiny and a good safety check anyway so I've merged it.

Gillibald commented 4 years ago

SkiaSharp more precisely the font manager should return SKTypeface.Default in case a specific font isn't found.

Gillibald commented 4 years ago

Also keep in mind that the instance of CreateDefault isn't guaranteed to be SKTypeface.Default

mattleibow commented 4 years ago

From the C++ code docs:

Creates a new reference to the typeface that most closely matches the requested familyName and fontStyle. This method allows extended font face specifiers as in the SkFontStyle type. Will never return null.

mattleibow commented 4 years ago

Oh, nice! Check this out from the Android implementation:

On Android, we must return nullptr when we can't find the requested named typeface so that the system/app can provide their own recovery mechanism. On other platforms we'd provide a typeface from the default family instead.

mattleibow commented 4 years ago

I opened this bug in SkiaSharp, but I am not sure at the moment what the correct fix should be: https://github.com/mono/SkiaSharp/issues/1058