Until found the reason of cache size appending, just keep this removal logic.
Change-Id: I9a1e6c2db486af9c711c80ab65bb03435719c3f9
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
#include <dali-toolkit/internal/text/logical-model-impl.h>
#include <dali-toolkit/internal/text/multi-language-helper-functions.h>
#include <dali-toolkit/internal/text/multi-language-support.h>
+#include <dali-toolkit/internal/text/multi-language-support-impl.h>
#include <dali-toolkit/internal/text/segmentation.h>
#include <dali-toolkit/internal/text/text-run-container.h>
#include <dali-toolkit-test-suite-utils.h>
using namespace Toolkit;
using namespace Text;
+
// Tests the following functions with different scripts.
//
// void MergeFontDescriptions(const Vector<FontDescriptionRun>& fontDescriptions,
tet_result(TET_PASS);
END_TEST;
}
+
+int UtcDaliTextMultiLanguageValidateFontsPerScriptCache(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliTextMultiLanguageValidateFontsPerScriptCache");
+
+ std::size_t MAX_VALIDATE_FONTS_PER_SCRIPT_CACHE_SIZE = 63u;
+ std::size_t VALIDATE_FONTS_PER_SCRIPT_REMAIN_COUNT = 8u;
+
+ Dali::Toolkit::Text::Internal::ValidateFontsPerScript* validateFontsPerScript = new Dali::Toolkit::Text::Internal::ValidateFontsPerScript();
+
+ for(std::size_t i = 0u; i < MAX_VALIDATE_FONTS_PER_SCRIPT_CACHE_SIZE; i ++)
+ {
+ FontId fontId = i;
+ validateFontsPerScript->Cache(fontId);
+ }
+
+ DALI_TEST_EQUALS(MAX_VALIDATE_FONTS_PER_SCRIPT_CACHE_SIZE, validateFontsPerScript->mValidFonts.Count(), TEST_LOCATION);
+
+ FontId fontId = MAX_VALIDATE_FONTS_PER_SCRIPT_CACHE_SIZE;
+ validateFontsPerScript->Cache(fontId);
+
+ DALI_TEST_EQUALS(VALIDATE_FONTS_PER_SCRIPT_REMAIN_COUNT, validateFontsPerScript->mValidFonts.Count(), TEST_LOCATION);
+
+ END_TEST;
+}
+
+int UtcDaliTextMultiLanguageDefaultFontsCache(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliTextMultiLanguageDefaultFontsCache");
+
+ std::size_t MAX_DEFAULT_FONTS_CACHE_SIZE = 15;
+ std::size_t DEFAULT_FONTS_REMAIN_COUNT = 2;
+
+ Dali::Toolkit::Text::Internal::DefaultFonts* defaultFontsPerScript = new Dali::Toolkit::Text::Internal::DefaultFonts();
+
+ for(std::size_t i = 0u; i < MAX_DEFAULT_FONTS_CACHE_SIZE; i ++)
+ {
+ TextAbstraction::FontDescription fontDescription;
+ FontId fontId = i;
+ defaultFontsPerScript->Cache(fontDescription, fontId);
+ }
+
+ DALI_TEST_EQUALS(MAX_DEFAULT_FONTS_CACHE_SIZE, defaultFontsPerScript->mFonts.size(), TEST_LOCATION);
+
+ TextAbstraction::FontDescription fontDescription;
+ FontId fontId = MAX_DEFAULT_FONTS_CACHE_SIZE;
+ defaultFontsPerScript->Cache(fontDescription, fontId);
+
+ DALI_TEST_EQUALS(DEFAULT_FONTS_REMAIN_COUNT, defaultFontsPerScript->mFonts.size(), TEST_LOCATION);
+
+ END_TEST;
+}
\ No newline at end of file
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_FONT_PERFORMANCE_MARKER, false);
const Dali::Toolkit::Text::Character UTF32_A = 0x0041;
+
+// TODO : Customization required for these values.
+constexpr std::size_t MAX_VALIDATE_FONTS_PER_SCRIPT_CACHE_SIZE = 63;
+constexpr std::size_t MAX_DEFAULT_FONTS_CACHE_SIZE = 15;
+
+constexpr int VALIDATE_FONTS_PER_SCRIPT_REMAIN_COUNT = 8;
+constexpr int DEFAULT_FONTS_REMAIN_COUNT = 2;
} // namespace
namespace Text
return false;
}
+void ValidateFontsPerScript::Cache(FontId fontId)
+{
+ mValidFonts.PushBack(fontId);
+ if(MAX_VALIDATE_FONTS_PER_SCRIPT_CACHE_SIZE < mValidFonts.Count())
+ {
+ // Clear cache but remaind some last items.
+ const auto offset = mValidFonts.Count() - VALIDATE_FONTS_PER_SCRIPT_REMAIN_COUNT;
+ for(int i = 0; i < VALIDATE_FONTS_PER_SCRIPT_REMAIN_COUNT; ++i)
+ {
+ mValidFonts[i] = std::move(mValidFonts[offset + i]);
+ }
+ mValidFonts.Resize(VALIDATE_FONTS_PER_SCRIPT_REMAIN_COUNT);
+ }
+}
FontId DefaultFonts::FindFont(TextAbstraction::FontClient& fontClient,
const TextAbstraction::FontDescription& description,
item.description = description;
item.fontId = fontId;
mFonts.push_back(item);
+ if(MAX_DEFAULT_FONTS_CACHE_SIZE < mFonts.size())
+ {
+ // Clear cache but remaind some last items.
+ const auto offset = mFonts.size() - DEFAULT_FONTS_REMAIN_COUNT;
+ for(int i = 0; i < DEFAULT_FONTS_REMAIN_COUNT; ++i)
+ {
+ mFonts[i] = std::move(mFonts[offset + i]);
+ }
+ mFonts.resize(DEFAULT_FONTS_REMAIN_COUNT);
+ }
}
MultilanguageSupport::MultilanguageSupport()
Vector<ScriptRun>::ConstIterator scriptRunEndIt = scripts.End();
bool isNewParagraphCharacter = false;
- FontId previousEmojiFontId = 0u;
- FontId currentFontId = 0u;
- FontId previousFontId = 0u;
- TextAbstraction::Script previousScript = TextAbstraction::UNKNOWN;
+ FontId previousEmojiFontId = 0u;
+ FontId currentFontId = 0u;
+ FontId previousFontId = 0u;
+ TextAbstraction::Script previousScript = TextAbstraction::UNKNOWN;
CharacterIndex lastCharacter = startIndex + numberOfCharacters - 1u;
for(Length index = startIndex; index <= lastCharacter; ++index)
*(validFontsPerScriptCacheBuffer + script) = validateFontsPerScript;
}
- validateFontsPerScript->mValidFonts.PushBack(fontId);
+ validateFontsPerScript->Cache(fontId);
}
if(!isValidFont && (fontId != cachedDefaultFontId) && (!TextAbstraction::IsNewParagraph(character))) // (3)
if(isValidCachedFont)
{
// Use the cached default font for the script if there is one.
- fontId = cachedDefaultFontId;
+ fontId = cachedDefaultFontId;
isValidFont = true;
}
else
#define DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
*/
bool IsValidFont(FontId fontId) const;
+ /**
+ * @brief Cache the given @p fontId in the vector of valid fonts.
+ * @note If cache size is big enough, we might remove some caches.
+ *
+ * @param[in] fontId The font id.
+ */
+ void Cache(FontId fontId);
+
Vector<FontId> mValidFonts;
};
const TextAbstraction::FontDescription& description,
PointSize26Dot6 size) const;
+ /**
+ * @brief Cache a default font for the given @p size.
+ * @note If cache size is big enough, we might remove some caches.
+ *
+ * @param[in] description The font's description.
+ * @param[in] fontId The font id.
+ */
void Cache(const TextAbstraction::FontDescription& description, FontId fontId);
std::vector<CacheItem> mFonts;