1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_VISUAL_H
5 * Copyright (c) 2019 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] propertyMap containing string keys or a mix of strings and indexes.
85 * @return Property::Map containing index keys.
87 static Property::Map ConvertStringKeysToIndexKeys( const Property::Map& propertyMap );
90 * @brief Retrieve the text's controller.
91 * @param[in] visual The text visual.
92 * @return The text controller
94 static Text::ControllerPtr GetController( Toolkit::Visual::Base visual )
96 return GetVisualObject( visual ).mController;
100 * @brief Set the index of the animatable text color property.
101 * @param[in] visual The text visual.
102 * @param[in] animatablePropertyIndex The index of the animatable property
104 static void SetAnimatableTextColorProperty( Toolkit::Visual::Base visual, Property::Index animatablePropertyIndex )
106 GetVisualObject( visual ).mAnimatableTextColorPropertyIndex = animatablePropertyIndex;
110 * @brief Set the flag to trigger the textures to be initialized and renderer to be added to the control.
111 * @param[in] visual The text visual.
113 static void EnableRendererUpdate( Toolkit::Visual::Base visual )
115 GetVisualObject( visual ).mRendererUpdateNeeded = true;
119 * @brief Instantly updates the renderer
120 * @param[in] visual The text visual.
122 static void UpdateRenderer( Toolkit::Visual::Base visual )
124 GetVisualObject( visual ).UpdateRenderer();
127 public: // from Visual::Base
130 * @copydoc Visual::Base::GetHeightForWidth()
132 float GetHeightForWidth( float width ) override;
135 * @copydoc Visual::Base::GetNaturalSize()
137 void GetNaturalSize( Vector2& naturalSize ) override;
140 * @copydoc Visual::Base::CreatePropertyMap()
142 void DoCreatePropertyMap( Property::Map& map ) const override;
145 * @copydoc Visual::Base::CreateInstancePropertyMap
147 void DoCreateInstancePropertyMap( Property::Map& map ) const override;
152 * @brief Constructor.
154 * @param[in] factoryCache The VisualFactoryCache object
156 TextVisual( VisualFactoryCache& factoryCache );
159 * @brief A reference counted object may only be deleted by calling Unreference().
161 virtual ~TextVisual();
166 * @copydoc Visual::Base::DoSetProperties()
168 void DoSetProperties( const Property::Map& propertyMap ) override;
171 * @copydoc Visual::Base::DoSetOnScene()
173 void DoSetOnScene( Actor& actor ) override;
176 * @copydoc Visual::Base::DoSetOffScene()
178 void DoSetOffScene( Actor& actor ) override;
181 * @copydoc Visual::Base::OnSetTransform
183 void OnSetTransform() override;
189 unsigned char* textBuffer;
190 unsigned char* styleBuffer;
191 unsigned char* maskBuffer;
194 Pixel::Format textPixelFormat;
198 TilingInfo( int width, int height, Pixel::Format textPixelFormat )
199 : textBuffer( NULL ),
204 textPixelFormat( textPixelFormat ),
229 * @brief Set the individual property to the given value.
231 * @param[in] index The index key used to reference this value within the initial property map.
233 * @param[in] propertyValue The value to set.
235 void DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
238 * @brief Updates the text's renderer.
240 void UpdateRenderer();
243 * @brief Removes the text's renderer.
245 void RemoveRenderer( Actor& actor );
248 * @brief Create a texture in textureSet and add it.
249 * @param[in] textureSet The textureSet to which the texture will be added.
250 * @param[in] data The PixelData to be uploaded to texture
251 * @param[in] sampler The sampler.
252 * @param[in] textureSetIndex The Index of TextureSet.
254 void AddTexture( TextureSet& textureSet, PixelData& data, Sampler& sampler, unsigned int textureSetIndex );
257 * @brief Convert the buffer to pixelData.
258 * @param[in] buffer The Buffer to be converted to pixelData.
259 * @param[in] width The width of pixel data.
260 * @param[in] height The height of pixel data.
261 * @param[in] offsetPosition The The buffer's start position.
262 * @param[in] textPixelFormat The PixelForma of text.
264 PixelData ConvertToPixelData( unsigned char* buffer, int width, int height, int offsetPosition, const Pixel::Format textPixelFormat );
267 * @brief Create the text's texture.
268 * @param[in] info This is the information you need to create a Tiling.
269 * @param[in] renderer The renderer to which the TextureSet will be added.
270 * @param[in] sampler The sampler.
271 * @param[in] hasMultipleTextColors Whether the text contains multiple colors.
272 * @param[in] containsColorGlyph Whether the text contains color glyph.
273 * @param[in] styleEnabled Whether the text contains any styles (e.g. shadow, underline, etc.).
275 void CreateTextureSet( TilingInfo& info, Renderer& renderer, Sampler& sampler, bool hasMultipleTextColors, bool containsColorGlyph, bool styleEnabled );
278 * Create renderer of the text for rendering.
279 * @param[in] actor The actor.
280 * @param[in] size The texture size.
281 * @param[in] hasMultipleTextColors Whether the text contains multiple colors.
282 * @param[in] containsColorGlyph Whether the text contains color glyph.
283 * @param[in] styleEnabled Whether the text contains any styles (e.g. shadow, underline, etc.).
285 void AddRenderer( Actor& actor, const Vector2& size, bool hasMultipleTextColors, bool containsColorGlyph, bool styleEnabled );
289 * Get the texture of the text for rendering.
290 * @param[in] size The texture size.
291 * @param[in] hasMultipleTextColors Whether the text contains multiple colors.
292 * @param[in] containsColorGlyph Whether the text contains color glyph.
293 * @param[in] styleEnabled Whether the text contains any styles (e.g. shadow, underline, etc.).
295 TextureSet GetTextTexture( const Vector2& size, bool hasMultipleTextColors, bool containsColorGlyph, bool styleEnabled );
298 * Get the text rendering shader.
299 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
300 * @param[in] hasMultipleTextColors Whether the text contains multiple colors.
301 * @param[in] containsColorGlyph Whether the text contains color glyph.
302 * @param[in] styleEnabled Whether the text contains any styles (e.g. shadow, underline, etc.).
304 Shader GetTextShader( VisualFactoryCache& factoryCache, bool hasMultipleTextColors, bool containsColorGlyph, bool styleEnabled );
307 * @brief Retrieve the TextVisual object.
308 * @param[in] visual A handle to the TextVisual
309 * @return The TextVisual object
311 static TextVisual& GetVisualObject( Toolkit::Visual::Base visual )
313 return static_cast< TextVisual& >( Toolkit::GetImplementation( visual ).GetVisualObject() );
318 typedef std::vector< Renderer > RendererContainer;
321 * Used as an alternative to boolean so that it is obvious whether the text contains single or multiple text colors, and emoji and styles.
327 SINGLE_COLOR_TEXT = 0, ///< The text contains single color only.
328 MULTI_COLOR_TEXT = 1, ///< The text contains multiple colors.
329 NO_EMOJI = 0, ///< The text contains no emoji.
330 HAS_EMOJI = 1, ///< The text contains emoji.
331 NO_STYLES = 0, ///< The text contains contains no styles.
332 HAS_SYLES = 1 ///< The text contains contains styles.
338 Text::ControllerPtr mController; ///< The text's controller.
339 Text::TypesetterPtr mTypesetter; ///< The text's typesetter.
340 WeakHandle<Actor> mControl; ///< The control where the renderer is added.
341 Property::Index mAnimatableTextColorPropertyIndex; ///< The index of animatable text color property registered by the control.
342 bool mRendererUpdateNeeded:1; ///< The flag to indicate whether the renderer needs to be updated.
343 RendererContainer mRendererList;
346 } // namespace Internal
348 } // namespace Toolkit
352 #endif /* DALI_TOOLKIT_INTERNAL_TEXT_VISUAL_H */