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