@@ -27,15 +27,32 @@ class JsiSkFontMgr : public JsiSkWrappingSkPtrHostObject<SkFontMgr> {
2727
2828 JsiSkFontMgr (std::shared_ptr<RNSkPlatformContext> context,
2929 sk_sp<SkFontMgr> fontMgr)
30- : JsiSkWrappingSkPtrHostObject(std::move(context), fontMgr) {}
30+ : JsiSkWrappingSkPtrHostObject(context, fontMgr),
31+ _systemFontFamilies (context->getSystemFontFamilies ()) {}
3132
32- JSI_HOST_FUNCTION (countFamilies) { return getObject ()->countFamilies (); }
33+ JSI_HOST_FUNCTION (countFamilies) {
34+ return static_cast <int >(getObject ()->countFamilies () +
35+ _systemFontFamilies.size ());
36+ }
3337
3438 JSI_HOST_FUNCTION (getFamilyName) {
3539 auto i = static_cast <int >(arguments[0 ].asNumber ());
36- SkString name;
37- getObject ()->getFamilyName (i, &name);
38- return jsi::String::createFromUtf8 (runtime, name.c_str ());
40+ auto baseFamilyCount = getObject ()->countFamilies ();
41+ if (i < baseFamilyCount) {
42+ SkString name;
43+ getObject ()->getFamilyName (i, &name);
44+ return jsi::String::createFromUtf8 (runtime, name.c_str ());
45+ }
46+ auto systemIndex = i - baseFamilyCount;
47+ if (systemIndex < static_cast <int >(_systemFontFamilies.size ())) {
48+ return jsi::String::createFromUtf8 (runtime,
49+ _systemFontFamilies[systemIndex]);
50+ }
51+ throw jsi::JSError (runtime, " Font family index out of bounds: " +
52+ std::to_string (i) + " (total families: " +
53+ std::to_string (baseFamilyCount +
54+ _systemFontFamilies.size ()) +
55+ " )" );
3956 }
4057
4158 JSI_HOST_FUNCTION (matchFamilyStyle) {
@@ -55,6 +72,9 @@ class JsiSkFontMgr : public JsiSkWrappingSkPtrHostObject<SkFontMgr> {
5572 JSI_EXPORT_FUNCTIONS (JSI_EXPORT_FUNC(JsiSkFontMgr, countFamilies),
5673 JSI_EXPORT_FUNC(JsiSkFontMgr, getFamilyName),
5774 JSI_EXPORT_FUNC(JsiSkFontMgr, matchFamilyStyle))
75+
76+ private:
77+ std::vector<std::string> _systemFontFamilies;
5878};
5979
6080} // namespace RNSkia
0 commit comments