SkiaSharp: [BUG?] SKTypeface.FromFamilyName should not return null... or could?

Description

Not sure what is going with SKTypeface.FromFamilyName. The code docs say it should NEVER return null, but does and should in some cases? Those are conflicting statements right there.

I see this previous issue where I say that there is no guarantee: https://github.com/mono/SkiaSharp/issues/643

But, there is in this 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.

https://github.com/mono/skia/blob/xamarin-mobile-bindings/include/core/SkTypeface.h#L95-L104

And then we go straight into this:

            // 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.

https://github.com/mono/skia/blob/xamarin-mobile-bindings/src/ports/SkFontMgr_android.cpp#L475-L484

Fear!

Never mind the fontconfig variants which basically just return nullptr: https://github.com/google/skia/blob/chrome/m68/src/ports/SkFontMgr_fontconfig.cpp#L894

Who knows at this point!

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 18 (18 by maintainers)

Most upvoted comments

I need a way to know that a font wasn’t found. If I can always compare with the default it is fine to return the default. I doubt that always works.