[dali_1.2.56] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / text / text-visual.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_VISUAL_H
3
4 /*
5  * Copyright (c) 2017 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/visuals/visual-base-impl.h>
26 #include <dali-toolkit/internal/text/rendering/text-typesetter.h>
27 #include <dali-toolkit/internal/text/text-controller.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 class TextVisual;
39 typedef IntrusivePtr< TextVisual > TextVisualPtr;
40
41 /**
42  * The visual which renders text
43  *
44  * The following properties are optional:
45  *
46  * | %Property Name      | Type    |
47  * |---------------------|---------|
48  * | renderingBackend    | INTEGER |
49  * | text                | STRING  |
50  * | fontFamily          | STRING  |
51  * | fontStyle           | STRING  |
52  * | pointSize           | FLOAT   |
53  * | multiLine           | BOOLEAN |
54  * | horizontalAlignment | STRING  |
55  * | verticalAlignment   | STRING  |
56  * | textColor           | VECTOR4 |
57  * | enableMarkup        | BOOLEAN |
58  * | enableAutoScroll    | BOOLEAN |
59  * | autoScrollSpeed     | INTEGER |
60  * | autoScrollLoopCount | INTEGER |
61  * | autoScrollGap       | INTEGER |
62  * | lineSpacing         | FLOAT   |
63  * | underline           | STRING  |
64  * | shadow              | STRING  |
65  * | outline             | STRING  |
66  *
67  */
68 class TextVisual : public Visual::Base
69 {
70 public:
71
72   /**
73    * @brief Create a new text visual.
74    *
75    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
76    * @param[in] properties A Property::Map containing settings for this visual
77    * @return A smart-pointer to the newly allocated visual.
78    */
79   static TextVisualPtr New( VisualFactoryCache& factoryCache, const Property::Map& properties );
80
81   /**
82    * @brief Converts all strings keys in property map to index keys.  Property Map can then be merged correctly.
83    * @param[in,out] propertyMap containing string keys or a mix of strings and indexes. Will be changed to index keys.
84    */
85   static void ConvertStringKeysToIndexKeys( Property::Map& propertyMap );
86
87   /**
88    * @brief Retrieve the text's controller.
89    * @param[in] visual The text visual.
90    * @return The text controller
91    */
92   static Text::ControllerPtr GetController( Toolkit::Visual::Base visual )
93   {
94     return GetVisualObject( visual ).mController;
95   };
96
97   /**
98    * @brief Set the index of the animatable text color property.
99    * @param[in] visual The text visual.
100    * @param[in] animatablePropertyIndex The index of the animatable property
101    */
102   static void SetAnimatableTextColorProperty( Toolkit::Visual::Base visual, Property::Index animatablePropertyIndex )
103   {
104     GetVisualObject( visual ).mAnimatableTextColorPropertyIndex = animatablePropertyIndex;
105   };
106
107   /**
108    * @brief Set the flag to trigger the textures to be initialized and renderer to be added to the control.
109    * @param[in] visual The text visual.
110    */
111   static void EnableRendererUpdate( Toolkit::Visual::Base visual )
112   {
113     GetVisualObject( visual ).mRendererUpdateNeeded = true;
114   };
115
116 public: // from Visual::Base
117
118   /**
119    * @copydoc Visual::Base::GetHeightForWidth()
120    */
121   virtual float GetHeightForWidth( float width );
122
123   /**
124    * @copydoc Visual::Base::GetNaturalSize()
125    */
126   virtual void GetNaturalSize( Vector2& naturalSize );
127
128   /**
129    * @copydoc Visual::Base::CreatePropertyMap()
130    */
131   virtual void DoCreatePropertyMap( Property::Map& map ) const;
132
133   /**
134    * @copydoc Visual::Base::CreateInstancePropertyMap
135    */
136   virtual void DoCreateInstancePropertyMap( Property::Map& map ) const;
137
138 protected:
139
140   /**
141    * @brief Constructor.
142    *
143    * @param[in] factoryCache The VisualFactoryCache object
144    */
145   TextVisual( VisualFactoryCache& factoryCache );
146
147   /**
148    * @brief A reference counted object may only be deleted by calling Unreference().
149    */
150   virtual ~TextVisual();
151
152   // from Visual::Base
153
154   /**
155    * @copydoc Visual::Base::DoSetProperties()
156    */
157   virtual void DoSetProperties( const Property::Map& propertyMap );
158
159   /**
160    * @copydoc Visual::Base::DoSetOnStage()
161    */
162   virtual void DoSetOnStage( Actor& actor );
163
164   /**
165    * @copydoc Visual::Base::DoSetOffStage()
166    */
167   virtual void DoSetOffStage( Actor& actor );
168
169   /**
170    * @copydoc Visual::Base::OnSetTransform
171    */
172   virtual void OnSetTransform();
173
174 private:
175   /**
176    * @brief Set the individual property to the given value.
177    *
178    * @param[in] index The index key used to reference this value within the initial property map.
179    *
180    * @param[in] propertyValue The value to set.
181    */
182   void DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
183
184   /**
185    * @brief Updates the text's renderer.
186    */
187   void UpdateRenderer();
188
189   /**
190    * @brief Removes the texture set from the renderer.
191    */
192   void RemoveTextureSet();
193
194   /**
195    * Get the text rendering shader.
196    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
197    * @param[in] isRgbaTexture Whether the texture is in RGBA format.
198    */
199   Shader GetTextShader( VisualFactoryCache& factoryCache, bool isRgbaTexture );
200
201   /**
202    * @brief Retrieve the text's controller.
203    * @param[in] visual The text visual.
204    * @return The text controller
205    */
206   static TextVisual& GetVisualObject( Toolkit::Visual::Base visual )
207   {
208     return static_cast<TextVisual&>( visual.GetBaseObject() );
209   };
210
211 private:
212   Text::ControllerPtr mController;                        ///< The text's controller.
213   Text::TypesetterPtr mTypesetter;                        ///< The text's typesetter.
214   WeakHandle<Actor>   mControl;                           ///< The control where the renderer is added.
215   Property::Index     mAnimatableTextColorPropertyIndex;  ///< The index of animatable text color property registered by the control.
216   bool                mRendererUpdateNeeded:1;            ///< The flag to indicate whether the renderer needs to be updated.
217 };
218
219 } // namespace Internal
220
221 } // namespace Toolkit
222
223 } // namespace Dali
224
225 #endif /* DALI_TOOLKIT_INTERNAL_TEXT_VISUAL_H */