Closed Clancey closed 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.
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.
SkiaSharp more precisely the font manager should return SKTypeface.Default in case a specific font isn't found.
Also keep in mind that the instance of CreateDefault isn't guaranteed to be SKTypeface.Default
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.
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.
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
If a font is not found, you get a null reference exception. This will create a default font to prevent crashes!