2 * Copyright (c) 2019 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/public-api/object/type-registry-helper.h>
23 #include <dali/public-api/common/stage.h>
24 #include <dali/devel-api/object/property-helper-devel.h>
25 #include <dali/devel-api/adaptor-framework/image-loading.h>
26 #include <dali/integration-api/debug.h>
29 #include <dali-toolkit/public-api/text/rendering-backend.h>
30 #include <dali-toolkit/public-api/text/text-enumerations.h>
31 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
32 #include <dali-toolkit/internal/text/property-string-parser.h>
33 #include <dali-toolkit/internal/text/rendering/text-backend.h>
34 #include <dali-toolkit/internal/text/text-effects-style.h>
35 #include <dali-toolkit/internal/text/text-font-style.h>
36 #include <dali-toolkit/internal/text/text-view.h>
37 #include <dali-toolkit/internal/text/text-definitions.h>
38 #include <dali-toolkit/internal/styling/style-manager-impl.h>
40 #include <dali-toolkit/public-api/align-enumerations.h>
41 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
42 #include <dali-toolkit/devel-api/controls/control-devel.h>
43 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
44 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
45 #include <dali-toolkit/public-api/visuals/visual-properties.h>
46 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
48 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
50 using namespace Dali::Toolkit::Text;
63 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
66 * @brief How the text visual should be aligned vertically inside the control.
68 * 0.0f aligns the text to the top, 0.5f aligns the text to the center, 1.0f aligns the text to the bottom.
69 * The alignment depends on the alignment value of the text label (Use Text::VerticalAlignment enumerations).
71 const float VERTICAL_ALIGNMENT_TABLE[ Text::VerticalAlignment::BOTTOM + 1 ] =
73 0.0f, // VerticalAlignment::TOP
74 0.5f, // VerticalAlignment::CENTER
75 1.0f // VerticalAlignment::BOTTOM
78 const std::string TEXT_FIT_ENABLE_KEY( "enable" );
79 const std::string TEXT_FIT_MIN_SIZE_KEY( "minSize" );
80 const std::string TEXT_FIT_MAX_SIZE_KEY( "maxSize" );
81 const std::string TEXT_FIT_STEP_SIZE_KEY( "stepSize" );
82 const std::string TEXT_FIT_FONT_SIZE_TYPE_KEY( "fontSizeType" );
88 #if defined ( DEBUG_ENABLED )
89 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
92 const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] =
94 { "IMMEDIATE", Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE },
95 { "FINISH_LOOP", Toolkit::TextLabel::AutoScrollStopMode::FINISH_LOOP },
97 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof( AUTO_SCROLL_STOP_MODE_TABLE ) / sizeof( AUTO_SCROLL_STOP_MODE_TABLE[0] );
102 return Toolkit::TextLabel::New();
105 // Setup properties, signals and actions using the type-registry.
106 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "text", STRING, TEXT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily", STRING, FONT_FAMILY )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle", MAP, FONT_STYLE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize", FLOAT, POINT_SIZE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine", BOOLEAN, MULTI_LINE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "unusedPropertyTextColor", VECTOR4, UNUSED_PROPERTY_TEXT_COLOR )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "reservedProperty01", STRING, RESERVED_PROPERTY_01 )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "reservedProperty02", STRING, RESERVED_PROPERTY_02 )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "reservedProperty03", STRING, RESERVED_PROPERTY_03 )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "reservedProperty04", STRING, RESERVED_PROPERTY_04 )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "reservedProperty05", STRING, RESERVED_PROPERTY_05 )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline", MAP, UNDERLINE )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow", MAP, SHADOW )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss", MAP, EMBOSS )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP, OUTLINE )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
133 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
134 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
135 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE )
136 DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT )
137 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", INTEGER, LINE_WRAP_MODE )
138 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "textDirection", INTEGER, TEXT_DIRECTION )
139 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalLineAlignment", INTEGER, VERTICAL_LINE_ALIGNMENT )
140 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textBackground", MAP, BACKGROUND )
141 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ignoreSpacesAfterText", BOOLEAN, IGNORE_SPACES_AFTER_TEXT )
142 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
143 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textFit", MAP, TEXT_FIT )
144 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR )
145 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0 )
146 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1 )
147 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorBlue", TEXT_COLOR_BLUE, TEXT_COLOR, 2 )
148 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3 )
149 DALI_TYPE_REGISTRATION_END()
153 Toolkit::TextLabel TextLabel::New()
155 // Create the implementation, temporarily owned by this handle on stack
156 IntrusivePtr< TextLabel > impl = new TextLabel();
158 // Pass ownership to CustomActor handle
159 Toolkit::TextLabel handle( *impl );
161 // Second-phase init of the implementation
162 // This can only be done after the CustomActor connection has been made...
168 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
170 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
174 TextLabel& impl( GetImpl( label ) );
177 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
179 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
181 int backend = value.Get< int >();
183 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
184 if( Text::RENDERING_VECTOR_BASED == backend )
186 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
189 if( impl.mRenderingBackend != backend )
191 impl.mRenderingBackend = backend;
192 impl.mTextUpdateNeeded = true;
194 if( impl.mController )
196 // When using the vector-based rendering, the size of the GLyphs are different
197 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
198 impl.mController->SetGlyphType( glyphType );
203 case Toolkit::TextLabel::Property::TEXT:
205 if( impl.mController )
207 impl.mController->SetText( value.Get< std::string >() );
211 case Toolkit::TextLabel::Property::FONT_FAMILY:
213 if( impl.mController )
215 const std::string& fontFamily = value.Get< std::string >();
217 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
218 impl.mController->SetDefaultFontFamily( fontFamily );
222 case Toolkit::TextLabel::Property::FONT_STYLE:
224 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
227 case Toolkit::TextLabel::Property::POINT_SIZE:
229 if( impl.mController )
231 const float pointSize = value.Get< float >();
233 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
235 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
240 case Toolkit::TextLabel::Property::MULTI_LINE:
242 if( impl.mController )
244 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
248 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
250 if( impl.mController )
252 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
253 if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) )
255 impl.mController->SetHorizontalAlignment( alignment );
260 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
262 if( impl.mController )
264 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
265 if( Text::GetVerticalAlignmentEnumeration( value, alignment ) )
267 impl.mController->SetVerticalAlignment( alignment );
273 case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
275 label.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, value );
276 impl.mTextUpdateNeeded = true;
279 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
281 if( impl.mController )
283 const bool enableMarkup = value.Get<bool>();
284 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
288 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
290 if( impl.mController )
292 const bool enableAutoScroll = value.Get<bool>();
293 // If request to auto scroll is the same as current state then do nothing.
294 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
296 // If request is disable (false) and auto scrolling is enabled then need to stop it
297 if ( enableAutoScroll == false )
299 if( impl.mTextScroller )
301 impl.mTextScroller->StopScrolling();
304 // If request is enable (true) then start autoscroll as not already running
307 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
313 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
315 if( !impl.mTextScroller )
317 impl.mTextScroller = Text::TextScroller::New( impl );
319 Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
320 if( Scripting::GetEnumerationProperty< Toolkit::TextLabel::AutoScrollStopMode::Type >( value,
321 AUTO_SCROLL_STOP_MODE_TABLE,
322 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
325 impl.mTextScroller->SetStopMode( stopMode );
329 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
331 if( !impl.mTextScroller )
333 impl.mTextScroller = Text::TextScroller::New( impl );
335 impl.mTextScroller->SetSpeed( value.Get<int>() );
338 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
340 if( !impl.mTextScroller )
342 impl.mTextScroller = Text::TextScroller::New( impl );
344 impl.mTextScroller->SetLoopCount( value.Get<int>() );
347 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
349 if( !impl.mTextScroller )
351 impl.mTextScroller = Text::TextScroller::New( impl );
353 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
356 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
358 if( !impl.mTextScroller )
360 impl.mTextScroller = Text::TextScroller::New( impl );
362 impl.mTextScroller->SetGap( value.Get<float>() );
365 case Toolkit::TextLabel::Property::LINE_SPACING:
367 if( impl.mController )
369 const float lineSpacing = value.Get<float>();
371 // Don't trigger anything if the line spacing didn't change
372 if( impl.mController->SetDefaultLineSpacing( lineSpacing ) )
374 impl.mTextUpdateNeeded = true;
379 case Toolkit::TextLabel::Property::UNDERLINE:
381 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
384 impl.mTextUpdateNeeded = true;
388 case Toolkit::TextLabel::Property::SHADOW:
390 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
393 impl.mTextUpdateNeeded = true;
397 case Toolkit::TextLabel::Property::EMBOSS:
399 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
402 impl.mTextUpdateNeeded = true;
406 case Toolkit::TextLabel::Property::OUTLINE:
408 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
411 impl.mTextUpdateNeeded = true;
415 case Toolkit::TextLabel::Property::PIXEL_SIZE:
417 if( impl.mController )
419 const float pixelSize = value.Get< float >();
420 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
422 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
424 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
429 case Toolkit::TextLabel::Property::ELLIPSIS:
431 if( impl.mController )
433 const bool ellipsis = value.Get<bool>();
434 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
436 impl.mController->SetTextElideEnabled( ellipsis );
440 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
442 if( impl.mController )
444 Text::LineWrap::Mode lineWrapMode( static_cast< Text::LineWrap::Mode >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
445 if( GetLineWrapModeEnumeration( value, lineWrapMode ) )
447 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode );
448 impl.mController->SetLineWrapMode( lineWrapMode );
453 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
455 if( impl.mController && impl.mController->GetTextModel() )
457 DevelText::VerticalLineAlignment::Type alignment = static_cast<DevelText::VerticalLineAlignment::Type>( value.Get<int>() );
459 impl.mController->SetVerticalLineAlignment( alignment );
461 // Property doesn't affect the layout, only Visual must be updated
462 TextVisual::EnableRendererUpdate( impl.mVisual );
464 // No need to trigger full re-layout. Instead call UpdateRenderer() directly
465 TextVisual::UpdateRenderer( impl.mVisual );
469 case Toolkit::DevelTextLabel::Property::BACKGROUND:
471 const bool update = SetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
474 impl.mTextUpdateNeeded = true;
478 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
480 impl.mController->SetIgnoreSpacesAfterText(value.Get< bool >());
483 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
485 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
488 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
490 const Property::Map& propertiesMap = value.Get<Property::Map>();
492 bool enabled = false;
495 float stepSize = 0.f;
496 bool isMinSizeSet = false, isMaxSizeSet = false, isStepSizeSet = false;
497 Controller::FontSizeType type = Controller::FontSizeType::POINT_SIZE;
499 if ( !propertiesMap.Empty() )
501 const unsigned int numberOfItems = propertiesMap.Count();
503 // Parses and applies
504 for( unsigned int index = 0u; index < numberOfItems; ++index )
506 const KeyValuePair& valueGet = propertiesMap.GetKeyValue( index );
508 if( ( Controller::TextFitInfo::Property::TEXT_FIT_ENABLE == valueGet.first.indexKey ) || ( TEXT_FIT_ENABLE_KEY == valueGet.first.stringKey ) )
511 enabled = valueGet.second.Get< bool >();
513 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MIN_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MIN_SIZE_KEY == valueGet.first.stringKey ) )
516 minSize = valueGet.second.Get< float >();
519 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MAX_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MAX_SIZE_KEY == valueGet.first.stringKey ) )
522 maxSize = valueGet.second.Get< float >();
525 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_STEP_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_STEP_SIZE_KEY == valueGet.first.stringKey ) )
528 stepSize = valueGet.second.Get< float >();
529 isStepSizeSet = true;
531 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_FONT_SIZE_TYPE == valueGet.first.indexKey ) || ( TEXT_FIT_FONT_SIZE_TYPE_KEY == valueGet.first.stringKey ) )
533 if( "pixelSize" == valueGet.second.Get< std::string >() )
535 type = Controller::FontSizeType::PIXEL_SIZE;
540 impl.mController->SetTextFitEnabled( enabled );
543 impl.mController->SetTextFitMinSize( minSize, type );
547 impl.mController->SetTextFitMaxSize( maxSize, type );
551 impl.mController->SetTextFitStepSize( stepSize, type );
558 // Request relayout when text update is needed. It's necessary to call it
559 // as changing the property not via UI interaction brings no effect if only
560 // the mTextUpdateNeeded is changed.
561 if( impl.mTextUpdateNeeded )
563 // need to request relayout as size of text may have changed
564 impl.RequestTextRelayout();
569 Text::ControllerPtr TextLabel::getController() { return mController; }
571 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
573 Property::Value value;
575 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
579 TextLabel& impl( GetImpl( label ) );
582 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
584 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
586 value = impl.mRenderingBackend;
589 case Toolkit::TextLabel::Property::TEXT:
591 if( impl.mController )
594 impl.mController->GetText( text );
599 case Toolkit::TextLabel::Property::FONT_FAMILY:
601 if( impl.mController )
603 value = impl.mController->GetDefaultFontFamily();
607 case Toolkit::TextLabel::Property::FONT_STYLE:
609 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
612 case Toolkit::TextLabel::Property::POINT_SIZE:
614 if( impl.mController )
616 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
620 case Toolkit::TextLabel::Property::MULTI_LINE:
622 if( impl.mController )
624 value = impl.mController->IsMultiLineEnabled();
628 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
630 if( impl.mController )
632 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
636 value = std::string( name );
641 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
643 if( impl.mController )
645 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
648 value = std::string( name );
653 case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
655 value = label.GetProperty( Toolkit::TextLabel::Property::TEXT_COLOR );
658 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
660 if( impl.mController )
662 value = impl.mController->IsMarkupProcessorEnabled();
666 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
668 if( impl.mController )
670 value = impl.mController->IsAutoScrollEnabled();
674 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
676 if( impl.mTextScroller )
678 const char* mode = Scripting::GetEnumerationName< Toolkit::TextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
679 AUTO_SCROLL_STOP_MODE_TABLE,
680 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
683 value = std::string( mode );
688 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
690 TextLabel& impl( GetImpl( label ) );
691 if ( impl.mTextScroller )
693 value = impl.mTextScroller->GetSpeed();
697 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
699 if( impl.mController )
701 TextLabel& impl( GetImpl( label ) );
702 if ( impl.mTextScroller )
704 value = impl.mTextScroller->GetLoopCount();
709 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
711 if( impl.mController )
713 TextLabel& impl( GetImpl( label ) );
714 if ( impl.mTextScroller )
716 value = impl.mTextScroller->GetLoopDelay();
721 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
723 TextLabel& impl( GetImpl( label ) );
724 if ( impl.mTextScroller )
726 value = impl.mTextScroller->GetGap();
730 case Toolkit::TextLabel::Property::LINE_SPACING:
732 if( impl.mController )
734 value = impl.mController->GetDefaultLineSpacing();
738 case Toolkit::TextLabel::Property::UNDERLINE:
740 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
743 case Toolkit::TextLabel::Property::SHADOW:
745 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
748 case Toolkit::TextLabel::Property::EMBOSS:
750 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
753 case Toolkit::TextLabel::Property::OUTLINE:
755 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
758 case Toolkit::TextLabel::Property::PIXEL_SIZE:
760 if( impl.mController )
762 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
766 case Toolkit::TextLabel::Property::ELLIPSIS:
768 if( impl.mController )
770 value = impl.mController->IsTextElideEnabled();
774 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
776 if( impl.mController )
778 value = impl.mController->GetLineWrapMode();
782 case Toolkit::TextLabel::Property::LINE_COUNT:
784 if( impl.mController )
786 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
787 value = impl.mController->GetLineCount( width );
791 case Toolkit::DevelTextLabel::Property::TEXT_DIRECTION:
793 if( impl.mController )
795 value = impl.mController->GetTextDirection();
799 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
801 if( impl.mController )
803 value = impl.mController->GetVerticalLineAlignment();
807 case Toolkit::DevelTextLabel::Property::BACKGROUND:
809 GetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
812 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
814 value = impl.mController->IsIgnoreSpacesAfterText();
817 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
819 value = impl.mController->IsMatchSystemLanguageDirection();
822 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
824 const bool enabled = impl.mController->IsTextFitEnabled();
825 const float minSize = impl.mController->GetTextFitMinSize();
826 const float maxSize = impl.mController->GetTextFitMaxSize();
827 const float stepSize = impl.mController->GetTextFitStepSize();
830 map.Insert( TEXT_FIT_ENABLE_KEY, enabled );
831 map.Insert( TEXT_FIT_MIN_SIZE_KEY, minSize );
832 map.Insert( TEXT_FIT_MAX_SIZE_KEY, maxSize );
833 map.Insert( TEXT_FIT_STEP_SIZE_KEY, stepSize );
834 map.Insert( TEXT_FIT_FONT_SIZE_TYPE_KEY, "pointSize" );
845 void TextLabel::OnInitialize()
849 Property::Map propertyMap;
850 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
852 mVisual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
853 DevelControl::RegisterVisual( *this, Toolkit::TextLabel::Property::TEXT, mVisual );
855 TextVisual::SetAnimatableTextColorProperty( mVisual, Toolkit::TextLabel::Property::TEXT_COLOR );
857 mController = TextVisual::GetController(mVisual);
860 mController->SetControlInterface(this);
863 // Use height-for-width negotiation by default
864 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
865 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
867 // Enable the text ellipsis.
868 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
870 // Sets layoutDirection value
871 Dali::Stage stage = Dali::Stage::GetCurrent();
872 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
873 mController->SetLayoutDirection( layoutDirection );
875 Layout::Engine& engine = mController->GetLayoutEngine();
876 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
879 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
881 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
885 case StyleChange::DEFAULT_FONT_CHANGE:
887 // Property system did not set the font so should update it.
888 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
889 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
890 mController->UpdateAfterFontChange( newFont );
894 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
896 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
900 case StyleChange::THEME_CHANGE:
902 // Nothing to do, let control base class handle this
907 // Up call to Control
908 Control::OnStyleChange( styleManager, change );
911 Vector3 TextLabel::GetNaturalSize()
914 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
916 Vector3 naturalSize = mController->GetNaturalSize();
917 naturalSize.width += ( padding.start + padding.end );
918 naturalSize.height += ( padding.top + padding.bottom );
923 float TextLabel::GetHeightForWidth( float width )
926 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
928 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
931 void TextLabel::OnPropertySet( Property::Index index, Property::Value propertyValue )
933 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
937 case Toolkit::TextLabel::Property::TEXT_COLOR:
939 const Vector4& textColor = propertyValue.Get< Vector4 >();
940 if( mController->GetDefaultColor() != textColor )
942 mController->SetDefaultColor( textColor );
943 mTextUpdateNeeded = true;
949 Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
955 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
957 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
960 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
962 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
964 if( mController->IsTextFitEnabled() )
966 mController->FitPointSizeforLayout( contentSize );
967 mController->SetTextFitContentSize( contentSize );
970 // Support Right-To-Left
971 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
973 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
975 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
976 || mTextUpdateNeeded )
978 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
981 TextVisual::EnableRendererUpdate( mVisual );
983 // Support Right-To-Left of padding
984 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
986 std::swap( padding.start, padding.end );
989 // Calculate the size of the visual that can fit the text
990 Size layoutSize = mController->GetTextModel()->GetLayoutSize();
991 layoutSize.x = contentSize.x;
993 const Vector2& shadowOffset = mController->GetTextModel()->GetShadowOffset();
994 if ( shadowOffset.y > Math::MACHINE_EPSILON_1 )
996 layoutSize.y += shadowOffset.y;
999 float outlineWidth = mController->GetTextModel()->GetOutlineWidth();
1000 layoutSize.y += outlineWidth * 2.0f;
1001 layoutSize.y = std::min( layoutSize.y, contentSize.y );
1003 // Calculate the offset for vertical alignment only, as the layout engine will do the horizontal alignment.
1004 Vector2 alignmentOffset;
1005 alignmentOffset.x = 0.0f;
1006 alignmentOffset.y = ( contentSize.y - layoutSize.y ) * VERTICAL_ALIGNMENT_TABLE[mController->GetVerticalAlignment()];
1008 Property::Map visualTransform;
1009 visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, layoutSize )
1010 .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
1011 .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( padding.start, padding.top ) + alignmentOffset )
1012 .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
1013 .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
1014 .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
1015 mVisual.SetTransformAndSize( visualTransform, size );
1017 if ( mController->IsAutoScrollEnabled() )
1019 SetUpAutoScrolling();
1022 mTextUpdateNeeded = false;
1026 void TextLabel::RequestTextRelayout()
1029 // Signal that a Relayout may be needed
1032 void TextLabel::SetUpAutoScrolling()
1034 const Size& controlSize = mController->GetView().GetControlSize();
1035 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.
1036 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
1038 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n",
1039 textNaturalSize.x,textNaturalSize.y , controlSize.x,controlSize.y );
1041 if ( !mTextScroller )
1043 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
1045 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
1046 mTextScroller = Text::TextScroller::New( *this );
1049 // Calculate the actual gap before scrolling wraps.
1050 int textPadding = std::max( controlSize.x - textNaturalSize.x, 0.0f );
1051 float wrapGap = std::max( mTextScroller->GetGap(), textPadding );
1052 Vector2 textureSize = textNaturalSize + Vector2(wrapGap, 0.0f); // Add the gap as a part of the texture
1054 // Create a texture of the text for scrolling
1055 Size verifiedSize = textureSize;
1056 const int maxTextureSize = Dali::GetMaxTextureSize();
1058 //if the texture size width exceed maxTextureSize, modify the visual model size and enabled the ellipsis
1059 if( verifiedSize.width > maxTextureSize )
1061 verifiedSize.width = maxTextureSize;
1062 if( textNaturalSize.width > maxTextureSize )
1064 mController->SetTextElideEnabled( true );
1066 GetHeightForWidth( maxTextureSize );
1067 wrapGap = std::max( maxTextureSize - textNaturalSize.width, 0.0f );
1070 Text::TypesetterPtr typesetter = Text::Typesetter::New( mController->GetTextModel() );
1072 PixelData data = typesetter->Render( verifiedSize, mController->GetTextDirection(), Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888 ); // ignore the horizontal alignment
1073 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D,
1074 data.GetPixelFormat(),
1077 texture.Upload( data );
1079 TextureSet textureSet = TextureSet::New();
1080 textureSet.SetTexture( 0u, texture );
1082 // Filter mode needs to be set to linear to produce better quality while scaling.
1083 Sampler sampler = Sampler::New();
1084 sampler.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
1085 sampler.SetWrapMode( Dali::WrapMode::DEFAULT, Dali::WrapMode::REPEAT, Dali::WrapMode::DEFAULT ); // Wrap the texture in the x direction
1086 textureSet.SetSampler( 0u, sampler );
1088 // Set parameters for scrolling
1089 Renderer renderer = static_cast<Internal::Visual::Base&>( GetImplementation( mVisual ) ).GetRenderer();
1090 mTextScroller->SetParameters( Self(), renderer, textureSet, controlSize, verifiedSize, wrapGap, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment() );
1093 void TextLabel::ScrollingFinished()
1095 // Pure Virtual from TextScroller Interface
1096 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
1097 mController->SetAutoScrollEnabled( false );
1098 mController->SetTextElideEnabled( true );
1099 RequestTextRelayout();
1102 TextLabel::TextLabel()
1103 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1104 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1105 mTextUpdateNeeded( false )
1107 DevelControl::SetAccessibilityConstructor( Self(), []( Dali::Actor actor ) {
1108 return std::unique_ptr< Dali::Accessibility::Accessible >(
1109 new AccessibleImpl( actor, Dali::Accessibility::Role::LABEL ) );
1113 TextLabel::~TextLabel()
1117 std::string TextLabel::AccessibleImpl::GetNameRaw()
1119 auto slf = Toolkit::TextLabel::DownCast( self );
1120 return slf.GetProperty( Toolkit::TextLabel::Property::TEXT ).Get< std::string >();
1123 std::string TextLabel::AccessibleImpl::GetText( size_t startOffset,
1126 if( endOffset <= startOffset )
1129 auto slf = Toolkit::TextLabel::DownCast( self );
1131 slf.GetProperty( Toolkit::TextLabel::Property::TEXT ).Get< std::string >();
1133 if( startOffset > txt.size() || endOffset > txt.size() )
1136 return txt.substr( startOffset, endOffset - startOffset );
1139 size_t TextLabel::AccessibleImpl::GetCharacterCount()
1141 auto slf = Toolkit::TextLabel::DownCast( self );
1143 slf.GetProperty( Toolkit::TextLabel::Property::TEXT ).Get< std::string >();
1148 size_t TextLabel::AccessibleImpl::GetCaretOffset()
1153 bool TextLabel::AccessibleImpl::SetCaretOffset(size_t offset)
1158 Dali::Accessibility::Range TextLabel::AccessibleImpl::GetTextAtOffset(
1159 size_t offset, Dali::Accessibility::TextBoundary boundary )
1161 auto slf = Toolkit::TextLabel::DownCast( self );
1162 auto txt = slf.GetProperty( Toolkit::TextLabel::Property::TEXT ).Get< std::string >();
1163 auto txt_size = txt.size();
1165 auto range = Dali::Accessibility::Range{};
1169 case Dali::Accessibility::TextBoundary::CHARACTER:
1171 if (offset < txt_size)
1173 range.content = txt[offset];
1174 range.startOffset = offset;
1175 range.endOffset = offset + 1;
1179 case Dali::Accessibility::TextBoundary::WORD:
1180 case Dali::Accessibility::TextBoundary::LINE:
1182 auto txt_c_string = txt.c_str();
1183 auto breaks = std::vector< char >( txt_size, 0 );
1184 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1185 Accessibility::Accessible::FindWordSeparationsUtf8((const utf8_t *) txt_c_string, txt_size, "", breaks.data());
1187 Accessibility::Accessible::FindLineSeparationsUtf8((const utf8_t *) txt_c_string, txt_size, "", breaks.data());
1190 while( index < txt_size && counter <= offset )
1195 while(breaks[index])
1201 if (boundary == Dali::Accessibility::TextBoundary::WORD)
1203 if (boundary == Dali::Accessibility::TextBoundary::LINE)
1206 if ((counter - 1) == offset)
1208 range.content = txt.substr(start, index - start + 1);
1209 range.startOffset = start;
1210 range.endOffset = index + 1;
1212 if (boundary == Dali::Accessibility::TextBoundary::LINE)
1217 case Dali::Accessibility::TextBoundary::SENTENCE:
1219 /* not supported by efl */
1222 case Dali::Accessibility::TextBoundary::PARAGRAPH:
1224 /* Paragraph is not supported by libunibreak library */
1234 Dali::Accessibility::Range
1235 TextLabel::AccessibleImpl::GetSelection( size_t selectionNum )
1237 // Since DALi supports only one selection indexes higher than 0 are ignored
1238 if( selectionNum > 0 )
1241 auto slf = Toolkit::TextLabel::DownCast( self );
1242 auto ctrl = Dali::Toolkit::GetImpl( slf ).getController();
1244 ctrl->RetrieveSelection( ret );
1245 auto r = ctrl->GetSelectionIndexes();
1247 return { static_cast<size_t>(r.first), static_cast<size_t>(r.second), ret };
1250 bool TextLabel::AccessibleImpl::RemoveSelection( size_t selectionNum )
1252 // Since DALi supports only one selection indexes higher than 0 are ignored
1253 if( selectionNum > 0 )
1256 auto slf = Toolkit::TextLabel::DownCast( self );
1257 Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( 0, 0 );
1261 bool TextLabel::AccessibleImpl::SetSelection( size_t selectionNum,
1265 // Since DALi supports only one selection indexes higher than 0 are ignored
1266 if( selectionNum > 0 )
1269 auto slf = Toolkit::TextLabel::DownCast( self );
1270 Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( startOffset,
1275 } // namespace Internal
1277 } // namespace Toolkit