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