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