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