Merge "(Text Controller) Moved some input properties into a different class & some...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / multi-language-support-impl.h
1 #ifndef DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H
2 #define DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/base-object.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/text/multi-language-support.h>
26
27 namespace Dali
28 {
29 namespace TextAbstraction
30 {
31 //Forward declaration
32 class FontClient;
33 } // namespace TextAbstraction
34
35 namespace Toolkit
36 {
37 namespace Text
38 {
39 namespace Internal
40 {
41 /**
42  * @brief Stores valid font ids per script.
43  */
44 struct ValidateFontsPerScript
45 {
46   /**
47    * Default constructor.
48    */
49   ValidateFontsPerScript()
50   : mValidFonts()
51   {
52   }
53
54   /**
55    * Default destructor.
56    */
57   ~ValidateFontsPerScript()
58   {
59   }
60
61   /**
62    * @brief Whether the given @p fontId is in the vector of valid fonts.
63    *
64    * @param[in] fontId The font id.
65    *
66    * @return @e true if the font is in the vector of valid fonts.
67    */
68   bool IsValidFont(FontId fontId) const;
69
70   Vector<FontId> mValidFonts;
71 };
72
73 /**
74  * @brief Stores default font ids per script. It can be different sizes for a default font family.
75  */
76 struct DefaultFonts
77 {
78   struct CacheItem
79   {
80     TextAbstraction::FontDescription description;
81     FontId                           fontId;
82   };
83
84   /**
85    * Default constructor.
86    */
87   DefaultFonts()
88   : mFonts()
89   {
90   }
91
92   /**
93    * Default destructor.
94    */
95   ~DefaultFonts()
96   {
97   }
98
99   /**
100    * @brief Finds a default font for the given @p size.
101    *
102    * @param[in] fontClient The font client.
103    * @param[in] description The font's description.
104    * @param[in] size The given size.
105    *
106    * @return The font id of a default font for the given @p size. If there isn't any font cached it returns 0.
107    */
108   FontId FindFont(TextAbstraction::FontClient&            fontClient,
109                   const TextAbstraction::FontDescription& description,
110                   PointSize26Dot6                         size) const;
111
112   void Cache(const TextAbstraction::FontDescription& description, FontId fontId);
113
114   std::vector<CacheItem> mFonts;
115 };
116
117 /**
118  * @brief Multi-language support implementation. @see Text::MultilanguageSupport.
119  */
120 class MultilanguageSupport : public BaseObject
121 {
122 public:
123   /**
124    * Constructor
125    */
126   MultilanguageSupport();
127
128   /**
129    * Destructor
130    *
131    * This is non-virtual since derived Handle types must not contain data or virtual methods.
132    */
133   ~MultilanguageSupport();
134
135   /**
136    * @copydoc Dali::MultilanguageSupport::Get()
137    */
138   static Text::MultilanguageSupport Get();
139
140   /**
141    * @copydoc Dali::MultilanguageSupport::SetScripts()
142    */
143   void SetScripts(const Vector<Character>& text,
144                   CharacterIndex           startIndex,
145                   Length                   numberOfCharacters,
146                   Vector<ScriptRun>&       scripts);
147
148   /**
149    * @copydoc Dali::MultilanguageSupport::ValidateFonts()
150    */
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);
159
160 private:
161   Vector<DefaultFonts*>           mDefaultFontPerScriptCache; ///< Caches default fonts for a script.
162   Vector<ValidateFontsPerScript*> mValidFontsPerScriptCache;  ///< Caches valid fonts for a script.
163
164   //Methods
165
166   /**
167  * @brief Add the current script to scripts and create new script.
168  *
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.
176  *
177  */
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);
185 };
186
187 } // namespace Internal
188
189 inline static Internal::MultilanguageSupport& GetImplementation(MultilanguageSupport& multilanguageSupport)
190 {
191   DALI_ASSERT_ALWAYS(multilanguageSupport && "multi-language handle is empty");
192   BaseObject& handle = multilanguageSupport.GetBaseObject();
193   return static_cast<Internal::MultilanguageSupport&>(handle);
194 }
195
196 inline static const Internal::MultilanguageSupport& GetImplementation(const MultilanguageSupport& multilanguageSupport)
197 {
198   DALI_ASSERT_ALWAYS(multilanguageSupport && "multi-language handle is empty");
199   const BaseObject& handle = multilanguageSupport.GetBaseObject();
200   return static_cast<const Internal::MultilanguageSupport&>(handle);
201 }
202
203 } // namespace Text
204
205 } // namespace Toolkit
206
207 } // namespace Dali
208
209 #endif // DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H