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 )
145 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT(Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR )
146 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0)
147 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1)
148 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColorBlue", TEXT_COLOR_BLUE, TEXT_COLOR, 2)
149 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3)
151 DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "anchorClicked", SIGNAL_ANCHOR_CLICKED)
152 DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "textFitChanged", SIGNAL_TEXT_FIT_CHANGED)
154 DALI_TYPE_REGISTRATION_END()
157 /// Parses the property map for the TEXT_FIT property
158 void ParseTextFitProperty(Text::ControllerPtr& controller, const Property::Map* propertiesMap)
160 if(propertiesMap && !propertiesMap->Empty())
162 bool enabled = false;
165 float stepSize = 0.f;
166 bool isMinSizeSet = false, isMaxSizeSet = false, isStepSizeSet = false;
167 Controller::FontSizeType type = Controller::FontSizeType::POINT_SIZE;
169 const unsigned int numberOfItems = propertiesMap->Count();
171 // Parses and applies
172 for(unsigned int index = 0u; index < numberOfItems; ++index)
174 const KeyValuePair& valueGet = propertiesMap->GetKeyValue(index);
176 if((Controller::TextFitInfo::Property::TEXT_FIT_ENABLE == valueGet.first.indexKey) || (TEXT_FIT_ENABLE_KEY == valueGet.first.stringKey))
179 enabled = valueGet.second.Get<bool>();
181 else if((Controller::TextFitInfo::Property::TEXT_FIT_MIN_SIZE == valueGet.first.indexKey) || (TEXT_FIT_MIN_SIZE_KEY == valueGet.first.stringKey))
184 minSize = valueGet.second.Get<float>();
187 else if((Controller::TextFitInfo::Property::TEXT_FIT_MAX_SIZE == valueGet.first.indexKey) || (TEXT_FIT_MAX_SIZE_KEY == valueGet.first.stringKey))
190 maxSize = valueGet.second.Get<float>();
193 else if((Controller::TextFitInfo::Property::TEXT_FIT_STEP_SIZE == valueGet.first.indexKey) || (TEXT_FIT_STEP_SIZE_KEY == valueGet.first.stringKey))
196 stepSize = valueGet.second.Get<float>();
197 isStepSizeSet = true;
199 else if((Controller::TextFitInfo::Property::TEXT_FIT_FONT_SIZE_TYPE == valueGet.first.indexKey) || (TEXT_FIT_FONT_SIZE_TYPE_KEY == valueGet.first.stringKey))
201 if("pixelSize" == valueGet.second.Get<std::string>())
203 type = Controller::FontSizeType::PIXEL_SIZE;
208 controller->SetTextFitEnabled(enabled);
209 // The TextFit operation is performed based on the MinLineSize set in the TextLabel at the moment when the TextFit property is set.
210 // So, if you change the TextLabel's MinLineSize after setting the TextFit property, it does not affect the operation of TextFit.
211 // This may require a new LineSize item in TextFit.
212 controller->SetTextFitLineSize(controller->GetDefaultLineSize());
215 controller->SetTextFitMinSize(minSize, type);
219 controller->SetTextFitMaxSize(maxSize, type);
223 controller->SetTextFitStepSize(stepSize, type);
230 Toolkit::TextLabel TextLabel::New(ControlBehaviour additionalBehaviour)
232 // Create the implementation, temporarily owned by this handle on stack
233 IntrusivePtr<TextLabel> impl = new TextLabel(additionalBehaviour);
235 // Pass ownership to CustomActor handle
236 Toolkit::TextLabel handle(*impl);
238 // Second-phase init of the implementation
239 // This can only be done after the CustomActor connection has been made...
245 void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
247 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast(Dali::BaseHandle(object));
251 TextLabel& impl(GetImpl(label));
252 DALI_ASSERT_ALWAYS(impl.mController && "No text contoller");
256 case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
258 int backend = value.Get<int>();
260 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
261 if(DevelText::RENDERING_VECTOR_BASED == backend)
263 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
266 if(impl.mRenderingBackend != backend)
268 impl.mRenderingBackend = backend;
269 impl.mTextUpdateNeeded = true;
271 // When using the vector-based rendering, the size of the GLyphs are different
272 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
273 impl.mController->SetGlyphType(glyphType);
277 case Toolkit::TextLabel::Property::TEXT:
279 impl.mController->SetText(value.Get<std::string>());
281 if(impl.mController->HasAnchors())
283 // Forward input events to controller
284 impl.EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
288 impl.DisableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
293 case Toolkit::TextLabel::Property::FONT_FAMILY:
295 const std::string& fontFamily = value.Get<std::string>();
297 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str());
298 impl.mController->SetDefaultFontFamily(fontFamily);
301 case Toolkit::TextLabel::Property::FONT_STYLE:
303 SetFontStyleProperty(impl.mController, value, Text::FontStyle::DEFAULT);
306 case Toolkit::TextLabel::Property::POINT_SIZE:
308 const float pointSize = value.Get<float>();
310 if(!Equals(impl.mController->GetDefaultFontSize(Text::Controller::POINT_SIZE), pointSize))
312 impl.mController->SetDefaultFontSize(pointSize, Text::Controller::POINT_SIZE);
316 case Toolkit::TextLabel::Property::MULTI_LINE:
318 impl.mController->SetMultiLineEnabled(value.Get<bool>());
321 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
323 Text::HorizontalAlignment::Type alignment(static_cast<Text::HorizontalAlignment::Type>(-1)); // Set to invalid value to ensure a valid mode does get set
324 if(Text::GetHorizontalAlignmentEnumeration(value, alignment))
326 impl.mController->SetHorizontalAlignment(alignment);
330 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
332 Toolkit::Text::VerticalAlignment::Type alignment(static_cast<Text::VerticalAlignment::Type>(-1)); // Set to invalid value to ensure a valid mode does get set
333 if(Text::GetVerticalAlignmentEnumeration(value, alignment))
335 impl.mController->SetVerticalAlignment(alignment);
339 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
341 const bool enableMarkup = value.Get<bool>();
342 impl.mController->SetMarkupProcessorEnabled(enableMarkup);
344 if(impl.mController->HasAnchors())
346 // Forward input events to controller
347 impl.EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
351 impl.DisableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
355 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
357 const bool enableAutoScroll = value.Get<bool>();
358 impl.mLastAutoScrollEnabled = enableAutoScroll;
359 // If request to auto scroll is the same as current state then do nothing.
360 if(enableAutoScroll != impl.mController->IsAutoScrollEnabled())
362 // If request is disable (false) and auto scrolling is enabled then need to stop it
363 if(enableAutoScroll == false)
365 if(impl.mTextScroller)
367 impl.mTextScroller->StopScrolling();
370 // If request is enable (true) then start autoscroll as not already running
373 impl.mController->SetAutoScrollEnabled(enableAutoScroll);
378 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
380 Text::TextScrollerPtr textScroller = impl.GetTextScroller();
381 Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = textScroller->GetStopMode();
382 if(Scripting::GetEnumerationProperty<Toolkit::TextLabel::AutoScrollStopMode::Type>(value,
383 AUTO_SCROLL_STOP_MODE_TABLE,
384 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
387 textScroller->SetStopMode(stopMode);
391 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
393 impl.GetTextScroller()->SetSpeed(value.Get<int>());
396 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
398 impl.GetTextScroller()->SetLoopCount(value.Get<int>());
401 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
403 impl.GetTextScroller()->SetLoopDelay(value.Get<float>());
406 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
408 impl.GetTextScroller()->SetGap(value.Get<float>());
411 case Toolkit::TextLabel::Property::LINE_SPACING:
413 const float lineSpacing = value.Get<float>();
414 impl.mTextUpdateNeeded = impl.mController->SetDefaultLineSpacing(lineSpacing) || impl.mTextUpdateNeeded;
417 case Toolkit::TextLabel::Property::UNDERLINE:
419 impl.mTextUpdateNeeded = SetUnderlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
422 case Toolkit::TextLabel::Property::SHADOW:
424 impl.mTextUpdateNeeded = SetShadowProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
427 case Toolkit::TextLabel::Property::EMBOSS:
429 impl.mTextUpdateNeeded = SetEmbossProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
432 case Toolkit::TextLabel::Property::OUTLINE:
434 impl.mTextUpdateNeeded = SetOutlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
437 case Toolkit::TextLabel::Property::PIXEL_SIZE:
439 const float pixelSize = value.Get<float>();
440 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize);
442 if(!Equals(impl.mController->GetDefaultFontSize(Text::Controller::PIXEL_SIZE), pixelSize))
444 impl.mController->SetDefaultFontSize(pixelSize, Text::Controller::PIXEL_SIZE);
448 case Toolkit::TextLabel::Property::ELLIPSIS:
450 const bool ellipsis = value.Get<bool>();
451 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis);
453 impl.mController->SetTextElideEnabled(ellipsis);
456 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
458 Text::LineWrap::Mode lineWrapMode(static_cast<Text::LineWrap::Mode>(-1)); // Set to invalid value to ensure a valid mode does get set
459 if(GetLineWrapModeEnumeration(value, lineWrapMode))
461 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode);
462 impl.mController->SetLineWrapMode(lineWrapMode);
466 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
468 if(impl.mController->GetTextModel())
470 DevelText::VerticalLineAlignment::Type alignment = static_cast<DevelText::VerticalLineAlignment::Type>(value.Get<int>());
472 impl.mController->SetVerticalLineAlignment(alignment);
474 // Property doesn't affect the layout, only Visual must be updated
475 TextVisual::EnableRendererUpdate(impl.mVisual);
477 // No need to trigger full re-layout. Instead call UpdateRenderer() directly
478 TextVisual::UpdateRenderer(impl.mVisual);
482 case Toolkit::DevelTextLabel::Property::BACKGROUND:
484 impl.mTextUpdateNeeded = SetBackgroundProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
487 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
489 impl.mController->SetIgnoreSpacesAfterText(value.Get<bool>());
492 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
494 impl.mController->SetMatchLayoutDirection(value.Get<bool>() ? DevelText::MatchLayoutDirection::LOCALE : DevelText::MatchLayoutDirection::CONTENTS);
497 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
499 // If TextFitArray is enabled, this should be disabled.
500 if(impl.mController->IsTextFitArrayEnabled())
502 impl.mController->SetDefaultLineSize(impl.mController->GetCurrentLineSize());
503 impl.mController->SetTextFitArrayEnabled(false);
506 ParseTextFitProperty(impl.mController, value.GetMap());
507 impl.mController->SetTextFitChanged(true);
510 case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
512 const float lineSize = value.Get<float>();
513 // If TextFitArray is enabled, do not update the default line size.
514 if(!impl.mController->IsTextFitArrayEnabled())
516 impl.mTextUpdateNeeded = impl.mController->SetDefaultLineSize(lineSize) || impl.mTextUpdateNeeded;
518 impl.mController->SetCurrentLineSize(lineSize);
521 case Toolkit::DevelTextLabel::Property::FONT_SIZE_SCALE:
523 const float scale = value.Get<float>();
524 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p FONT_SIZE_SCALE %f\n", impl.mController.Get(), scale);
526 if(!Equals(impl.mController->GetFontSizeScale(), scale))
528 impl.mController->SetFontSizeScale(scale);
532 case Toolkit::DevelTextLabel::Property::ENABLE_FONT_SIZE_SCALE:
534 const bool enableFontSizeScale = value.Get<bool>();
535 if(!Equals(impl.mController->IsFontSizeScaleEnabled(), enableFontSizeScale))
537 impl.mController->SetFontSizeScaleEnabled(enableFontSizeScale);
541 case Toolkit::DevelTextLabel::Property::ELLIPSIS_POSITION:
543 DevelText::EllipsisPosition::Type ellipsisPositionType(static_cast<DevelText::EllipsisPosition::Type>(-1)); // Set to invalid value to ensure a valid mode does get set
544 if(GetEllipsisPositionTypeEnumeration(value, ellipsisPositionType))
546 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p EllipsisPosition::Type %d\n", impl.mController.Get(), ellipsisPositionType);
547 impl.mController->SetEllipsisPosition(ellipsisPositionType);
551 case Toolkit::DevelTextLabel::Property::STRIKETHROUGH:
553 impl.mTextUpdateNeeded = SetStrikethroughProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
556 case Toolkit::DevelTextLabel::Property::CHARACTER_SPACING:
558 const float characterSpacing = value.Get<float>();
559 impl.mController->SetCharacterSpacing(characterSpacing);
562 case Toolkit::DevelTextLabel::Property::RELATIVE_LINE_SIZE:
564 const float relativeLineSize = value.Get<float>();
565 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel %p RELATIVE_LINE_SIZE %f\n", impl.mController.Get(), relativeLineSize);
567 impl.mController->SetRelativeLineSize(relativeLineSize);
572 // Request relayout when text update is needed. It's necessary to call it
573 // as changing the property not via UI interaction brings no effect if only
574 // the mTextUpdateNeeded is changed.
575 if(impl.mTextUpdateNeeded)
577 // need to request relayout as size of text may have changed
578 impl.RequestTextRelayout();
583 Text::ControllerPtr TextLabel::GetTextController()
588 Property::Value TextLabel::GetProperty(BaseObject* object, Property::Index index)
590 Property::Value value;
592 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast(Dali::BaseHandle(object));
596 TextLabel& impl(GetImpl(label));
597 DALI_ASSERT_DEBUG(impl.mController && "No text contoller");
601 case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
603 value = impl.mRenderingBackend;
606 case Toolkit::TextLabel::Property::TEXT:
609 impl.mController->GetText(text);
613 case Toolkit::TextLabel::Property::FONT_FAMILY:
615 value = impl.mController->GetDefaultFontFamily();
618 case Toolkit::TextLabel::Property::FONT_STYLE:
620 GetFontStyleProperty(impl.mController, value, Text::FontStyle::DEFAULT);
623 case Toolkit::TextLabel::Property::POINT_SIZE:
625 value = impl.mController->GetDefaultFontSize(Text::Controller::POINT_SIZE);
628 case Toolkit::TextLabel::Property::MULTI_LINE:
630 value = impl.mController->IsMultiLineEnabled();
633 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
635 const char* name = Text::GetHorizontalAlignmentString(impl.mController->GetHorizontalAlignment());
639 value = std::string(name);
643 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
645 const char* name = Text::GetVerticalAlignmentString(impl.mController->GetVerticalAlignment());
648 value = std::string(name);
652 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
654 value = impl.mController->IsMarkupProcessorEnabled();
657 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
659 value = impl.mController->IsAutoScrollEnabled();
662 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
664 if(impl.mTextScroller)
666 const char* mode = Scripting::GetEnumerationName<Toolkit::TextLabel::AutoScrollStopMode::Type>(impl.mTextScroller->GetStopMode(),
667 AUTO_SCROLL_STOP_MODE_TABLE,
668 AUTO_SCROLL_STOP_MODE_TABLE_COUNT);
671 value = std::string(mode);
676 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
678 if(impl.mTextScroller)
680 value = impl.mTextScroller->GetSpeed();
684 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
686 if(impl.mTextScroller)
688 value = impl.mTextScroller->GetLoopCount();
692 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
694 if(impl.mTextScroller)
696 value = impl.mTextScroller->GetLoopDelay();
700 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
702 if(impl.mTextScroller)
704 value = impl.mTextScroller->GetGap();
708 case Toolkit::TextLabel::Property::LINE_SPACING:
710 value = impl.mController->GetDefaultLineSpacing();
713 case Toolkit::TextLabel::Property::UNDERLINE:
715 GetUnderlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
718 case Toolkit::TextLabel::Property::SHADOW:
720 GetShadowProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
723 case Toolkit::TextLabel::Property::EMBOSS:
725 GetEmbossProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
728 case Toolkit::TextLabel::Property::OUTLINE:
730 GetOutlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
733 case Toolkit::TextLabel::Property::PIXEL_SIZE:
735 value = impl.mController->GetDefaultFontSize(Text::Controller::PIXEL_SIZE);
738 case Toolkit::TextLabel::Property::ELLIPSIS:
740 value = impl.mController->IsTextElideEnabled();
743 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
745 value = impl.mController->GetLineWrapMode();
748 case Toolkit::TextLabel::Property::LINE_COUNT:
750 float width = label.GetProperty(Actor::Property::SIZE_WIDTH).Get<float>();
751 value = impl.mController->GetLineCount(width);
754 case Toolkit::DevelTextLabel::Property::TEXT_DIRECTION:
756 value = impl.mController->GetTextDirection();
759 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
761 value = impl.mController->GetVerticalLineAlignment();
764 case Toolkit::DevelTextLabel::Property::BACKGROUND:
766 GetBackgroundProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
769 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
771 value = impl.mController->IsIgnoreSpacesAfterText();
774 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
776 value = impl.mController->GetMatchLayoutDirection() != DevelText::MatchLayoutDirection::CONTENTS;
779 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
781 const bool enabled = impl.mController->IsTextFitEnabled();
782 const float minSize = impl.mController->GetTextFitMinSize();
783 const float maxSize = impl.mController->GetTextFitMaxSize();
784 const float stepSize = impl.mController->GetTextFitStepSize();
785 const float pointSize = impl.mController->GetTextFitPointSize();
788 map.Insert(TEXT_FIT_ENABLE_KEY, enabled);
789 map.Insert(TEXT_FIT_MIN_SIZE_KEY, minSize);
790 map.Insert(TEXT_FIT_MAX_SIZE_KEY, maxSize);
791 map.Insert(TEXT_FIT_STEP_SIZE_KEY, stepSize);
792 map.Insert(TEXT_FIT_FONT_SIZE_KEY, pointSize);
793 map.Insert(TEXT_FIT_FONT_SIZE_TYPE_KEY, "pointSize");
798 case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
800 // If TextFitArray is enabled, the stored value (MIN_LINE_SIZE set by the user) is retrun.
801 value = impl.mController->IsTextFitArrayEnabled() ? impl.mController->GetCurrentLineSize() : impl.mController->GetDefaultLineSize();
804 case Toolkit::DevelTextLabel::Property::FONT_SIZE_SCALE:
806 value = impl.mController->GetFontSizeScale();
809 case Toolkit::DevelTextLabel::Property::ENABLE_FONT_SIZE_SCALE:
811 value = impl.mController->IsFontSizeScaleEnabled();
814 case Toolkit::DevelTextLabel::Property::ELLIPSIS_POSITION:
816 value = impl.mController->GetEllipsisPosition();
819 case Toolkit::DevelTextLabel::Property::STRIKETHROUGH:
821 GetStrikethroughProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
824 case Toolkit::DevelTextLabel::Property::CHARACTER_SPACING:
826 value = impl.mController->GetCharacterSpacing();
829 case Toolkit::DevelTextLabel::Property::RELATIVE_LINE_SIZE:
831 value = impl.mController->GetRelativeLineSize();
840 bool TextLabel::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
842 Dali::BaseHandle handle(object);
844 bool connected(true);
845 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast(handle);
847 if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
851 Internal::TextLabel& labelImpl(GetImpl(label));
852 labelImpl.AnchorClickedSignal().Connect(tracker, functor);
855 else if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_FIT_CHANGED))
859 Internal::TextLabel& labelImpl(GetImpl(label));
860 labelImpl.TextFitChangedSignal().Connect(tracker, functor);
865 // signalName does not match any signal
872 DevelTextLabel::AnchorClickedSignalType& TextLabel::AnchorClickedSignal()
874 return mAnchorClickedSignal;
877 DevelTextLabel::TextFitChangedSignalType& TextLabel::TextFitChangedSignal()
879 return mTextFitChangedSignal;
882 void TextLabel::OnInitialize()
886 Property::Map propertyMap;
887 propertyMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT);
889 mVisual = Toolkit::VisualFactory::Get().CreateVisual(propertyMap);
890 DevelControl::RegisterVisual(*this, Toolkit::TextLabel::Property::TEXT, mVisual);
892 TextVisual::SetAnimatableTextColorProperty(mVisual, Toolkit::TextLabel::Property::TEXT_COLOR);
894 mController = TextVisual::GetController(mVisual);
895 DALI_ASSERT_DEBUG(mController && "Invalid Text Controller")
897 mController->SetControlInterface(this);
898 mController->SetAnchorControlInterface(this);
900 // Use height-for-width negotiation by default
901 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
902 self.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT);
904 // Enable the text ellipsis.
905 mController->SetTextElideEnabled(true); // If false then text larger than control will overflow
907 // Sets layoutDirection value
908 Dali::Stage stage = Dali::Stage::GetCurrent();
909 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
910 mController->SetLayoutDirection(layoutDirection);
912 self.LayoutDirectionChangedSignal().Connect(this, &TextLabel::OnLayoutDirectionChanged);
914 Layout::Engine& engine = mController->GetLayoutEngine();
915 engine.SetCursorWidth(0u); // Do not layout space for the cursor.
918 self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::LABEL);
919 self.SetProperty(DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
921 Accessibility::Bridge::EnabledSignal().Connect(this, &TextLabel::OnAccessibilityStatusChanged);
922 Accessibility::Bridge::DisabledSignal().Connect(this, &TextLabel::OnAccessibilityStatusChanged);
925 DevelControl::ControlAccessible* TextLabel::CreateAccessibleObject()
927 return new TextLabelAccessible(Self());
930 void TextLabel::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
932 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
936 case StyleChange::DEFAULT_FONT_CHANGE:
938 // Property system did not set the font so should update it.
939 const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
940 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str());
941 mController->UpdateAfterFontChange(newFont);
945 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
947 GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
951 case StyleChange::THEME_CHANGE:
953 // Nothing to do, let control base class handle this
958 // Up call to Control
959 Control::OnStyleChange(styleManager, change);
962 void TextLabel::OnTap(const TapGesture& gesture)
964 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::OnTap %p\n", mController.Get());
966 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
968 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
969 const Vector2& localPoint = gesture.GetLocalPoint();
970 mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
973 void TextLabel::AnchorClicked(const std::string& href)
975 Dali::Toolkit::TextLabel handle(GetOwner());
976 mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
979 Vector3 TextLabel::GetNaturalSize()
982 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
984 Vector3 naturalSize = mController->GetNaturalSize();
985 naturalSize.width += (padding.start + padding.end);
986 naturalSize.height += (padding.top + padding.bottom);
991 float TextLabel::GetHeightForWidth(float width)
994 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
996 return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
999 void TextLabel::OnPropertySet(Property::Index index, const Property::Value& propertyValue)
1001 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index);
1005 case Toolkit::TextLabel::Property::TEXT_COLOR:
1007 const Vector4& textColor = propertyValue.Get<Vector4>();
1008 if(mController->GetDefaultColor() != textColor)
1010 mController->SetDefaultColor(textColor);
1011 mTextUpdateNeeded = true;
1015 case Toolkit::TextLabel::Property::TEXT:
1016 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
1018 CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
1023 Control::OnPropertySet(index, propertyValue); // up call to control for non-handled properties
1029 void TextLabel::OnSceneConnection(int depth)
1031 if(mController->IsAutoScrollEnabled() || mLastAutoScrollEnabled)
1033 mController->SetAutoScrollEnabled(true);
1035 Control::OnSceneConnection(depth);
1038 void TextLabel::OnSceneDisconnection()
1042 if(mLastAutoScrollEnabled && !mController->IsAutoScrollEnabled())
1044 mLastAutoScrollEnabled = false;
1047 const Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = mTextScroller->GetStopMode();
1048 mTextScroller->SetStopMode(Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE);
1049 mTextScroller->StopScrolling();
1050 mTextScroller->SetStopMode(stopMode);
1052 Control::OnSceneDisconnection();
1055 void TextLabel::OnRelayout(const Vector2& size, RelayoutContainer& container)
1057 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnRelayout\n");
1059 Actor self = Self();
1062 padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
1064 Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
1066 if(mController->IsTextFitArrayEnabled())
1068 mController->FitArrayPointSizeforLayout(contentSize);
1069 mController->SetTextFitContentSize(contentSize);
1071 else if(mController->IsTextFitEnabled())
1073 mController->FitPointSizeforLayout(contentSize);
1074 mController->SetTextFitContentSize(contentSize);
1077 // Support Right-To-Left
1078 Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
1080 const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
1082 if((Text::Controller::NONE_UPDATED != (Text::Controller::MODEL_UPDATED & updateTextType)) || mTextUpdateNeeded)
1084 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", (mController->IsAutoScrollEnabled()) ? "true" : "false", this);
1086 // Update the visual
1087 TextVisual::EnableRendererUpdate(mVisual);
1089 // Support Right-To-Left of padding
1090 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
1092 std::swap(padding.start, padding.end);
1095 // Calculate the size of the visual that can fit the text
1096 Size layoutSize = mController->GetTextModel()->GetLayoutSize();
1097 layoutSize.x = contentSize.x;
1099 const Vector2& shadowOffset = mController->GetTextModel()->GetShadowOffset();
1100 if(shadowOffset.y > Math::MACHINE_EPSILON_1)
1102 layoutSize.y += shadowOffset.y;
1105 float outlineWidth = mController->GetTextModel()->GetOutlineWidth();
1106 layoutSize.y += outlineWidth * 2.0f;
1107 layoutSize.y = std::min(layoutSize.y, contentSize.y);
1109 // Calculate the offset for vertical alignment only, as the layout engine will do the horizontal alignment.
1110 Vector2 alignmentOffset;
1111 alignmentOffset.x = 0.0f;
1112 alignmentOffset.y = (contentSize.y - layoutSize.y) * VERTICAL_ALIGNMENT_TABLE[mController->GetVerticalAlignment()];
1114 const int maxTextureSize = Dali::GetMaxTextureSize();
1115 if(layoutSize.width > maxTextureSize)
1117 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);
1118 layoutSize.width = maxTextureSize;
1121 // This affects font rendering quality.
1122 // It need to be integerized.
1123 Vector2 visualTransformOffset;
1124 visualTransformOffset.x = roundf(padding.start + alignmentOffset.x);
1125 visualTransformOffset.y = roundf(padding.top + alignmentOffset.y);
1127 Property::Map visualTransform;
1128 visualTransform.Add(Toolkit::Visual::Transform::Property::SIZE, layoutSize)
1129 .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
1130 .Add(Toolkit::Visual::Transform::Property::OFFSET, visualTransformOffset)
1131 .Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
1132 .Add(Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN)
1133 .Add(Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN);
1134 mVisual.SetTransformAndSize(visualTransform, size);
1136 if(mController->IsAutoScrollEnabled())
1138 SetUpAutoScrolling();
1141 mTextUpdateNeeded = false;
1144 if(mController->IsTextFitChanged())
1146 EmitTextFitChangedSignal();
1147 mController->SetTextFitChanged(false);
1151 void TextLabel::RequestTextRelayout()
1154 // Signal that a Relayout may be needed
1157 void TextLabel::SetUpAutoScrolling()
1159 const Size& controlSize = mController->GetView().GetControlSize();
1160 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.
1161 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
1163 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n", textNaturalSize.x, textNaturalSize.y, controlSize.x, controlSize.y);
1167 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n");
1169 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
1170 mTextScroller = Text::TextScroller::New(*this);
1173 // Calculate the actual gap before scrolling wraps.
1174 int textPadding = std::max(controlSize.x - textNaturalSize.x, 0.0f);
1175 float wrapGap = std::max(mTextScroller->GetGap(), textPadding);
1176 Vector2 textureSize = textNaturalSize + Vector2(wrapGap, 0.0f); // Add the gap as a part of the texture
1178 // Create a texture of the text for scrolling
1179 Size verifiedSize = textureSize;
1180 const int maxTextureSize = Dali::GetMaxTextureSize();
1182 //if the texture size width exceed maxTextureSize, modify the visual model size and enabled the ellipsis
1183 bool actualellipsis = mController->IsTextElideEnabled();
1184 if(verifiedSize.width > maxTextureSize)
1186 verifiedSize.width = maxTextureSize;
1187 if(textNaturalSize.width > maxTextureSize)
1189 mController->SetTextElideEnabled(true);
1190 mController->SetAutoScrollMaxTextureExceeded(true);
1192 GetHeightForWidth(maxTextureSize);
1193 wrapGap = std::max(maxTextureSize - textNaturalSize.width, 0.0f);
1196 Text::TypesetterPtr typesetter = Text::Typesetter::New(mController->GetTextModel());
1198 PixelData data = typesetter->Render(verifiedSize, mController->GetTextDirection(), Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888); // ignore the horizontal alignment
1199 Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D,
1200 data.GetPixelFormat(),
1203 texture.Upload(data);
1205 TextureSet textureSet = TextureSet::New();
1206 textureSet.SetTexture(0u, texture);
1208 // Filter mode needs to be set to linear to produce better quality while scaling.
1209 Sampler sampler = Sampler::New();
1210 sampler.SetFilterMode(FilterMode::LINEAR, FilterMode::LINEAR);
1211 sampler.SetWrapMode(Dali::WrapMode::DEFAULT, Dali::WrapMode::REPEAT, Dali::WrapMode::DEFAULT); // Wrap the texture in the x direction
1212 textureSet.SetSampler(0u, sampler);
1214 // Set parameters for scrolling
1215 Renderer renderer = static_cast<Internal::Visual::Base&>(GetImplementation(mVisual)).GetRenderer();
1216 mTextScroller->SetParameters(Self(), renderer, textureSet, controlSize, verifiedSize, wrapGap, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment());
1217 mController->SetTextElideEnabled(actualellipsis);
1218 mController->SetAutoScrollMaxTextureExceeded(false);
1221 void TextLabel::ScrollingFinished()
1223 // Pure Virtual from TextScroller Interface
1224 DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
1226 if(mController->IsAutoScrollEnabled() || !mController->IsMultiLineEnabled())
1228 mController->SetAutoScrollEnabled(false);
1229 RequestTextRelayout();
1233 void TextLabel::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1235 mController->ChangedLayoutDirection();
1238 void TextLabel::EmitTextFitChangedSignal()
1240 Dali::Toolkit::TextLabel handle(GetOwner());
1241 mTextFitChangedSignal.Emit(handle);
1244 void TextLabel::OnAccessibilityStatusChanged()
1246 CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
1249 TextLabel::TextLabel(ControlBehaviour additionalBehaviour)
1250 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour)),
1251 mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1252 mTextUpdateNeeded(false),
1253 mLastAutoScrollEnabled(false)
1257 TextLabel::~TextLabel()
1261 Vector<Vector2> TextLabel::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
1263 return mController->GetTextSize(startIndex, endIndex);
1266 Vector<Vector2> TextLabel::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
1268 return mController->GetTextPosition(startIndex, endIndex);
1271 Rect<float> TextLabel::GetLineBoundingRectangle(const uint32_t lineIndex) const
1273 return mController->GetLineBoundingRectangle(lineIndex);
1276 Rect<float> TextLabel::GetCharacterBoundingRectangle(const uint32_t charIndex) const
1278 return mController->GetCharacterBoundingRectangle(charIndex);
1281 int TextLabel::GetCharacterIndexAtPosition(float visualX, float visualY) const
1283 return mController->GetCharacterIndexAtPosition(visualX, visualY);
1286 Rect<> TextLabel::GetTextBoundingRectangle(uint32_t startIndex, uint32_t endIndex) const
1288 return mController->GetTextBoundingRectangle(startIndex, endIndex);
1291 void TextLabel::SetSpannedText(const Text::Spanned& spannedText)
1293 mController->SetSpannedText(spannedText);
1296 void TextLabel::SetTextFitArray(const bool enable, std::vector<Toolkit::DevelTextLabel::FitOption>& fitOptions)
1300 // If TextFitArray is disabled, MinLineSize shoud be restored to its original size.
1301 mController->SetDefaultLineSize(mController->GetCurrentLineSize());
1303 mController->SetTextFitArrayEnabled(enable);
1304 mController->SetTextFitArray(fitOptions);
1307 std::vector<Toolkit::DevelTextLabel::FitOption>& TextLabel::GetTextFitArray()
1309 return mController->GetTextFitArray();
1312 bool TextLabel::IsTextFitArrayEnabled() const
1314 return mController->IsTextFitArrayEnabled();
1317 std::string TextLabel::TextLabelAccessible::GetNameRaw() const
1319 return GetWholeText();
1322 Property::Index TextLabel::TextLabelAccessible::GetNamePropertyIndex()
1324 return Toolkit::TextLabel::Property::TEXT;
1327 const std::vector<Toolkit::TextAnchor>& TextLabel::TextLabelAccessible::GetTextAnchors() const
1329 auto self = Toolkit::TextLabel::DownCast(Self());
1331 return Toolkit::GetImpl(self).mAnchorActors;
1334 Toolkit::Text::ControllerPtr TextLabel::TextLabelAccessible::GetTextController() const
1336 auto self = Toolkit::TextLabel::DownCast(Self());
1338 return Toolkit::GetImpl(self).GetTextController();
1341 } // namespace Internal
1343 } // namespace Toolkit