[4.0] Fix the issue that GetHeightForWidth returns wrong height after calling GetText...
[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) 2015 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 #include <dali/integration-api/adaptors/adaptor.h>
27
28 namespace Dali
29 {
30
31 namespace TextAbstraction
32 {
33 //Forward declaration
34 class FontClient;
35 }
36
37 namespace Toolkit
38 {
39
40 namespace Text
41 {
42
43 namespace Internal
44 {
45
46 /**
47  * @brief Stores valid font ids per script.
48  */
49 struct ValidateFontsPerScript
50 {
51   /**
52    * Default constructor.
53    */
54   ValidateFontsPerScript()
55   : mValidFonts()
56   {}
57
58   /**
59    * Default destructor.
60    */
61   ~ValidateFontsPerScript()
62   {}
63
64   /**
65    * @brief Whether the given @p fontId is in the vector of valid fonts.
66    *
67    * @param[in] fontId The font id.
68    *
69    * @return @e true if the font is in the vector of valid fonts.
70    */
71   bool IsValidFont( FontId fontId ) const;
72
73   Vector<FontId> mValidFonts;
74 };
75
76 /**
77  * @brief Stores default font ids per script. It can be different sizes for a default font family.
78  */
79 struct DefaultFonts
80 {
81   struct CacheItem
82   {
83     TextAbstraction::FontDescription description;
84     FontId fontId;
85   };
86
87   /**
88    * Default constructor.
89    */
90   DefaultFonts()
91   : mFonts()
92   {}
93
94   /**
95    * Default destructor.
96    */
97   ~DefaultFonts()
98   {}
99
100   /**
101    * @brief Finds a default font for the given @p size.
102    *
103    * @param[in] fontClient The font client.
104    * @param[in] description The font's description.
105    * @param[in] size The given size.
106    *
107    * @return The font id of a default font for the given @p size. If there isn't any font cached it returns 0.
108    */
109   FontId FindFont( TextAbstraction::FontClient& fontClient,
110                    const TextAbstraction::FontDescription& description,
111                    PointSize26Dot6 size ) const;
112
113   void Cache( const TextAbstraction::FontDescription& description, FontId fontId );
114
115   std::vector<CacheItem> mFonts;
116 };
117
118 /**
119  * @brief Multi-language support implementation. @see Text::MultilanguageSupport.
120  */
121 class MultilanguageSupport : public BaseObject
122 {
123 public:
124
125   /**
126    * Constructor
127    */
128   MultilanguageSupport();
129
130   /**
131    * Destructor
132    *
133    * This is non-virtual since derived Handle types must not contain data or virtual methods.
134    */
135   ~MultilanguageSupport();
136
137
138   /**
139    * Dali::MultilanguageSupport::OnLanguageChanged()
140    *
141    * Get notice when system language is changed.
142    */
143   void OnLanguageChanged( Dali::Adaptor& adaptor );
144
145   /**
146    * @copydoc Dali::MultilanguageSupport::Get()
147    */
148   static Text::MultilanguageSupport Get();
149
150   /**
151    * @copydoc Dali::MultilanguageSupport::SetScripts()
152    */
153   void SetScripts( const Vector<Character>& text,
154                    CharacterIndex startIndex,
155                    Length numberOfCharacters,
156                    Vector<ScriptRun>& scripts );
157
158   /**
159    * @copydoc Dali::MultilanguageSupport::ValidateFonts()
160    */
161   void ValidateFonts( const Vector<Character>& text,
162                       const Vector<ScriptRun>& scripts,
163                       const Vector<FontDescriptionRun>& fontDescriptions,
164                       const TextAbstraction::FontDescription& defaultFontDescription,
165                       TextAbstraction::PointSize26Dot6 defaultFontPointSize,
166                       CharacterIndex startIndex,
167                       Length numberOfCharacters,
168                       Vector<FontRun>& fonts );
169
170 private:
171   Vector<DefaultFonts*>                  mDefaultFontPerScriptCache; ///< Caches default fonts for a script.
172   Vector<ValidateFontsPerScript*>        mValidFontsPerScriptCache;  ///< Caches valid fonts for a script.
173   SlotDelegate< MultilanguageSupport >   mSlotDelegate; //< SlotDelegate to listen LanguageChangedSignal.
174 };
175
176 } // namespace Internal
177
178 inline static Internal::MultilanguageSupport& GetImplementation( MultilanguageSupport& multilanguageSupport )
179 {
180   DALI_ASSERT_ALWAYS( multilanguageSupport && "multi-language handle is empty" );
181   BaseObject& handle = multilanguageSupport.GetBaseObject();
182   return static_cast<Internal::MultilanguageSupport&>( handle );
183 }
184
185 inline static const Internal::MultilanguageSupport& GetImplementation( const MultilanguageSupport& multilanguageSupport )
186 {
187   DALI_ASSERT_ALWAYS( multilanguageSupport && "multi-language handle is empty" );
188   const BaseObject& handle = multilanguageSupport.GetBaseObject();
189   return static_cast<const Internal::MultilanguageSupport&>( handle );
190 }
191
192 } // namespace Text
193
194 } // namespace Toolkit
195
196 } // namespace Dali
197
198 #endif // __DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H__