1 #ifndef DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H
2 #define DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/object/base-object.h>
23 #include <dali/public-api/signals/connection-tracker.h>
26 #include <dali-toolkit/internal/text/multi-language-support.h>
30 namespace TextAbstraction
34 } // namespace TextAbstraction
43 * @brief Stores valid font ids per script.
45 struct ValidateFontsPerScript
48 * Default constructor.
50 ValidateFontsPerScript()
58 ~ValidateFontsPerScript()
63 * @brief Whether the given @p fontId is in the vector of valid fonts.
65 * @param[in] fontId The font id.
67 * @return @e true if the font is in the vector of valid fonts.
69 bool IsValidFont(FontId fontId) const;
72 * @brief Cache the given @p fontId in the vector of valid fonts.
73 * @note If cache size is big enough, we might remove some caches.
75 * @param[in] fontId The font id.
77 void Cache(FontId fontId);
79 Vector<FontId> mValidFonts;
83 * @brief Stores default font ids per script. It can be different sizes for a default font family.
89 TextAbstraction::FontDescription description;
94 * Default constructor.
102 * Default destructor.
109 * @brief Finds a default font for the given @p size.
111 * @param[in] fontClient The font client.
112 * @param[in] description The font's description.
113 * @param[in] size The given size.
115 * @return The font id of a default font for the given @p size. If there isn't any font cached it returns 0.
117 FontId FindFont(TextAbstraction::FontClient& fontClient,
118 const TextAbstraction::FontDescription& description,
119 PointSize26Dot6 size) const;
122 * @brief Cache a default font for the given @p size.
123 * @note If cache size is big enough, we might remove some caches.
125 * @param[in] description The font's description.
126 * @param[in] fontId The font id.
128 void Cache(const TextAbstraction::FontDescription& description, FontId fontId);
130 std::vector<CacheItem> mFonts;
134 * @brief Multi-language support implementation. @see Text::MultilanguageSupport.
136 class MultilanguageSupport : public BaseObject, public ConnectionTracker
142 MultilanguageSupport();
147 * This is non-virtual since derived Handle types must not contain data or virtual methods.
149 ~MultilanguageSupport();
152 * @copydoc Dali::MultilanguageSupport::Get()
154 static Text::MultilanguageSupport Get();
157 * @copydoc Dali::MultilanguageSupport::SetScripts()
159 void SetScripts(const Vector<Character>& text,
160 CharacterIndex startIndex,
161 Length numberOfCharacters,
162 Vector<ScriptRun>& scripts);
165 * @copydoc Dali::MultilanguageSupport::ValidateFonts()
167 void ValidateFonts(const Vector<Character>& text,
168 const Vector<ScriptRun>& scripts,
169 const Vector<FontDescriptionRun>& fontDescriptions,
170 const TextAbstraction::FontDescription& defaultFontDescription,
171 TextAbstraction::PointSize26Dot6 defaultFontPointSize,
173 CharacterIndex startIndex,
174 Length numberOfCharacters,
175 Vector<FontRun>& fonts);
178 * @brief Callback function for when the locale is changed.
179 * @param[in] locale The new system locale.
181 void OnLocaleChanged(std::string locale);
184 * @brief Clear font caches when locale changed.
189 * @brief Gets the locale.
191 std::string GetLocale();
194 Vector<DefaultFonts*> mDefaultFontPerScriptCache; ///< Caches default fonts for a script.
195 Vector<ValidateFontsPerScript*> mValidFontsPerScriptCache; ///< Caches valid fonts for a script.
202 * @brief Add the current script to scripts and create new script.
204 * @param[in] requestedScript The script of the new script run.
205 * @param[in] isRightToLeft The direction of the new script run.
206 * @param[in] addScriptCharactersToNewScript Whether to add the pending characters to the new script run or to the current script run.
207 * @param[inout] currentScriptRun The current character script run and it will be updated it to the new script run.
208 * @param[inout] numberOfAllScriptCharacters The pending characters.
209 * @param[inout] scripts The list of scripts.
210 * @param[inout] scriptIndex The current index of scripts.
213 void AddCurrentScriptAndCreatNewScript(const Script requestedScript,
214 const bool isRightToLeft,
215 const bool addScriptCharactersToNewScript,
216 ScriptRun& currentScriptRun,
217 Length& numberOfAllScriptCharacters,
218 Vector<ScriptRun>& scripts,
219 ScriptRunIndex& scriptIndex);
222 } // namespace Internal
224 inline static Internal::MultilanguageSupport& GetImplementation(MultilanguageSupport& multilanguageSupport)
226 DALI_ASSERT_ALWAYS(multilanguageSupport && "multi-language handle is empty");
227 BaseObject& handle = multilanguageSupport.GetBaseObject();
228 return static_cast<Internal::MultilanguageSupport&>(handle);
231 inline static const Internal::MultilanguageSupport& GetImplementation(const MultilanguageSupport& multilanguageSupport)
233 DALI_ASSERT_ALWAYS(multilanguageSupport && "multi-language handle is empty");
234 const BaseObject& handle = multilanguageSupport.GetBaseObject();
235 return static_cast<const Internal::MultilanguageSupport&>(handle);
240 } // namespace Toolkit
244 #endif // DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H