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