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