From 102667d4af02a93144f7e0dc4aeb852a85e08787 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Thu, 24 Mar 2022 17:44:13 +0900 Subject: [PATCH] Cache default fontDescription + use default when fontDescription empty When font description is empty, we will validate font in ValidateFont function. And inside of that function, fontDescription become mDefaultDescription. Due to the validateId is not matched, we always fail to get cached font info. This patch make realFontDescription = mDefaultDescription when input fontDescription family information is broken, so we can use font cache feature well. And also, ValidateFont API runtime is too long. So when we get default font description, caching it immediatly. It will make that normal case don't call ValidateFont API. Change-Id: Iacb8ff84f159da5ee0d80f90c47001da54035e7e Signed-off-by: Eunki, Hong --- dali/devel-api/text-abstraction/font-list.h | 17 ++++++- .../plugin/font-client-plugin-impl.cpp | 53 ++++++++++++++++++++-- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/dali/devel-api/text-abstraction/font-list.h b/dali/devel-api/text-abstraction/font-list.h index 747e802..13e459d 100644 --- a/dali/devel-api/text-abstraction/font-list.h +++ b/dali/devel-api/text-abstraction/font-list.h @@ -2,7 +2,7 @@ #define DALI_TEXT_ABSTRACTION_FONT_LIST_H /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -152,6 +152,21 @@ struct FontDescription { } + FontDescription(const FontPath& path, + const FontFamily& family, + const FontWidth::Type& width, + const FontWeight::Type& weight, + const FontSlant::Type& slant, + const Type& type) + : path(path), + family(family), + width(width), + weight(weight), + slant(slant), + type(type) + { + } + ~FontDescription() { } diff --git a/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.cpp b/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.cpp index 5668718..57ea4fb 100644 --- a/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.cpp +++ b/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -478,8 +478,39 @@ void FontClient::Plugin::GetDefaultPlatformFontDescription(FontDescription& font FcDefaultSubstitute(matchPattern); FcCharSet* characterSet = nullptr; - MatchFontDescriptionToPattern(matchPattern, mDefaultFontDescription, &characterSet); + bool matched = MatchFontDescriptionToPattern(matchPattern, mDefaultFontDescription, &characterSet); + + // Caching the default font description + if(matched) + { + // Copy default font description info. + // Due to the type changed, we need to make some temperal font description. + FontDescription tempFontDescription = mDefaultFontDescription; + + // Add the path to the cache. + tempFontDescription.type = FontDescription::FACE_FONT; + mFontDescriptionCache.push_back(tempFontDescription); + + // Set the index to the vector of paths to font file names. + const FontDescriptionId validatedFontId = mFontDescriptionCache.size(); + + FONT_LOG_DESCRIPTION(tempFontDescription, "default platform font"); + DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " default font validatedFontId : %d\n", validatedFontId); + + // Cache the index and the matched font's description. + FontDescriptionCacheItem item(tempFontDescription, + validatedFontId); + + mValidatedFontCache.push_back(std::move(item)); + } + else + { + DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " default font validation failed for font [%s]\n", mDefaultFontDescription.family.c_str()); + } + // Decrease the reference counter of the character set as it's not stored. + // Note. the cached default font description will increase reference counter by + // mFontDescriptionCache. So we can decrease reference counter here. FcCharSetDestroy(characterSet); // Destroys the pattern created. @@ -832,6 +863,18 @@ FontId FontClient::Plugin::GetFontId(const FontDescription& fontDescription, { DALI_LOG_TRACE_METHOD(gFontClientLogFilter); FONT_LOG_DESCRIPTION(fontDescription, ""); + + // Special case when font Description don't have family information. + // In this case, we just use default description family and path. + const FontDescription& realFontDescription = fontDescription.family.empty() ? FontDescription(mDefaultFontDescription.path, + mDefaultFontDescription.family, + fontDescription.width, + fontDescription.weight, + fontDescription.slant, + fontDescription.type) + : fontDescription; + + FONT_LOG_DESCRIPTION(realFontDescription, ""); DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize); // This method uses three vectors which caches: @@ -856,7 +899,7 @@ FontId FontClient::Plugin::GetFontId(const FontDescription& fontDescription, FontId fontId = 0u; // Check first if the font description matches with a previously loaded bitmap font. - if(FindBitmapFont(fontDescription.family, fontId)) + if(FindBitmapFont(realFontDescription.family, fontId)) { return fontId; } @@ -864,11 +907,11 @@ FontId FontClient::Plugin::GetFontId(const FontDescription& fontDescription, // Check if the font's description have been validated before. FontDescriptionId validatedFontId = 0u; - if(!FindValidatedFont(fontDescription, + if(!FindValidatedFont(realFontDescription, validatedFontId)) { // Use font config to validate the font's description. - ValidateFont(fontDescription, + ValidateFont(realFontDescription, validatedFontId); } -- 2.7.4