diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2021-06-16 01:07:45 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2021-06-16 01:07:45 +0000 |
commit | dc505a70cc8699d614bbf20044d39e1067d6b70c (patch) | |
tree | ec5bc1c91ca33edd214357b76698c03f0f128600 | |
parent | 1f2d7611d4de035bb604b2e020f3fd3a666a74bf (diff) | |
parent | 554cb50b2d283bafe8fb1e4337920ac7967e3cd5 (diff) | |
download | minikin-android12-s4-release.tar.gz |
Snap for 7460608 from 554cb50b2d283bafe8fb1e4337920ac7967e3cd5 to sc-releaseandroid-vts-12.0_r9android-vts-12.0_r8android-vts-12.0_r7android-vts-12.0_r6android-vts-12.0_r5android-vts-12.0_r4android-vts-12.0_r3android-vts-12.0_r2android-vts-12.0_r12android-vts-12.0_r11android-vts-12.0_r10android-vts-12.0_r1android-security-12.0.0_r41android-security-12.0.0_r40android-security-12.0.0_r39android-security-12.0.0_r38android-security-12.0.0_r37android-security-12.0.0_r36android-security-12.0.0_r35android-security-12.0.0_r34android-platform-12.0.0_r9android-platform-12.0.0_r8android-platform-12.0.0_r7android-platform-12.0.0_r6android-platform-12.0.0_r5android-platform-12.0.0_r4android-platform-12.0.0_r3android-platform-12.0.0_r2android-platform-12.0.0_r13android-platform-12.0.0_r12android-platform-12.0.0_r11android-platform-12.0.0_r10android-platform-12.0.0_r1android-cts-12.0_r9android-cts-12.0_r8android-cts-12.0_r7android-cts-12.0_r6android-cts-12.0_r5android-cts-12.0_r4android-cts-12.0_r3android-cts-12.0_r2android-cts-12.0_r12android-cts-12.0_r11android-cts-12.0_r10android-cts-12.0_r1android-12.0.0_r9android-12.0.0_r8android-12.0.0_r34android-12.0.0_r33android-12.0.0_r31android-12.0.0_r30android-12.0.0_r3android-12.0.0_r25android-12.0.0_r2android-12.0.0_r11android-12.0.0_r10android-12.0.0_r1android12-tests-releaseandroid12-s5-releaseandroid12-s4-releaseandroid12-s3-releaseandroid12-s2-releaseandroid12-s1-releaseandroid12-release
Change-Id: Ia69fffb366ba3ed73df2d43c7470529ebc84fbd6
-rw-r--r-- | include/minikin/Font.h | 28 | ||||
-rw-r--r-- | libs/minikin/Font.cpp | 2 | ||||
-rw-r--r-- | tests/util/FreeTypeMinikinFontForTest.cpp | 11 | ||||
-rw-r--r-- | tests/util/FreeTypeMinikinFontForTest.h | 2 |
4 files changed, 28 insertions, 15 deletions
diff --git a/include/minikin/Font.h b/include/minikin/Font.h index cfd8478..67feecf 100644 --- a/include/minikin/Font.h +++ b/include/minikin/Font.h @@ -17,7 +17,6 @@ #ifndef MINIKIN_FONT_H #define MINIKIN_FONT_H -#include <functional> #include <memory> #include <mutex> #include <unordered_set> @@ -112,18 +111,20 @@ public: }; // Type for functions to load MinikinFont lazily. - using TypefaceLoader = std::function<std::shared_ptr<MinikinFont>()>; - // Type for functions to read MinikinFont metadata and construct + using TypefaceLoader = std::shared_ptr<MinikinFont>(BufferReader reader); + // Type for functions to read MinikinFont metadata and return // TypefaceLoader. - using TypefaceReader = TypefaceLoader(BufferReader* reader); + using TypefaceReader = TypefaceLoader*(BufferReader* reader); // Type for functions to write MinikinFont metadata. using TypefaceWriter = void(BufferWriter* writer, const MinikinFont* typeface); template <TypefaceReader typefaceReader> static std::shared_ptr<Font> readFrom(BufferReader* reader, uint32_t localeListId) { FontStyle style = FontStyle(reader); - TypefaceLoader typefaceLoader = typefaceReader(reader); - return std::shared_ptr<Font>(new Font(style, std::move(typefaceLoader), localeListId)); + BufferReader typefaceMetadataReader = *reader; + TypefaceLoader* typefaceLoader = typefaceReader(reader); + return std::shared_ptr<Font>( + new Font(style, typefaceMetadataReader, typefaceLoader, localeListId)); } template <TypefaceWriter typefaceWriter> @@ -138,6 +139,7 @@ public: const std::shared_ptr<MinikinFont>& typeface() const; inline FontStyle style() const { return mStyle; } const HbFontUniquePtr& baseFont() const; + BufferReader typefaceMetadataReader() const { return mTypefaceMetadataReader; } std::unordered_set<AxisTag> getSupportedAxes() const; @@ -148,10 +150,14 @@ private: : mTypeface(std::move(typeface)), mStyle(style), mBaseFont(std::move(baseFont)), + mTypefaceLoader(nullptr), + mTypefaceMetadataReader(nullptr), mLocaleListId(localeListId) {} - Font(FontStyle style, TypefaceLoader&& typefaceLoader, uint32_t localeListId) + Font(FontStyle style, BufferReader typefaceMetadataReader, TypefaceLoader* typefaceLoader, + uint32_t localeListId) : mStyle(style), - mTypefaceLoader(std::move(typefaceLoader)), + mTypefaceLoader(typefaceLoader), + mTypefaceMetadataReader(typefaceMetadataReader), mLocaleListId(localeListId) {} void initTypefaceLocked() const EXCLUSIVE_LOCKS_REQUIRED(mTypefaceMutex); @@ -166,8 +172,10 @@ private: mutable HbFontUniquePtr mBaseFont GUARDED_BY(mTypefaceMutex); mutable std::mutex mTypefaceMutex; - // Non-empty if created by readFrom(). - TypefaceLoader mTypefaceLoader; + // Non-null if created by readFrom(). + TypefaceLoader* mTypefaceLoader; + // Non-null if created by readFrom(). + BufferReader mTypefaceMetadataReader; uint32_t mLocaleListId; diff --git a/libs/minikin/Font.cpp b/libs/minikin/Font.cpp index ba42b2c..c2e74b7 100644 --- a/libs/minikin/Font.cpp +++ b/libs/minikin/Font.cpp @@ -69,7 +69,7 @@ const HbFontUniquePtr& Font::baseFont() const { void Font::initTypefaceLocked() const { if (mTypeface) return; MINIKIN_ASSERT(mTypefaceLoader, "mTypefaceLoader should not be empty when mTypeface is null"); - mTypeface = mTypefaceLoader(); + mTypeface = mTypefaceLoader(mTypefaceMetadataReader); } // static diff --git a/tests/util/FreeTypeMinikinFontForTest.cpp b/tests/util/FreeTypeMinikinFontForTest.cpp index bed6b4e..1be466a 100644 --- a/tests/util/FreeTypeMinikinFontForTest.cpp +++ b/tests/util/FreeTypeMinikinFontForTest.cpp @@ -116,9 +116,14 @@ void writeFreeTypeMinikinFontForTest(BufferWriter* writer, const MinikinFont* ty writer->writeString(typeface->GetFontPath()); } -Font::TypefaceLoader readFreeTypeMinikinFontForTest(BufferReader* reader) { - std::string fontPath(reader->readString()); - return [fontPath]() { return std::make_shared<FreeTypeMinikinFontForTest>(fontPath); }; +std::shared_ptr<MinikinFont> loadFreeTypeMinikinFontForTest(BufferReader reader) { + std::string fontPath(reader.readString()); + return std::make_shared<FreeTypeMinikinFontForTest>(fontPath); +} + +Font::TypefaceLoader* readFreeTypeMinikinFontForTest(BufferReader* reader) { + reader->skipString(); // fontPath + return &loadFreeTypeMinikinFontForTest; } } // namespace minikin diff --git a/tests/util/FreeTypeMinikinFontForTest.h b/tests/util/FreeTypeMinikinFontForTest.h index 4f63638..4cdb6d8 100644 --- a/tests/util/FreeTypeMinikinFontForTest.h +++ b/tests/util/FreeTypeMinikinFontForTest.h @@ -66,7 +66,7 @@ private: void writeFreeTypeMinikinFontForTest(BufferWriter* writer, const MinikinFont* typeface); -Font::TypefaceLoader readFreeTypeMinikinFontForTest(BufferReader* reader); +Font::TypefaceLoader* readFreeTypeMinikinFontForTest(BufferReader* reader); } // namespace minikin |