There is a problem that ellipsis does not work properly when MIN_LINE_SIZE is set.
[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) 2019 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
30 namespace TextAbstraction
31 {
32 //Forward declaration
33 class FontClient;
34 }
35
36 namespace Toolkit
37 {
38
39 namespace Text
40 {
41
42 namespace Internal
43 {
44
45 /**
46  * @brief Stores valid font ids per script.
47  */
48 struct ValidateFontsPerScript
49 {
50   /**
51    * Default constructor.
52    */
53   ValidateFontsPerScript()
54   : mValidFonts()
55   {}
56
57   /**
58    * Default destructor.
59    */
60   ~ValidateFontsPerScript()
61   {}
62
63   /**
64    * @brief Whether the given @p fontId is in the vector of valid fonts.
65    *
66    * @param[in] fontId The font id.
67    *
68    * @return @e true if the font is in the vector of valid fonts.
69    */
70   bool IsValidFont( FontId fontId ) const;
71
72   Vector<FontId> mValidFonts;
73 };
74
75 /**
76  * @brief Stores default font ids per script. It can be different sizes for a default font family.
77  */
78 struct DefaultFonts
79 {
80   struct CacheItem
81   {
82     TextAbstraction::FontDescription description;
83     FontId fontId;
84   };
85
86   /**
87    * Default constructor.
88    */
89   DefaultFonts()
90   : mFonts()
91   {}
92
93   /**
94    * Default destructor.
95    */
96   ~DefaultFonts()
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   /**
125    * Constructor
126    */
127   MultilanguageSupport();
128
129   /**
130    * Destructor
131    *
132    * This is non-virtual since derived Handle types must not contain data or virtual methods.
133    */
134   ~MultilanguageSupport();
135
136   /**
137    * @copydoc Dali::MultilanguageSupport::Get()
138    */
139   static Text::MultilanguageSupport Get();
140
141   /**
142    * @copydoc Dali::MultilanguageSupport::SetScripts()
143    */
144   void SetScripts( const Vector<Character>& text,
145                    CharacterIndex startIndex,
146                    Length numberOfCharacters,
147                    Vector<ScriptRun>& scripts );
148
149   /**
150    * @copydoc Dali::MultilanguageSupport::ValidateFonts()
151    */
152   void ValidateFonts( const Vector<Character>& text,
153                       const Vector<ScriptRun>& scripts,
154                       const Vector<FontDescriptionRun>& fontDescriptions,
155                       const TextAbstraction::FontDescription& defaultFontDescription,
156                       TextAbstraction::PointSize26Dot6 defaultFontPointSize,
157                       CharacterIndex startIndex,
158                       Length numberOfCharacters,
159                       Vector<FontRun>& fonts );
160
161 private:
162   Vector<DefaultFonts*>           mDefaultFontPerScriptCache; ///< Caches default fonts for a script.
163   Vector<ValidateFontsPerScript*> mValidFontsPerScriptCache;  ///< Caches valid fonts for a script.
164 };
165
166 } // namespace Internal
167
168 inline static Internal::MultilanguageSupport& GetImplementation( MultilanguageSupport& multilanguageSupport )
169 {
170   DALI_ASSERT_ALWAYS( multilanguageSupport && "multi-language handle is empty" );
171   BaseObject& handle = multilanguageSupport.GetBaseObject();
172   return static_cast<Internal::MultilanguageSupport&>( handle );
173 }
174
175 inline static const Internal::MultilanguageSupport& GetImplementation( const MultilanguageSupport& multilanguageSupport )
176 {
177   DALI_ASSERT_ALWAYS( multilanguageSupport && "multi-language handle is empty" );
178   const BaseObject& handle = multilanguageSupport.GetBaseObject();
179   return static_cast<const Internal::MultilanguageSupport&>( handle );
180 }
181
182 } // namespace Text
183
184 } // namespace Toolkit
185
186 } // namespace Dali
187
188 #endif // DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H