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