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>
25 #include <dali-toolkit/internal/text/multi-language-support.h>
29 namespace TextAbstraction
33 } // namespace TextAbstraction
42 * @brief Stores valid font ids per script.
44 struct ValidateFontsPerScript
47 * Default constructor.
49 ValidateFontsPerScript()
57 ~ValidateFontsPerScript()
62 * @brief Whether the given @p fontId is in the vector of valid fonts.
64 * @param[in] fontId The font id.
66 * @return @e true if the font is in the vector of valid fonts.
68 bool IsValidFont(FontId fontId) const;
71 * @brief Cache the given @p fontId in the vector of valid fonts.
72 * @note If cache size is big enough, we might remove some caches.
74 * @param[in] fontId The font id.
76 void Cache(FontId fontId);
78 Vector<FontId> mValidFonts;
82 * @brief Stores default font ids per script. It can be different sizes for a default font family.
88 TextAbstraction::FontDescription description;
93 * Default constructor.
101 * Default destructor.
108 * @brief Finds a default font for the given @p size.
110 * @param[in] fontClient The font client.
111 * @param[in] description The font's description.
112 * @param[in] size The given size.
114 * @return The font id of a default font for the given @p size. If there isn't any font cached it returns 0.
116 FontId FindFont(TextAbstraction::FontClient& fontClient,
117 const TextAbstraction::FontDescription& description,
118 PointSize26Dot6 size) const;
121 * @brief Cache a default font for the given @p size.
122 * @note If cache size is big enough, we might remove some caches.
124 * @param[in] description The font's description.
125 * @param[in] fontId The font id.
127 void Cache(const TextAbstraction::FontDescription& description, FontId fontId);
129 std::vector<CacheItem> mFonts;
133 * @brief Multi-language support implementation. @see Text::MultilanguageSupport.
135 class MultilanguageSupport : public BaseObject
141 MultilanguageSupport();
146 * This is non-virtual since derived Handle types must not contain data or virtual methods.
148 ~MultilanguageSupport();
151 * @copydoc Dali::MultilanguageSupport::Get()
153 static Text::MultilanguageSupport Get();
156 * @copydoc Dali::MultilanguageSupport::SetScripts()
158 void SetScripts(const Vector<Character>& text,
159 CharacterIndex startIndex,
160 Length numberOfCharacters,
161 Vector<ScriptRun>& scripts);
164 * @copydoc Dali::MultilanguageSupport::ValidateFonts()
166 void ValidateFonts(const Vector<Character>& text,
167 const Vector<ScriptRun>& scripts,
168 const Vector<FontDescriptionRun>& fontDescriptions,
169 const TextAbstraction::FontDescription& defaultFontDescription,
170 TextAbstraction::PointSize26Dot6 defaultFontPointSize,
171 CharacterIndex startIndex,
172 Length numberOfCharacters,
173 Vector<FontRun>& fonts);
176 Vector<DefaultFonts*> mDefaultFontPerScriptCache; ///< Caches default fonts for a script.
177 Vector<ValidateFontsPerScript*> mValidFontsPerScriptCache; ///< Caches valid fonts for a script.
182 * @brief Add the current script to scripts and create new script.
184 * @param[in] requestedScript The script of the new script run.
185 * @param[in] isRightToLeft The direction of the new script run.
186 * @param[in] addScriptCharactersToNewScript Whether to add the pending characters to the new script run or to the current script run.
187 * @param[inout] currentScriptRun The current character script run and it will be updated it to the new script run.
188 * @param[inout] numberOfAllScriptCharacters The pending characters.
189 * @param[inout] scripts The list of scripts.
190 * @param[inout] scriptIndex The current index of scripts.
193 void AddCurrentScriptAndCreatNewScript(const Script requestedScript,
194 const bool isRightToLeft,
195 const bool addScriptCharactersToNewScript,
196 ScriptRun& currentScriptRun,
197 Length& numberOfAllScriptCharacters,
198 Vector<ScriptRun>& scripts,
199 ScriptRunIndex& scriptIndex);
202 } // namespace Internal
204 inline static Internal::MultilanguageSupport& GetImplementation(MultilanguageSupport& multilanguageSupport)
206 DALI_ASSERT_ALWAYS(multilanguageSupport && "multi-language handle is empty");
207 BaseObject& handle = multilanguageSupport.GetBaseObject();
208 return static_cast<Internal::MultilanguageSupport&>(handle);
211 inline static const Internal::MultilanguageSupport& GetImplementation(const MultilanguageSupport& multilanguageSupport)
213 DALI_ASSERT_ALWAYS(multilanguageSupport && "multi-language handle is empty");
214 const BaseObject& handle = multilanguageSupport.GetBaseObject();
215 return static_cast<const Internal::MultilanguageSupport&>(handle);
220 } // namespace Toolkit
224 #endif // DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H