Skip to content

fix(🔤): accept a TypefaceFontProvider wherever a FontMgr is expected - #4541

Merged
wcandillon merged 1 commit into
wcandillon:mainfrom
filipemsilv4:fix/svg-accept-typeface-font-provider
Nov 26, 2026
Merged

wcandillon merged 1 commit into
wcandillon:mainfrom
filipemsilv4:fix/svg-accept-typeface-font-provider

Conversation

@filipemsilv4

@filipemsilv4 filipemsilv4 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #4543

I ran into this bug while building an Expo 58 app that renders SVGs with text using useFonts() the way the SVG docs show, and the app crashed on native with Expected FontMgr but got different type. TypefaceFontProvider already extends SkFontMgr in TypeScript, on web, and in Skia C++, but JsiSkFontMgr::fromValue rejected its native object.

(Translated from Portuguese with AI.)

Agent-written content

Summary

  • In packages/skia/cpp/api/JsiSkFontMgr.h, JsiSkFontMgr::fromValue now checks tryGetJsiObject<JsiSkTypefaceFontProvider>(runtime, obj) first and returns provider->getObject() (whose sk_sp<skia::textlayout::TypefaceFontProvider> converts implicitly to sk_sp<SkFontMgr>).
  • Anything else still falls through to objectFromValue(runtime, obj), preserving the strict Expected FontMgr but got different type error for invalid objects and the disposed-object check on disposed providers.
  • JsiSkSVGFactory (MakeFromString and MakeFromData) is the only native caller today; typed sk_sp<SkFontMgr> arguments via JSIConverter get the same behavior automatically.
  • No circular includes (JsiSkTypefaceFontProvider.h does not include JsiSkFontMgr.h, and JsiSkParagraphBuilder.h already includes both).

Tests (packages/skia/src/renderer/__tests__/e2e/SVG.spec.tsx)

  • MakeFromString and MakeFromData accept a TypefaceFontProvider with Roboto registered, and drawing <text font-family="Roboto"> paints pixels on an offscreen surface. FontMgr.System() continues to work.
  • Passing a non-FontMgr object (Skia.Paint()) still throws Expected FontMgr but got different type.

Local verification

  • cpplint (exact ci.yml command), clang-format, eslint, prettier, yarn tsc, and clang++ -std=c++20 -fsyntax-only against the pinned Skia headers all passed.
  • E2E tests have not been executed on a local simulator/device and will run on CI.

Skia.SVG.MakeFromString and MakeFromData document useFonts() as their
font manager, and SkTypefaceFontProvider extends SkFontMgr in the types,
on the web and in Skia itself. On iOS and Android, JsiSkFontMgr::fromValue
only accepted a JsiSkFontMgr, so passing a provider threw "Expected FontMgr
but got different type".

fromValue now also unwraps a JsiSkTypefaceFontProvider; anything else still
goes through the strict check.
@wcandillon
wcandillon merged commit d0e4075 into wcandillon:main Nov 26, 2026
12 checks passed
@filipemsilv4
filipemsilv4 deleted the fix/svg-accept-typeface-font-provider branch November 26, 2026 07:45
wcandillon pushed a commit that referenced this pull request Nov 26, 2026
…(2.x backport of #4541) (#4542)

Skia.SVG.MakeFromString and MakeFromData document useFonts() as their
font manager, and SkTypefaceFontProvider extends SkFontMgr in the types,
on the web and in Skia itself. On iOS and Android, JsiSkFontMgr::fromValue
only accepted a JsiSkFontMgr, so passing a provider threw "Expected FontMgr
but got different type".

fromValue now also unwraps a JsiSkTypefaceFontProvider; anything else still
goes through the strict check.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Skia.SVG.MakeFromString / MakeFromData throw "Expected FontMgr but got different type" when passed useFonts() (SkTypefaceFontProvider)

2 participants