Support Asynchronous Loading of Animated Image
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-label-impl.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/controls/text-controls/text-label-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry-helper.h>
23 #include <dali/public-api/common/stage.h>
24 #include <dali/devel-api/object/property-helper-devel.h>
25 #include <dali/devel-api/adaptor-framework/image-loading.h>
26 #include <dali/integration-api/debug.h>
27
28 // INTERNAL INCLUDES
29 #include <dali-toolkit/public-api/text/rendering-backend.h>
30 #include <dali-toolkit/public-api/text/text-enumerations.h>
31 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
32 #include <dali-toolkit/internal/text/property-string-parser.h>
33 #include <dali-toolkit/internal/text/rendering/text-backend.h>
34 #include <dali-toolkit/internal/text/text-effects-style.h>
35 #include <dali-toolkit/internal/text/text-font-style.h>
36 #include <dali-toolkit/internal/text/text-view.h>
37 #include <dali-toolkit/internal/text/text-definitions.h>
38 #include <dali-toolkit/internal/styling/style-manager-impl.h>
39
40 #include <dali-toolkit/public-api/align-enumerations.h>
41 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
42 #include <dali-toolkit/devel-api/controls/control-devel.h>
43 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
44 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
45 #include <dali-toolkit/public-api/visuals/visual-properties.h>
46 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
47
48 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
49
50 using namespace Dali::Toolkit::Text;
51
52 namespace Dali
53 {
54
55 namespace Toolkit
56 {
57
58 namespace Internal
59 {
60
61 namespace
62 {
63   const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
64
65   /**
66    * @brief How the text visual should be aligned vertically inside the control.
67    *
68    * 0.0f aligns the text to the top, 0.5f aligns the text to the center, 1.0f aligns the text to the bottom.
69    * The alignment depends on the alignment value of the text label (Use Text::VerticalAlignment enumerations).
70    */
71   const float VERTICAL_ALIGNMENT_TABLE[ Text::VerticalAlignment::BOTTOM + 1 ] =
72   {
73     0.0f,  // VerticalAlignment::TOP
74     0.5f,  // VerticalAlignment::CENTER
75     1.0f   // VerticalAlignment::BOTTOM
76   };
77
78   const std::string TEXT_FIT_ENABLE_KEY( "enable" );
79   const std::string TEXT_FIT_MIN_SIZE_KEY( "minSize" );
80   const std::string TEXT_FIT_MAX_SIZE_KEY( "maxSize" );
81   const std::string TEXT_FIT_STEP_SIZE_KEY( "stepSize" );
82   const std::string TEXT_FIT_FONT_SIZE_TYPE_KEY( "fontSizeType" );
83 }
84
85 namespace
86 {
87
88 #if defined ( DEBUG_ENABLED )
89   Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
90 #endif
91
92 const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] =
93 {
94   { "IMMEDIATE", Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE },
95   { "FINISH_LOOP",  Toolkit::TextLabel::AutoScrollStopMode::FINISH_LOOP  },
96 };
97 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof( AUTO_SCROLL_STOP_MODE_TABLE ) / sizeof( AUTO_SCROLL_STOP_MODE_TABLE[0] );
98
99 // Type registration
100 BaseHandle Create()
101 {
102   return Toolkit::TextLabel::New();
103 }
104
105 // Setup properties, signals and actions using the type-registry.
106 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
107
108 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "renderingBackend",          INTEGER, RENDERING_BACKEND          )
109 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "text",                      STRING,  TEXT                       )
110 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "fontFamily",                STRING,  FONT_FAMILY                )
111 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "fontStyle",                 MAP,     FONT_STYLE                 )
112 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "pointSize",                 FLOAT,   POINT_SIZE                 )
113 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "multiLine",                 BOOLEAN, MULTI_LINE                 )
114 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "horizontalAlignment",       STRING,  HORIZONTAL_ALIGNMENT       )
115 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "verticalAlignment",         STRING,  VERTICAL_ALIGNMENT         )
116 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "enableMarkup",              BOOLEAN, ENABLE_MARKUP              )
117 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "enableAutoScroll",          BOOLEAN, ENABLE_AUTO_SCROLL         )
118 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "autoScrollSpeed",           INTEGER, AUTO_SCROLL_SPEED          )
119 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "autoScrollLoopCount",       INTEGER, AUTO_SCROLL_LOOP_COUNT     )
120 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "autoScrollGap",             FLOAT,   AUTO_SCROLL_GAP            )
121 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "lineSpacing",               FLOAT,   LINE_SPACING               )
122 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "underline",                 MAP,     UNDERLINE                  )
123 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "shadow",                    MAP,     SHADOW                     )
124 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "emboss",                    MAP,     EMBOSS                     )
125 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "outline",                   MAP,     OUTLINE                    )
126 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "pixelSize",                 FLOAT,   PIXEL_SIZE                 )
127 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "ellipsis",                  BOOLEAN, ELLIPSIS                   )
128 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "autoScrollLoopDelay",       FLOAT,   AUTO_SCROLL_LOOP_DELAY     )
129 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "autoScrollStopMode",        STRING,  AUTO_SCROLL_STOP_MODE      )
130 DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount",                 INTEGER, LINE_COUNT                 )
131 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "lineWrapMode",              INTEGER, LINE_WRAP_MODE             )
132 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "textDirection",       INTEGER, TEXT_DIRECTION             )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "verticalLineAlignment",     INTEGER, VERTICAL_LINE_ALIGNMENT    )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "textBackground",            MAP,     BACKGROUND                 )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "ignoreSpacesAfterText",     BOOLEAN, IGNORE_SPACES_AFTER_TEXT   )
136 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "textFit",                   MAP,     TEXT_FIT                   )
138 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "minLineSize",               FLOAT,   MIN_LINE_SIZE              )
139 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor",      Color::BLACK,     TEXT_COLOR     )
140 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit,    TextLabel, "textColorRed",   TEXT_COLOR_RED,   TEXT_COLOR, 0  )
141 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit,    TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1  )
142 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit,    TextLabel, "textColorBlue",  TEXT_COLOR_BLUE,  TEXT_COLOR, 2  )
143 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit,    TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3  )
144 DALI_TYPE_REGISTRATION_END()
145
146 } // namespace
147
148 Toolkit::TextLabel TextLabel::New()
149 {
150   // Create the implementation, temporarily owned by this handle on stack
151   IntrusivePtr< TextLabel > impl = new TextLabel();
152
153   // Pass ownership to CustomActor handle
154   Toolkit::TextLabel handle( *impl );
155
156   // Second-phase init of the implementation
157   // This can only be done after the CustomActor connection has been made...
158   impl->Initialize();
159
160   return handle;
161 }
162
163 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
164 {
165   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
166
167   if( label )
168   {
169     TextLabel& impl( GetImpl( label ) );
170     switch( index )
171     {
172       case Toolkit::TextLabel::Property::RENDERING_BACKEND:
173       {
174         DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
175
176         int backend = value.Get< int >();
177
178 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
179         if( Text::RENDERING_VECTOR_BASED == backend )
180         {
181           backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
182         }
183 #endif
184         if( impl.mRenderingBackend != backend )
185         {
186           impl.mRenderingBackend = backend;
187           impl.mTextUpdateNeeded = true;
188
189           if( impl.mController )
190           {
191             // When using the vector-based rendering, the size of the GLyphs are different
192             TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
193             impl.mController->SetGlyphType( glyphType );
194           }
195         }
196         break;
197       }
198       case Toolkit::TextLabel::Property::TEXT:
199       {
200         if( impl.mController )
201         {
202           impl.mController->SetText( value.Get< std::string >() );
203         }
204         break;
205       }
206       case Toolkit::TextLabel::Property::FONT_FAMILY:
207       {
208         if( impl.mController )
209         {
210           const std::string& fontFamily = value.Get< std::string >();
211
212           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
213           impl.mController->SetDefaultFontFamily( fontFamily );
214         }
215         break;
216       }
217       case Toolkit::TextLabel::Property::FONT_STYLE:
218       {
219         SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
220         break;
221       }
222       case Toolkit::TextLabel::Property::POINT_SIZE:
223       {
224         if( impl.mController )
225         {
226           const float pointSize = value.Get< float >();
227
228           if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
229           {
230             impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
231           }
232         }
233         break;
234       }
235       case Toolkit::TextLabel::Property::MULTI_LINE:
236       {
237         if( impl.mController )
238         {
239           impl.mController->SetMultiLineEnabled( value.Get< bool >() );
240         }
241         break;
242       }
243       case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
244       {
245         if( impl.mController )
246         {
247           Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
248           if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) )
249           {
250             impl.mController->SetHorizontalAlignment( alignment );
251           }
252         }
253         break;
254       }
255       case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
256       {
257         if( impl.mController )
258         {
259           Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
260           if( Text::GetVerticalAlignmentEnumeration( value, alignment ) )
261           {
262             impl.mController->SetVerticalAlignment( alignment );
263           }
264         }
265         break;
266       }
267       case Toolkit::TextLabel::Property::ENABLE_MARKUP:
268       {
269         if( impl.mController )
270         {
271           const bool enableMarkup = value.Get<bool>();
272           impl.mController->SetMarkupProcessorEnabled( enableMarkup );
273         }
274         break;
275       }
276       case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
277       {
278         if( impl.mController )
279         {
280           const bool enableAutoScroll = value.Get<bool>();
281           // If request to auto scroll is the same as current state then do nothing.
282           if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
283           {
284              // If request is disable (false) and auto scrolling is enabled then need to stop it
285              if ( enableAutoScroll == false )
286              {
287                if( impl.mTextScroller )
288                {
289                  impl.mTextScroller->StopScrolling();
290                }
291              }
292              // If request is enable (true) then start autoscroll as not already running
293              else
294              {
295                impl.mController->SetAutoScrollEnabled( enableAutoScroll );
296              }
297           }
298         }
299         break;
300       }
301       case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
302       {
303         if( !impl.mTextScroller )
304         {
305           impl.mTextScroller = Text::TextScroller::New( impl );
306         }
307         Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
308         if( Scripting::GetEnumerationProperty< Toolkit::TextLabel::AutoScrollStopMode::Type >( value,
309                                                                                                     AUTO_SCROLL_STOP_MODE_TABLE,
310                                                                                                     AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
311                                                                                                     stopMode ) )
312         {
313             impl.mTextScroller->SetStopMode( stopMode );
314         }
315         break;
316       }
317       case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
318       {
319         if( !impl.mTextScroller )
320         {
321           impl.mTextScroller = Text::TextScroller::New( impl );
322         }
323         impl.mTextScroller->SetSpeed( value.Get<int>() );
324         break;
325       }
326       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
327       {
328         if( !impl.mTextScroller )
329         {
330           impl.mTextScroller = Text::TextScroller::New( impl );
331         }
332         impl.mTextScroller->SetLoopCount( value.Get<int>() );
333         break;
334       }
335       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
336       {
337          if( !impl.mTextScroller )
338         {
339           impl.mTextScroller = Text::TextScroller::New( impl );
340         }
341         impl.mTextScroller->SetLoopDelay( value.Get<float>() );
342         break;
343       }
344       case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
345       {
346         if( !impl.mTextScroller )
347         {
348           impl.mTextScroller = Text::TextScroller::New( impl );
349         }
350         impl.mTextScroller->SetGap( value.Get<float>() );
351         break;
352       }
353       case Toolkit::TextLabel::Property::LINE_SPACING:
354       {
355         if( impl.mController )
356         {
357           const float lineSpacing = value.Get<float>();
358
359           // Don't trigger anything if the line spacing didn't change
360           if( impl.mController->SetDefaultLineSpacing( lineSpacing ) )
361           {
362             impl.mTextUpdateNeeded = true;
363           }
364         }
365         break;
366       }
367       case Toolkit::TextLabel::Property::UNDERLINE:
368       {
369         const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
370         if( update )
371         {
372           impl.mTextUpdateNeeded = true;
373         }
374         break;
375       }
376       case Toolkit::TextLabel::Property::SHADOW:
377       {
378         const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
379         if( update )
380         {
381           impl.mTextUpdateNeeded = true;
382         }
383         break;
384       }
385       case Toolkit::TextLabel::Property::EMBOSS:
386       {
387         const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
388         if( update )
389         {
390           impl.mTextUpdateNeeded = true;
391         }
392         break;
393       }
394       case Toolkit::TextLabel::Property::OUTLINE:
395       {
396         const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
397         if( update )
398         {
399           impl.mTextUpdateNeeded = true;
400         }
401         break;
402       }
403       case Toolkit::TextLabel::Property::PIXEL_SIZE:
404       {
405         if( impl.mController )
406         {
407           const float pixelSize = value.Get< float >();
408           DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
409
410           if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
411           {
412             impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
413           }
414         }
415         break;
416       }
417       case Toolkit::TextLabel::Property::ELLIPSIS:
418       {
419         if( impl.mController )
420         {
421           const bool ellipsis = value.Get<bool>();
422           DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
423
424           impl.mController->SetTextElideEnabled( ellipsis );
425         }
426         break;
427       }
428       case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
429       {
430         if( impl.mController )
431         {
432           Text::LineWrap::Mode lineWrapMode( static_cast< Text::LineWrap::Mode >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
433           if( GetLineWrapModeEnumeration( value, lineWrapMode ) )
434           {
435             DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode );
436             impl.mController->SetLineWrapMode( lineWrapMode );
437           }
438         }
439         break;
440       }
441       case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
442       {
443         if( impl.mController && impl.mController->GetTextModel() )
444         {
445           DevelText::VerticalLineAlignment::Type alignment = static_cast<DevelText::VerticalLineAlignment::Type>( value.Get<int>() );
446
447           impl.mController->SetVerticalLineAlignment( alignment );
448
449           // Property doesn't affect the layout, only Visual must be updated
450           TextVisual::EnableRendererUpdate( impl.mVisual );
451
452           // No need to trigger full re-layout. Instead call UpdateRenderer() directly
453           TextVisual::UpdateRenderer( impl.mVisual );
454         }
455         break;
456       }
457       case Toolkit::DevelTextLabel::Property::BACKGROUND:
458       {
459         const bool update = SetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
460         if( update )
461         {
462           impl.mTextUpdateNeeded = true;
463         }
464         break;
465       }
466       case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
467       {
468         impl.mController->SetIgnoreSpacesAfterText(value.Get< bool >());
469         break;
470       }
471       case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
472       {
473         impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
474         break;
475       }
476       case Toolkit::DevelTextLabel::Property::TEXT_FIT:
477       {
478         const Property::Map& propertiesMap = value.Get<Property::Map>();
479
480         bool enabled = false;
481         float minSize = 0.f;
482         float maxSize = 0.f;
483         float stepSize = 0.f;
484         bool isMinSizeSet = false, isMaxSizeSet = false, isStepSizeSet = false;
485         Controller::FontSizeType type = Controller::FontSizeType::POINT_SIZE;
486
487         if ( !propertiesMap.Empty() )
488         {
489           const unsigned int numberOfItems = propertiesMap.Count();
490
491           // Parses and applies
492           for( unsigned int index = 0u; index < numberOfItems; ++index )
493           {
494             const KeyValuePair& valueGet = propertiesMap.GetKeyValue( index );
495
496             if( ( Controller::TextFitInfo::Property::TEXT_FIT_ENABLE == valueGet.first.indexKey ) || ( TEXT_FIT_ENABLE_KEY == valueGet.first.stringKey ) )
497             {
498               /// Enable key.
499               enabled = valueGet.second.Get< bool >();
500             }
501             else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MIN_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MIN_SIZE_KEY == valueGet.first.stringKey ) )
502             {
503               /// min size.
504               minSize = valueGet.second.Get< float >();
505               isMinSizeSet = true;
506             }
507             else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MAX_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MAX_SIZE_KEY == valueGet.first.stringKey ) )
508             {
509               /// max size.
510               maxSize = valueGet.second.Get< float >();
511               isMaxSizeSet = true;
512             }
513             else if( ( Controller::TextFitInfo::Property::TEXT_FIT_STEP_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_STEP_SIZE_KEY == valueGet.first.stringKey ) )
514             {
515               /// step size.
516               stepSize = valueGet.second.Get< float >();
517               isStepSizeSet = true;
518             }
519             else if( ( Controller::TextFitInfo::Property::TEXT_FIT_FONT_SIZE_TYPE == valueGet.first.indexKey ) || ( TEXT_FIT_FONT_SIZE_TYPE_KEY == valueGet.first.stringKey ) )
520             {
521               if( "pixelSize" == valueGet.second.Get< std::string >() )
522               {
523                 type = Controller::FontSizeType::PIXEL_SIZE;
524               }
525             }
526           }
527
528           impl.mController->SetTextFitEnabled( enabled );
529           if( isMinSizeSet )
530           {
531             impl.mController->SetTextFitMinSize( minSize, type );
532           }
533           if( isMaxSizeSet )
534           {
535             impl.mController->SetTextFitMaxSize( maxSize, type );
536           }
537           if( isStepSizeSet )
538           {
539             impl.mController->SetTextFitStepSize( stepSize, type );
540           }
541         }
542         break;
543       }
544       case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
545       {
546         if( impl.mController )
547         {
548           const float lineSize = value.Get<float>();
549
550           if( impl.mController->SetDefaultLineSize( lineSize ) )
551           {
552             impl.mTextUpdateNeeded = true;
553           }
554         }
555         break;
556       }
557     }
558
559     // Request relayout when text update is needed. It's necessary to call it
560     // as changing the property not via UI interaction brings no effect if only
561     // the mTextUpdateNeeded is changed.
562     if( impl.mTextUpdateNeeded )
563     {
564       // need to request relayout as size of text may have changed
565       impl.RequestTextRelayout();
566     }
567   }
568 }
569
570 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
571 {
572   Property::Value value;
573
574   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
575
576   if( label )
577   {
578     TextLabel& impl( GetImpl( label ) );
579     switch( index )
580     {
581       case Toolkit::TextLabel::Property::RENDERING_BACKEND:
582       {
583         DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
584
585         value = impl.mRenderingBackend;
586         break;
587       }
588       case Toolkit::TextLabel::Property::TEXT:
589       {
590         if( impl.mController )
591         {
592           std::string text;
593           impl.mController->GetText( text );
594           value = text;
595         }
596         break;
597       }
598       case Toolkit::TextLabel::Property::FONT_FAMILY:
599       {
600         if( impl.mController )
601         {
602           value = impl.mController->GetDefaultFontFamily();
603         }
604         break;
605       }
606       case Toolkit::TextLabel::Property::FONT_STYLE:
607       {
608         GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
609         break;
610       }
611       case Toolkit::TextLabel::Property::POINT_SIZE:
612       {
613         if( impl.mController )
614         {
615           value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
616         }
617         break;
618       }
619       case Toolkit::TextLabel::Property::MULTI_LINE:
620       {
621         if( impl.mController )
622         {
623           value = impl.mController->IsMultiLineEnabled();
624         }
625         break;
626       }
627       case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
628       {
629         if( impl.mController )
630         {
631           const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
632
633            if ( name )
634            {
635              value = std::string( name );
636            }
637         }
638         break;
639       }
640       case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
641       {
642         if( impl.mController )
643         {
644           const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
645           if( name )
646           {
647             value = std::string( name );
648           }
649         }
650         break;
651       }
652       case Toolkit::TextLabel::Property::ENABLE_MARKUP:
653       {
654         if( impl.mController )
655         {
656           value = impl.mController->IsMarkupProcessorEnabled();
657         }
658         break;
659       }
660       case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
661       {
662         if( impl.mController )
663         {
664           value = impl.mController->IsAutoScrollEnabled();
665         }
666         break;
667       }
668       case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
669       {
670         if( impl.mTextScroller )
671         {
672           const char* mode = Scripting::GetEnumerationName< Toolkit::TextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
673                                                                                                                  AUTO_SCROLL_STOP_MODE_TABLE,
674                                                                                                                  AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
675           if( mode )
676           {
677             value = std::string( mode );
678           }
679         }
680         break;
681       }
682       case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
683       {
684         TextLabel& impl( GetImpl( label ) );
685         if ( impl.mTextScroller )
686         {
687           value = impl.mTextScroller->GetSpeed();
688         }
689         break;
690       }
691       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
692       {
693         if( impl.mController )
694         {
695           TextLabel& impl( GetImpl( label ) );
696           if ( impl.mTextScroller )
697           {
698             value = impl.mTextScroller->GetLoopCount();
699           }
700         }
701         break;
702       }
703       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
704       {
705         if( impl.mController )
706         {
707           TextLabel& impl( GetImpl( label ) );
708           if ( impl.mTextScroller )
709           {
710             value = impl.mTextScroller->GetLoopDelay();
711           }
712         }
713         break;
714       }
715       case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
716       {
717         TextLabel& impl( GetImpl( label ) );
718         if ( impl.mTextScroller )
719         {
720           value = impl.mTextScroller->GetGap();
721         }
722         break;
723       }
724       case Toolkit::TextLabel::Property::LINE_SPACING:
725       {
726         if( impl.mController )
727         {
728           value = impl.mController->GetDefaultLineSpacing();
729         }
730         break;
731       }
732       case Toolkit::TextLabel::Property::UNDERLINE:
733       {
734         GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
735         break;
736       }
737       case Toolkit::TextLabel::Property::SHADOW:
738       {
739         GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
740         break;
741       }
742       case Toolkit::TextLabel::Property::EMBOSS:
743       {
744         GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
745         break;
746       }
747       case Toolkit::TextLabel::Property::OUTLINE:
748       {
749         GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
750         break;
751       }
752       case Toolkit::TextLabel::Property::PIXEL_SIZE:
753       {
754         if( impl.mController )
755         {
756           value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
757         }
758         break;
759       }
760       case Toolkit::TextLabel::Property::ELLIPSIS:
761       {
762         if( impl.mController )
763         {
764           value = impl.mController->IsTextElideEnabled();
765         }
766         break;
767       }
768       case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
769       {
770         if( impl.mController )
771         {
772           value = impl.mController->GetLineWrapMode();
773         }
774         break;
775       }
776       case Toolkit::TextLabel::Property::LINE_COUNT:
777       {
778         if( impl.mController )
779         {
780           float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
781           value = impl.mController->GetLineCount( width );
782         }
783         break;
784       }
785       case Toolkit::DevelTextLabel::Property::TEXT_DIRECTION:
786       {
787         if( impl.mController )
788         {
789           value = impl.mController->GetTextDirection();
790         }
791         break;
792       }
793       case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
794       {
795         if( impl.mController )
796         {
797           value = impl.mController->GetVerticalLineAlignment();
798         }
799         break;
800       }
801       case Toolkit::DevelTextLabel::Property::BACKGROUND:
802       {
803         GetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
804         break;
805       }
806       case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
807       {
808         value = impl.mController->IsIgnoreSpacesAfterText();
809         break;
810       }
811       case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
812       {
813         value = impl.mController->IsMatchSystemLanguageDirection();
814         break;
815       }
816       case Toolkit::DevelTextLabel::Property::TEXT_FIT:
817       {
818         const bool enabled = impl.mController->IsTextFitEnabled();
819         const float minSize = impl.mController->GetTextFitMinSize();
820         const float maxSize = impl.mController->GetTextFitMaxSize();
821         const float stepSize = impl.mController->GetTextFitStepSize();
822
823         Property::Map map;
824         map.Insert( TEXT_FIT_ENABLE_KEY, enabled );
825         map.Insert( TEXT_FIT_MIN_SIZE_KEY, minSize );
826         map.Insert( TEXT_FIT_MAX_SIZE_KEY, maxSize );
827         map.Insert( TEXT_FIT_STEP_SIZE_KEY, stepSize );
828         map.Insert( TEXT_FIT_FONT_SIZE_TYPE_KEY, "pointSize" );
829
830         value = map;
831         break;
832       }
833       case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
834       {
835         if( impl.mController )
836         {
837           value = impl.mController->GetDefaultLineSize();
838         }
839         break;
840       }
841     }
842   }
843
844   return value;
845 }
846
847 void TextLabel::OnInitialize()
848 {
849   Actor self = Self();
850
851   Property::Map propertyMap;
852   propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
853
854   mVisual =  Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
855   DevelControl::RegisterVisual( *this, Toolkit::TextLabel::Property::TEXT, mVisual  );
856
857   TextVisual::SetAnimatableTextColorProperty( mVisual, Toolkit::TextLabel::Property::TEXT_COLOR );
858
859   mController = TextVisual::GetController(mVisual);
860   if( mController )
861   {
862     mController->SetControlInterface(this);
863   }
864
865   // Use height-for-width negotiation by default
866   self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
867   self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
868
869   // Enable the text ellipsis.
870   mController->SetTextElideEnabled( true );   // If false then text larger than control will overflow
871
872   // Sets layoutDirection value
873   Dali::Stage stage = Dali::Stage::GetCurrent();
874   Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
875   mController->SetLayoutDirection( layoutDirection );
876
877   Layout::Engine& engine = mController->GetLayoutEngine();
878   engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
879 }
880
881 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
882 {
883   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
884
885   switch ( change )
886   {
887     case StyleChange::DEFAULT_FONT_CHANGE:
888     {
889       // Property system did not set the font so should update it.
890       const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
891       DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
892       mController->UpdateAfterFontChange( newFont );
893       RelayoutRequest();
894       break;
895     }
896     case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
897     {
898       GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
899       RelayoutRequest();
900       break;
901     }
902     case StyleChange::THEME_CHANGE:
903     {
904       // Nothing to do, let control base class handle this
905       break;
906     }
907   }
908
909   // Up call to Control
910   Control::OnStyleChange( styleManager, change );
911 }
912
913 Vector3 TextLabel::GetNaturalSize()
914 {
915   Extents padding;
916   padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
917
918   Vector3 naturalSize = mController->GetNaturalSize();
919   naturalSize.width += ( padding.start + padding.end );
920   naturalSize.height += ( padding.top + padding.bottom );
921
922   return naturalSize;
923 }
924
925 float TextLabel::GetHeightForWidth( float width )
926 {
927   Extents padding;
928   padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
929
930   return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
931 }
932
933 void TextLabel::OnPropertySet( Property::Index index, Property::Value propertyValue )
934 {
935   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
936
937   switch ( index )
938   {
939     case Toolkit::TextLabel::Property::TEXT_COLOR:
940     {
941       const Vector4& textColor = propertyValue.Get< Vector4 >();
942       if( mController->GetDefaultColor() != textColor )
943       {
944          mController->SetDefaultColor( textColor );
945          mTextUpdateNeeded = true;
946       }
947       break;
948     }
949     default:
950     {
951       Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
952       break;
953     }
954   }
955 }
956
957 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
958 {
959   DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
960
961   Extents padding;
962   padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
963
964   Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
965
966   if( mController->IsTextFitEnabled() )
967   {
968     mController->FitPointSizeforLayout( contentSize );
969     mController->SetTextFitContentSize( contentSize );
970   }
971
972   // Support Right-To-Left
973   Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
974
975   const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
976
977   if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
978      || mTextUpdateNeeded )
979   {
980     DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
981
982     // Update the visual
983     TextVisual::EnableRendererUpdate( mVisual );
984
985     // Support Right-To-Left of padding
986     if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
987     {
988       std::swap( padding.start, padding.end );
989     }
990
991     // Calculate the size of the visual that can fit the text
992     Size layoutSize = mController->GetTextModel()->GetLayoutSize();
993     layoutSize.x = contentSize.x;
994
995     const Vector2& shadowOffset = mController->GetTextModel()->GetShadowOffset();
996     if ( shadowOffset.y > Math::MACHINE_EPSILON_1 )
997     {
998       layoutSize.y += shadowOffset.y;
999     }
1000
1001     float outlineWidth = mController->GetTextModel()->GetOutlineWidth();
1002     layoutSize.y += outlineWidth * 2.0f;
1003     layoutSize.y = std::min( layoutSize.y, contentSize.y );
1004
1005     // Calculate the offset for vertical alignment only, as the layout engine will do the horizontal alignment.
1006     Vector2 alignmentOffset;
1007     alignmentOffset.x = 0.0f;
1008     alignmentOffset.y = ( contentSize.y - layoutSize.y ) * VERTICAL_ALIGNMENT_TABLE[mController->GetVerticalAlignment()];
1009
1010     Property::Map visualTransform;
1011     visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, layoutSize )
1012                    .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
1013                    .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( padding.start, padding.top ) + alignmentOffset )
1014                    .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
1015                    .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
1016                    .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
1017     mVisual.SetTransformAndSize( visualTransform, size );
1018
1019     if ( mController->IsAutoScrollEnabled() )
1020     {
1021       SetUpAutoScrolling();
1022     }
1023
1024     mTextUpdateNeeded = false;
1025   }
1026 }
1027
1028 void TextLabel::RequestTextRelayout()
1029 {
1030   RelayoutRequest();
1031   // Signal that a Relayout may be needed
1032 }
1033
1034 void TextLabel::SetUpAutoScrolling()
1035 {
1036   const Size& controlSize = mController->GetView().GetControlSize();
1037   const Size textNaturalSize = GetNaturalSize().GetVectorXY(); // As relayout of text may not be done at this point natural size is used to get size. Single line scrolling only.
1038   const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
1039
1040   DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n",
1041                  textNaturalSize.x,textNaturalSize.y , controlSize.x,controlSize.y );
1042
1043   if ( !mTextScroller )
1044   {
1045     DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
1046
1047     // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
1048     mTextScroller = Text::TextScroller::New( *this );
1049   }
1050
1051   // Calculate the actual gap before scrolling wraps.
1052   int textPadding = std::max( controlSize.x - textNaturalSize.x, 0.0f );
1053   float wrapGap = std::max( mTextScroller->GetGap(), textPadding );
1054   Vector2 textureSize = textNaturalSize + Vector2(wrapGap, 0.0f); // Add the gap as a part of the texture
1055
1056   // Create a texture of the text for scrolling
1057   Size verifiedSize = textureSize;
1058   const int maxTextureSize = Dali::GetMaxTextureSize();
1059
1060   //if the texture size width exceed maxTextureSize, modify the visual model size and enabled the ellipsis
1061   bool actualellipsis = mController->IsTextElideEnabled();
1062   if( verifiedSize.width > maxTextureSize )
1063   {
1064     verifiedSize.width = maxTextureSize;
1065     if( textNaturalSize.width > maxTextureSize )
1066     {
1067       mController->SetTextElideEnabled( true );
1068     }
1069     GetHeightForWidth( maxTextureSize );
1070     wrapGap = std::max( maxTextureSize - textNaturalSize.width, 0.0f );
1071   }
1072
1073   Text::TypesetterPtr typesetter = Text::Typesetter::New( mController->GetTextModel() );
1074
1075   PixelData data = typesetter->Render( verifiedSize, mController->GetTextDirection(), Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888 ); // ignore the horizontal alignment
1076   Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D,
1077                                   data.GetPixelFormat(),
1078                                   data.GetWidth(),
1079                                   data.GetHeight() );
1080   texture.Upload( data );
1081
1082   TextureSet textureSet = TextureSet::New();
1083   textureSet.SetTexture( 0u, texture );
1084
1085   // Filter mode needs to be set to linear to produce better quality while scaling.
1086   Sampler sampler = Sampler::New();
1087   sampler.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
1088   sampler.SetWrapMode( Dali::WrapMode::DEFAULT, Dali::WrapMode::REPEAT, Dali::WrapMode::DEFAULT ); // Wrap the texture in the x direction
1089   textureSet.SetSampler( 0u, sampler );
1090
1091   // Set parameters for scrolling
1092   Renderer renderer = static_cast<Internal::Visual::Base&>( GetImplementation( mVisual ) ).GetRenderer();
1093   mTextScroller->SetParameters( Self(), renderer, textureSet, controlSize, verifiedSize, wrapGap, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment() );
1094   mController->SetTextElideEnabled( actualellipsis );
1095 }
1096
1097 void TextLabel::ScrollingFinished()
1098 {
1099   // Pure Virtual from TextScroller Interface
1100   DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
1101   mController->SetAutoScrollEnabled( false );
1102   RequestTextRelayout();
1103 }
1104
1105 TextLabel::TextLabel()
1106 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1107   mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1108   mTextUpdateNeeded( false )
1109 {
1110 }
1111
1112 TextLabel::~TextLabel()
1113 {
1114 }
1115
1116 } // namespace Internal
1117
1118 } // namespace Toolkit
1119
1120 } // namespace Dali