summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeigo Nonaka <nona@google.com>2021-04-14 19:23:23 -0700
committerSeigo Nonaka <nona@google.com>2021-04-14 19:24:06 -0700
commitb67f9c4a19d87a49501765ffdc1cfca1457c003d (patch)
tree7719cfa78b77359036ab330e1ffe1b11f324cf4b
parent55702506cd11b2fb091334933be9ac7f98def4fe (diff)
downloadminikin-b67f9c4a19d87a49501765ffdc1cfca1457c003d.tar.gz
Update native font API to read updated font files
Bug: 184974821 Test: atest NativeSystemFontTest Change-Id: I21e386408632bd3c0b3b9e0bdb13222f6ec9fda1
-rw-r--r--include/minikin/SystemFonts.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/include/minikin/SystemFonts.h b/include/minikin/SystemFonts.h
index 686f32e..616997d 100644
--- a/include/minikin/SystemFonts.h
+++ b/include/minikin/SystemFonts.h
@@ -43,6 +43,18 @@ public:
return getInstance().registerDefaultInternal(fc);
}
+ using FontMapDeleter = std::function<void()>;
+
+ static void addFontMap(std::shared_ptr<FontCollection>&& collections) {
+ return getInstance().addFontMapInternal(std::move(collections));
+ }
+
+ // This obtains a mutex inside, so do not call this method inside callback.
+ static void getFontMap(
+ std::function<void(const std::vector<std::shared_ptr<FontCollection>>&)> func) {
+ return getInstance().getFontMapInternal(func);
+ }
+
protected:
// Visible for testing purposes.
SystemFonts() {}
@@ -60,11 +72,24 @@ protected:
mDefaultFallback = fc;
}
+ void addFontMapInternal(std::shared_ptr<FontCollection>&& collections) {
+ std::lock_guard<std::mutex> lock(mMutex);
+ mCollections.emplace_back(std::move(collections));
+ }
+
+ void getFontMapInternal(
+ std::function<void(const std::vector<std::shared_ptr<FontCollection>>&)> func) {
+ std::lock_guard<std::mutex> lock(mMutex);
+ func(mCollections);
+ }
+
private:
static SystemFonts& getInstance();
std::map<std::string, std::shared_ptr<FontCollection>> mSystemFallbacks GUARDED_BY(mMutex);
std::shared_ptr<FontCollection> mDefaultFallback GUARDED_BY(mMutex);
+ std::vector<std::shared_ptr<FontCollection>> mCollections GUARDED_BY(mMutex);
+
std::mutex mMutex;
};