2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/controls/text-controls/text-label-impl.h>
22 #include <dali/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/adaptor-framework/image-loading.h>
24 #include <dali/devel-api/common/stage.h>
25 #include <dali/devel-api/object/property-helper-devel.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/public-api/common/dali-common.h>
28 #include <dali/public-api/object/type-registry-helper.h>
31 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
32 #include <dali-toolkit/devel-api/text/rendering-backend.h>
33 #include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
34 #include <dali-toolkit/internal/styling/style-manager-impl.h>
35 #include <dali-toolkit/internal/text/property-string-parser.h>
36 #include <dali-toolkit/internal/text/rendering/text-backend.h>
37 #include <dali-toolkit/internal/text/text-definitions.h>
38 #include <dali-toolkit/internal/text/text-effects-style.h>
39 #include <dali-toolkit/internal/text/text-font-style.h>
40 #include <dali-toolkit/internal/text/text-view.h>
41 #include <dali-toolkit/public-api/text/text-enumerations.h>
43 #include <dali-toolkit/devel-api/controls/control-devel.h>
44 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
45 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
46 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
47 #include <dali-toolkit/public-api/align-enumerations.h>
48 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
49 #include <dali-toolkit/public-api/visuals/visual-properties.h>
52 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
54 using namespace Dali::Toolkit::Text;
64 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
67 * @brief How the text visual should be aligned vertically inside the control.
69 * 0.0f aligns the text to the top, 0.5f aligns the text to the center, 1.0f aligns the text to the bottom.
70 * The alignment depends on the alignment value of the text label (Use Text::VerticalAlignment enumerations).
72 const float VERTICAL_ALIGNMENT_TABLE[Text::VerticalAlignment::BOTTOM + 1] =
74 0.0f, // VerticalAlignment::TOP
75 0.5f, // VerticalAlignment::CENTER
76 1.0f // VerticalAlignment::BOTTOM
79 const std::string TEXT_FIT_ENABLE_KEY("enable");
80 const std::string TEXT_FIT_MIN_SIZE_KEY("minSize");
81 const std::string TEXT_FIT_MAX_SIZE_KEY("maxSize");
82 const std::string TEXT_FIT_STEP_SIZE_KEY("stepSize");
83 const std::string TEXT_FIT_FONT_SIZE_KEY("fontSize");
84 const std::string TEXT_FIT_FONT_SIZE_TYPE_KEY("fontSizeType");
86 #if defined(DEBUG_ENABLED)
87 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
90 const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] =
92 {"IMMEDIATE", Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE},
93 {"FINISH_LOOP", Toolkit::TextLabel::AutoScrollStopMode::FINISH_LOOP},
95 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof(AUTO_SCROLL_STOP_MODE_TABLE) / sizeof(AUTO_SCROLL_STOP_MODE_TABLE[0]);
100 return Toolkit::TextLabel::New();
104 // Setup properties, signals and actions using the type-registry.
105 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::TextLabel, Toolkit::Control, Create);
107 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "text", STRING, TEXT )
108 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "fontFamily", STRING, FONT_FAMILY )
109 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "fontStyle", MAP, FONT_STYLE )
110 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "pointSize", FLOAT, POINT_SIZE )
111 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "multiLine", BOOLEAN, MULTI_LINE )
112 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
113 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
114 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
115 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
116 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
117 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
118 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
119 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
120 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "underline", MAP, UNDERLINE )
121 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "shadow", MAP, SHADOW )
122 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "emboss", MAP, EMBOSS )
123 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "outline", MAP, OUTLINE )
124 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
125 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
126 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
127 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE )
128 DALI_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT )
129 DALI_PROPERTY_REGISTRATION(Toolkit, TextLabel, "lineWrapMode", INTEGER, LINE_WRAP_MODE )
130 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextLabel, "textDirection", INTEGER, TEXT_DIRECTION )
131 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "verticalLineAlignment", INTEGER, VERTICAL_LINE_ALIGNMENT )
132 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "textBackground", MAP, BACKGROUND )
133 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "ignoreSpacesAfterText", BOOLEAN, IGNORE_SPACES_AFTER_TEXT )
134 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION)
135 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "textFit", MAP, TEXT_FIT )
136 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "minLineSize", FLOAT, MIN_LINE_SIZE )
137 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND )
138 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "fontSizeScale", FLOAT, FONT_SIZE_SCALE )
139 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "ellipsisPosition", INTEGER, ELLIPSIS_POSITION )
140 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "strikethrough", MAP, STRIKETHROUGH )
142 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT(Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR )
143 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0)
144 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1)
145 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColorBlue", TEXT_COLOR_BLUE, TEXT_COLOR, 2)
146 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3)
148 DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "anchorClicked", SIGNAL_ANCHOR_CLICKED)
149 DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "textFitChanged", SIGNAL_TEXT_FIT_CHANGED)
151 DALI_TYPE_REGISTRATION_END()
154 /// Parses the property map for the TEXT_FIT property
155 void ParseTextFitProperty(Text::ControllerPtr& controller, const Property::Map* propertiesMap)
157 if(propertiesMap && !propertiesMap->Empty())
159 bool enabled = false;
162 float stepSize = 0.f;
163 bool isMinSizeSet = false, isMaxSizeSet = false, isStepSizeSet = false;
164 Controller::FontSizeType type = Controller::FontSizeType::POINT_SIZE;
166 const unsigned int numberOfItems = propertiesMap->Count();
168 // Parses and applies
169 for(unsigned int index = 0u; index < numberOfItems; ++index)
171 const KeyValuePair& valueGet = propertiesMap->GetKeyValue(index);
173 if((Controller::TextFitInfo::Property::TEXT_FIT_ENABLE == valueGet.first.indexKey) || (TEXT_FIT_ENABLE_KEY == valueGet.first.stringKey))
176 enabled = valueGet.second.Get<bool>();
178 else if((Controller::TextFitInfo::Property::TEXT_FIT_MIN_SIZE == valueGet.first.indexKey) || (TEXT_FIT_MIN_SIZE_KEY == valueGet.first.stringKey))
181 minSize = valueGet.second.Get<float>();
184 else if((Controller::TextFitInfo::Property::TEXT_FIT_MAX_SIZE == valueGet.first.indexKey) || (TEXT_FIT_MAX_SIZE_KEY == valueGet.first.stringKey))
187 maxSize = valueGet.second.Get<float>();
190 else if((Controller::TextFitInfo::Property::TEXT_FIT_STEP_SIZE == valueGet.first.indexKey) || (TEXT_FIT_STEP_SIZE_KEY == valueGet.first.stringKey))
193 stepSize = valueGet.second.Get<float>();
194 isStepSizeSet = true;
196 else if((Controller::TextFitInfo::Property::TEXT_FIT_FONT_SIZE_TYPE == valueGet.first.indexKey) || (TEXT_FIT_FONT_SIZE_TYPE_KEY == valueGet.first.stringKey))
198 if("pixelSize" == valueGet.second.Get<std::string>())
200 type = Controller::FontSizeType::PIXEL_SIZE;
205 controller->SetTextFitEnabled(enabled);
208 controller->SetTextFitMinSize(minSize, type);
212 controller->SetTextFitMaxSize(maxSize, type);
216 controller->SetTextFitStepSize(stepSize, type);
223 Toolkit::TextLabel TextLabel::New()
225 // Create the implementation, temporarily owned by this handle on stack
226 IntrusivePtr<TextLabel> impl = new TextLabel();
228 // Pass ownership to CustomActor handle
229 Toolkit::TextLabel handle(*impl);
231 // Second-phase init of the implementation
232 // This can only be done after the CustomActor connection has been made...
238 void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
240 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast(Dali::BaseHandle(object));
244 TextLabel& impl(GetImpl(label));
245 DALI_ASSERT_ALWAYS(impl.mController && "No text contoller");
249 case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
251 int backend = value.Get<int>();
253 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
254 if(DevelText::RENDERING_VECTOR_BASED == backend)
256 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
259 if(impl.mRenderingBackend != backend)
261 impl.mRenderingBackend = backend;
262 impl.mTextUpdateNeeded = true;
264 // When using the vector-based rendering, the size of the GLyphs are different
265 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
266 impl.mController->SetGlyphType(glyphType);
270 case Toolkit::TextLabel::Property::TEXT:
272 impl.mController->SetText(value.Get<std::string>());
274 if(impl.mController->HasAnchors())
276 // Forward input events to controller
277 impl.EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
281 impl.DisableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
286 case Toolkit::TextLabel::Property::FONT_FAMILY:
288 const std::string& fontFamily = value.Get<std::string>();
290 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str());
291 impl.mController->SetDefaultFontFamily(fontFamily);
294 case Toolkit::TextLabel::Property::FONT_STYLE:
296 SetFontStyleProperty(impl.mController, value, Text::FontStyle::DEFAULT);
299 case Toolkit::TextLabel::Property::POINT_SIZE:
301 const float pointSize = value.Get<float>();
303 if(!Equals(impl.mController->GetDefaultFontSize(Text::Controller::POINT_SIZE), pointSize))
305 impl.mController->SetDefaultFontSize(pointSize, Text::Controller::POINT_SIZE);
309 case Toolkit::TextLabel::Property::MULTI_LINE:
311 impl.mController->SetMultiLineEnabled(value.Get<bool>());
314 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
316 Text::HorizontalAlignment::Type alignment(static_cast<Text::HorizontalAlignment::Type>(-1)); // Set to invalid value to ensure a valid mode does get set
317 if(Text::GetHorizontalAlignmentEnumeration(value, alignment))
319 impl.mController->SetHorizontalAlignment(alignment);
323 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
325 Toolkit::Text::VerticalAlignment::Type alignment(static_cast<Text::VerticalAlignment::Type>(-1)); // Set to invalid value to ensure a valid mode does get set
326 if(Text::GetVerticalAlignmentEnumeration(value, alignment))
328 impl.mController->SetVerticalAlignment(alignment);
332 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
334 const bool enableMarkup = value.Get<bool>();
335 impl.mController->SetMarkupProcessorEnabled(enableMarkup);
337 if(impl.mController->HasAnchors())
339 // Forward input events to controller
340 impl.EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
344 impl.DisableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
348 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
350 const bool enableAutoScroll = value.Get<bool>();
351 // If request to auto scroll is the same as current state then do nothing.
352 if(enableAutoScroll != impl.mController->IsAutoScrollEnabled())
354 // If request is disable (false) and auto scrolling is enabled then need to stop it
355 if(enableAutoScroll == false)
357 if(impl.mTextScroller)
359 impl.mTextScroller->StopScrolling();
362 // If request is enable (true) then start autoscroll as not already running
365 impl.mController->SetAutoScrollEnabled(enableAutoScroll);
370 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
372 Text::TextScrollerPtr textScroller = impl.GetTextScroller();
373 Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = textScroller->GetStopMode();
374 if(Scripting::GetEnumerationProperty<Toolkit::TextLabel::AutoScrollStopMode::Type>(value,
375 AUTO_SCROLL_STOP_MODE_TABLE,
376 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
379 textScroller->SetStopMode(stopMode);
383 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
385 impl.GetTextScroller()->SetSpeed(value.Get<int>());
388 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
390 impl.GetTextScroller()->SetLoopCount(value.Get<int>());
393 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
395 impl.GetTextScroller()->SetLoopDelay(value.Get<float>());
398 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
400 impl.GetTextScroller()->SetGap(value.Get<float>());
403 case Toolkit::TextLabel::Property::LINE_SPACING:
405 const float lineSpacing = value.Get<float>();
406 impl.mTextUpdateNeeded = impl.mController->SetDefaultLineSpacing(lineSpacing) || impl.mTextUpdateNeeded;
409 case Toolkit::TextLabel::Property::UNDERLINE:
411 impl.mTextUpdateNeeded = SetUnderlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
414 case Toolkit::TextLabel::Property::SHADOW:
416 impl.mTextUpdateNeeded = SetShadowProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
419 case Toolkit::TextLabel::Property::EMBOSS:
421 impl.mTextUpdateNeeded = SetEmbossProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
424 case Toolkit::TextLabel::Property::OUTLINE:
426 impl.mTextUpdateNeeded = SetOutlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
429 case Toolkit::TextLabel::Property::PIXEL_SIZE:
431 const float pixelSize = value.Get<float>();
432 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize);
434 if(!Equals(impl.mController->GetDefaultFontSize(Text::Controller::PIXEL_SIZE), pixelSize))
436 impl.mController->SetDefaultFontSize(pixelSize, Text::Controller::PIXEL_SIZE);
440 case Toolkit::TextLabel::Property::ELLIPSIS:
442 const bool ellipsis = value.Get<bool>();
443 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis);
445 impl.mController->SetTextElideEnabled(ellipsis);
448 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
450 Text::LineWrap::Mode lineWrapMode(static_cast<Text::LineWrap::Mode>(-1)); // Set to invalid value to ensure a valid mode does get set
451 if(GetLineWrapModeEnumeration(value, lineWrapMode))
453 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode);
454 impl.mController->SetLineWrapMode(lineWrapMode);
458 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
460 if(impl.mController->GetTextModel())
462 DevelText::VerticalLineAlignment::Type alignment = static_cast<DevelText::VerticalLineAlignment::Type>(value.Get<int>());
464 impl.mController->SetVerticalLineAlignment(alignment);
466 // Property doesn't affect the layout, only Visual must be updated
467 TextVisual::EnableRendererUpdate(impl.mVisual);
469 // No need to trigger full re-layout. Instead call UpdateRenderer() directly
470 TextVisual::UpdateRenderer(impl.mVisual);
474 case Toolkit::DevelTextLabel::Property::BACKGROUND:
476 impl.mTextUpdateNeeded = SetBackgroundProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
479 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
481 impl.mController->SetIgnoreSpacesAfterText(value.Get<bool>());
484 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
486 impl.mController->SetMatchLayoutDirection(value.Get<bool>() ? DevelText::MatchLayoutDirection::LOCALE : DevelText::MatchLayoutDirection::CONTENTS);
489 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
491 ParseTextFitProperty(impl.mController, value.GetMap());
492 impl.mController->SetTextFitChanged(true);
495 case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
497 const float lineSize = value.Get<float>();
498 impl.mTextUpdateNeeded = impl.mController->SetDefaultLineSize(lineSize) || impl.mTextUpdateNeeded;
501 case Toolkit::DevelTextLabel::Property::FONT_SIZE_SCALE:
503 const float scale = value.Get<float>();
504 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p FONT_SIZE_SCALE %f\n", impl.mController.Get(), scale);
506 if(!Equals(impl.mController->GetFontSizeScale(), scale))
508 impl.mController->SetFontSizeScale(scale);
512 case Toolkit::DevelTextLabel::Property::ELLIPSIS_POSITION:
514 DevelText::EllipsisPosition::Type ellipsisPositionType(static_cast<DevelText::EllipsisPosition::Type>(-1)); // Set to invalid value to ensure a valid mode does get set
515 if(GetEllipsisPositionTypeEnumeration(value, ellipsisPositionType))
517 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p EllipsisPosition::Type %d\n", impl.mController.Get(), ellipsisPositionType);
518 impl.mController->SetEllipsisPosition(ellipsisPositionType);
522 case Toolkit::DevelTextLabel::Property::STRIKETHROUGH:
524 impl.mTextUpdateNeeded = SetStrikethroughProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
529 // Request relayout when text update is needed. It's necessary to call it
530 // as changing the property not via UI interaction brings no effect if only
531 // the mTextUpdateNeeded is changed.
532 if(impl.mTextUpdateNeeded)
534 // need to request relayout as size of text may have changed
535 impl.RequestTextRelayout();
540 Text::ControllerPtr TextLabel::GetTextController()
545 Property::Value TextLabel::GetProperty(BaseObject* object, Property::Index index)
547 Property::Value value;
549 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast(Dali::BaseHandle(object));
553 TextLabel& impl(GetImpl(label));
554 DALI_ASSERT_DEBUG(impl.mController && "No text contoller");
558 case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
560 value = impl.mRenderingBackend;
563 case Toolkit::TextLabel::Property::TEXT:
566 impl.mController->GetText(text);
570 case Toolkit::TextLabel::Property::FONT_FAMILY:
572 value = impl.mController->GetDefaultFontFamily();
575 case Toolkit::TextLabel::Property::FONT_STYLE:
577 GetFontStyleProperty(impl.mController, value, Text::FontStyle::DEFAULT);
580 case Toolkit::TextLabel::Property::POINT_SIZE:
582 value = impl.mController->GetDefaultFontSize(Text::Controller::POINT_SIZE);
585 case Toolkit::TextLabel::Property::MULTI_LINE:
587 value = impl.mController->IsMultiLineEnabled();
590 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
592 const char* name = Text::GetHorizontalAlignmentString(impl.mController->GetHorizontalAlignment());
596 value = std::string(name);
600 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
602 const char* name = Text::GetVerticalAlignmentString(impl.mController->GetVerticalAlignment());
605 value = std::string(name);
609 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
611 value = impl.mController->IsMarkupProcessorEnabled();
614 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
616 value = impl.mController->IsAutoScrollEnabled();
619 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
621 if(impl.mTextScroller)
623 const char* mode = Scripting::GetEnumerationName<Toolkit::TextLabel::AutoScrollStopMode::Type>(impl.mTextScroller->GetStopMode(),
624 AUTO_SCROLL_STOP_MODE_TABLE,
625 AUTO_SCROLL_STOP_MODE_TABLE_COUNT);
628 value = std::string(mode);
633 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
635 if(impl.mTextScroller)
637 value = impl.mTextScroller->GetSpeed();
641 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
643 if(impl.mTextScroller)
645 value = impl.mTextScroller->GetLoopCount();
649 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
651 if(impl.mTextScroller)
653 value = impl.mTextScroller->GetLoopDelay();
657 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
659 if(impl.mTextScroller)
661 value = impl.mTextScroller->GetGap();
665 case Toolkit::TextLabel::Property::LINE_SPACING:
667 value = impl.mController->GetDefaultLineSpacing();
670 case Toolkit::TextLabel::Property::UNDERLINE:
672 GetUnderlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
675 case Toolkit::TextLabel::Property::SHADOW:
677 GetShadowProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
680 case Toolkit::TextLabel::Property::EMBOSS:
682 GetEmbossProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
685 case Toolkit::TextLabel::Property::OUTLINE:
687 GetOutlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
690 case Toolkit::TextLabel::Property::PIXEL_SIZE:
692 value = impl.mController->GetDefaultFontSize(Text::Controller::PIXEL_SIZE);
695 case Toolkit::TextLabel::Property::ELLIPSIS:
697 value = impl.mController->IsTextElideEnabled();
700 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
702 value = impl.mController->GetLineWrapMode();
705 case Toolkit::TextLabel::Property::LINE_COUNT:
707 float width = label.GetProperty(Actor::Property::SIZE_WIDTH).Get<float>();
708 value = impl.mController->GetLineCount(width);
711 case Toolkit::DevelTextLabel::Property::TEXT_DIRECTION:
713 value = impl.mController->GetTextDirection();
716 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
718 value = impl.mController->GetVerticalLineAlignment();
721 case Toolkit::DevelTextLabel::Property::BACKGROUND:
723 GetBackgroundProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
726 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
728 value = impl.mController->IsIgnoreSpacesAfterText();
731 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
733 value = impl.mController->GetMatchLayoutDirection() != DevelText::MatchLayoutDirection::CONTENTS;
736 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
738 const bool enabled = impl.mController->IsTextFitEnabled();
739 const float minSize = impl.mController->GetTextFitMinSize();
740 const float maxSize = impl.mController->GetTextFitMaxSize();
741 const float stepSize = impl.mController->GetTextFitStepSize();
742 const float pointSize = impl.mController->GetTextFitPointSize();
745 map.Insert(TEXT_FIT_ENABLE_KEY, enabled);
746 map.Insert(TEXT_FIT_MIN_SIZE_KEY, minSize);
747 map.Insert(TEXT_FIT_MAX_SIZE_KEY, maxSize);
748 map.Insert(TEXT_FIT_STEP_SIZE_KEY, stepSize);
749 map.Insert(TEXT_FIT_FONT_SIZE_KEY, pointSize);
750 map.Insert(TEXT_FIT_FONT_SIZE_TYPE_KEY, "pointSize");
755 case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
757 value = impl.mController->GetDefaultLineSize();
760 case Toolkit::DevelTextLabel::Property::FONT_SIZE_SCALE:
762 value = impl.mController->GetFontSizeScale();
765 case Toolkit::DevelTextLabel::Property::ELLIPSIS_POSITION:
767 value = impl.mController->GetEllipsisPosition();
770 case Toolkit::DevelTextLabel::Property::STRIKETHROUGH:
772 GetStrikethroughProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
781 bool TextLabel::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
783 Dali::BaseHandle handle(object);
785 bool connected(true);
786 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast(handle);
788 if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
792 Internal::TextLabel& labelImpl(GetImpl(label));
793 labelImpl.AnchorClickedSignal().Connect(tracker, functor);
796 else if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_FIT_CHANGED))
800 Internal::TextLabel& labelImpl(GetImpl(label));
801 labelImpl.TextFitChangedSignal().Connect(tracker, functor);
806 // signalName does not match any signal
813 DevelTextLabel::AnchorClickedSignalType& TextLabel::AnchorClickedSignal()
815 return mAnchorClickedSignal;
818 DevelTextLabel::TextFitChangedSignalType& TextLabel::TextFitChangedSignal()
820 return mTextFitChangedSignal;
823 void TextLabel::OnInitialize()
827 Property::Map propertyMap;
828 propertyMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT);
830 mVisual = Toolkit::VisualFactory::Get().CreateVisual(propertyMap);
831 DevelControl::RegisterVisual(*this, Toolkit::TextLabel::Property::TEXT, mVisual);
833 TextVisual::SetAnimatableTextColorProperty(mVisual, Toolkit::TextLabel::Property::TEXT_COLOR);
835 mController = TextVisual::GetController(mVisual);
836 DALI_ASSERT_DEBUG(mController && "Invalid Text Controller")
838 mController->SetControlInterface(this);
839 mController->SetAnchorControlInterface(this);
841 // Use height-for-width negotiation by default
842 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
843 self.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT);
845 // Enable highlightability
846 self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
848 // Enable the text ellipsis.
849 mController->SetTextElideEnabled(true); // If false then text larger than control will overflow
851 // Sets layoutDirection value
852 Dali::Stage stage = Dali::Stage::GetCurrent();
853 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
854 mController->SetLayoutDirection(layoutDirection);
856 self.LayoutDirectionChangedSignal().Connect(this, &TextLabel::OnLayoutDirectionChanged);
858 Layout::Engine& engine = mController->GetLayoutEngine();
859 engine.SetCursorWidth(0u); // Do not layout space for the cursor.
861 DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) {
862 return std::unique_ptr<Dali::Accessibility::Accessible>(
863 new AccessibleImpl(actor, Dali::Accessibility::Role::LABEL));
866 Accessibility::Bridge::EnabledSignal().Connect(this, &TextLabel::OnAccessibilityStatusChanged);
867 Accessibility::Bridge::DisabledSignal().Connect(this, &TextLabel::OnAccessibilityStatusChanged);
870 void TextLabel::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
872 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
876 case StyleChange::DEFAULT_FONT_CHANGE:
878 // Property system did not set the font so should update it.
879 const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
880 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str());
881 mController->UpdateAfterFontChange(newFont);
885 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
887 GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
891 case StyleChange::THEME_CHANGE:
893 // Nothing to do, let control base class handle this
898 // Up call to Control
899 Control::OnStyleChange(styleManager, change);
902 void TextLabel::OnTap(const TapGesture& gesture)
904 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::OnTap %p\n", mController.Get());
906 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
908 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
909 const Vector2& localPoint = gesture.GetLocalPoint();
910 mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
913 void TextLabel::AnchorClicked(const std::string& href)
915 Dali::Toolkit::TextLabel handle(GetOwner());
916 mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
919 Vector3 TextLabel::GetNaturalSize()
922 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
924 Vector3 naturalSize = mController->GetNaturalSize();
925 naturalSize.width += (padding.start + padding.end);
926 naturalSize.height += (padding.top + padding.bottom);
931 float TextLabel::GetHeightForWidth(float width)
934 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
936 return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
939 void TextLabel::OnPropertySet(Property::Index index, const Property::Value& propertyValue)
941 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index);
945 case Toolkit::TextLabel::Property::TEXT_COLOR:
947 const Vector4& textColor = propertyValue.Get<Vector4>();
948 if(mController->GetDefaultColor() != textColor)
950 mController->SetDefaultColor(textColor);
951 mTextUpdateNeeded = true;
955 case Toolkit::TextLabel::Property::TEXT:
956 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
958 CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
963 Control::OnPropertySet(index, propertyValue); // up call to control for non-handled properties
969 void TextLabel::OnRelayout(const Vector2& size, RelayoutContainer& container)
971 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnRelayout\n");
976 padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
978 Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
980 if(mController->IsTextFitEnabled())
982 mController->FitPointSizeforLayout(contentSize);
983 mController->SetTextFitContentSize(contentSize);
986 // Support Right-To-Left
987 Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
989 const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
991 if((Text::Controller::NONE_UPDATED != (Text::Controller::MODEL_UPDATED & updateTextType)) || mTextUpdateNeeded)
993 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", (mController->IsAutoScrollEnabled()) ? "true" : "false", this);
996 TextVisual::EnableRendererUpdate(mVisual);
998 // Support Right-To-Left of padding
999 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
1001 std::swap(padding.start, padding.end);
1004 // Calculate the size of the visual that can fit the text
1005 Size layoutSize = mController->GetTextModel()->GetLayoutSize();
1006 layoutSize.x = contentSize.x;
1008 const Vector2& shadowOffset = mController->GetTextModel()->GetShadowOffset();
1009 if(shadowOffset.y > Math::MACHINE_EPSILON_1)
1011 layoutSize.y += shadowOffset.y;
1014 float outlineWidth = mController->GetTextModel()->GetOutlineWidth();
1015 layoutSize.y += outlineWidth * 2.0f;
1016 layoutSize.y = std::min(layoutSize.y, contentSize.y);
1018 // Calculate the offset for vertical alignment only, as the layout engine will do the horizontal alignment.
1019 Vector2 alignmentOffset;
1020 alignmentOffset.x = 0.0f;
1021 alignmentOffset.y = (contentSize.y - layoutSize.y) * VERTICAL_ALIGNMENT_TABLE[mController->GetVerticalAlignment()];
1023 Property::Map visualTransform;
1024 visualTransform.Add(Toolkit::Visual::Transform::Property::SIZE, layoutSize)
1025 .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
1026 .Add(Toolkit::Visual::Transform::Property::OFFSET, Vector2(padding.start, padding.top) + alignmentOffset)
1027 .Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
1028 .Add(Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN)
1029 .Add(Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN);
1030 mVisual.SetTransformAndSize(visualTransform, size);
1032 if(mController->IsAutoScrollEnabled())
1034 SetUpAutoScrolling();
1037 mTextUpdateNeeded = false;
1040 if(mController->IsTextFitChanged())
1042 EmitTextFitChangedSignal();
1043 mController->SetTextFitChanged(false);
1047 void TextLabel::RequestTextRelayout()
1050 // Signal that a Relayout may be needed
1053 void TextLabel::SetUpAutoScrolling()
1055 const Size& controlSize = mController->GetView().GetControlSize();
1056 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.
1057 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
1059 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n", textNaturalSize.x, textNaturalSize.y, controlSize.x, controlSize.y);
1063 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n");
1065 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
1066 mTextScroller = Text::TextScroller::New(*this);
1069 // Calculate the actual gap before scrolling wraps.
1070 int textPadding = std::max(controlSize.x - textNaturalSize.x, 0.0f);
1071 float wrapGap = std::max(mTextScroller->GetGap(), textPadding);
1072 Vector2 textureSize = textNaturalSize + Vector2(wrapGap, 0.0f); // Add the gap as a part of the texture
1074 // Create a texture of the text for scrolling
1075 Size verifiedSize = textureSize;
1076 const int maxTextureSize = Dali::GetMaxTextureSize();
1078 //if the texture size width exceed maxTextureSize, modify the visual model size and enabled the ellipsis
1079 bool actualellipsis = mController->IsTextElideEnabled();
1080 if(verifiedSize.width > maxTextureSize)
1082 verifiedSize.width = maxTextureSize;
1083 if(textNaturalSize.width > maxTextureSize)
1085 mController->SetTextElideEnabled(true);
1087 GetHeightForWidth(maxTextureSize);
1088 wrapGap = std::max(maxTextureSize - textNaturalSize.width, 0.0f);
1091 Text::TypesetterPtr typesetter = Text::Typesetter::New(mController->GetTextModel());
1093 PixelData data = typesetter->Render(verifiedSize, mController->GetTextDirection(), Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888); // ignore the horizontal alignment
1094 Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D,
1095 data.GetPixelFormat(),
1098 texture.Upload(data);
1100 TextureSet textureSet = TextureSet::New();
1101 textureSet.SetTexture(0u, texture);
1103 // Filter mode needs to be set to linear to produce better quality while scaling.
1104 Sampler sampler = Sampler::New();
1105 sampler.SetFilterMode(FilterMode::LINEAR, FilterMode::LINEAR);
1106 sampler.SetWrapMode(Dali::WrapMode::DEFAULT, Dali::WrapMode::REPEAT, Dali::WrapMode::DEFAULT); // Wrap the texture in the x direction
1107 textureSet.SetSampler(0u, sampler);
1109 // Set parameters for scrolling
1110 Renderer renderer = static_cast<Internal::Visual::Base&>(GetImplementation(mVisual)).GetRenderer();
1111 mTextScroller->SetParameters(Self(), renderer, textureSet, controlSize, verifiedSize, wrapGap, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment());
1112 mController->SetTextElideEnabled(actualellipsis);
1115 void TextLabel::ScrollingFinished()
1117 // Pure Virtual from TextScroller Interface
1118 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
1119 mController->SetAutoScrollEnabled(false);
1120 RequestTextRelayout();
1123 void TextLabel::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1125 mController->ChangedLayoutDirection();
1128 void TextLabel::EmitTextFitChangedSignal()
1130 Dali::Toolkit::TextLabel handle(GetOwner());
1131 mTextFitChangedSignal.Emit(handle);
1134 void TextLabel::OnAccessibilityStatusChanged()
1136 CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
1139 TextLabel::TextLabel()
1140 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
1141 mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1142 mTextUpdateNeeded(false)
1146 TextLabel::~TextLabel()
1150 Vector<Vector2> TextLabel::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
1152 return mController->GetTextSize(startIndex, endIndex);
1155 Vector<Vector2> TextLabel::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
1157 return mController->GetTextPosition(startIndex, endIndex);
1160 std::string TextLabel::AccessibleImpl::GetNameRaw()
1162 auto self = Toolkit::TextLabel::DownCast(Self());
1163 return self.GetProperty(Toolkit::TextLabel::Property::TEXT).Get<std::string>();
1166 Property::Index TextLabel::AccessibleImpl::GetNamePropertyIndex()
1168 return Toolkit::TextLabel::Property::TEXT;
1171 std::string TextLabel::AccessibleImpl::GetText(size_t startOffset, size_t endOffset)
1173 if(endOffset <= startOffset)
1178 auto self = Toolkit::TextLabel::DownCast(Self());
1179 auto text = self.GetProperty(Toolkit::TextLabel::Property::TEXT).Get<std::string>();
1181 if(startOffset > text.size() || endOffset > text.size())
1186 return text.substr(startOffset, endOffset - startOffset);
1189 size_t TextLabel::AccessibleImpl::GetCharacterCount()
1191 auto self = Toolkit::TextLabel::DownCast(Self());
1192 auto text = self.GetProperty(Toolkit::TextLabel::Property::TEXT).Get<std::string>();
1197 size_t TextLabel::AccessibleImpl::GetCursorOffset()
1202 bool TextLabel::AccessibleImpl::SetCursorOffset(size_t offset)
1207 Dali::Accessibility::Range TextLabel::AccessibleImpl::GetTextAtOffset(size_t offset, Dali::Accessibility::TextBoundary boundary)
1209 auto self = Toolkit::TextLabel::DownCast(Self());
1210 auto text = self.GetProperty(Toolkit::TextLabel::Property::TEXT).Get<std::string>();
1211 auto textSize = text.size();
1213 auto range = Dali::Accessibility::Range{};
1217 case Dali::Accessibility::TextBoundary::CHARACTER:
1219 if(offset < textSize)
1221 range.content = text[offset];
1222 range.startOffset = offset;
1223 range.endOffset = offset + 1;
1227 case Dali::Accessibility::TextBoundary::WORD:
1228 case Dali::Accessibility::TextBoundary::LINE:
1230 auto textString = text.c_str();
1231 auto breaks = std::vector<char>(textSize, 0);
1233 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1235 Accessibility::Accessible::FindWordSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1239 Accessibility::Accessible::FindLineSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1244 while(index < textSize && counter <= offset)
1249 while(breaks[index])
1257 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1261 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1267 if((counter > 0) && ((counter - 1) == offset))
1269 range.content = text.substr(start, index - start + 1);
1270 range.startOffset = start;
1271 range.endOffset = index + 1;
1274 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1281 case Dali::Accessibility::TextBoundary::SENTENCE:
1283 /* not supported by default */
1286 case Dali::Accessibility::TextBoundary::PARAGRAPH:
1288 /* Paragraph is not supported by libunibreak library */
1298 Dali::Accessibility::Range TextLabel::AccessibleImpl::GetRangeOfSelection(size_t selectionIndex)
1300 // Since DALi supports only one selection indexes higher than 0 are ignored
1301 if(selectionIndex > 0)
1306 auto self = Toolkit::TextLabel::DownCast(Self());
1307 auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1308 std::string value{};
1309 controller->RetrieveSelection(value);
1310 auto indices = controller->GetSelectionIndexes();
1312 return {static_cast<size_t>(indices.first), static_cast<size_t>(indices.second), value};
1315 bool TextLabel::AccessibleImpl::RemoveSelection(size_t selectionIndex)
1317 // Since DALi supports only one selection indexes higher than 0 are ignored
1318 if(selectionIndex > 0)
1323 auto self = Toolkit::TextLabel::DownCast(Self());
1324 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(0, 0);
1328 bool TextLabel::AccessibleImpl::SetRangeOfSelection(size_t selectionIndex, size_t startOffset, size_t endOffset)
1330 // Since DALi supports only one selection indexes higher than 0 are ignored
1331 if(selectionIndex > 0)
1336 auto self = Toolkit::TextLabel::DownCast(Self());
1337 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(startOffset, endOffset);
1341 int32_t TextLabel::AccessibleImpl::GetLinkCount() const
1343 auto self = Toolkit::TextLabel::DownCast(Self());
1344 return Dali::Toolkit::GetImpl(self).mAnchorActors.size();
1347 Accessibility::Hyperlink* TextLabel::AccessibleImpl::GetLink(int32_t linkIndex) const
1349 if(linkIndex < 0 || linkIndex >= GetLinkCount())
1353 auto self = Toolkit::TextLabel::DownCast(Self());
1354 auto anchorActor = Dali::Toolkit::GetImpl(self).mAnchorActors[linkIndex];
1355 return dynamic_cast<Accessibility::Hyperlink*>(Dali::Accessibility::Accessible::Get(anchorActor));
1358 int32_t TextLabel::AccessibleImpl::GetLinkIndex(int32_t characterOffset) const
1360 auto self = Toolkit::TextLabel::DownCast(Self());
1361 auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1362 return controller->GetAnchorIndex(static_cast<size_t>(characterOffset));
1365 } // namespace Internal
1367 } // namespace Toolkit