From bb53b4d94386481ec8f8a7592ed2a818904a6946 Mon Sep 17 00:00:00 2001 From: Kohsuke Yatoh Date: Tue, 9 Aug 2022 00:41:00 +0000 Subject: [PATCH] Use FontFamily/FontCollection::create() in hwui. Minikin will hide FontFamily/FontCollection constructors. This CL updates hwui to use create() instead. Bug: 174672300 Test: m -j Change-Id: Ie910b0d7608df681443f862aa67d402809c38514 --- libs/hwui/hwui/Typeface.cpp | 6 +++--- libs/hwui/jni/FontFamily.cpp | 6 +++--- libs/hwui/jni/fonts/FontFamily.cpp | 6 +++--- libs/hwui/tests/unit/TypefaceTests.cpp | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libs/hwui/hwui/Typeface.cpp b/libs/hwui/hwui/Typeface.cpp index 5a9d2508230eb..9a4bda2ee1df5 100644 --- a/libs/hwui/hwui/Typeface.cpp +++ b/libs/hwui/hwui/Typeface.cpp @@ -127,7 +127,7 @@ Typeface* Typeface::createWithDifferentBaseWeight(Typeface* src, int weight) { Typeface* Typeface::createFromFamilies(std::vector>&& families, int weight, int italic) { Typeface* result = new Typeface; - result->fFontCollection.reset(new minikin::FontCollection(families)); + result->fFontCollection = minikin::FontCollection::create(families); if (weight == RESOLVE_BY_FONT_TABLE || italic == RESOLVE_BY_FONT_TABLE) { int weightFromFont; @@ -191,8 +191,8 @@ void Typeface::setRobotoTypefaceForTest() { std::vector> fonts; fonts.push_back(minikin::Font::Builder(font).build()); - std::shared_ptr collection = std::make_shared( - std::make_shared(std::move(fonts))); + std::shared_ptr collection = + minikin::FontCollection::create(minikin::FontFamily::create(std::move(fonts))); Typeface* hwTypeface = new Typeface(); hwTypeface->fFontCollection = collection; diff --git a/libs/hwui/jni/FontFamily.cpp b/libs/hwui/jni/FontFamily.cpp index acc1b04240303..c146adac6b699 100644 --- a/libs/hwui/jni/FontFamily.cpp +++ b/libs/hwui/jni/FontFamily.cpp @@ -85,9 +85,9 @@ static jlong FontFamily_create(CRITICAL_JNI_PARAMS_COMMA jlong builderPtr) { if (builder->fonts.empty()) { return 0; } - std::shared_ptr family = std::make_shared( - builder->langId, builder->variant, std::move(builder->fonts), - true /* isCustomFallback */); + std::shared_ptr family = + minikin::FontFamily::create(builder->langId, builder->variant, + std::move(builder->fonts), true /* isCustomFallback */); if (family->getCoverage().length() == 0) { return 0; } diff --git a/libs/hwui/jni/fonts/FontFamily.cpp b/libs/hwui/jni/fonts/FontFamily.cpp index b68213549938d..fbfc07e1f89db 100644 --- a/libs/hwui/jni/fonts/FontFamily.cpp +++ b/libs/hwui/jni/fonts/FontFamily.cpp @@ -66,9 +66,9 @@ static jlong FontFamily_Builder_build(JNIEnv* env, jobject clazz, jlong builderP ScopedUtfChars str(env, langTags); localeId = minikin::registerLocaleList(str.c_str()); } - std::shared_ptr family = std::make_shared( - localeId, static_cast(variant), std::move(builder->fonts), - isCustomFallback); + std::shared_ptr family = + minikin::FontFamily::create(localeId, static_cast(variant), + std::move(builder->fonts), isCustomFallback); if (family->getCoverage().length() == 0) { // No coverage means minikin rejected given font for some reasons. jniThrowException(env, "java/lang/IllegalArgumentException", diff --git a/libs/hwui/tests/unit/TypefaceTests.cpp b/libs/hwui/tests/unit/TypefaceTests.cpp index 9295a938f397e..25cc8ca0dafb4 100644 --- a/libs/hwui/tests/unit/TypefaceTests.cpp +++ b/libs/hwui/tests/unit/TypefaceTests.cpp @@ -64,7 +64,7 @@ std::shared_ptr buildFamily(const char* fileName) { std::vector()); std::vector> fonts; fonts.push_back(minikin::Font::Builder(font).build()); - return std::make_shared(std::move(fonts)); + return minikin::FontFamily::create(std::move(fonts)); } std::vector> makeSingleFamlyVector(const char* fileName) {