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