75518d1de51579540a9c2371bbca3a05e19f6cb0
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-label-impl.cpp
1 /*
2  * Copyright (c) 2017 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/devel-api/object/property-helper-devel.h>
24 #include <dali/integration-api/debug.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/public-api/text/rendering-backend.h>
28 #include <dali-toolkit/public-api/text/text-enumerations.h>
29 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
30 #include <dali-toolkit/internal/text/property-string-parser.h>
31 #include <dali-toolkit/internal/text/rendering/text-backend.h>
32 #include <dali-toolkit/internal/text/text-effects-style.h>
33 #include <dali-toolkit/internal/text/text-font-style.h>
34 #include <dali-toolkit/internal/text/text-view.h>
35 #include <dali-toolkit/internal/text/text-definitions.h>
36 #include <dali-toolkit/internal/styling/style-manager-impl.h>
37
38 #include <dali-toolkit/public-api/align-enumerations.h>
39 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
40 #include <dali-toolkit/devel-api/controls/control-devel.h>
41 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
42 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
43 #include <dali-toolkit/public-api/visuals/visual-properties.h>
44 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
45
46 using namespace Dali::Toolkit::Text;
47
48 namespace Dali
49 {
50
51 namespace Toolkit
52 {
53
54 namespace Internal
55 {
56
57 namespace
58 {
59   const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
60 }
61
62 namespace
63 {
64
65 #if defined ( DEBUG_ENABLED )
66   Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
67 #endif
68
69 const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] =
70 {
71   { "IMMEDIATE", Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE },
72   { "FINISH_LOOP",  Toolkit::TextLabel::AutoScrollStopMode::FINISH_LOOP  },
73 };
74 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof( AUTO_SCROLL_STOP_MODE_TABLE ) / sizeof( AUTO_SCROLL_STOP_MODE_TABLE[0] );
75
76 const Scripting::StringEnum LINE_WRAP_MODE_STRING_TABLE[] =
77 {
78   { "WRAP_MODE_WORD",      Toolkit::Text::Layout::LineWrap::WORD  },
79   { "WRAP_MODE_CHARACTER", Toolkit::Text::Layout::LineWrap::CHARACTER }
80 };
81 const unsigned int LINE_WRAP_MODE_STRING_TABLE_COUNT = sizeof( LINE_WRAP_MODE_STRING_TABLE ) / sizeof( LINE_WRAP_MODE_STRING_TABLE[0] );
82
83 // Type registration
84 BaseHandle Create()
85 {
86   return Toolkit::TextLabel::New();
87 }
88
89 // Setup properties, signals and actions using the type-registry.
90 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
91
92 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "renderingBackend",          INTEGER, RENDERING_BACKEND          )
93 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "text",                      STRING,  TEXT                       )
94 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "fontFamily",                STRING,  FONT_FAMILY                )
95 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "fontStyle",                 MAP,     FONT_STYLE                 )
96 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "pointSize",                 FLOAT,   POINT_SIZE                 )
97 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "multiLine",                 BOOLEAN, MULTI_LINE                 )
98 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "horizontalAlignment",       STRING,  HORIZONTAL_ALIGNMENT       )
99 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "verticalAlignment",         STRING,  VERTICAL_ALIGNMENT         )
100 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "unusedPropertyTextColor",   VECTOR4, UNUSED_PROPERTY_TEXT_COLOR )
101 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "shadowOffset",              VECTOR2, SHADOW_OFFSET              )
102 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "shadowColor",               VECTOR4, SHADOW_COLOR               )
103 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "underlineEnabled",          BOOLEAN, UNDERLINE_ENABLED          )
104 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "underlineColor",            VECTOR4, UNDERLINE_COLOR            )
105 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "underlineHeight",           FLOAT,   UNDERLINE_HEIGHT           )
106 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "enableMarkup",              BOOLEAN, ENABLE_MARKUP              )
107 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "enableAutoScroll",          BOOLEAN, ENABLE_AUTO_SCROLL         )
108 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "autoScrollSpeed",           INTEGER, AUTO_SCROLL_SPEED          )
109 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "autoScrollLoopCount",       INTEGER, AUTO_SCROLL_LOOP_COUNT     )
110 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "autoScrollGap",             FLOAT,   AUTO_SCROLL_GAP            )
111 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "lineSpacing",               FLOAT,   LINE_SPACING               )
112 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "underline",                 MAP,     UNDERLINE                  )
113 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "shadow",                    MAP,     SHADOW                     )
114 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "emboss",                    MAP,     EMBOSS                     )
115 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "outline",                   MAP,     OUTLINE                    )
116 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "pixelSize",                 FLOAT,   PIXEL_SIZE                 )
117 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "ellipsis",                  BOOLEAN, ELLIPSIS                   )
118 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "autoScrollLoopDelay",       FLOAT,   AUTO_SCROLL_LOOP_DELAY     )
119 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "autoScrollStopMode",        STRING,  AUTO_SCROLL_STOP_MODE      )
120 DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount",                 INTEGER, LINE_COUNT                 )
121 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "lineWrapMode",              STRING,  LINE_WRAP_MODE             )
122 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor",      Color::BLACK,     TEXT_COLOR     )
123 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit,    TextLabel, "textColorRed",   TEXT_COLOR_RED,   TEXT_COLOR, 0  )
124 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit,    TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1  )
125 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit,    TextLabel, "textColorBlue",  TEXT_COLOR_BLUE,  TEXT_COLOR, 2  )
126 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit,    TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3  )
127 DALI_TYPE_REGISTRATION_END()
128
129 } // namespace
130
131 Toolkit::TextLabel TextLabel::New()
132 {
133   // Create the implementation, temporarily owned by this handle on stack
134   IntrusivePtr< TextLabel > impl = new TextLabel();
135
136   // Pass ownership to CustomActor handle
137   Toolkit::TextLabel handle( *impl );
138
139   // Second-phase init of the implementation
140   // This can only be done after the CustomActor connection has been made...
141   impl->Initialize();
142
143   return handle;
144 }
145
146 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
147 {
148   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
149
150   if( label )
151   {
152     TextLabel& impl( GetImpl( label ) );
153     switch( index )
154     {
155       case Toolkit::TextLabel::Property::RENDERING_BACKEND:
156       {
157         DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
158
159         int backend = value.Get< int >();
160
161 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
162         if( Text::RENDERING_VECTOR_BASED == backend )
163         {
164           backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
165         }
166 #endif
167         if( impl.mRenderingBackend != backend )
168         {
169           impl.mRenderingBackend = backend;
170           impl.mTextUpdateNeeded = true;
171
172           if( impl.mController )
173           {
174             // When using the vector-based rendering, the size of the GLyphs are different
175             TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
176             impl.mController->SetGlyphType( glyphType );
177           }
178         }
179         break;
180       }
181       case Toolkit::TextLabel::Property::TEXT:
182       {
183         if( impl.mController )
184         {
185           impl.mController->SetText( value.Get< std::string >() );
186         }
187         break;
188       }
189       case Toolkit::TextLabel::Property::FONT_FAMILY:
190       {
191         if( impl.mController )
192         {
193           const std::string& fontFamily = value.Get< std::string >();
194
195           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
196           impl.mController->SetDefaultFontFamily( fontFamily );
197         }
198         break;
199       }
200       case Toolkit::TextLabel::Property::FONT_STYLE:
201       {
202         SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
203         break;
204       }
205       case Toolkit::TextLabel::Property::POINT_SIZE:
206       {
207         if( impl.mController )
208         {
209           const float pointSize = value.Get< float >();
210
211           if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
212           {
213             impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
214           }
215         }
216         break;
217       }
218       case Toolkit::TextLabel::Property::MULTI_LINE:
219       {
220         if( impl.mController )
221         {
222           impl.mController->SetMultiLineEnabled( value.Get< bool >() );
223         }
224         break;
225       }
226       case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
227       {
228         if( impl.mController )
229         {
230           Toolkit::Text::HorizontalAlignment::Type alignment( Toolkit::Text::HorizontalAlignment::BEGIN );
231           Text::GetHorizontalAlignmentEnum( value, alignment );
232
233           impl.mController->SetHorizontalAlignment( alignment );
234
235         }
236         break;
237       }
238       case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
239       {
240         if( impl.mController )
241         {
242           Toolkit::Text::VerticalAlignment::Type alignment( Toolkit::Text::VerticalAlignment::BOTTOM );
243           Text::GetVerticalAlignmentEnum( value, alignment );
244
245           impl.mController->SetVerticalAlignment( alignment );
246         }
247         break;
248       }
249
250       case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
251       {
252         label.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, value );
253         impl.mTextUpdateNeeded = true;
254         break;
255       }
256
257       case Toolkit::TextLabel::Property::SHADOW_OFFSET:
258       {
259         if( impl.mController )
260         {
261           const Vector2& shadowOffset = value.Get< Vector2 >();
262           if ( impl.mController->GetShadowOffset() != shadowOffset )
263           {
264             impl.mController->SetShadowOffset( shadowOffset );
265             impl.mTextUpdateNeeded = true;
266           }
267         }
268         break;
269       }
270       case Toolkit::TextLabel::Property::SHADOW_COLOR:
271       {
272         if( impl.mController )
273         {
274           const Vector4& shadowColor = value.Get< Vector4 >();
275           if ( impl.mController->GetShadowColor() != shadowColor )
276           {
277             impl.mController->SetShadowColor( shadowColor );
278             impl.mTextUpdateNeeded = true;
279           }
280         }
281         break;
282       }
283       case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
284       {
285         if( impl.mController )
286         {
287           const Vector4& color = value.Get< Vector4 >();
288           if ( impl.mController->GetUnderlineColor() != color )
289           {
290             impl.mController->SetUnderlineColor( color );
291             impl.mTextUpdateNeeded = true;
292           }
293         }
294         break;
295       }
296       case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
297       {
298         if( impl.mController )
299         {
300           const bool enabled = value.Get< bool >();
301           if ( impl.mController->IsUnderlineEnabled() != enabled )
302           {
303             impl.mController->SetUnderlineEnabled( enabled );
304             impl.mTextUpdateNeeded = true;
305           }
306         }
307         break;
308       }
309
310       case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
311       {
312         if( impl.mController )
313         {
314           float height = value.Get< float >();
315           if( fabsf( impl.mController->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 )
316           {
317             impl.mController->SetUnderlineHeight( height );
318             impl.mTextUpdateNeeded = true;
319           }
320         }
321         break;
322       }
323       case Toolkit::TextLabel::Property::ENABLE_MARKUP:
324       {
325         if( impl.mController )
326         {
327           const bool enableMarkup = value.Get<bool>();
328           impl.mController->SetMarkupProcessorEnabled( enableMarkup );
329         }
330         break;
331       }
332       case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
333       {
334         if( impl.mController )
335         {
336           const bool enableAutoScroll = value.Get<bool>();
337           // If request to auto scroll is the same as current state then do nothing.
338           if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
339           {
340              // If request is disable (false) and auto scrolling is enabled then need to stop it
341              if ( enableAutoScroll == false )
342              {
343                if( impl.mTextScroller )
344                {
345                  impl.mTextScroller->StopScrolling();
346                }
347              }
348              // If request is enable (true) then start autoscroll as not already running
349              else
350              {
351                impl.mController->SetTextElideEnabled( false );
352                impl.mController->SetAutoScrollEnabled( enableAutoScroll );
353              }
354           }
355         }
356         break;
357       }
358       case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
359       {
360         if( !impl.mTextScroller )
361         {
362           impl.mTextScroller = Text::TextScroller::New( impl );
363         }
364         Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
365         if( Scripting::GetEnumerationProperty< Toolkit::TextLabel::AutoScrollStopMode::Type >( value,
366                                                                                                     AUTO_SCROLL_STOP_MODE_TABLE,
367                                                                                                     AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
368                                                                                                     stopMode ) )
369         {
370             impl.mTextScroller->SetStopMode( stopMode );
371         }
372         break;
373       }
374       case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
375       {
376         if( !impl.mTextScroller )
377         {
378           impl.mTextScroller = Text::TextScroller::New( impl );
379         }
380         impl.mTextScroller->SetSpeed( value.Get<int>() );
381         break;
382       }
383       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
384       {
385         if( !impl.mTextScroller )
386         {
387           impl.mTextScroller = Text::TextScroller::New( impl );
388         }
389         impl.mTextScroller->SetLoopCount( value.Get<int>() );
390         break;
391       }
392       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
393       {
394          if( !impl.mTextScroller )
395         {
396           impl.mTextScroller = Text::TextScroller::New( impl );
397         }
398         impl.mTextScroller->SetLoopDelay( value.Get<float>() );
399         break;
400       }
401       case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
402       {
403         if( !impl.mTextScroller )
404         {
405           impl.mTextScroller = Text::TextScroller::New( impl );
406         }
407         impl.mTextScroller->SetGap( value.Get<float>() );
408         break;
409       }
410       case Toolkit::TextLabel::Property::LINE_SPACING:
411       {
412         if( impl.mController )
413         {
414           const float lineSpacing = value.Get<float>();
415           impl.mController->SetDefaultLineSpacing( lineSpacing );
416           impl.mTextUpdateNeeded = true;
417         }
418         break;
419       }
420       case Toolkit::TextLabel::Property::UNDERLINE:
421       {
422         const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
423         if( update )
424         {
425           impl.mTextUpdateNeeded = true;
426         }
427         break;
428       }
429       case Toolkit::TextLabel::Property::SHADOW:
430       {
431         const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
432         if( update )
433         {
434           impl.mTextUpdateNeeded = true;
435         }
436         break;
437       }
438       case Toolkit::TextLabel::Property::EMBOSS:
439       {
440         const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
441         if( update )
442         {
443           impl.mTextUpdateNeeded = true;
444         }
445         break;
446       }
447       case Toolkit::TextLabel::Property::OUTLINE:
448       {
449         const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
450         if( update )
451         {
452           impl.mTextUpdateNeeded = true;
453         }
454         break;
455       }
456       case Toolkit::TextLabel::Property::PIXEL_SIZE:
457       {
458         if( impl.mController )
459         {
460           const float pixelSize = value.Get< float >();
461           DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
462
463           if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
464           {
465             impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
466           }
467         }
468         break;
469       }
470       case Toolkit::TextLabel::Property::ELLIPSIS:
471       {
472         if( impl.mController )
473         {
474           const bool ellipsis = value.Get<bool>();
475           DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
476
477           impl.mController->SetTextElideEnabled( ellipsis );
478         }
479         break;
480       }
481       case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
482       {
483         const std::string& wrapModeStr = value.Get< std::string >();
484         DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LINE_WRAP_MODE %s\n", impl.mController.Get(), wrapModeStr.c_str() );
485
486         Layout::LineWrap::Mode lineWrapMode( Layout::LineWrap::WORD );
487         if( Scripting::GetEnumeration< Layout::LineWrap::Mode >( wrapModeStr.c_str(),
488                                                                  LINE_WRAP_MODE_STRING_TABLE,
489                                                                  LINE_WRAP_MODE_STRING_TABLE_COUNT,
490                                                                  lineWrapMode ) )
491         {
492           impl.mController->SetLineWrapMode( lineWrapMode );
493         }
494         break;
495       }
496     }
497   }
498 }
499
500 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
501 {
502   Property::Value value;
503
504   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
505
506   if( label )
507   {
508     TextLabel& impl( GetImpl( label ) );
509     switch( index )
510     {
511       case Toolkit::TextLabel::Property::RENDERING_BACKEND:
512       {
513         DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
514
515         value = impl.mRenderingBackend;
516         break;
517       }
518       case Toolkit::TextLabel::Property::TEXT:
519       {
520         if( impl.mController )
521         {
522           std::string text;
523           impl.mController->GetText( text );
524           value = text;
525         }
526         break;
527       }
528       case Toolkit::TextLabel::Property::FONT_FAMILY:
529       {
530         if( impl.mController )
531         {
532           value = impl.mController->GetDefaultFontFamily();
533         }
534         break;
535       }
536       case Toolkit::TextLabel::Property::FONT_STYLE:
537       {
538         GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
539         break;
540       }
541       case Toolkit::TextLabel::Property::POINT_SIZE:
542       {
543         if( impl.mController )
544         {
545           value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
546         }
547         break;
548       }
549       case Toolkit::TextLabel::Property::MULTI_LINE:
550       {
551         if( impl.mController )
552         {
553           value = impl.mController->IsMultiLineEnabled();
554         }
555         break;
556       }
557       case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
558       {
559         if( impl.mController )
560         {
561           const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
562
563            if ( name )
564            {
565              value = std::string( name );
566            }
567         }
568         break;
569       }
570       case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
571       {
572         if( impl.mController )
573         {
574           const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
575           if( name )
576           {
577             value = std::string( name );
578           }
579         }
580         break;
581       }
582       case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
583       {
584         value = label.GetProperty( Toolkit::TextLabel::Property::TEXT_COLOR );
585         break;
586       }
587       case Toolkit::TextLabel::Property::SHADOW_OFFSET:
588       {
589         if ( impl.mController )
590         {
591           value = impl.mController->GetShadowOffset();
592         }
593         break;
594       }
595       case Toolkit::TextLabel::Property::SHADOW_COLOR:
596       {
597         if ( impl.mController )
598         {
599           value = impl.mController->GetShadowColor();
600         }
601         break;
602       }
603       case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
604       {
605         if ( impl.mController )
606         {
607           value = impl.mController->GetUnderlineColor();
608         }
609         break;
610       }
611       case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
612       {
613         if ( impl.mController )
614         {
615           value = impl.mController->IsUnderlineEnabled();
616         }
617         break;
618       }
619       case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
620       {
621         if ( impl.mController )
622         {
623           value = impl.mController->GetUnderlineHeight();
624         }
625         break;
626       }
627       case Toolkit::TextLabel::Property::ENABLE_MARKUP:
628       {
629         if( impl.mController )
630         {
631           value = impl.mController->IsMarkupProcessorEnabled();
632         }
633         break;
634       }
635       case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
636       {
637         if( impl.mController )
638         {
639           value = impl.mController->IsAutoScrollEnabled();
640         }
641         break;
642       }
643       case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
644       {
645         if( impl.mTextScroller )
646         {
647           const char* mode = Scripting::GetEnumerationName< Toolkit::TextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
648                                                                                                                  AUTO_SCROLL_STOP_MODE_TABLE,
649                                                                                                                  AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
650           if( mode )
651           {
652             value = std::string( mode );
653           }
654         }
655         break;
656       }
657       case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
658       {
659         TextLabel& impl( GetImpl( label ) );
660         if ( impl.mTextScroller )
661         {
662           value = impl.mTextScroller->GetSpeed();
663         }
664         break;
665       }
666       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
667       {
668         if( impl.mController )
669         {
670           TextLabel& impl( GetImpl( label ) );
671           if ( impl.mTextScroller )
672           {
673             value = impl.mTextScroller->GetLoopCount();
674           }
675         }
676         break;
677       }
678       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
679       {
680         if( impl.mController )
681         {
682           TextLabel& impl( GetImpl( label ) );
683           if ( impl.mTextScroller )
684           {
685             value = impl.mTextScroller->GetLoopDelay();
686           }
687         }
688         break;
689       }
690       case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
691       {
692         TextLabel& impl( GetImpl( label ) );
693         if ( impl.mTextScroller )
694         {
695           value = impl.mTextScroller->GetGap();
696         }
697         break;
698       }
699       case Toolkit::TextLabel::Property::LINE_SPACING:
700       {
701         if( impl.mController )
702         {
703           value = impl.mController->GetDefaultLineSpacing();
704         }
705         break;
706       }
707       case Toolkit::TextLabel::Property::UNDERLINE:
708       {
709         GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
710         break;
711       }
712       case Toolkit::TextLabel::Property::SHADOW:
713       {
714         GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
715         break;
716       }
717       case Toolkit::TextLabel::Property::EMBOSS:
718       {
719         GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
720         break;
721       }
722       case Toolkit::TextLabel::Property::OUTLINE:
723       {
724         GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
725         break;
726       }
727       case Toolkit::TextLabel::Property::PIXEL_SIZE:
728       {
729         if( impl.mController )
730         {
731           value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
732         }
733         break;
734       }
735       case Toolkit::TextLabel::Property::ELLIPSIS:
736       {
737         if( impl.mController )
738         {
739           value = impl.mController->IsTextElideEnabled();
740         }
741         break;
742       }
743       case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
744       {
745         if( impl.mController )
746         {
747           value = impl.mController->GetLineWrapMode();
748         }
749         break;
750       }
751       case Toolkit::TextLabel::Property::LINE_COUNT:
752       {
753         if( impl.mController )
754         {
755           float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
756           value = impl.mController->GetLineCount( width );
757         }
758         break;
759       }
760     }
761   }
762
763   return value;
764 }
765
766 void TextLabel::OnInitialize()
767 {
768   Actor self = Self();
769
770   Property::Map propertyMap;
771   propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
772
773   mVisual =  Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
774   DevelControl::RegisterVisual( *this, Toolkit::TextLabel::Property::TEXT, mVisual  );
775
776   TextVisual::SetAnimatableTextColorProperty( mVisual, Toolkit::TextLabel::Property::TEXT_COLOR );
777
778   mController = TextVisual::GetController(mVisual);
779   if( mController )
780   {
781     mController->SetControlInterface(this);
782   }
783
784   // Use height-for-width negotiation by default
785   self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
786   self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
787
788   // Enable the text ellipsis.
789   mController->SetTextElideEnabled( true );   // If false then text larger than control will overflow
790
791   Layout::Engine& engine = mController->GetLayoutEngine();
792   engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
793 }
794
795 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
796 {
797   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
798
799   switch ( change )
800   {
801     case StyleChange::DEFAULT_FONT_CHANGE:
802     {
803       // Property system did not set the font so should update it.
804       const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
805       DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
806       mController->UpdateAfterFontChange( newFont );
807       RelayoutRequest();
808       break;
809     }
810     case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
811     {
812       GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
813       RelayoutRequest();
814       break;
815     }
816     case StyleChange::THEME_CHANGE:
817     {
818       // Nothing to do, let control base class handle this
819       break;
820     }
821   }
822
823   // Up call to Control
824   Control::OnStyleChange( styleManager, change );
825 }
826
827 Vector3 TextLabel::GetNaturalSize()
828 {
829   return mController->GetNaturalSize();
830 }
831
832 float TextLabel::GetHeightForWidth( float width )
833 {
834   Padding padding;
835   Self().GetPadding( padding );
836   return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
837 }
838
839 void TextLabel::OnPropertySet( Property::Index index, Property::Value propertyValue )
840 {
841   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
842
843   switch ( index )
844   {
845     case Toolkit::TextLabel::Property::TEXT_COLOR:
846     {
847       const Vector4& textColor = propertyValue.Get< Vector4 >();
848       if( mController->GetDefaultColor() != textColor )
849       {
850          mController->SetDefaultColor( textColor );
851          mTextUpdateNeeded = true;
852       }
853       break;
854     }
855     default:
856     {
857       Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
858       break;
859     }
860   }
861 }
862
863 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
864 {
865   DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
866
867   Padding padding;
868   Self().GetPadding( padding );
869   Vector2 contentSize( size.x - ( padding.left + padding.right ), size.y - ( padding.top + padding.bottom ) );
870
871   const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
872
873   if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
874      || mTextUpdateNeeded )
875   {
876     DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
877
878     // Update the visual
879     TextVisual::EnableRendererUpdate( mVisual );
880
881     Padding padding;
882     Self().GetPadding( padding );
883
884     Property::Map visualTransform;
885     visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, contentSize )
886                    .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
887                    .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2(padding.left, padding.top) )
888                    .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
889                    .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
890                    .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
891     mVisual.SetTransformAndSize( visualTransform, size );
892
893     if ( mController->IsAutoScrollEnabled() )
894     {
895       SetUpAutoScrolling();
896     }
897
898     mTextUpdateNeeded = false;
899   }
900 }
901
902 void TextLabel::RequestTextRelayout()
903 {
904   RelayoutRequest();
905 }
906
907 void TextLabel::SetUpAutoScrolling()
908 {
909   const Size& controlSize = mController->GetView().GetControlSize();
910   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.
911   const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
912
913   DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n",
914                  textNaturalSize.x,textNaturalSize.y , controlSize.x,controlSize.y );
915
916   if ( !mTextScroller )
917   {
918     DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
919
920     // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
921     mTextScroller = Text::TextScroller::New( *this );
922   }
923
924   // Create a texture of the text for scrolling
925   Text::TypesetterPtr typesetter = Text::Typesetter::New( mController->GetTextModel() );
926   PixelData data = typesetter->Render( textNaturalSize, Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888 ); // ignore the horizontal alignment
927   Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D,
928                                   data.GetPixelFormat(),
929                                   data.GetWidth(),
930                                   data.GetHeight() );
931   texture.Upload( data );
932
933   TextureSet textureSet = TextureSet::New();
934   textureSet.SetTexture( 0u, texture );
935
936   // Filter mode needs to be set to linear to produce better quality while scaling.
937   Sampler sampler = Sampler::New();
938   sampler.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
939   textureSet.SetSampler( 0u, sampler );
940
941   // Set parameters for scrolling
942   Renderer renderer = static_cast<Internal::Visual::Base&>( GetImplementation( mVisual ) ).GetRenderer();
943   mTextScroller->SetParameters( Self(), renderer, textureSet, controlSize, textNaturalSize, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment() );
944 }
945
946 void TextLabel::ScrollingFinished()
947 {
948   // Pure Virtual from TextScroller Interface
949   DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
950   mController->SetAutoScrollEnabled( false );
951   mController->SetTextElideEnabled( true );
952   RequestTextRelayout();
953 }
954
955 TextLabel::TextLabel()
956 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
957   mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
958   mTextUpdateNeeded( false )
959 {
960 }
961
962 TextLabel::~TextLabel()
963 {
964 }
965
966 } // namespace Internal
967
968 } // namespace Toolkit
969
970 } // namespace Dali