Fix for multi-language support.
[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
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   /**
81    * Default constructor.
82    */
83   DefaultFonts()
84   : mFonts()
85   {}
86
87   /**
88    * Default destructor.
89    */
90   ~DefaultFonts()
91   {}
92
93   /**
94    * @brief Finds a default font for the given @p size.
95    *
96    * @param[in] fontClient The font client.
97    * @param[in] description The font's description.
98    * @param[in] size The given size.
99    *
100    * @return The font id of a default font for the given @p size. If there isn't any font cached it returns 0.
101    */
102   FontId FindFont( TextAbstraction::FontClient& fontClient,
103                    const TextAbstraction::FontDescription& description,
104                    PointSize26Dot6 size ) const;
105
106   Vector<FontId> mFonts;
107 };
108
109 /**
110  * @brief Multi-language support implementation. @see Text::MultilanguageSupport.
111  */
112 class MultilanguageSupport : public BaseObject
113 {
114 public:
115
116   /**
117    * Constructor
118    */
119   MultilanguageSupport();
120
121   /**
122    * Destructor
123    *
124    * This is non-virtual since derived Handle types must not contain data or virtual methods.
125    */
126   ~MultilanguageSupport();
127
128   /**
129    * @copydoc Dali::MultilanguageSupport::Get()
130    */
131   static Text::MultilanguageSupport Get();
132
133   /**
134    * @copydoc Dali::MultilanguageSupport::SetScripts()
135    */
136   void SetScripts( const Vector<Character>& text,
137                    CharacterIndex startIndex,
138                    Length numberOfCharacters,
139                    Vector<ScriptRun>& scripts );
140
141   /**
142    * @copydoc Dali::MultilanguageSupport::ValidateFonts()
143    */
144   void ValidateFonts( const Vector<Character>& text,
145                       const Vector<ScriptRun>& scripts,
146                       const Vector<FontDescriptionRun>& fontDescriptions,
147                       const TextAbstraction::FontDescription& defaultFontDescription,
148                       TextAbstraction::PointSize26Dot6 defaultFontPointSize,
149                       CharacterIndex startIndex,
150                       Length numberOfCharacters,
151                       Vector<FontRun>& fonts );
152
153 private:
154   Vector<DefaultFonts*>           mDefaultFontPerScriptCache; ///< Caches default fonts for a script.
155   Vector<ValidateFontsPerScript*> mValidFontsPerScriptCache;  ///< Caches valid fonts for a script.
156 };
157
158 } // namespace Internal
159
160 inline static Internal::MultilanguageSupport& GetImplementation( MultilanguageSupport& multilanguageSupport )
161 {
162   DALI_ASSERT_ALWAYS( multilanguageSupport && "multi-language handle is empty" );
163   BaseObject& handle = multilanguageSupport.GetBaseObject();
164   return static_cast<Internal::MultilanguageSupport&>( handle );
165 }
166
167 inline static const Internal::MultilanguageSupport& GetImplementation( const MultilanguageSupport& multilanguageSupport )
168 {
169   DALI_ASSERT_ALWAYS( multilanguageSupport && "multi-language handle is empty" );
170   const BaseObject& handle = multilanguageSupport.GetBaseObject();
171   return static_cast<const Internal::MultilanguageSupport&>( handle );
172 }
173
174 } // namespace Text
175
176 } // namespace Toolkit
177
178 } // namespace Dali
179
180 #endif // __DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H__