1 #ifndef DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H
2 #define DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H
5 * Copyright (c) 2021 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;
70 Vector<FontId> mValidFonts;
74 * @brief Stores default font ids per script. It can be different sizes for a default font family.
80 TextAbstraction::FontDescription description;
85 * Default constructor.
100 * @brief Finds a default font for the given @p size.
102 * @param[in] fontClient The font client.
103 * @param[in] description The font's description.
104 * @param[in] size The given size.
106 * @return The font id of a default font for the given @p size. If there isn't any font cached it returns 0.
108 FontId FindFont(TextAbstraction::FontClient& fontClient,
109 const TextAbstraction::FontDescription& description,
110 PointSize26Dot6 size) const;
112 void Cache(const TextAbstraction::FontDescription& description, FontId fontId);
114 std::vector<CacheItem> mFonts;
118 * @brief Multi-language support implementation. @see Text::MultilanguageSupport.
120 class MultilanguageSupport : public BaseObject
126 MultilanguageSupport();
131 * This is non-virtual since derived Handle types must not contain data or virtual methods.
133 ~MultilanguageSupport();
136 * @copydoc Dali::MultilanguageSupport::Get()
138 static Text::MultilanguageSupport Get();
141 * @copydoc Dali::MultilanguageSupport::SetScripts()
143 void SetScripts(const Vector<Character>& text,
144 CharacterIndex startIndex,
145 Length numberOfCharacters,
146 Vector<ScriptRun>& scripts);
149 * @copydoc Dali::MultilanguageSupport::ValidateFonts()
151 void ValidateFonts(const Vector<Character>& text,
152 const Vector<ScriptRun>& scripts,
153 const Vector<FontDescriptionRun>& fontDescriptions,
154 const TextAbstraction::FontDescription& defaultFontDescription,
155 TextAbstraction::PointSize26Dot6 defaultFontPointSize,
156 CharacterIndex startIndex,
157 Length numberOfCharacters,
158 Vector<FontRun>& fonts);
161 Vector<DefaultFonts*> mDefaultFontPerScriptCache; ///< Caches default fonts for a script.
162 Vector<ValidateFontsPerScript*> mValidFontsPerScriptCache; ///< Caches valid fonts for a script.
167 * @brief Add the current script to scripts and create new script.
169 * @param[in] requestedScript The script of the new script run.
170 * @param[in] isRightToLeft The direction of the new script run.
171 * @param[in] addScriptCharactersToNewScript Whether to add the pending characters to the new script run or to the current script run.
172 * @param[inout] currentScriptRun The current character script run and it will be updated it to the new script run.
173 * @param[inout] numberOfAllScriptCharacters The pending characters.
174 * @param[inout] scripts The list of scripts.
175 * @param[inout] scriptIndex The current index of scripts.
178 void AddCurrentScriptAndCreatNewScript(const Script requestedScript,
179 const bool isRightToLeft,
180 const bool addScriptCharactersToNewScript,
181 ScriptRun& currentScriptRun,
182 Length& numberOfAllScriptCharacters,
183 Vector<ScriptRun>& scripts,
184 ScriptRunIndex& scriptIndex);
187 } // namespace Internal
189 inline static Internal::MultilanguageSupport& GetImplementation(MultilanguageSupport& multilanguageSupport)
191 DALI_ASSERT_ALWAYS(multilanguageSupport && "multi-language handle is empty");
192 BaseObject& handle = multilanguageSupport.GetBaseObject();
193 return static_cast<Internal::MultilanguageSupport&>(handle);
196 inline static const Internal::MultilanguageSupport& GetImplementation(const MultilanguageSupport& multilanguageSupport)
198 DALI_ASSERT_ALWAYS(multilanguageSupport && "multi-language handle is empty");
199 const BaseObject& handle = multilanguageSupport.GetBaseObject();
200 return static_cast<const Internal::MultilanguageSupport&>(handle);
205 } // namespace Toolkit
209 #endif // DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H