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