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