Add AnchorColor Property
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-label-impl.cpp
1 /*
2  * Copyright (c) 2022 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/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/adaptor-framework/image-loading.h>
24 #include <dali/devel-api/common/stage.h>
25 #include <dali/devel-api/object/property-helper-devel.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/public-api/common/dali-common.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29
30 // INTERNAL INCLUDES
31 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
32 #include <dali-toolkit/devel-api/text/rendering-backend.h>
33 #include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
34 #include <dali-toolkit/internal/styling/style-manager-impl.h>
35 #include <dali-toolkit/internal/text/property-string-parser.h>
36 #include <dali-toolkit/internal/text/rendering/text-backend.h>
37 #include <dali-toolkit/internal/text/text-definitions.h>
38 #include <dali-toolkit/internal/text/text-effects-style.h>
39 #include <dali-toolkit/internal/text/text-font-style.h>
40 #include <dali-toolkit/internal/text/text-view.h>
41 #include <dali-toolkit/public-api/text/text-enumerations.h>
42
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/devel-api/visual-factory/visual-factory.h>
46 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
47 #include <dali-toolkit/public-api/align-enumerations.h>
48 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
49 #include <dali-toolkit/public-api/visuals/visual-properties.h>
50
51 // DEVEL INCLUDES
52 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
53
54 using namespace Dali::Toolkit::Text;
55
56 namespace Dali
57 {
58 namespace Toolkit
59 {
60 namespace Internal
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 char* TEXT_FIT_ENABLE_KEY("enable");
80 const char* TEXT_FIT_MIN_SIZE_KEY("minSize");
81 const char* TEXT_FIT_MAX_SIZE_KEY("maxSize");
82 const char* TEXT_FIT_STEP_SIZE_KEY("stepSize");
83 const char* TEXT_FIT_FONT_SIZE_KEY("fontSize");
84 const char* TEXT_FIT_FONT_SIZE_TYPE_KEY("fontSizeType");
85
86 #if defined(DEBUG_ENABLED)
87 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
88 #endif
89
90 const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] =
91 {
92     {"IMMEDIATE", Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE},
93     {"FINISH_LOOP", Toolkit::TextLabel::AutoScrollStopMode::FINISH_LOOP},
94 };
95 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof(AUTO_SCROLL_STOP_MODE_TABLE) / sizeof(AUTO_SCROLL_STOP_MODE_TABLE[0]);
96
97 // Type registration
98 BaseHandle Create()
99 {
100   return Toolkit::TextLabel::New();
101 }
102
103 // clang-format off
104 // Setup properties, signals and actions using the type-registry.
105 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::TextLabel, Toolkit::Control, Create);
106
107 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "text",                         STRING,  TEXT                           )
108 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "fontFamily",                   STRING,  FONT_FAMILY                    )
109 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "fontStyle",                    MAP,     FONT_STYLE                     )
110 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "pointSize",                    FLOAT,   POINT_SIZE                     )
111 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "multiLine",                    BOOLEAN, MULTI_LINE                     )
112 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "horizontalAlignment",          STRING,  HORIZONTAL_ALIGNMENT           )
113 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "verticalAlignment",            STRING,  VERTICAL_ALIGNMENT             )
114 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "enableMarkup",                 BOOLEAN, ENABLE_MARKUP                  )
115 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "enableAutoScroll",             BOOLEAN, ENABLE_AUTO_SCROLL             )
116 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "autoScrollSpeed",              INTEGER, AUTO_SCROLL_SPEED              )
117 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "autoScrollLoopCount",          INTEGER, AUTO_SCROLL_LOOP_COUNT         )
118 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "autoScrollGap",                FLOAT,   AUTO_SCROLL_GAP                )
119 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "lineSpacing",                  FLOAT,   LINE_SPACING                   )
120 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "underline",                    MAP,     UNDERLINE                      )
121 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "shadow",                       MAP,     SHADOW                         )
122 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "emboss",                       MAP,     EMBOSS                         )
123 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "outline",                      MAP,     OUTLINE                        )
124 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "pixelSize",                    FLOAT,   PIXEL_SIZE                     )
125 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "ellipsis",                     BOOLEAN, ELLIPSIS                       )
126 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "autoScrollLoopDelay",          FLOAT,   AUTO_SCROLL_LOOP_DELAY         )
127 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "autoScrollStopMode",           STRING,  AUTO_SCROLL_STOP_MODE          )
128 DALI_PROPERTY_REGISTRATION_READ_ONLY(Toolkit,       TextLabel, "lineCount",                    INTEGER, LINE_COUNT                     )
129 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "lineWrapMode",                 INTEGER, LINE_WRAP_MODE                 )
130 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextLabel, "textDirection",                INTEGER, TEXT_DIRECTION                 )
131 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "verticalLineAlignment",        INTEGER, VERTICAL_LINE_ALIGNMENT        )
132 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "textBackground",               MAP,     BACKGROUND                     )
133 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "ignoreSpacesAfterText",        BOOLEAN, IGNORE_SPACES_AFTER_TEXT       )
134 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION)
135 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "textFit",                      MAP,     TEXT_FIT                       )
136 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "minLineSize",                  FLOAT,   MIN_LINE_SIZE                  )
137 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "renderingBackend",             INTEGER, RENDERING_BACKEND              )
138 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "fontSizeScale",                FLOAT,   FONT_SIZE_SCALE                )
139 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "enableFontSizeScale",          BOOLEAN, ENABLE_FONT_SIZE_SCALE         )
140 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "ellipsisPosition",             INTEGER, ELLIPSIS_POSITION              )
141 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "strikethrough",                MAP,     STRIKETHROUGH                  )
142 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "characterSpacing",             FLOAT,   CHARACTER_SPACING              )
143 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "relativeLineSize",             FLOAT,   RELATIVE_LINE_SIZE             )
144 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "anchorColor",                  VECTOR4, ANCHOR_COLOR                   )
145 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "anchorClickedColor",           VECTOR4, ANCHOR_CLICKED_COLOR           )
146
147 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT(Toolkit, TextLabel, "textColor",      Color::BLACK,     TEXT_COLOR   )
148 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit,    TextLabel, "textColorRed",   TEXT_COLOR_RED,   TEXT_COLOR, 0)
149 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit,    TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1)
150 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit,    TextLabel, "textColorBlue",  TEXT_COLOR_BLUE,  TEXT_COLOR, 2)
151 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit,    TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3)
152
153 DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "anchorClicked", SIGNAL_ANCHOR_CLICKED)
154 DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "textFitChanged", SIGNAL_TEXT_FIT_CHANGED)
155
156 DALI_TYPE_REGISTRATION_END()
157 // clang-format on
158
159 /// Parses the property map for the TEXT_FIT property
160 void ParseTextFitProperty(Text::ControllerPtr& controller, const Property::Map* propertiesMap)
161 {
162   if(propertiesMap && !propertiesMap->Empty())
163   {
164     bool                     enabled      = false;
165     float                    minSize      = 0.f;
166     float                    maxSize      = 0.f;
167     float                    stepSize     = 0.f;
168     bool                     isMinSizeSet = false, isMaxSizeSet = false, isStepSizeSet = false;
169     Controller::FontSizeType type = Controller::FontSizeType::POINT_SIZE;
170
171     const unsigned int numberOfItems = propertiesMap->Count();
172
173     // Parses and applies
174     for(unsigned int index = 0u; index < numberOfItems; ++index)
175     {
176       const KeyValuePair& valueGet = propertiesMap->GetKeyValue(index);
177
178       if((Controller::TextFitInfo::Property::TEXT_FIT_ENABLE == valueGet.first.indexKey) || (TEXT_FIT_ENABLE_KEY == valueGet.first.stringKey))
179       {
180         /// Enable key.
181         enabled = valueGet.second.Get<bool>();
182       }
183       else if((Controller::TextFitInfo::Property::TEXT_FIT_MIN_SIZE == valueGet.first.indexKey) || (TEXT_FIT_MIN_SIZE_KEY == valueGet.first.stringKey))
184       {
185         /// min size.
186         minSize      = valueGet.second.Get<float>();
187         isMinSizeSet = true;
188       }
189       else if((Controller::TextFitInfo::Property::TEXT_FIT_MAX_SIZE == valueGet.first.indexKey) || (TEXT_FIT_MAX_SIZE_KEY == valueGet.first.stringKey))
190       {
191         /// max size.
192         maxSize      = valueGet.second.Get<float>();
193         isMaxSizeSet = true;
194       }
195       else if((Controller::TextFitInfo::Property::TEXT_FIT_STEP_SIZE == valueGet.first.indexKey) || (TEXT_FIT_STEP_SIZE_KEY == valueGet.first.stringKey))
196       {
197         /// step size.
198         stepSize      = valueGet.second.Get<float>();
199         isStepSizeSet = true;
200       }
201       else if((Controller::TextFitInfo::Property::TEXT_FIT_FONT_SIZE_TYPE == valueGet.first.indexKey) || (TEXT_FIT_FONT_SIZE_TYPE_KEY == valueGet.first.stringKey))
202       {
203         if("pixelSize" == valueGet.second.Get<std::string>())
204         {
205           type = Controller::FontSizeType::PIXEL_SIZE;
206         }
207       }
208     }
209
210     controller->SetTextFitEnabled(enabled);
211     // The TextFit operation is performed based on the MinLineSize set in the TextLabel at the moment when the TextFit property is set.
212     // So, if you change the TextLabel's MinLineSize after setting the TextFit property, it does not affect the operation of TextFit.
213     // This may require a new LineSize item in TextFit.
214     controller->SetTextFitLineSize(controller->GetDefaultLineSize());
215     if(isMinSizeSet)
216     {
217       controller->SetTextFitMinSize(minSize, type);
218     }
219     if(isMaxSizeSet)
220     {
221       controller->SetTextFitMaxSize(maxSize, type);
222     }
223     if(isStepSizeSet)
224     {
225       controller->SetTextFitStepSize(stepSize, type);
226     }
227   }
228 }
229
230 } // namespace
231
232 Toolkit::TextLabel TextLabel::New(ControlBehaviour additionalBehaviour)
233 {
234   // Create the implementation, temporarily owned by this handle on stack
235   IntrusivePtr<TextLabel> impl = new TextLabel(additionalBehaviour);
236
237   // Pass ownership to CustomActor handle
238   Toolkit::TextLabel handle(*impl);
239
240   // Second-phase init of the implementation
241   // This can only be done after the CustomActor connection has been made...
242   impl->Initialize();
243
244   return handle;
245 }
246
247 void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
248 {
249   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast(Dali::BaseHandle(object));
250
251   if(label)
252   {
253     TextLabel& impl(GetImpl(label));
254     DALI_ASSERT_ALWAYS(impl.mController && "No text contoller");
255
256     switch(index)
257     {
258       case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
259       {
260         int backend = value.Get<int>();
261
262 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
263         if(DevelText::RENDERING_VECTOR_BASED == backend)
264         {
265           backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
266         }
267 #endif
268         if(impl.mRenderingBackend != backend)
269         {
270           impl.mRenderingBackend = backend;
271           impl.mTextUpdateNeeded = true;
272
273           // When using the vector-based rendering, the size of the GLyphs are different
274           TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
275           impl.mController->SetGlyphType(glyphType);
276         }
277         break;
278       }
279       case Toolkit::TextLabel::Property::TEXT:
280       {
281         impl.mController->SetText(value.Get<std::string>());
282
283         if(impl.mController->HasAnchors())
284         {
285           // Forward input events to controller
286           impl.EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
287         }
288         else
289         {
290           impl.DisableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
291         }
292
293         break;
294       }
295       case Toolkit::TextLabel::Property::FONT_FAMILY:
296       {
297         const std::string& fontFamily = value.Get<std::string>();
298
299         DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str());
300         impl.mController->SetDefaultFontFamily(fontFamily);
301         break;
302       }
303       case Toolkit::TextLabel::Property::FONT_STYLE:
304       {
305         SetFontStyleProperty(impl.mController, value, Text::FontStyle::DEFAULT);
306         break;
307       }
308       case Toolkit::TextLabel::Property::POINT_SIZE:
309       {
310         const float pointSize = value.Get<float>();
311
312         if(!Equals(impl.mController->GetDefaultFontSize(Text::Controller::POINT_SIZE), pointSize))
313         {
314           impl.mController->SetDefaultFontSize(pointSize, Text::Controller::POINT_SIZE);
315         }
316         break;
317       }
318       case Toolkit::TextLabel::Property::MULTI_LINE:
319       {
320         impl.mController->SetMultiLineEnabled(value.Get<bool>());
321         break;
322       }
323       case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
324       {
325         Text::HorizontalAlignment::Type alignment(static_cast<Text::HorizontalAlignment::Type>(-1)); // Set to invalid value to ensure a valid mode does get set
326         if(Text::GetHorizontalAlignmentEnumeration(value, alignment))
327         {
328           impl.mController->SetHorizontalAlignment(alignment);
329         }
330         break;
331       }
332       case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
333       {
334         Toolkit::Text::VerticalAlignment::Type alignment(static_cast<Text::VerticalAlignment::Type>(-1)); // Set to invalid value to ensure a valid mode does get set
335         if(Text::GetVerticalAlignmentEnumeration(value, alignment))
336         {
337           impl.mController->SetVerticalAlignment(alignment);
338         }
339         break;
340       }
341       case Toolkit::TextLabel::Property::ENABLE_MARKUP:
342       {
343         const bool enableMarkup = value.Get<bool>();
344         impl.mController->SetMarkupProcessorEnabled(enableMarkup);
345
346         if(impl.mController->HasAnchors())
347         {
348           // Forward input events to controller
349           impl.EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
350         }
351         else
352         {
353           impl.DisableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
354         }
355         break;
356       }
357       case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
358       {
359         const bool enableAutoScroll = value.Get<bool>();
360         impl.mLastAutoScrollEnabled = enableAutoScroll;
361         // If request to auto scroll is the same as current state then do nothing.
362         if(enableAutoScroll != impl.mController->IsAutoScrollEnabled())
363         {
364           // If request is disable (false) and auto scrolling is enabled then need to stop it
365           if(enableAutoScroll == false)
366           {
367             if(impl.mTextScroller)
368             {
369               impl.mTextScroller->StopScrolling();
370             }
371           }
372           // If request is enable (true) then start autoscroll as not already running
373           else
374           {
375             impl.mController->SetAutoScrollEnabled(enableAutoScroll);
376           }
377         }
378         break;
379       }
380       case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
381       {
382         Text::TextScrollerPtr                        textScroller = impl.GetTextScroller();
383         Toolkit::TextLabel::AutoScrollStopMode::Type stopMode     = textScroller->GetStopMode();
384         if(Scripting::GetEnumerationProperty<Toolkit::TextLabel::AutoScrollStopMode::Type>(value,
385                                                                                            AUTO_SCROLL_STOP_MODE_TABLE,
386                                                                                            AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
387                                                                                            stopMode))
388         {
389           textScroller->SetStopMode(stopMode);
390         }
391         break;
392       }
393       case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
394       {
395         impl.GetTextScroller()->SetSpeed(value.Get<int>());
396         break;
397       }
398       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
399       {
400         impl.GetTextScroller()->SetLoopCount(value.Get<int>());
401         break;
402       }
403       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
404       {
405         impl.GetTextScroller()->SetLoopDelay(value.Get<float>());
406         break;
407       }
408       case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
409       {
410         impl.GetTextScroller()->SetGap(value.Get<float>());
411         break;
412       }
413       case Toolkit::TextLabel::Property::LINE_SPACING:
414       {
415         const float lineSpacing = value.Get<float>();
416         impl.mTextUpdateNeeded  = impl.mController->SetDefaultLineSpacing(lineSpacing) || impl.mTextUpdateNeeded;
417         break;
418       }
419       case Toolkit::TextLabel::Property::UNDERLINE:
420       {
421         impl.mTextUpdateNeeded = SetUnderlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
422         break;
423       }
424       case Toolkit::TextLabel::Property::SHADOW:
425       {
426         impl.mTextUpdateNeeded = SetShadowProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
427         break;
428       }
429       case Toolkit::TextLabel::Property::EMBOSS:
430       {
431         impl.mTextUpdateNeeded = SetEmbossProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
432         break;
433       }
434       case Toolkit::TextLabel::Property::OUTLINE:
435       {
436         impl.mTextUpdateNeeded = SetOutlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
437         break;
438       }
439       case Toolkit::TextLabel::Property::PIXEL_SIZE:
440       {
441         const float pixelSize = value.Get<float>();
442         DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize);
443
444         if(!Equals(impl.mController->GetDefaultFontSize(Text::Controller::PIXEL_SIZE), pixelSize))
445         {
446           impl.mController->SetDefaultFontSize(pixelSize, Text::Controller::PIXEL_SIZE);
447         }
448         break;
449       }
450       case Toolkit::TextLabel::Property::ELLIPSIS:
451       {
452         const bool ellipsis = value.Get<bool>();
453         DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis);
454
455         impl.mController->SetTextElideEnabled(ellipsis);
456         break;
457       }
458       case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
459       {
460         Text::LineWrap::Mode lineWrapMode(static_cast<Text::LineWrap::Mode>(-1)); // Set to invalid value to ensure a valid mode does get set
461         if(GetLineWrapModeEnumeration(value, lineWrapMode))
462         {
463           DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode);
464           impl.mController->SetLineWrapMode(lineWrapMode);
465         }
466         break;
467       }
468       case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
469       {
470         if(impl.mController->GetTextModel())
471         {
472           DevelText::VerticalLineAlignment::Type alignment = static_cast<DevelText::VerticalLineAlignment::Type>(value.Get<int>());
473
474           impl.mController->SetVerticalLineAlignment(alignment);
475
476           // Property doesn't affect the layout, only Visual must be updated
477           TextVisual::EnableRendererUpdate(impl.mVisual);
478
479           // No need to trigger full re-layout. Instead call UpdateRenderer() directly
480           TextVisual::UpdateRenderer(impl.mVisual);
481         }
482         break;
483       }
484       case Toolkit::DevelTextLabel::Property::BACKGROUND:
485       {
486         impl.mTextUpdateNeeded = SetBackgroundProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
487         break;
488       }
489       case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
490       {
491         impl.mController->SetIgnoreSpacesAfterText(value.Get<bool>());
492         break;
493       }
494       case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
495       {
496         impl.mController->SetMatchLayoutDirection(value.Get<bool>() ? DevelText::MatchLayoutDirection::LOCALE : DevelText::MatchLayoutDirection::CONTENTS);
497         break;
498       }
499       case Toolkit::DevelTextLabel::Property::TEXT_FIT:
500       {
501         // If TextFitArray is enabled, this should be disabled.
502         if(impl.mController->IsTextFitArrayEnabled())
503         {
504           impl.mController->SetDefaultLineSize(impl.mController->GetCurrentLineSize());
505           impl.mController->SetTextFitArrayEnabled(false);
506         }
507
508         ParseTextFitProperty(impl.mController, value.GetMap());
509         impl.mController->SetTextFitChanged(true);
510         break;
511       }
512       case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
513       {
514         const float lineSize = value.Get<float>();
515         // If TextFitArray is enabled, do not update the default line size.
516         if(!impl.mController->IsTextFitArrayEnabled())
517         {
518           impl.mTextUpdateNeeded = impl.mController->SetDefaultLineSize(lineSize) || impl.mTextUpdateNeeded;
519         }
520         impl.mController->SetCurrentLineSize(lineSize);
521         break;
522       }
523       case Toolkit::DevelTextLabel::Property::FONT_SIZE_SCALE:
524       {
525         const float scale = value.Get<float>();
526         DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p FONT_SIZE_SCALE %f\n", impl.mController.Get(), scale);
527
528         if(!Equals(impl.mController->GetFontSizeScale(), scale))
529         {
530           impl.mController->SetFontSizeScale(scale);
531         }
532         break;
533       }
534       case Toolkit::DevelTextLabel::Property::ENABLE_FONT_SIZE_SCALE:
535       {
536         const bool enableFontSizeScale = value.Get<bool>();
537         if(!Equals(impl.mController->IsFontSizeScaleEnabled(), enableFontSizeScale))
538         {
539           impl.mController->SetFontSizeScaleEnabled(enableFontSizeScale);
540         }
541         break;
542       }
543       case Toolkit::DevelTextLabel::Property::ELLIPSIS_POSITION:
544       {
545         DevelText::EllipsisPosition::Type ellipsisPositionType(static_cast<DevelText::EllipsisPosition::Type>(-1)); // Set to invalid value to ensure a valid mode does get set
546         if(GetEllipsisPositionTypeEnumeration(value, ellipsisPositionType))
547         {
548           DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p EllipsisPosition::Type %d\n", impl.mController.Get(), ellipsisPositionType);
549           impl.mController->SetEllipsisPosition(ellipsisPositionType);
550         }
551         break;
552       }
553       case Toolkit::DevelTextLabel::Property::STRIKETHROUGH:
554       {
555         impl.mTextUpdateNeeded = SetStrikethroughProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
556         break;
557       }
558       case Toolkit::DevelTextLabel::Property::CHARACTER_SPACING:
559       {
560         const float characterSpacing = value.Get<float>();
561         impl.mController->SetCharacterSpacing(characterSpacing);
562         break;
563       }
564       case Toolkit::DevelTextLabel::Property::RELATIVE_LINE_SIZE:
565       {
566         const float relativeLineSize = value.Get<float>();
567         DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel %p RELATIVE_LINE_SIZE %f\n", impl.mController.Get(), relativeLineSize);
568
569         impl.mController->SetRelativeLineSize(relativeLineSize);
570         break;
571       }
572       case Toolkit::DevelTextLabel::Property::ANCHOR_COLOR:
573       {
574         const Vector4& anchorColor = value.Get<Vector4>();
575         if(impl.mController->GetAnchorColor() != anchorColor)
576         {
577           impl.mController->SetAnchorColor(anchorColor);
578           impl.mTextUpdateNeeded = true;
579         }
580         break;
581       }
582       case Toolkit::DevelTextLabel::Property::ANCHOR_CLICKED_COLOR:
583       {
584         const Vector4& anchorClickedColor = value.Get<Vector4>();
585         if(impl.mController->GetAnchorClickedColor() != anchorClickedColor)
586         {
587           impl.mController->SetAnchorClickedColor(anchorClickedColor);
588           impl.mTextUpdateNeeded = true;
589         }
590         break;
591       }
592     }
593
594     // Request relayout when text update is needed. It's necessary to call it
595     // as changing the property not via UI interaction brings no effect if only
596     // the mTextUpdateNeeded is changed.
597     if(impl.mTextUpdateNeeded)
598     {
599       // need to request relayout as size of text may have changed
600       impl.RequestTextRelayout();
601     }
602   }
603 }
604
605 Text::ControllerPtr TextLabel::GetTextController()
606 {
607   return mController;
608 }
609
610 Property::Value TextLabel::GetProperty(BaseObject* object, Property::Index index)
611 {
612   Property::Value value;
613
614   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast(Dali::BaseHandle(object));
615
616   if(label)
617   {
618     TextLabel& impl(GetImpl(label));
619     DALI_ASSERT_DEBUG(impl.mController && "No text contoller");
620
621     switch(index)
622     {
623       case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
624       {
625         value = impl.mRenderingBackend;
626         break;
627       }
628       case Toolkit::TextLabel::Property::TEXT:
629       {
630         std::string text;
631         impl.mController->GetText(text);
632         value = text;
633         break;
634       }
635       case Toolkit::TextLabel::Property::FONT_FAMILY:
636       {
637         value = impl.mController->GetDefaultFontFamily();
638         break;
639       }
640       case Toolkit::TextLabel::Property::FONT_STYLE:
641       {
642         GetFontStyleProperty(impl.mController, value, Text::FontStyle::DEFAULT);
643         break;
644       }
645       case Toolkit::TextLabel::Property::POINT_SIZE:
646       {
647         value = impl.mController->GetDefaultFontSize(Text::Controller::POINT_SIZE);
648         break;
649       }
650       case Toolkit::TextLabel::Property::MULTI_LINE:
651       {
652         value = impl.mController->IsMultiLineEnabled();
653         break;
654       }
655       case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
656       {
657         const char* name = Text::GetHorizontalAlignmentString(impl.mController->GetHorizontalAlignment());
658
659         if(name)
660         {
661           value = std::string(name);
662         }
663         break;
664       }
665       case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
666       {
667         const char* name = Text::GetVerticalAlignmentString(impl.mController->GetVerticalAlignment());
668         if(name)
669         {
670           value = std::string(name);
671         }
672         break;
673       }
674       case Toolkit::TextLabel::Property::ENABLE_MARKUP:
675       {
676         value = impl.mController->IsMarkupProcessorEnabled();
677         break;
678       }
679       case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
680       {
681         value = impl.mController->IsAutoScrollEnabled();
682         break;
683       }
684       case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
685       {
686         if(impl.mTextScroller)
687         {
688           const char* mode = Scripting::GetEnumerationName<Toolkit::TextLabel::AutoScrollStopMode::Type>(impl.mTextScroller->GetStopMode(),
689                                                                                                          AUTO_SCROLL_STOP_MODE_TABLE,
690                                                                                                          AUTO_SCROLL_STOP_MODE_TABLE_COUNT);
691           if(mode)
692           {
693             value = std::string(mode);
694           }
695         }
696         break;
697       }
698       case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
699       {
700         if(impl.mTextScroller)
701         {
702           value = impl.mTextScroller->GetSpeed();
703         }
704         break;
705       }
706       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
707       {
708         if(impl.mTextScroller)
709         {
710           value = impl.mTextScroller->GetLoopCount();
711         }
712         break;
713       }
714       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
715       {
716         if(impl.mTextScroller)
717         {
718           value = impl.mTextScroller->GetLoopDelay();
719         }
720         break;
721       }
722       case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
723       {
724         if(impl.mTextScroller)
725         {
726           value = impl.mTextScroller->GetGap();
727         }
728         break;
729       }
730       case Toolkit::TextLabel::Property::LINE_SPACING:
731       {
732         value = impl.mController->GetDefaultLineSpacing();
733         break;
734       }
735       case Toolkit::TextLabel::Property::UNDERLINE:
736       {
737         GetUnderlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
738         break;
739       }
740       case Toolkit::TextLabel::Property::SHADOW:
741       {
742         GetShadowProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
743         break;
744       }
745       case Toolkit::TextLabel::Property::EMBOSS:
746       {
747         GetEmbossProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
748         break;
749       }
750       case Toolkit::TextLabel::Property::OUTLINE:
751       {
752         GetOutlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
753         break;
754       }
755       case Toolkit::TextLabel::Property::PIXEL_SIZE:
756       {
757         value = impl.mController->GetDefaultFontSize(Text::Controller::PIXEL_SIZE);
758         break;
759       }
760       case Toolkit::TextLabel::Property::ELLIPSIS:
761       {
762         value = impl.mController->IsTextElideEnabled();
763         break;
764       }
765       case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
766       {
767         value = impl.mController->GetLineWrapMode();
768         break;
769       }
770       case Toolkit::TextLabel::Property::LINE_COUNT:
771       {
772         float width = label.GetProperty(Actor::Property::SIZE_WIDTH).Get<float>();
773         value       = impl.mController->GetLineCount(width);
774         break;
775       }
776       case Toolkit::DevelTextLabel::Property::TEXT_DIRECTION:
777       {
778         value = impl.mController->GetTextDirection();
779         break;
780       }
781       case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
782       {
783         value = impl.mController->GetVerticalLineAlignment();
784         break;
785       }
786       case Toolkit::DevelTextLabel::Property::BACKGROUND:
787       {
788         GetBackgroundProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
789         break;
790       }
791       case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
792       {
793         value = impl.mController->IsIgnoreSpacesAfterText();
794         break;
795       }
796       case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
797       {
798         value = impl.mController->GetMatchLayoutDirection() != DevelText::MatchLayoutDirection::CONTENTS;
799         break;
800       }
801       case Toolkit::DevelTextLabel::Property::TEXT_FIT:
802       {
803         const bool  enabled   = impl.mController->IsTextFitEnabled();
804         const float minSize   = impl.mController->GetTextFitMinSize();
805         const float maxSize   = impl.mController->GetTextFitMaxSize();
806         const float stepSize  = impl.mController->GetTextFitStepSize();
807         const float pointSize = impl.mController->GetTextFitPointSize();
808
809         Property::Map map;
810         map.Insert(TEXT_FIT_ENABLE_KEY, enabled);
811         map.Insert(TEXT_FIT_MIN_SIZE_KEY, minSize);
812         map.Insert(TEXT_FIT_MAX_SIZE_KEY, maxSize);
813         map.Insert(TEXT_FIT_STEP_SIZE_KEY, stepSize);
814         map.Insert(TEXT_FIT_FONT_SIZE_KEY, pointSize);
815         map.Insert(TEXT_FIT_FONT_SIZE_TYPE_KEY, "pointSize");
816
817         value = map;
818         break;
819       }
820       case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
821       {
822         // If TextFitArray is enabled, the stored value (MIN_LINE_SIZE set by the user) is retrun.
823         value = impl.mController->IsTextFitArrayEnabled() ? impl.mController->GetCurrentLineSize() : impl.mController->GetDefaultLineSize();
824         break;
825       }
826       case Toolkit::DevelTextLabel::Property::FONT_SIZE_SCALE:
827       {
828         value = impl.mController->GetFontSizeScale();
829         break;
830       }
831       case Toolkit::DevelTextLabel::Property::ENABLE_FONT_SIZE_SCALE:
832       {
833         value = impl.mController->IsFontSizeScaleEnabled();
834         break;
835       }
836       case Toolkit::DevelTextLabel::Property::ELLIPSIS_POSITION:
837       {
838         value = impl.mController->GetEllipsisPosition();
839         break;
840       }
841       case Toolkit::DevelTextLabel::Property::STRIKETHROUGH:
842       {
843         GetStrikethroughProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
844         break;
845       }
846       case Toolkit::DevelTextLabel::Property::CHARACTER_SPACING:
847       {
848         value = impl.mController->GetCharacterSpacing();
849         break;
850       }
851       case Toolkit::DevelTextLabel::Property::RELATIVE_LINE_SIZE:
852       {
853         value = impl.mController->GetRelativeLineSize();
854         break;
855       }
856       case Toolkit::DevelTextLabel::Property::ANCHOR_COLOR:
857       {
858         value = impl.mController->GetAnchorColor();
859         break;
860       }
861       case Toolkit::DevelTextLabel::Property::ANCHOR_CLICKED_COLOR:
862       {
863         value = impl.mController->GetAnchorClickedColor();
864         break;
865       }
866     }
867   }
868
869   return value;
870 }
871
872 bool TextLabel::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
873 {
874   Dali::BaseHandle handle(object);
875
876   bool               connected(true);
877   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast(handle);
878
879   if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
880   {
881     if(label)
882     {
883       Internal::TextLabel& labelImpl(GetImpl(label));
884       labelImpl.AnchorClickedSignal().Connect(tracker, functor);
885     }
886   }
887   else if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_FIT_CHANGED))
888   {
889     if(label)
890     {
891       Internal::TextLabel& labelImpl(GetImpl(label));
892       labelImpl.TextFitChangedSignal().Connect(tracker, functor);
893     }
894   }
895   else
896   {
897     // signalName does not match any signal
898     connected = false;
899   }
900
901   return connected;
902 }
903
904 DevelTextLabel::AnchorClickedSignalType& TextLabel::AnchorClickedSignal()
905 {
906   return mAnchorClickedSignal;
907 }
908
909 DevelTextLabel::TextFitChangedSignalType& TextLabel::TextFitChangedSignal()
910 {
911   return mTextFitChangedSignal;
912 }
913
914 void TextLabel::OnInitialize()
915 {
916   Actor self = Self();
917
918   Property::Map propertyMap;
919   propertyMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT);
920
921   mVisual = Toolkit::VisualFactory::Get().CreateVisual(propertyMap);
922   DevelControl::RegisterVisual(*this, Toolkit::TextLabel::Property::TEXT, mVisual);
923
924   TextVisual::SetAnimatableTextColorProperty(mVisual, Toolkit::TextLabel::Property::TEXT_COLOR);
925
926   mController = TextVisual::GetController(mVisual);
927   DALI_ASSERT_DEBUG(mController && "Invalid Text Controller")
928
929   mController->SetControlInterface(this);
930   mController->SetAnchorControlInterface(this);
931
932   // Use height-for-width negotiation by default
933   self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
934   self.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT);
935
936   // Enable the text ellipsis.
937   mController->SetTextElideEnabled(true); // If false then text larger than control will overflow
938
939   // Sets layoutDirection value
940   Dali::Stage                 stage           = Dali::Stage::GetCurrent();
941   Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
942   mController->SetLayoutDirection(layoutDirection);
943
944   self.LayoutDirectionChangedSignal().Connect(this, &TextLabel::OnLayoutDirectionChanged);
945
946   Layout::Engine& engine = mController->GetLayoutEngine();
947   engine.SetCursorWidth(0u); // Do not layout space for the cursor.
948
949   // Accessibility
950   self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::LABEL);
951   self.SetProperty(DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
952
953   Accessibility::Bridge::EnabledSignal().Connect(this, &TextLabel::OnAccessibilityStatusChanged);
954   Accessibility::Bridge::DisabledSignal().Connect(this, &TextLabel::OnAccessibilityStatusChanged);
955 }
956
957 DevelControl::ControlAccessible* TextLabel::CreateAccessibleObject()
958 {
959   return new TextLabelAccessible(Self());
960 }
961
962 void TextLabel::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
963 {
964   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
965
966   switch(change)
967   {
968     case StyleChange::DEFAULT_FONT_CHANGE:
969     {
970       // Property system did not set the font so should update it.
971       const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
972       DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str());
973       mController->UpdateAfterFontChange(newFont);
974       RelayoutRequest();
975       break;
976     }
977     case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
978     {
979       GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
980       RelayoutRequest();
981       break;
982     }
983     case StyleChange::THEME_CHANGE:
984     {
985       // Nothing to do, let control base class handle this
986       break;
987     }
988   }
989
990   // Up call to Control
991   Control::OnStyleChange(styleManager, change);
992 }
993
994 void TextLabel::OnTap(const TapGesture& gesture)
995 {
996   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::OnTap %p\n", mController.Get());
997
998   // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
999   Extents padding;
1000   padding                   = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
1001   const Vector2& localPoint = gesture.GetLocalPoint();
1002   mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
1003 }
1004
1005 void TextLabel::AnchorClicked(const std::string& href)
1006 {
1007   Dali::Toolkit::TextLabel handle(GetOwner());
1008   mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
1009 }
1010
1011 Vector3 TextLabel::GetNaturalSize()
1012 {
1013   Extents padding;
1014   padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
1015
1016   Vector3 naturalSize = mController->GetNaturalSize();
1017   naturalSize.width += (padding.start + padding.end);
1018   naturalSize.height += (padding.top + padding.bottom);
1019
1020   return naturalSize;
1021 }
1022
1023 float TextLabel::GetHeightForWidth(float width)
1024 {
1025   Extents padding;
1026   padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
1027
1028   return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
1029 }
1030
1031 void TextLabel::OnPropertySet(Property::Index index, const Property::Value& propertyValue)
1032 {
1033   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index);
1034
1035   switch(index)
1036   {
1037     case Toolkit::TextLabel::Property::TEXT_COLOR:
1038     {
1039       const Vector4& textColor = propertyValue.Get<Vector4>();
1040       if(mController->GetDefaultColor() != textColor)
1041       {
1042         mController->SetDefaultColor(textColor);
1043         mTextUpdateNeeded = true;
1044       }
1045       break;
1046     }
1047     case Toolkit::TextLabel::Property::TEXT:
1048     case Toolkit::TextLabel::Property::ENABLE_MARKUP:
1049     {
1050       CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
1051       break;
1052     }
1053     default:
1054     {
1055       Control::OnPropertySet(index, propertyValue); // up call to control for non-handled properties
1056       break;
1057     }
1058   }
1059 }
1060
1061 void TextLabel::OnSceneConnection(int depth)
1062 {
1063   if(mController->IsAutoScrollEnabled() || mLastAutoScrollEnabled)
1064   {
1065     mController->SetAutoScrollEnabled(true);
1066   }
1067   Control::OnSceneConnection(depth);
1068 }
1069
1070 void TextLabel::OnSceneDisconnection()
1071 {
1072   if(mTextScroller)
1073   {
1074     if(mLastAutoScrollEnabled && !mController->IsAutoScrollEnabled())
1075     {
1076       mLastAutoScrollEnabled = false;
1077     }
1078
1079     const Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = mTextScroller->GetStopMode();
1080     mTextScroller->SetStopMode(Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE);
1081     mTextScroller->StopScrolling();
1082     mTextScroller->SetStopMode(stopMode);
1083   }
1084   Control::OnSceneDisconnection();
1085 }
1086
1087 void TextLabel::OnRelayout(const Vector2& size, RelayoutContainer& container)
1088 {
1089   DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnRelayout\n");
1090
1091   Actor self = Self();
1092
1093   Extents padding;
1094   padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
1095
1096   Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
1097
1098   if(mController->IsTextFitArrayEnabled())
1099   {
1100     mController->FitArrayPointSizeforLayout(contentSize);
1101     mController->SetTextFitContentSize(contentSize);
1102   }
1103   else if(mController->IsTextFitEnabled())
1104   {
1105     mController->FitPointSizeforLayout(contentSize);
1106     mController->SetTextFitContentSize(contentSize);
1107   }
1108
1109   // Support Right-To-Left
1110   Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
1111
1112   const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
1113
1114   if((Text::Controller::NONE_UPDATED != (Text::Controller::MODEL_UPDATED & updateTextType)) || mTextUpdateNeeded)
1115   {
1116     DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", (mController->IsAutoScrollEnabled()) ? "true" : "false", this);
1117
1118     // Update the visual
1119     TextVisual::EnableRendererUpdate(mVisual);
1120
1121     // Support Right-To-Left of padding
1122     if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
1123     {
1124       std::swap(padding.start, padding.end);
1125     }
1126
1127     // Calculate the size of the visual that can fit the text
1128     Size layoutSize = mController->GetTextModel()->GetLayoutSize();
1129     layoutSize.x    = contentSize.x;
1130
1131     const Vector2& shadowOffset = mController->GetTextModel()->GetShadowOffset();
1132     if(shadowOffset.y > Math::MACHINE_EPSILON_1)
1133     {
1134       layoutSize.y += shadowOffset.y;
1135     }
1136
1137     float outlineWidth = mController->GetTextModel()->GetOutlineWidth();
1138     layoutSize.y += outlineWidth * 2.0f;
1139     layoutSize.y = std::min(layoutSize.y, contentSize.y);
1140
1141     // Calculate the offset for vertical alignment only, as the layout engine will do the horizontal alignment.
1142     Vector2 alignmentOffset;
1143     alignmentOffset.x = 0.0f;
1144     alignmentOffset.y = (contentSize.y - layoutSize.y) * VERTICAL_ALIGNMENT_TABLE[mController->GetVerticalAlignment()];
1145
1146     const int maxTextureSize = Dali::GetMaxTextureSize();
1147     if(layoutSize.width > maxTextureSize)
1148     {
1149       DALI_LOG_WARNING("layoutSize(%f) > maxTextureSize(%d): To guarantee the behavior of Texture::New, layoutSize must not be bigger than maxTextureSize\n", layoutSize.width, maxTextureSize);
1150       layoutSize.width = maxTextureSize;
1151     }
1152
1153     // This affects font rendering quality.
1154     // It need to be integerized.
1155     Vector2 visualTransformOffset;
1156     visualTransformOffset.x = roundf(padding.start + alignmentOffset.x);
1157     visualTransformOffset.y = roundf(padding.top + alignmentOffset.y);
1158
1159     Property::Map visualTransform;
1160     visualTransform.Add(Toolkit::Visual::Transform::Property::SIZE, layoutSize)
1161       .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
1162       .Add(Toolkit::Visual::Transform::Property::OFFSET, visualTransformOffset)
1163       .Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
1164       .Add(Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN)
1165       .Add(Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN);
1166     mVisual.SetTransformAndSize(visualTransform, size);
1167
1168     if(mController->IsAutoScrollEnabled())
1169     {
1170       SetUpAutoScrolling();
1171     }
1172
1173     mTextUpdateNeeded = false;
1174   }
1175
1176   if(mController->IsTextFitChanged())
1177   {
1178     EmitTextFitChangedSignal();
1179     mController->SetTextFitChanged(false);
1180   }
1181 }
1182
1183 void TextLabel::RequestTextRelayout()
1184 {
1185   RelayoutRequest();
1186   // Signal that a Relayout may be needed
1187 }
1188
1189 void TextLabel::SetUpAutoScrolling()
1190 {
1191   const Size&                    controlSize     = mController->GetView().GetControlSize();
1192   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.
1193   const Text::CharacterDirection direction       = mController->GetAutoScrollDirection();
1194
1195   DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n", textNaturalSize.x, textNaturalSize.y, controlSize.x, controlSize.y);
1196
1197   if(!mTextScroller)
1198   {
1199     DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n");
1200
1201     // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
1202     mTextScroller = Text::TextScroller::New(*this);
1203   }
1204
1205   // Calculate the actual gap before scrolling wraps.
1206   int     textPadding = std::max(controlSize.x - textNaturalSize.x, 0.0f);
1207   float   wrapGap     = std::max(mTextScroller->GetGap(), textPadding);
1208   Vector2 textureSize = textNaturalSize + Vector2(wrapGap, 0.0f); // Add the gap as a part of the texture
1209
1210   // Create a texture of the text for scrolling
1211   Size      verifiedSize   = textureSize;
1212   const int maxTextureSize = Dali::GetMaxTextureSize();
1213
1214   //if the texture size width exceed maxTextureSize, modify the visual model size and enabled the ellipsis
1215   bool actualellipsis = mController->IsTextElideEnabled();
1216   if(verifiedSize.width > maxTextureSize)
1217   {
1218     verifiedSize.width = maxTextureSize;
1219     if(textNaturalSize.width > maxTextureSize)
1220     {
1221       mController->SetTextElideEnabled(true);
1222       mController->SetAutoScrollMaxTextureExceeded(true);
1223     }
1224     GetHeightForWidth(maxTextureSize);
1225     wrapGap = std::max(maxTextureSize - textNaturalSize.width, 0.0f);
1226   }
1227
1228   Text::TypesetterPtr typesetter = Text::Typesetter::New(mController->GetTextModel());
1229
1230   PixelData data    = typesetter->Render(verifiedSize, mController->GetTextDirection(), Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888); // ignore the horizontal alignment
1231   Texture   texture = Texture::New(Dali::TextureType::TEXTURE_2D,
1232                                  data.GetPixelFormat(),
1233                                  data.GetWidth(),
1234                                  data.GetHeight());
1235   texture.Upload(data);
1236
1237   TextureSet textureSet = TextureSet::New();
1238   textureSet.SetTexture(0u, texture);
1239
1240   // Filter mode needs to be set to linear to produce better quality while scaling.
1241   Sampler sampler = Sampler::New();
1242   sampler.SetFilterMode(FilterMode::LINEAR, FilterMode::LINEAR);
1243   sampler.SetWrapMode(Dali::WrapMode::DEFAULT, Dali::WrapMode::REPEAT, Dali::WrapMode::DEFAULT); // Wrap the texture in the x direction
1244   textureSet.SetSampler(0u, sampler);
1245
1246   // Set parameters for scrolling
1247   Renderer renderer = static_cast<Internal::Visual::Base&>(GetImplementation(mVisual)).GetRenderer();
1248   mTextScroller->SetParameters(Self(), renderer, textureSet, controlSize, verifiedSize, wrapGap, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment());
1249   mController->SetTextElideEnabled(actualellipsis);
1250   mController->SetAutoScrollMaxTextureExceeded(false);
1251 }
1252
1253 void TextLabel::ScrollingFinished()
1254 {
1255   // Pure Virtual from TextScroller Interface
1256   DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
1257
1258   if(mController->IsAutoScrollEnabled() || !mController->IsMultiLineEnabled())
1259   {
1260     mController->SetAutoScrollEnabled(false);
1261     RequestTextRelayout();
1262   }
1263 }
1264
1265 void TextLabel::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1266 {
1267   mController->ChangedLayoutDirection();
1268 }
1269
1270 void TextLabel::EmitTextFitChangedSignal()
1271 {
1272   Dali::Toolkit::TextLabel handle(GetOwner());
1273   mTextFitChangedSignal.Emit(handle);
1274 }
1275
1276 void TextLabel::OnAccessibilityStatusChanged()
1277 {
1278   CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
1279 }
1280
1281 TextLabel::TextLabel(ControlBehaviour additionalBehaviour)
1282 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour)),
1283   mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1284   mTextUpdateNeeded(false),
1285   mLastAutoScrollEnabled(false)
1286 {
1287 }
1288
1289 TextLabel::~TextLabel()
1290 {
1291 }
1292
1293 Vector<Vector2> TextLabel::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
1294 {
1295   return mController->GetTextSize(startIndex, endIndex);
1296 }
1297
1298 Vector<Vector2> TextLabel::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
1299 {
1300   return mController->GetTextPosition(startIndex, endIndex);
1301 }
1302
1303 Rect<float> TextLabel::GetLineBoundingRectangle(const uint32_t lineIndex) const
1304 {
1305   return mController->GetLineBoundingRectangle(lineIndex);
1306 }
1307
1308 Rect<float> TextLabel::GetCharacterBoundingRectangle(const uint32_t charIndex) const
1309 {
1310   return mController->GetCharacterBoundingRectangle(charIndex);
1311 }
1312
1313 int TextLabel::GetCharacterIndexAtPosition(float visualX, float visualY) const
1314 {
1315   return mController->GetCharacterIndexAtPosition(visualX, visualY);
1316 }
1317
1318 Rect<> TextLabel::GetTextBoundingRectangle(uint32_t startIndex, uint32_t endIndex) const
1319 {
1320   return mController->GetTextBoundingRectangle(startIndex, endIndex);
1321 }
1322
1323 void TextLabel::SetSpannedText(const Text::Spanned& spannedText)
1324 {
1325   mController->SetSpannedText(spannedText);
1326 }
1327
1328 void TextLabel::SetTextFitArray(const bool enable, std::vector<Toolkit::DevelTextLabel::FitOption>& fitOptions)
1329 {
1330   if(!enable)
1331   {
1332     // If TextFitArray is disabled, MinLineSize shoud be restored to its original size.
1333     mController->SetDefaultLineSize(mController->GetCurrentLineSize());
1334   }
1335   mController->SetTextFitArrayEnabled(enable);
1336   mController->SetTextFitArray(fitOptions);
1337 }
1338
1339 std::vector<Toolkit::DevelTextLabel::FitOption>& TextLabel::GetTextFitArray()
1340 {
1341   return mController->GetTextFitArray();
1342 }
1343
1344 bool TextLabel::IsTextFitArrayEnabled() const
1345 {
1346   return mController->IsTextFitArrayEnabled();
1347 }
1348
1349 std::string TextLabel::TextLabelAccessible::GetNameRaw() const
1350 {
1351   return GetWholeText();
1352 }
1353
1354 Property::Index TextLabel::TextLabelAccessible::GetNamePropertyIndex()
1355 {
1356   return Toolkit::TextLabel::Property::TEXT;
1357 }
1358
1359 const std::vector<Toolkit::TextAnchor>& TextLabel::TextLabelAccessible::GetTextAnchors() const
1360 {
1361   auto self = Toolkit::TextLabel::DownCast(Self());
1362
1363   return Toolkit::GetImpl(self).mAnchorActors;
1364 }
1365
1366 Toolkit::Text::ControllerPtr TextLabel::TextLabelAccessible::GetTextController() const
1367 {
1368   auto self = Toolkit::TextLabel::DownCast(Self());
1369
1370   return Toolkit::GetImpl(self).GetTextController();
1371 }
1372
1373 } // namespace Internal
1374
1375 } // namespace Toolkit
1376
1377 } // namespace Dali