Make SkFontMgr_New_Custom_Data public
Surface SkFontMgr_New_Custom_Data in include/ports/SkFontMgr_data.h,
similar to SkFontMgr_directory.h etc.
While at it, update the API to use SkSpan instead of rawptr + count.
Change-Id: Id340762d0787d726f917b14af9bbf688de5d1486
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/656217
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Florin Malita <fmalita@google.com>
diff --git a/include/ports/BUILD.bazel b/include/ports/BUILD.bazel
index 62871c5..d3d8e7b 100644
--- a/include/ports/BUILD.bazel
+++ b/include/ports/BUILD.bazel
@@ -10,6 +10,7 @@
{
"//bazel/common_config_settings:uses_android_fontmgr": ["SkFontMgr_android.h"],
"//bazel/common_config_settings:uses_custom_directory_fontmgr": ["SkFontMgr_directory.h"],
+ "//bazel/common_config_settings:uses_custom_embedded_fontmgr": ["SkFontMgr_data.h"],
"//bazel/common_config_settings:uses_custom_empty_fontmgr": ["SkFontMgr_empty.h"],
"//bazel/common_config_settings:uses_fontconfig_fontmgr": ["SkFontMgr_fontconfig.h"],
"//bazel/common_config_settings:uses_fci_fontmgr": [
diff --git a/include/ports/SkFontMgr_data.h b/include/ports/SkFontMgr_data.h
new file mode 100644
index 0000000..6a22365
--- /dev/null
+++ b/include/ports/SkFontMgr_data.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2023 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#ifndef SkFontMgr_data_DEFINED
+#define SkFontMgr_data_DEFINED
+
+#include "include/core/SkData.h"
+#include "include/core/SkRefCnt.h"
+#include "include/core/SkSpan.h"
+#include "include/core/SkTypes.h"
+
+class SkFontMgr;
+
+/** Create a custom font manager which wraps a collection of SkData-stored fonts.
+ * This font manager uses FreeType for rendering.
+ */
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_Custom_Data(SkSpan<sk_sp<SkData>>);
+
+#endif // SkFontMgr_data_DEFINED
diff --git a/modules/canvaskit/canvaskit_bindings.cpp b/modules/canvaskit/canvaskit_bindings.cpp
index 8a613c3..14a9429 100644
--- a/modules/canvaskit/canvaskit_bindings.cpp
+++ b/modules/canvaskit/canvaskit_bindings.cpp
@@ -112,7 +112,7 @@
#endif
#ifndef CK_NO_FONTS
-sk_sp<SkFontMgr> SkFontMgr_New_Custom_Data(sk_sp<SkData>* datas, int n);
+#include "include/ports/SkFontMgr_data.h"
#endif
struct OptionalMatrix : SkMatrix {
@@ -1446,7 +1446,7 @@
skdatas[i] = SkData::MakeFromMalloc(datas[i], sizes[i]);
}
- return SkFontMgr_New_Custom_Data(skdatas.get(), numFonts);
+ return SkFontMgr_New_Custom_Data(SkSpan(skdatas.get(), numFonts));
}), allow_raw_pointers())
.function("countFamilies", &SkFontMgr::countFamilies)
.function("getFamilyName", optional_override([](SkFontMgr& self, int index)->JSString {
diff --git a/public.bzl b/public.bzl
index 08596db..7182ce6 100644
--- a/public.bzl
+++ b/public.bzl
@@ -178,6 +178,7 @@
"include/ports/SkCFObject.h",
"include/ports/SkFontConfigInterface.h",
"include/ports/SkFontMgr_android.h",
+ "include/ports/SkFontMgr_data.h",
"include/ports/SkFontMgr_directory.h",
"include/ports/SkFontMgr_empty.h",
"include/ports/SkFontMgr_fontconfig.h",
@@ -1925,6 +1926,7 @@
"src/ports/SkFontHost_FreeType.cpp",
"src/ports/SkFontMgr_custom.cpp",
"src/ports/SkFontMgr_custom.h",
+ "src/ports/SkFontMgr_custom_embedded.cpp",
"src/ports/SkFontMgr_empty_factory.cpp",
"src/ports/SkGlobalInitialization_default.cpp",
"src/ports/SkImageGenerator_skia.cpp",
diff --git a/src/ports/SkFontMgr_custom_embedded.cpp b/src/ports/SkFontMgr_custom_embedded.cpp
index bd74c27..aae51d0 100644
--- a/src/ports/SkFontMgr_custom_embedded.cpp
+++ b/src/ports/SkFontMgr_custom_embedded.cpp
@@ -6,6 +6,7 @@
*/
#include "include/core/SkStream.h"
+#include "include/ports/SkFontMgr_data.h"
#include "src/core/SkFontDescriptor.h"
#include "src/ports/SkFontMgr_custom.h"
@@ -110,9 +111,7 @@
return sk_make_sp<SkFontMgr_Custom>(EmbeddedSystemFontLoader(header));
}
-// SkFontMgr_New_Custom_Data expects to be called with the data for n font files.
-sk_sp<SkFontMgr> SkFontMgr_New_Custom_Data(sk_sp<SkData>* datas, int n) {
- SkASSERT(datas != nullptr);
- SkASSERT(n > 0);
- return sk_make_sp<SkFontMgr_Custom>(DataFontLoader(datas, n));
+sk_sp<SkFontMgr> SkFontMgr_New_Custom_Data(SkSpan<sk_sp<SkData>> datas) {
+ SkASSERT(!datas.empty());
+ return sk_make_sp<SkFontMgr_Custom>(DataFontLoader(datas.data(), datas.size()));
}