1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_VISUAL_H
5 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/object/base-object.h>
23 #include <dali/public-api/object/weak-handle.h>
26 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
27 #include <dali-toolkit/internal/text/rendering/text-typesetter.h>
28 #include <dali-toolkit/internal/text/text-controller.h>
40 typedef IntrusivePtr< TextVisual > TextVisualPtr;
43 * The visual which renders text
45 * The following properties are optional:
47 * | %Property Name | Type |
48 * |---------------------|---------|
49 * | renderingBackend | INTEGER |
51 * | fontFamily | STRING |
52 * | fontStyle | STRING |
53 * | pointSize | FLOAT |
54 * | multiLine | BOOLEAN |
55 * | horizontalAlignment | STRING |
56 * | verticalAlignment | STRING |
57 * | textColor | VECTOR4 |
58 * | enableMarkup | BOOLEAN |
59 * | enableAutoScroll | BOOLEAN |
60 * | autoScrollSpeed | INTEGER |
61 * | autoScrollLoopCount | INTEGER |
62 * | autoScrollGap | INTEGER |
63 * | lineSpacing | FLOAT |
64 * | underline | STRING |
66 * | outline | STRING |
69 class TextVisual : public Visual::Base
74 * @brief Create a new text visual.
76 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
77 * @param[in] properties A Property::Map containing settings for this visual
78 * @return A smart-pointer to the newly allocated visual.
80 static TextVisualPtr New( VisualFactoryCache& factoryCache, const Property::Map& properties );
83 * @brief Converts all strings keys in property map to index keys. Property Map can then be merged correctly.
84 * @param[in,out] propertyMap containing string keys or a mix of strings and indexes. Will be changed to index keys.
86 static void ConvertStringKeysToIndexKeys( Property::Map& propertyMap );
89 * @brief Retrieve the text's controller.
90 * @param[in] visual The text visual.
91 * @return The text controller
93 static Text::ControllerPtr GetController( Toolkit::Visual::Base visual )
95 return GetVisualObject( visual ).mController;
99 * @brief Set the index of the animatable text color property.
100 * @param[in] visual The text visual.
101 * @param[in] animatablePropertyIndex The index of the animatable property
103 static void SetAnimatableTextColorProperty( Toolkit::Visual::Base visual, Property::Index animatablePropertyIndex )
105 GetVisualObject( visual ).mAnimatableTextColorPropertyIndex = animatablePropertyIndex;
109 * @brief Set the flag to trigger the textures to be initialized and renderer to be added to the control.
110 * @param[in] visual The text visual.
112 static void EnableRendererUpdate( Toolkit::Visual::Base visual )
114 GetVisualObject( visual ).mRendererUpdateNeeded = true;
117 public: // from Visual::Base
120 * @copydoc Visual::Base::GetHeightForWidth()
122 virtual float GetHeightForWidth( float width );
125 * @copydoc Visual::Base::GetNaturalSize()
127 virtual void GetNaturalSize( Vector2& naturalSize );
130 * @copydoc Visual::Base::CreatePropertyMap()
132 virtual void DoCreatePropertyMap( Property::Map& map ) const;
135 * @copydoc Visual::Base::CreateInstancePropertyMap
137 virtual void DoCreateInstancePropertyMap( Property::Map& map ) const;
142 * @brief Constructor.
144 * @param[in] factoryCache The VisualFactoryCache object
146 TextVisual( VisualFactoryCache& factoryCache );
149 * @brief A reference counted object may only be deleted by calling Unreference().
151 virtual ~TextVisual();
156 * @copydoc Visual::Base::DoSetProperties()
158 virtual void DoSetProperties( const Property::Map& propertyMap );
161 * @copydoc Visual::Base::DoSetOnStage()
163 virtual void DoSetOnStage( Actor& actor );
166 * @copydoc Visual::Base::DoSetOffStage()
168 virtual void DoSetOffStage( Actor& actor );
171 * @copydoc Visual::Base::OnSetTransform
173 virtual void OnSetTransform();
177 * @brief Set the individual property to the given value.
179 * @param[in] index The index key used to reference this value within the initial property map.
181 * @param[in] propertyValue The value to set.
183 void DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
186 * @brief Updates the text's renderer.
188 void UpdateRenderer();
191 * @brief Removes the texture set from the renderer.
193 void RemoveTextureSet();
196 * Get the texture of the text for rendering.
197 * @param[in] size The texture size.
198 * @param[in] hasMultipleTextColors Whether the text contains multiple colors.
199 * @param[in] containsEmoji Whether the text contains emoji.
200 * @param[in] styleEnabled Whether the text contains any styles (e.g. shadow, underline, etc.).
202 TextureSet GetTextTexture( const Vector2& size, bool hasMultipleTextColors, bool containsEmoji, bool styleEnabled );
205 * Get the text rendering shader.
206 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
207 * @param[in] hasMultipleTextColors Whether the text contains multiple colors.
208 * @param[in] containsEmoji Whether the text contains emoji.
209 * @param[in] styleEnabled Whether the text contains any styles (e.g. shadow, underline, etc.).
211 Shader GetTextShader( VisualFactoryCache& factoryCache, bool hasMultipleTextColors, bool containsEmoji, bool styleEnabled );
214 * @brief Retrieve the text's controller.
215 * @param[in] visual The text visual.
216 * @return The text controller
218 static TextVisual& GetVisualObject( Toolkit::Visual::Base visual )
220 return static_cast<TextVisual&>( visual.GetBaseObject() );
226 * Used as an alternative to boolean so that it is obvious whether the text contains single or multiple text colors, and emoji and styles.
232 SINGLE_COLOR_TEXT = 0, ///< The text contains single color only.
233 MULTI_COLOR_TEXT = 1, ///< The text contains multiple colors.
234 NO_EMOJI = 0, ///< The text contains no emoji.
235 HAS_EMOJI = 1, ///< The text contains emoji.
236 NO_STYLES = 0, ///< The text contains contains no styles.
237 HAS_SYLES = 1 ///< The text contains contains styles.
242 Text::ControllerPtr mController; ///< The text's controller.
243 Text::TypesetterPtr mTypesetter; ///< The text's typesetter.
244 WeakHandle<Actor> mControl; ///< The control where the renderer is added.
245 Property::Index mAnimatableTextColorPropertyIndex; ///< The index of animatable text color property registered by the control.
246 bool mRendererUpdateNeeded:1; ///< The flag to indicate whether the renderer needs to be updated.
249 } // namespace Internal
251 } // namespace Toolkit
255 #endif /* DALI_TOOLKIT_INTERNAL_TEXT_VISUAL_H */