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