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;
118 * @brief Instantly updates the renderer
119 * @param[in] visual The text visual.
121 static void UpdateRenderer( Toolkit::Visual::Base visual )
123 GetVisualObject( visual ).UpdateRenderer();
126 public: // from Visual::Base
129 * @copydoc Visual::Base::GetHeightForWidth()
131 virtual float GetHeightForWidth( float width );
134 * @copydoc Visual::Base::GetNaturalSize()
136 virtual void GetNaturalSize( Vector2& naturalSize );
139 * @copydoc Visual::Base::CreatePropertyMap()
141 virtual void DoCreatePropertyMap( Property::Map& map ) const;
144 * @copydoc Visual::Base::CreateInstancePropertyMap
146 virtual void DoCreateInstancePropertyMap( Property::Map& map ) const;
151 * @brief Constructor.
153 * @param[in] factoryCache The VisualFactoryCache object
155 TextVisual( VisualFactoryCache& factoryCache );
158 * @brief A reference counted object may only be deleted by calling Unreference().
160 virtual ~TextVisual();
165 * @copydoc Visual::Base::DoSetProperties()
167 virtual void DoSetProperties( const Property::Map& propertyMap );
170 * @copydoc Visual::Base::DoSetOnStage()
172 virtual void DoSetOnStage( Actor& actor );
175 * @copydoc Visual::Base::DoSetOffStage()
177 virtual void DoSetOffStage( Actor& actor );
180 * @copydoc Visual::Base::OnSetTransform
182 virtual void OnSetTransform();
186 * @brief Set the individual property to the given value.
188 * @param[in] index The index key used to reference this value within the initial property map.
190 * @param[in] propertyValue The value to set.
192 void DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
195 * @brief Updates the text's renderer.
197 void UpdateRenderer();
200 * @brief Removes the texture set from the renderer.
202 void RemoveTextureSet();
205 * Get the texture of the text for rendering.
206 * @param[in] size The texture size.
207 * @param[in] hasMultipleTextColors Whether the text contains multiple colors.
208 * @param[in] containsColorGlyph Whether the text contains color glyph.
209 * @param[in] styleEnabled Whether the text contains any styles (e.g. shadow, underline, etc.).
211 TextureSet GetTextTexture( const Vector2& size, bool hasMultipleTextColors, bool containsColorGlyph, bool styleEnabled );
214 * Get the text rendering shader.
215 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
216 * @param[in] hasMultipleTextColors Whether the text contains multiple colors.
217 * @param[in] containsColorGlyph Whether the text contains color glyph.
218 * @param[in] styleEnabled Whether the text contains any styles (e.g. shadow, underline, etc.).
220 Shader GetTextShader( VisualFactoryCache& factoryCache, bool hasMultipleTextColors, bool containsColorGlyph, bool styleEnabled );
223 * @brief Retrieve the text's controller.
224 * @param[in] visual The text visual.
225 * @return The text controller
227 static TextVisual& GetVisualObject( Toolkit::Visual::Base visual )
229 return static_cast<TextVisual&>( visual.GetBaseObject() );
235 * Used as an alternative to boolean so that it is obvious whether the text contains single or multiple text colors, and emoji and styles.
241 SINGLE_COLOR_TEXT = 0, ///< The text contains single color only.
242 MULTI_COLOR_TEXT = 1, ///< The text contains multiple colors.
243 NO_EMOJI = 0, ///< The text contains no emoji.
244 HAS_EMOJI = 1, ///< The text contains emoji.
245 NO_STYLES = 0, ///< The text contains contains no styles.
246 HAS_SYLES = 1 ///< The text contains contains styles.
251 Text::ControllerPtr mController; ///< The text's controller.
252 Text::TypesetterPtr mTypesetter; ///< The text's typesetter.
253 WeakHandle<Actor> mControl; ///< The control where the renderer is added.
254 Property::Index mAnimatableTextColorPropertyIndex; ///< The index of animatable text color property registered by the control.
255 bool mRendererUpdateNeeded:1; ///< The flag to indicate whether the renderer needs to be updated.
258 } // namespace Internal
260 } // namespace Toolkit
264 #endif /* DALI_TOOLKIT_INTERNAL_TEXT_VISUAL_H */