Merge remote-tracking branch 'origin/tizen' into new_text
[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 // INTERNAL INCLUDES
22 #include <dali-toolkit/public-api/text/multi-language-support.h>
23
24 // EXTERNAL INCLUDES
25 #include <dali/public-api/object/base-object.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Text
34 {
35
36 namespace Internal
37 {
38
39 /**
40  * @brief Stores valid font ids per script.
41  */
42 struct ValidateFontsPerScript
43 {
44   /**
45    * Default constructor.
46    */
47   ValidateFontsPerScript()
48   : mValidFonts()
49   {}
50
51   /**
52    * Default destructor.
53    */
54   ~ValidateFontsPerScript()
55   {}
56
57   /**
58    * @brief Whether the given @p fontId is in the vector of valid fonts.
59    *
60    * @param[in] fontId The font id.
61    *
62    * @return @e true if the font is in the vector of valid fonts.
63    */
64   bool FindValidFont( FontId fontId ) const;
65
66   Vector<FontId> mValidFonts;
67 };
68
69 /**
70  * @brief Multi-language support implementation. @see Text::MultilanguageSupport.
71  */
72 class MultilanguageSupport : public BaseObject
73 {
74 public:
75
76   /**
77    * Constructor
78    */
79   MultilanguageSupport();
80
81   /**
82    * Destructor
83    *
84    * This is non-virtual since derived Handle types must not contain data or virtual methods.
85    */
86   ~MultilanguageSupport();
87
88   /**
89    * @copydoc Dali::MultilanguageSupport::Get()
90    */
91   static Text::MultilanguageSupport Get();
92
93   /**
94    * @copydoc Dali::MultilanguageSupport::SetScripts()
95    */
96   void SetScripts( const Vector<Character>& text,
97                    Vector<ScriptRun>& scripts );
98   /**
99    * @copydoc Dali::MultilanguageSupport::ValidateFonts()
100    */
101   void ValidateFonts( const Vector<Character>& text,
102                       const Vector<ScriptRun>& scripts,
103                       Vector<FontRun>& fonts );
104
105 private:
106   Vector<FontId>                  mDefaultFontPerScriptCache; ///< Caches the default font for a script.
107   Vector<ValidateFontsPerScript*> mValidFontsPerScriptCache;  ///< Caches valid fonts for a script.
108 };
109
110 } // namespace Internal
111
112 inline static Internal::MultilanguageSupport& GetImplementation( MultilanguageSupport& multilanguageSupport )
113 {
114   DALI_ASSERT_ALWAYS( multilanguageSupport && "multi-language handle is empty" );
115   BaseObject& handle = multilanguageSupport.GetBaseObject();
116   return static_cast<Internal::MultilanguageSupport&>( handle );
117 }
118
119 inline static const Internal::MultilanguageSupport& GetImplementation( const MultilanguageSupport& multilanguageSupport )
120 {
121   DALI_ASSERT_ALWAYS( multilanguageSupport && "multi-language handle is empty" );
122   const BaseObject& handle = multilanguageSupport.GetBaseObject();
123   return static_cast<const Internal::MultilanguageSupport&>( handle );
124 }
125
126 } // namespace Text
127
128 } // namespace Toolkit
129
130 } // namespace Dali
131
132 #endif // __DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H__