2 * Copyright (c) 2022 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 char* TEXT_FIT_ENABLE_KEY("enable");
80 const char* TEXT_FIT_MIN_SIZE_KEY("minSize");
81 const char* TEXT_FIT_MAX_SIZE_KEY("maxSize");
82 const char* TEXT_FIT_STEP_SIZE_KEY("stepSize");
83 const char* TEXT_FIT_FONT_SIZE_KEY("fontSize");
84 const char* 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, "enableFontSizeScale", BOOLEAN, ENABLE_FONT_SIZE_SCALE )
140 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "ellipsisPosition", INTEGER, ELLIPSIS_POSITION )
141 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "strikethrough", MAP, STRIKETHROUGH )
142 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "characterSpacing", FLOAT, CHARACTER_SPACING )
143 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "relativeLineSize", FLOAT, RELATIVE_LINE_SIZE )
144 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "anchorColor", VECTOR4, ANCHOR_COLOR )
145 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "anchorClickedColor", VECTOR4, ANCHOR_CLICKED_COLOR )
147 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT(Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR )
148 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0)
149 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1)
150 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColorBlue", TEXT_COLOR_BLUE, TEXT_COLOR, 2)
151 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3)
153 DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "anchorClicked", SIGNAL_ANCHOR_CLICKED)
154 DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "textFitChanged", SIGNAL_TEXT_FIT_CHANGED)
156 DALI_TYPE_REGISTRATION_END()
159 /// Parses the property map for the TEXT_FIT property
160 void ParseTextFitProperty(Text::ControllerPtr& controller, const Property::Map* propertiesMap)
162 if(propertiesMap && !propertiesMap->Empty())
164 bool enabled = false;
167 float stepSize = 0.f;
168 bool isMinSizeSet = false, isMaxSizeSet = false, isStepSizeSet = false;
169 Controller::FontSizeType type = Controller::FontSizeType::POINT_SIZE;
171 const unsigned int numberOfItems = propertiesMap->Count();
173 // Parses and applies
174 for(unsigned int index = 0u; index < numberOfItems; ++index)
176 const KeyValuePair& valueGet = propertiesMap->GetKeyValue(index);
178 if((Controller::TextFitInfo::Property::TEXT_FIT_ENABLE == valueGet.first.indexKey) || (TEXT_FIT_ENABLE_KEY == valueGet.first.stringKey))
181 enabled = valueGet.second.Get<bool>();
183 else if((Controller::TextFitInfo::Property::TEXT_FIT_MIN_SIZE == valueGet.first.indexKey) || (TEXT_FIT_MIN_SIZE_KEY == valueGet.first.stringKey))
186 minSize = valueGet.second.Get<float>();
189 else if((Controller::TextFitInfo::Property::TEXT_FIT_MAX_SIZE == valueGet.first.indexKey) || (TEXT_FIT_MAX_SIZE_KEY == valueGet.first.stringKey))
192 maxSize = valueGet.second.Get<float>();
195 else if((Controller::TextFitInfo::Property::TEXT_FIT_STEP_SIZE == valueGet.first.indexKey) || (TEXT_FIT_STEP_SIZE_KEY == valueGet.first.stringKey))
198 stepSize = valueGet.second.Get<float>();
199 isStepSizeSet = true;
201 else if((Controller::TextFitInfo::Property::TEXT_FIT_FONT_SIZE_TYPE == valueGet.first.indexKey) || (TEXT_FIT_FONT_SIZE_TYPE_KEY == valueGet.first.stringKey))
203 if("pixelSize" == valueGet.second.Get<std::string>())
205 type = Controller::FontSizeType::PIXEL_SIZE;
210 controller->SetTextFitEnabled(enabled);
211 // The TextFit operation is performed based on the MinLineSize set in the TextLabel at the moment when the TextFit property is set.
212 // So, if you change the TextLabel's MinLineSize after setting the TextFit property, it does not affect the operation of TextFit.
213 // This may require a new LineSize item in TextFit.
214 controller->SetTextFitLineSize(controller->GetDefaultLineSize());
217 controller->SetTextFitMinSize(minSize, type);
221 controller->SetTextFitMaxSize(maxSize, type);
225 controller->SetTextFitStepSize(stepSize, type);
232 Toolkit::TextLabel TextLabel::New(ControlBehaviour additionalBehaviour)
234 // Create the implementation, temporarily owned by this handle on stack
235 IntrusivePtr<TextLabel> impl = new TextLabel(additionalBehaviour);
237 // Pass ownership to CustomActor handle
238 Toolkit::TextLabel handle(*impl);
240 // Second-phase init of the implementation
241 // This can only be done after the CustomActor connection has been made...
247 void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
249 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast(Dali::BaseHandle(object));
253 TextLabel& impl(GetImpl(label));
254 DALI_ASSERT_ALWAYS(impl.mController && "No text contoller");
258 case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
260 int backend = value.Get<int>();
262 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
263 if(DevelText::RENDERING_VECTOR_BASED == backend)
265 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
268 if(impl.mRenderingBackend != backend)
270 impl.mRenderingBackend = backend;
271 impl.mTextUpdateNeeded = true;
273 // When using the vector-based rendering, the size of the GLyphs are different
274 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
275 impl.mController->SetGlyphType(glyphType);
279 case Toolkit::TextLabel::Property::TEXT:
281 impl.mController->SetText(value.Get<std::string>());
283 if(impl.mController->HasAnchors())
285 // Forward input events to controller
286 impl.EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
290 impl.DisableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
295 case Toolkit::TextLabel::Property::FONT_FAMILY:
297 const std::string& fontFamily = value.Get<std::string>();
299 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str());
300 impl.mController->SetDefaultFontFamily(fontFamily);
303 case Toolkit::TextLabel::Property::FONT_STYLE:
305 SetFontStyleProperty(impl.mController, value, Text::FontStyle::DEFAULT);
308 case Toolkit::TextLabel::Property::POINT_SIZE:
310 const float pointSize = value.Get<float>();
312 if(!Equals(impl.mController->GetDefaultFontSize(Text::Controller::POINT_SIZE), pointSize))
314 impl.mController->SetDefaultFontSize(pointSize, Text::Controller::POINT_SIZE);
318 case Toolkit::TextLabel::Property::MULTI_LINE:
320 impl.mController->SetMultiLineEnabled(value.Get<bool>());
323 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
325 Text::HorizontalAlignment::Type alignment(static_cast<Text::HorizontalAlignment::Type>(-1)); // Set to invalid value to ensure a valid mode does get set
326 if(Text::GetHorizontalAlignmentEnumeration(value, alignment))
328 impl.mController->SetHorizontalAlignment(alignment);
332 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
334 Toolkit::Text::VerticalAlignment::Type alignment(static_cast<Text::VerticalAlignment::Type>(-1)); // Set to invalid value to ensure a valid mode does get set
335 if(Text::GetVerticalAlignmentEnumeration(value, alignment))
337 impl.mController->SetVerticalAlignment(alignment);
341 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
343 const bool enableMarkup = value.Get<bool>();
344 impl.mController->SetMarkupProcessorEnabled(enableMarkup);
346 if(impl.mController->HasAnchors())
348 // Forward input events to controller
349 impl.EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
353 impl.DisableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
357 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
359 const bool enableAutoScroll = value.Get<bool>();
360 impl.mLastAutoScrollEnabled = enableAutoScroll;
361 // If request to auto scroll is the same as current state then do nothing.
362 if(enableAutoScroll != impl.mController->IsAutoScrollEnabled())
364 // If request is disable (false) and auto scrolling is enabled then need to stop it
365 if(enableAutoScroll == false)
367 if(impl.mTextScroller)
369 impl.mTextScroller->StopScrolling();
372 // If request is enable (true) then start autoscroll as not already running
375 impl.mController->SetAutoScrollEnabled(enableAutoScroll);
380 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
382 Text::TextScrollerPtr textScroller = impl.GetTextScroller();
383 Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = textScroller->GetStopMode();
384 if(Scripting::GetEnumerationProperty<Toolkit::TextLabel::AutoScrollStopMode::Type>(value,
385 AUTO_SCROLL_STOP_MODE_TABLE,
386 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
389 textScroller->SetStopMode(stopMode);
393 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
395 impl.GetTextScroller()->SetSpeed(value.Get<int>());
398 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
400 impl.GetTextScroller()->SetLoopCount(value.Get<int>());
403 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
405 impl.GetTextScroller()->SetLoopDelay(value.Get<float>());
408 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
410 impl.GetTextScroller()->SetGap(value.Get<float>());
413 case Toolkit::TextLabel::Property::LINE_SPACING:
415 const float lineSpacing = value.Get<float>();
416 impl.mTextUpdateNeeded = impl.mController->SetDefaultLineSpacing(lineSpacing) || impl.mTextUpdateNeeded;
419 case Toolkit::TextLabel::Property::UNDERLINE:
421 impl.mTextUpdateNeeded = SetUnderlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
424 case Toolkit::TextLabel::Property::SHADOW:
426 impl.mTextUpdateNeeded = SetShadowProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
429 case Toolkit::TextLabel::Property::EMBOSS:
431 impl.mTextUpdateNeeded = SetEmbossProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
434 case Toolkit::TextLabel::Property::OUTLINE:
436 impl.mTextUpdateNeeded = SetOutlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
439 case Toolkit::TextLabel::Property::PIXEL_SIZE:
441 const float pixelSize = value.Get<float>();
442 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize);
444 if(!Equals(impl.mController->GetDefaultFontSize(Text::Controller::PIXEL_SIZE), pixelSize))
446 impl.mController->SetDefaultFontSize(pixelSize, Text::Controller::PIXEL_SIZE);
450 case Toolkit::TextLabel::Property::ELLIPSIS:
452 const bool ellipsis = value.Get<bool>();
453 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis);
455 impl.mController->SetTextElideEnabled(ellipsis);
458 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
460 Text::LineWrap::Mode lineWrapMode(static_cast<Text::LineWrap::Mode>(-1)); // Set to invalid value to ensure a valid mode does get set
461 if(GetLineWrapModeEnumeration(value, lineWrapMode))
463 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode);
464 impl.mController->SetLineWrapMode(lineWrapMode);
468 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
470 if(impl.mController->GetTextModel())
472 DevelText::VerticalLineAlignment::Type alignment = static_cast<DevelText::VerticalLineAlignment::Type>(value.Get<int>());
474 impl.mController->SetVerticalLineAlignment(alignment);
476 // Property doesn't affect the layout, only Visual must be updated
477 TextVisual::EnableRendererUpdate(impl.mVisual);
479 // No need to trigger full re-layout. Instead call UpdateRenderer() directly
480 TextVisual::UpdateRenderer(impl.mVisual);
484 case Toolkit::DevelTextLabel::Property::BACKGROUND:
486 impl.mTextUpdateNeeded = SetBackgroundProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
489 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
491 impl.mController->SetIgnoreSpacesAfterText(value.Get<bool>());
494 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
496 impl.mController->SetMatchLayoutDirection(value.Get<bool>() ? DevelText::MatchLayoutDirection::LOCALE : DevelText::MatchLayoutDirection::CONTENTS);
499 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
501 // If TextFitArray is enabled, this should be disabled.
502 if(impl.mController->IsTextFitArrayEnabled())
504 impl.mController->SetDefaultLineSize(impl.mController->GetCurrentLineSize());
505 impl.mController->SetTextFitArrayEnabled(false);
508 ParseTextFitProperty(impl.mController, value.GetMap());
509 impl.mController->SetTextFitChanged(true);
512 case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
514 const float lineSize = value.Get<float>();
515 // If TextFitArray is enabled, do not update the default line size.
516 if(!impl.mController->IsTextFitArrayEnabled())
518 impl.mTextUpdateNeeded = impl.mController->SetDefaultLineSize(lineSize) || impl.mTextUpdateNeeded;
520 impl.mController->SetCurrentLineSize(lineSize);
523 case Toolkit::DevelTextLabel::Property::FONT_SIZE_SCALE:
525 const float scale = value.Get<float>();
526 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p FONT_SIZE_SCALE %f\n", impl.mController.Get(), scale);
528 if(!Equals(impl.mController->GetFontSizeScale(), scale))
530 impl.mController->SetFontSizeScale(scale);
534 case Toolkit::DevelTextLabel::Property::ENABLE_FONT_SIZE_SCALE:
536 const bool enableFontSizeScale = value.Get<bool>();
537 if(!Equals(impl.mController->IsFontSizeScaleEnabled(), enableFontSizeScale))
539 impl.mController->SetFontSizeScaleEnabled(enableFontSizeScale);
543 case Toolkit::DevelTextLabel::Property::ELLIPSIS_POSITION:
545 DevelText::EllipsisPosition::Type ellipsisPositionType(static_cast<DevelText::EllipsisPosition::Type>(-1)); // Set to invalid value to ensure a valid mode does get set
546 if(GetEllipsisPositionTypeEnumeration(value, ellipsisPositionType))
548 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p EllipsisPosition::Type %d\n", impl.mController.Get(), ellipsisPositionType);
549 impl.mController->SetEllipsisPosition(ellipsisPositionType);
553 case Toolkit::DevelTextLabel::Property::STRIKETHROUGH:
555 impl.mTextUpdateNeeded = SetStrikethroughProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
558 case Toolkit::DevelTextLabel::Property::CHARACTER_SPACING:
560 const float characterSpacing = value.Get<float>();
561 impl.mController->SetCharacterSpacing(characterSpacing);
564 case Toolkit::DevelTextLabel::Property::RELATIVE_LINE_SIZE:
566 const float relativeLineSize = value.Get<float>();
567 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel %p RELATIVE_LINE_SIZE %f\n", impl.mController.Get(), relativeLineSize);
569 impl.mController->SetRelativeLineSize(relativeLineSize);
572 case Toolkit::DevelTextLabel::Property::ANCHOR_COLOR:
574 const Vector4& anchorColor = value.Get<Vector4>();
575 if(impl.mController->GetAnchorColor() != anchorColor)
577 impl.mController->SetAnchorColor(anchorColor);
578 impl.mTextUpdateNeeded = true;
582 case Toolkit::DevelTextLabel::Property::ANCHOR_CLICKED_COLOR:
584 const Vector4& anchorClickedColor = value.Get<Vector4>();
585 if(impl.mController->GetAnchorClickedColor() != anchorClickedColor)
587 impl.mController->SetAnchorClickedColor(anchorClickedColor);
588 impl.mTextUpdateNeeded = true;
594 // Request relayout when text update is needed. It's necessary to call it
595 // as changing the property not via UI interaction brings no effect if only
596 // the mTextUpdateNeeded is changed.
597 if(impl.mTextUpdateNeeded)
599 // need to request relayout as size of text may have changed
600 impl.RequestTextRelayout();
605 Text::ControllerPtr TextLabel::GetTextController()
610 Property::Value TextLabel::GetProperty(BaseObject* object, Property::Index index)
612 Property::Value value;
614 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast(Dali::BaseHandle(object));
618 TextLabel& impl(GetImpl(label));
619 DALI_ASSERT_DEBUG(impl.mController && "No text contoller");
623 case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
625 value = impl.mRenderingBackend;
628 case Toolkit::TextLabel::Property::TEXT:
631 impl.mController->GetText(text);
635 case Toolkit::TextLabel::Property::FONT_FAMILY:
637 value = impl.mController->GetDefaultFontFamily();
640 case Toolkit::TextLabel::Property::FONT_STYLE:
642 GetFontStyleProperty(impl.mController, value, Text::FontStyle::DEFAULT);
645 case Toolkit::TextLabel::Property::POINT_SIZE:
647 value = impl.mController->GetDefaultFontSize(Text::Controller::POINT_SIZE);
650 case Toolkit::TextLabel::Property::MULTI_LINE:
652 value = impl.mController->IsMultiLineEnabled();
655 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
657 const char* name = Text::GetHorizontalAlignmentString(impl.mController->GetHorizontalAlignment());
661 value = std::string(name);
665 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
667 const char* name = Text::GetVerticalAlignmentString(impl.mController->GetVerticalAlignment());
670 value = std::string(name);
674 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
676 value = impl.mController->IsMarkupProcessorEnabled();
679 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
681 value = impl.mController->IsAutoScrollEnabled();
684 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
686 if(impl.mTextScroller)
688 const char* mode = Scripting::GetEnumerationName<Toolkit::TextLabel::AutoScrollStopMode::Type>(impl.mTextScroller->GetStopMode(),
689 AUTO_SCROLL_STOP_MODE_TABLE,
690 AUTO_SCROLL_STOP_MODE_TABLE_COUNT);
693 value = std::string(mode);
698 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
700 if(impl.mTextScroller)
702 value = impl.mTextScroller->GetSpeed();
706 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
708 if(impl.mTextScroller)
710 value = impl.mTextScroller->GetLoopCount();
714 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
716 if(impl.mTextScroller)
718 value = impl.mTextScroller->GetLoopDelay();
722 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
724 if(impl.mTextScroller)
726 value = impl.mTextScroller->GetGap();
730 case Toolkit::TextLabel::Property::LINE_SPACING:
732 value = impl.mController->GetDefaultLineSpacing();
735 case Toolkit::TextLabel::Property::UNDERLINE:
737 GetUnderlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
740 case Toolkit::TextLabel::Property::SHADOW:
742 GetShadowProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
745 case Toolkit::TextLabel::Property::EMBOSS:
747 GetEmbossProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
750 case Toolkit::TextLabel::Property::OUTLINE:
752 GetOutlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
755 case Toolkit::TextLabel::Property::PIXEL_SIZE:
757 value = impl.mController->GetDefaultFontSize(Text::Controller::PIXEL_SIZE);
760 case Toolkit::TextLabel::Property::ELLIPSIS:
762 value = impl.mController->IsTextElideEnabled();
765 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
767 value = impl.mController->GetLineWrapMode();
770 case Toolkit::TextLabel::Property::LINE_COUNT:
772 float width = label.GetProperty(Actor::Property::SIZE_WIDTH).Get<float>();
773 value = impl.mController->GetLineCount(width);
776 case Toolkit::DevelTextLabel::Property::TEXT_DIRECTION:
778 value = impl.mController->GetTextDirection();
781 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
783 value = impl.mController->GetVerticalLineAlignment();
786 case Toolkit::DevelTextLabel::Property::BACKGROUND:
788 GetBackgroundProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
791 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
793 value = impl.mController->IsIgnoreSpacesAfterText();
796 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
798 value = impl.mController->GetMatchLayoutDirection() != DevelText::MatchLayoutDirection::CONTENTS;
801 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
803 const bool enabled = impl.mController->IsTextFitEnabled();
804 const float minSize = impl.mController->GetTextFitMinSize();
805 const float maxSize = impl.mController->GetTextFitMaxSize();
806 const float stepSize = impl.mController->GetTextFitStepSize();
807 const float pointSize = impl.mController->GetTextFitPointSize();
810 map.Insert(TEXT_FIT_ENABLE_KEY, enabled);
811 map.Insert(TEXT_FIT_MIN_SIZE_KEY, minSize);
812 map.Insert(TEXT_FIT_MAX_SIZE_KEY, maxSize);
813 map.Insert(TEXT_FIT_STEP_SIZE_KEY, stepSize);
814 map.Insert(TEXT_FIT_FONT_SIZE_KEY, pointSize);
815 map.Insert(TEXT_FIT_FONT_SIZE_TYPE_KEY, "pointSize");
820 case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
822 // If TextFitArray is enabled, the stored value (MIN_LINE_SIZE set by the user) is retrun.
823 value = impl.mController->IsTextFitArrayEnabled() ? impl.mController->GetCurrentLineSize() : impl.mController->GetDefaultLineSize();
826 case Toolkit::DevelTextLabel::Property::FONT_SIZE_SCALE:
828 value = impl.mController->GetFontSizeScale();
831 case Toolkit::DevelTextLabel::Property::ENABLE_FONT_SIZE_SCALE:
833 value = impl.mController->IsFontSizeScaleEnabled();
836 case Toolkit::DevelTextLabel::Property::ELLIPSIS_POSITION:
838 value = impl.mController->GetEllipsisPosition();
841 case Toolkit::DevelTextLabel::Property::STRIKETHROUGH:
843 GetStrikethroughProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
846 case Toolkit::DevelTextLabel::Property::CHARACTER_SPACING:
848 value = impl.mController->GetCharacterSpacing();
851 case Toolkit::DevelTextLabel::Property::RELATIVE_LINE_SIZE:
853 value = impl.mController->GetRelativeLineSize();
856 case Toolkit::DevelTextLabel::Property::ANCHOR_COLOR:
858 value = impl.mController->GetAnchorColor();
861 case Toolkit::DevelTextLabel::Property::ANCHOR_CLICKED_COLOR:
863 value = impl.mController->GetAnchorClickedColor();
872 bool TextLabel::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
874 Dali::BaseHandle handle(object);
876 bool connected(true);
877 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast(handle);
879 if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
883 Internal::TextLabel& labelImpl(GetImpl(label));
884 labelImpl.AnchorClickedSignal().Connect(tracker, functor);
887 else if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_FIT_CHANGED))
891 Internal::TextLabel& labelImpl(GetImpl(label));
892 labelImpl.TextFitChangedSignal().Connect(tracker, functor);
897 // signalName does not match any signal
904 DevelTextLabel::AnchorClickedSignalType& TextLabel::AnchorClickedSignal()
906 return mAnchorClickedSignal;
909 DevelTextLabel::TextFitChangedSignalType& TextLabel::TextFitChangedSignal()
911 return mTextFitChangedSignal;
914 void TextLabel::OnInitialize()
918 Property::Map propertyMap;
919 propertyMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT);
921 mVisual = Toolkit::VisualFactory::Get().CreateVisual(propertyMap);
922 DevelControl::RegisterVisual(*this, Toolkit::TextLabel::Property::TEXT, mVisual);
924 TextVisual::SetAnimatableTextColorProperty(mVisual, Toolkit::TextLabel::Property::TEXT_COLOR);
926 mController = TextVisual::GetController(mVisual);
927 DALI_ASSERT_DEBUG(mController && "Invalid Text Controller")
929 mController->SetControlInterface(this);
930 mController->SetAnchorControlInterface(this);
932 // Use height-for-width negotiation by default
933 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
934 self.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT);
936 // Enable the text ellipsis.
937 mController->SetTextElideEnabled(true); // If false then text larger than control will overflow
939 // Sets layoutDirection value
940 Dali::Stage stage = Dali::Stage::GetCurrent();
941 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
942 mController->SetLayoutDirection(layoutDirection);
944 self.LayoutDirectionChangedSignal().Connect(this, &TextLabel::OnLayoutDirectionChanged);
946 Layout::Engine& engine = mController->GetLayoutEngine();
947 engine.SetCursorWidth(0u); // Do not layout space for the cursor.
950 self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::LABEL);
951 self.SetProperty(DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
953 Accessibility::Bridge::EnabledSignal().Connect(this, &TextLabel::OnAccessibilityStatusChanged);
954 Accessibility::Bridge::DisabledSignal().Connect(this, &TextLabel::OnAccessibilityStatusChanged);
957 DevelControl::ControlAccessible* TextLabel::CreateAccessibleObject()
959 return new TextLabelAccessible(Self());
962 void TextLabel::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
964 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
968 case StyleChange::DEFAULT_FONT_CHANGE:
970 // Property system did not set the font so should update it.
971 const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
972 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str());
973 mController->UpdateAfterFontChange(newFont);
977 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
979 GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
983 case StyleChange::THEME_CHANGE:
985 // Nothing to do, let control base class handle this
990 // Up call to Control
991 Control::OnStyleChange(styleManager, change);
994 void TextLabel::OnTap(const TapGesture& gesture)
996 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::OnTap %p\n", mController.Get());
998 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1000 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
1001 const Vector2& localPoint = gesture.GetLocalPoint();
1002 mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
1005 void TextLabel::AnchorClicked(const std::string& href)
1007 Dali::Toolkit::TextLabel handle(GetOwner());
1008 mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
1011 Vector3 TextLabel::GetNaturalSize()
1014 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
1016 Vector3 naturalSize = mController->GetNaturalSize();
1017 naturalSize.width += (padding.start + padding.end);
1018 naturalSize.height += (padding.top + padding.bottom);
1023 float TextLabel::GetHeightForWidth(float width)
1026 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
1028 return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
1031 void TextLabel::OnPropertySet(Property::Index index, const Property::Value& propertyValue)
1033 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index);
1037 case Toolkit::TextLabel::Property::TEXT_COLOR:
1039 const Vector4& textColor = propertyValue.Get<Vector4>();
1040 if(mController->GetDefaultColor() != textColor)
1042 mController->SetDefaultColor(textColor);
1043 mTextUpdateNeeded = true;
1047 case Toolkit::TextLabel::Property::TEXT:
1048 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
1050 CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
1055 Control::OnPropertySet(index, propertyValue); // up call to control for non-handled properties
1061 void TextLabel::OnSceneConnection(int depth)
1063 if(mController->IsAutoScrollEnabled() || mLastAutoScrollEnabled)
1065 mController->SetAutoScrollEnabled(true);
1067 Control::OnSceneConnection(depth);
1070 void TextLabel::OnSceneDisconnection()
1074 if(mLastAutoScrollEnabled && !mController->IsAutoScrollEnabled())
1076 mLastAutoScrollEnabled = false;
1079 const Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = mTextScroller->GetStopMode();
1080 mTextScroller->SetStopMode(Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE);
1081 mTextScroller->StopScrolling();
1082 mTextScroller->SetStopMode(stopMode);
1084 Control::OnSceneDisconnection();
1087 void TextLabel::OnRelayout(const Vector2& size, RelayoutContainer& container)
1089 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnRelayout\n");
1091 Actor self = Self();
1094 padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
1096 Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
1098 if(mController->IsTextFitArrayEnabled())
1100 mController->FitArrayPointSizeforLayout(contentSize);
1101 mController->SetTextFitContentSize(contentSize);
1103 else if(mController->IsTextFitEnabled())
1105 mController->FitPointSizeforLayout(contentSize);
1106 mController->SetTextFitContentSize(contentSize);
1109 // Support Right-To-Left
1110 Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
1112 const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
1114 if((Text::Controller::NONE_UPDATED != (Text::Controller::MODEL_UPDATED & updateTextType)) || mTextUpdateNeeded)
1116 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", (mController->IsAutoScrollEnabled()) ? "true" : "false", this);
1118 // Update the visual
1119 TextVisual::EnableRendererUpdate(mVisual);
1121 // Support Right-To-Left of padding
1122 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
1124 std::swap(padding.start, padding.end);
1127 // Calculate the size of the visual that can fit the text
1128 Size layoutSize = mController->GetTextModel()->GetLayoutSize();
1129 layoutSize.x = contentSize.x;
1131 const Vector2& shadowOffset = mController->GetTextModel()->GetShadowOffset();
1132 if(shadowOffset.y > Math::MACHINE_EPSILON_1)
1134 layoutSize.y += shadowOffset.y;
1137 float outlineWidth = mController->GetTextModel()->GetOutlineWidth();
1138 layoutSize.y += outlineWidth * 2.0f;
1139 layoutSize.y = std::min(layoutSize.y, contentSize.y);
1141 // Calculate the offset for vertical alignment only, as the layout engine will do the horizontal alignment.
1142 Vector2 alignmentOffset;
1143 alignmentOffset.x = 0.0f;
1144 alignmentOffset.y = (contentSize.y - layoutSize.y) * VERTICAL_ALIGNMENT_TABLE[mController->GetVerticalAlignment()];
1146 const int maxTextureSize = Dali::GetMaxTextureSize();
1147 if(layoutSize.width > maxTextureSize)
1149 DALI_LOG_WARNING("layoutSize(%f) > maxTextureSize(%d): To guarantee the behavior of Texture::New, layoutSize must not be bigger than maxTextureSize\n", layoutSize.width, maxTextureSize);
1150 layoutSize.width = maxTextureSize;
1153 // This affects font rendering quality.
1154 // It need to be integerized.
1155 Vector2 visualTransformOffset;
1156 visualTransformOffset.x = roundf(padding.start + alignmentOffset.x);
1157 visualTransformOffset.y = roundf(padding.top + alignmentOffset.y);
1159 Property::Map visualTransform;
1160 visualTransform.Add(Toolkit::Visual::Transform::Property::SIZE, layoutSize)
1161 .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
1162 .Add(Toolkit::Visual::Transform::Property::OFFSET, visualTransformOffset)
1163 .Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
1164 .Add(Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN)
1165 .Add(Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN);
1166 mVisual.SetTransformAndSize(visualTransform, size);
1168 if(mController->IsAutoScrollEnabled())
1170 SetUpAutoScrolling();
1173 mTextUpdateNeeded = false;
1176 if(mController->IsTextFitChanged())
1178 EmitTextFitChangedSignal();
1179 mController->SetTextFitChanged(false);
1183 void TextLabel::RequestTextRelayout()
1186 // Signal that a Relayout may be needed
1189 void TextLabel::SetUpAutoScrolling()
1191 const Size& controlSize = mController->GetView().GetControlSize();
1192 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.
1193 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
1195 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n", textNaturalSize.x, textNaturalSize.y, controlSize.x, controlSize.y);
1199 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n");
1201 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
1202 mTextScroller = Text::TextScroller::New(*this);
1205 // Calculate the actual gap before scrolling wraps.
1206 int textPadding = std::max(controlSize.x - textNaturalSize.x, 0.0f);
1207 float wrapGap = std::max(mTextScroller->GetGap(), textPadding);
1208 Vector2 textureSize = textNaturalSize + Vector2(wrapGap, 0.0f); // Add the gap as a part of the texture
1210 // Create a texture of the text for scrolling
1211 Size verifiedSize = textureSize;
1212 const int maxTextureSize = Dali::GetMaxTextureSize();
1214 //if the texture size width exceed maxTextureSize, modify the visual model size and enabled the ellipsis
1215 bool actualellipsis = mController->IsTextElideEnabled();
1216 if(verifiedSize.width > maxTextureSize)
1218 verifiedSize.width = maxTextureSize;
1219 if(textNaturalSize.width > maxTextureSize)
1221 mController->SetTextElideEnabled(true);
1222 mController->SetAutoScrollMaxTextureExceeded(true);
1224 GetHeightForWidth(maxTextureSize);
1225 wrapGap = std::max(maxTextureSize - textNaturalSize.width, 0.0f);
1228 Text::TypesetterPtr typesetter = Text::Typesetter::New(mController->GetTextModel());
1230 PixelData data = typesetter->Render(verifiedSize, mController->GetTextDirection(), Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888); // ignore the horizontal alignment
1231 Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D,
1232 data.GetPixelFormat(),
1235 texture.Upload(data);
1237 TextureSet textureSet = TextureSet::New();
1238 textureSet.SetTexture(0u, texture);
1240 // Filter mode needs to be set to linear to produce better quality while scaling.
1241 Sampler sampler = Sampler::New();
1242 sampler.SetFilterMode(FilterMode::LINEAR, FilterMode::LINEAR);
1243 sampler.SetWrapMode(Dali::WrapMode::DEFAULT, Dali::WrapMode::REPEAT, Dali::WrapMode::DEFAULT); // Wrap the texture in the x direction
1244 textureSet.SetSampler(0u, sampler);
1246 // Set parameters for scrolling
1247 Renderer renderer = static_cast<Internal::Visual::Base&>(GetImplementation(mVisual)).GetRenderer();
1248 mTextScroller->SetParameters(Self(), renderer, textureSet, controlSize, verifiedSize, wrapGap, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment());
1249 mController->SetTextElideEnabled(actualellipsis);
1250 mController->SetAutoScrollMaxTextureExceeded(false);
1253 void TextLabel::ScrollingFinished()
1255 // Pure Virtual from TextScroller Interface
1256 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
1258 if(mController->IsAutoScrollEnabled() || !mController->IsMultiLineEnabled())
1260 mController->SetAutoScrollEnabled(false);
1261 RequestTextRelayout();
1265 void TextLabel::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1267 mController->ChangedLayoutDirection();
1270 void TextLabel::EmitTextFitChangedSignal()
1272 Dali::Toolkit::TextLabel handle(GetOwner());
1273 mTextFitChangedSignal.Emit(handle);
1276 void TextLabel::OnAccessibilityStatusChanged()
1278 CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
1281 TextLabel::TextLabel(ControlBehaviour additionalBehaviour)
1282 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour)),
1283 mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1284 mTextUpdateNeeded(false),
1285 mLastAutoScrollEnabled(false)
1289 TextLabel::~TextLabel()
1293 Vector<Vector2> TextLabel::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
1295 return mController->GetTextSize(startIndex, endIndex);
1298 Vector<Vector2> TextLabel::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
1300 return mController->GetTextPosition(startIndex, endIndex);
1303 Rect<float> TextLabel::GetLineBoundingRectangle(const uint32_t lineIndex) const
1305 return mController->GetLineBoundingRectangle(lineIndex);
1308 Rect<float> TextLabel::GetCharacterBoundingRectangle(const uint32_t charIndex) const
1310 return mController->GetCharacterBoundingRectangle(charIndex);
1313 int TextLabel::GetCharacterIndexAtPosition(float visualX, float visualY) const
1315 return mController->GetCharacterIndexAtPosition(visualX, visualY);
1318 Rect<> TextLabel::GetTextBoundingRectangle(uint32_t startIndex, uint32_t endIndex) const
1320 return mController->GetTextBoundingRectangle(startIndex, endIndex);
1323 void TextLabel::SetSpannedText(const Text::Spanned& spannedText)
1325 mController->SetSpannedText(spannedText);
1328 void TextLabel::SetTextFitArray(const bool enable, std::vector<Toolkit::DevelTextLabel::FitOption>& fitOptions)
1332 // If TextFitArray is disabled, MinLineSize shoud be restored to its original size.
1333 mController->SetDefaultLineSize(mController->GetCurrentLineSize());
1335 mController->SetTextFitArrayEnabled(enable);
1336 mController->SetTextFitArray(fitOptions);
1339 std::vector<Toolkit::DevelTextLabel::FitOption>& TextLabel::GetTextFitArray()
1341 return mController->GetTextFitArray();
1344 bool TextLabel::IsTextFitArrayEnabled() const
1346 return mController->IsTextFitArrayEnabled();
1349 std::string TextLabel::TextLabelAccessible::GetNameRaw() const
1351 return GetWholeText();
1354 Property::Index TextLabel::TextLabelAccessible::GetNamePropertyIndex()
1356 return Toolkit::TextLabel::Property::TEXT;
1359 const std::vector<Toolkit::TextAnchor>& TextLabel::TextLabelAccessible::GetTextAnchors() const
1361 auto self = Toolkit::TextLabel::DownCast(Self());
1363 return Toolkit::GetImpl(self).mAnchorActors;
1366 Toolkit::Text::ControllerPtr TextLabel::TextLabelAccessible::GetTextController() const
1368 auto self = Toolkit::TextLabel::DownCast(Self());
1370 return Toolkit::GetImpl(self).GetTextController();
1373 } // namespace Internal
1375 } // namespace Toolkit