2 * Copyright (c) 2020 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/common/dali-common.h>
23 #include <dali/public-api/object/type-registry-helper.h>
24 #include <dali/devel-api/common/stage.h>
25 #include <dali/devel-api/object/property-helper-devel.h>
26 #include <dali/devel-api/adaptor-framework/image-loading.h>
27 #include <dali/devel-api/adaptor-framework/window-devel.h>
28 #include <dali/integration-api/debug.h>
31 #include <dali-toolkit/public-api/text/text-enumerations.h>
32 #include <dali-toolkit/devel-api/text/rendering-backend.h>
33 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
34 #include <dali-toolkit/internal/text/property-string-parser.h>
35 #include <dali-toolkit/internal/text/rendering/text-backend.h>
36 #include <dali-toolkit/internal/text/text-effects-style.h>
37 #include <dali-toolkit/internal/text/text-font-style.h>
38 #include <dali-toolkit/internal/text/text-view.h>
39 #include <dali-toolkit/internal/text/text-definitions.h>
40 #include <dali-toolkit/internal/styling/style-manager-impl.h>
42 #include <dali-toolkit/public-api/align-enumerations.h>
43 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
44 #include <dali-toolkit/devel-api/controls/control-devel.h>
45 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
46 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
47 #include <dali-toolkit/public-api/visuals/visual-properties.h>
48 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
50 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
52 using namespace Dali::Toolkit::Text;
65 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
68 * @brief How the text visual should be aligned vertically inside the control.
70 * 0.0f aligns the text to the top, 0.5f aligns the text to the center, 1.0f aligns the text to the bottom.
71 * The alignment depends on the alignment value of the text label (Use Text::VerticalAlignment enumerations).
73 const float VERTICAL_ALIGNMENT_TABLE[ Text::VerticalAlignment::BOTTOM + 1 ] =
75 0.0f, // VerticalAlignment::TOP
76 0.5f, // VerticalAlignment::CENTER
77 1.0f // VerticalAlignment::BOTTOM
80 const std::string TEXT_FIT_ENABLE_KEY( "enable" );
81 const std::string TEXT_FIT_MIN_SIZE_KEY( "minSize" );
82 const std::string TEXT_FIT_MAX_SIZE_KEY( "maxSize" );
83 const std::string TEXT_FIT_STEP_SIZE_KEY( "stepSize" );
84 const std::string TEXT_FIT_FONT_SIZE_TYPE_KEY( "fontSizeType" );
90 #if defined ( DEBUG_ENABLED )
91 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
94 const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] =
96 { "IMMEDIATE", Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE },
97 { "FINISH_LOOP", Toolkit::TextLabel::AutoScrollStopMode::FINISH_LOOP },
99 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof( AUTO_SCROLL_STOP_MODE_TABLE ) / sizeof( AUTO_SCROLL_STOP_MODE_TABLE[0] );
104 return Toolkit::TextLabel::New();
107 // Setup properties, signals and actions using the type-registry.
108 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "text", STRING, TEXT )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily", STRING, FONT_FAMILY )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle", MAP, FONT_STYLE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize", FLOAT, POINT_SIZE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine", BOOLEAN, MULTI_LINE )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline", MAP, UNDERLINE )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow", MAP, SHADOW )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss", MAP, EMBOSS )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP, OUTLINE )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE )
131 DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", INTEGER, LINE_WRAP_MODE )
133 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "textDirection", INTEGER, TEXT_DIRECTION )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalLineAlignment", INTEGER, VERTICAL_LINE_ALIGNMENT )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textBackground", MAP, BACKGROUND )
136 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ignoreSpacesAfterText", BOOLEAN, IGNORE_SPACES_AFTER_TEXT )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
138 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textFit", MAP, TEXT_FIT )
139 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "minLineSize", FLOAT, MIN_LINE_SIZE )
140 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND )
141 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR )
142 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0 )
143 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1 )
144 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorBlue", TEXT_COLOR_BLUE, TEXT_COLOR, 2 )
145 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3 )
146 DALI_TYPE_REGISTRATION_END()
150 Toolkit::TextLabel TextLabel::New()
152 // Create the implementation, temporarily owned by this handle on stack
153 IntrusivePtr< TextLabel > impl = new TextLabel();
155 // Pass ownership to CustomActor handle
156 Toolkit::TextLabel handle( *impl );
158 // Second-phase init of the implementation
159 // This can only be done after the CustomActor connection has been made...
165 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
167 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
171 TextLabel& impl( GetImpl( label ) );
172 DALI_ASSERT_ALWAYS( impl.mController && "No text contoller" );
176 case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
178 int backend = value.Get< int >();
180 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
181 if( DevelText::RENDERING_VECTOR_BASED == backend )
183 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
186 if( impl.mRenderingBackend != backend )
188 impl.mRenderingBackend = backend;
189 impl.mTextUpdateNeeded = true;
191 // When using the vector-based rendering, the size of the GLyphs are different
192 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
193 impl.mController->SetGlyphType( glyphType );
197 case Toolkit::TextLabel::Property::TEXT:
199 impl.mController->SetText( value.Get< std::string >() );
202 case Toolkit::TextLabel::Property::FONT_FAMILY:
204 const std::string& fontFamily = value.Get< std::string >();
206 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
207 impl.mController->SetDefaultFontFamily( fontFamily );
210 case Toolkit::TextLabel::Property::FONT_STYLE:
212 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
215 case Toolkit::TextLabel::Property::POINT_SIZE:
217 const float pointSize = value.Get< float >();
219 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
221 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
225 case Toolkit::TextLabel::Property::MULTI_LINE:
227 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
230 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
232 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
233 if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) )
235 impl.mController->SetHorizontalAlignment( alignment );
239 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
241 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
242 if( Text::GetVerticalAlignmentEnumeration( value, alignment ) )
244 impl.mController->SetVerticalAlignment( alignment );
248 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
250 const bool enableMarkup = value.Get<bool>();
251 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
254 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
256 const bool enableAutoScroll = value.Get<bool>();
257 // If request to auto scroll is the same as current state then do nothing.
258 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
260 // If request is disable (false) and auto scrolling is enabled then need to stop it
261 if ( enableAutoScroll == false )
263 if( impl.mTextScroller )
265 impl.mTextScroller->StopScrolling();
268 // If request is enable (true) then start autoscroll as not already running
271 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
276 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
278 if( !impl.mTextScroller )
280 impl.mTextScroller = Text::TextScroller::New( impl );
282 Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
283 if( Scripting::GetEnumerationProperty< Toolkit::TextLabel::AutoScrollStopMode::Type >( value,
284 AUTO_SCROLL_STOP_MODE_TABLE,
285 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
288 impl.mTextScroller->SetStopMode( stopMode );
292 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
294 if( !impl.mTextScroller )
296 impl.mTextScroller = Text::TextScroller::New( impl );
298 impl.mTextScroller->SetSpeed( value.Get<int>() );
301 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
303 if( !impl.mTextScroller )
305 impl.mTextScroller = Text::TextScroller::New( impl );
307 impl.mTextScroller->SetLoopCount( value.Get<int>() );
310 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
312 if( !impl.mTextScroller )
314 impl.mTextScroller = Text::TextScroller::New( impl );
316 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
319 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
321 if( !impl.mTextScroller )
323 impl.mTextScroller = Text::TextScroller::New( impl );
325 impl.mTextScroller->SetGap( value.Get<float>() );
328 case Toolkit::TextLabel::Property::LINE_SPACING:
330 const float lineSpacing = value.Get<float>();
332 // Don't trigger anything if the line spacing didn't change
333 if( impl.mController->SetDefaultLineSpacing( lineSpacing ) )
335 impl.mTextUpdateNeeded = true;
339 case Toolkit::TextLabel::Property::UNDERLINE:
341 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
344 impl.mTextUpdateNeeded = true;
348 case Toolkit::TextLabel::Property::SHADOW:
350 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
353 impl.mTextUpdateNeeded = true;
357 case Toolkit::TextLabel::Property::EMBOSS:
359 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
362 impl.mTextUpdateNeeded = true;
366 case Toolkit::TextLabel::Property::OUTLINE:
368 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
371 impl.mTextUpdateNeeded = true;
375 case Toolkit::TextLabel::Property::PIXEL_SIZE:
377 const float pixelSize = value.Get< float >();
378 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
380 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
382 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
386 case Toolkit::TextLabel::Property::ELLIPSIS:
388 const bool ellipsis = value.Get<bool>();
389 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
391 impl.mController->SetTextElideEnabled( ellipsis );
394 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
396 Text::LineWrap::Mode lineWrapMode( static_cast< Text::LineWrap::Mode >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
397 if( GetLineWrapModeEnumeration( value, lineWrapMode ) )
399 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode );
400 impl.mController->SetLineWrapMode( lineWrapMode );
404 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
406 if( impl.mController->GetTextModel() )
408 DevelText::VerticalLineAlignment::Type alignment = static_cast<DevelText::VerticalLineAlignment::Type>( value.Get<int>() );
410 impl.mController->SetVerticalLineAlignment( alignment );
412 // Property doesn't affect the layout, only Visual must be updated
413 TextVisual::EnableRendererUpdate( impl.mVisual );
415 // No need to trigger full re-layout. Instead call UpdateRenderer() directly
416 TextVisual::UpdateRenderer( impl.mVisual );
420 case Toolkit::DevelTextLabel::Property::BACKGROUND:
422 const bool update = SetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
425 impl.mTextUpdateNeeded = true;
429 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
431 impl.mController->SetIgnoreSpacesAfterText(value.Get< bool >());
434 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
436 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
439 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
441 const Property::Map& propertiesMap = value.Get<Property::Map>();
443 bool enabled = false;
446 float stepSize = 0.f;
447 bool isMinSizeSet = false, isMaxSizeSet = false, isStepSizeSet = false;
448 Controller::FontSizeType type = Controller::FontSizeType::POINT_SIZE;
450 if ( !propertiesMap.Empty() )
452 const unsigned int numberOfItems = propertiesMap.Count();
454 // Parses and applies
455 for( unsigned int index = 0u; index < numberOfItems; ++index )
457 const KeyValuePair& valueGet = propertiesMap.GetKeyValue( index );
459 if( ( Controller::TextFitInfo::Property::TEXT_FIT_ENABLE == valueGet.first.indexKey ) || ( TEXT_FIT_ENABLE_KEY == valueGet.first.stringKey ) )
462 enabled = valueGet.second.Get< bool >();
464 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MIN_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MIN_SIZE_KEY == valueGet.first.stringKey ) )
467 minSize = valueGet.second.Get< float >();
470 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MAX_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MAX_SIZE_KEY == valueGet.first.stringKey ) )
473 maxSize = valueGet.second.Get< float >();
476 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_STEP_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_STEP_SIZE_KEY == valueGet.first.stringKey ) )
479 stepSize = valueGet.second.Get< float >();
480 isStepSizeSet = true;
482 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_FONT_SIZE_TYPE == valueGet.first.indexKey ) || ( TEXT_FIT_FONT_SIZE_TYPE_KEY == valueGet.first.stringKey ) )
484 if( "pixelSize" == valueGet.second.Get< std::string >() )
486 type = Controller::FontSizeType::PIXEL_SIZE;
491 impl.mController->SetTextFitEnabled( enabled );
494 impl.mController->SetTextFitMinSize( minSize, type );
498 impl.mController->SetTextFitMaxSize( maxSize, type );
502 impl.mController->SetTextFitStepSize( stepSize, type );
507 case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
509 const float lineSize = value.Get<float>();
511 if( impl.mController->SetDefaultLineSize( lineSize ) )
513 impl.mTextUpdateNeeded = true;
519 // Request relayout when text update is needed. It's necessary to call it
520 // as changing the property not via UI interaction brings no effect if only
521 // the mTextUpdateNeeded is changed.
522 if( impl.mTextUpdateNeeded )
524 // need to request relayout as size of text may have changed
525 impl.RequestTextRelayout();
530 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
532 Property::Value value;
534 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
538 TextLabel& impl( GetImpl( label ) );
539 DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
543 case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
545 value = impl.mRenderingBackend;
548 case Toolkit::TextLabel::Property::TEXT:
551 impl.mController->GetText( text );
555 case Toolkit::TextLabel::Property::FONT_FAMILY:
557 value = impl.mController->GetDefaultFontFamily();
560 case Toolkit::TextLabel::Property::FONT_STYLE:
562 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
565 case Toolkit::TextLabel::Property::POINT_SIZE:
567 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
570 case Toolkit::TextLabel::Property::MULTI_LINE:
572 value = impl.mController->IsMultiLineEnabled();
575 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
577 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
581 value = std::string( name );
585 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
587 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
590 value = std::string( name );
594 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
596 value = impl.mController->IsMarkupProcessorEnabled();
599 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
601 value = impl.mController->IsAutoScrollEnabled();
604 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
606 if( impl.mTextScroller )
608 const char* mode = Scripting::GetEnumerationName< Toolkit::TextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
609 AUTO_SCROLL_STOP_MODE_TABLE,
610 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
613 value = std::string( mode );
618 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
620 if ( impl.mTextScroller )
622 value = impl.mTextScroller->GetSpeed();
626 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
628 if ( impl.mTextScroller )
630 value = impl.mTextScroller->GetLoopCount();
634 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
636 if ( impl.mTextScroller )
638 value = impl.mTextScroller->GetLoopDelay();
642 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
644 if ( impl.mTextScroller )
646 value = impl.mTextScroller->GetGap();
650 case Toolkit::TextLabel::Property::LINE_SPACING:
652 value = impl.mController->GetDefaultLineSpacing();
655 case Toolkit::TextLabel::Property::UNDERLINE:
657 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
660 case Toolkit::TextLabel::Property::SHADOW:
662 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
665 case Toolkit::TextLabel::Property::EMBOSS:
667 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
670 case Toolkit::TextLabel::Property::OUTLINE:
672 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
675 case Toolkit::TextLabel::Property::PIXEL_SIZE:
677 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
680 case Toolkit::TextLabel::Property::ELLIPSIS:
682 value = impl.mController->IsTextElideEnabled();
685 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
687 value = impl.mController->GetLineWrapMode();
690 case Toolkit::TextLabel::Property::LINE_COUNT:
692 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
693 value = impl.mController->GetLineCount( width );
696 case Toolkit::DevelTextLabel::Property::TEXT_DIRECTION:
698 value = impl.mController->GetTextDirection();
701 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
703 value = impl.mController->GetVerticalLineAlignment();
706 case Toolkit::DevelTextLabel::Property::BACKGROUND:
708 GetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
711 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
713 value = impl.mController->IsIgnoreSpacesAfterText();
716 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
718 value = impl.mController->IsMatchSystemLanguageDirection();
721 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
723 const bool enabled = impl.mController->IsTextFitEnabled();
724 const float minSize = impl.mController->GetTextFitMinSize();
725 const float maxSize = impl.mController->GetTextFitMaxSize();
726 const float stepSize = impl.mController->GetTextFitStepSize();
729 map.Insert( TEXT_FIT_ENABLE_KEY, enabled );
730 map.Insert( TEXT_FIT_MIN_SIZE_KEY, minSize );
731 map.Insert( TEXT_FIT_MAX_SIZE_KEY, maxSize );
732 map.Insert( TEXT_FIT_STEP_SIZE_KEY, stepSize );
733 map.Insert( TEXT_FIT_FONT_SIZE_TYPE_KEY, "pointSize" );
738 case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
740 value = impl.mController->GetDefaultLineSize();
749 void TextLabel::OnInitialize()
753 Property::Map propertyMap;
754 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
756 mVisual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
757 DevelControl::RegisterVisual( *this, Toolkit::TextLabel::Property::TEXT, mVisual );
759 TextVisual::SetAnimatableTextColorProperty( mVisual, Toolkit::TextLabel::Property::TEXT_COLOR );
761 mController = TextVisual::GetController(mVisual);
762 DALI_ASSERT_DEBUG( mController && "Invalid Text Controller")
764 mController->SetControlInterface(this);
766 // Use height-for-width negotiation by default
767 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
768 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
770 // Enable the text ellipsis.
771 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
773 // Sets layoutDirection value
774 Dali::Stage stage = Dali::Stage::GetCurrent();
775 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
776 mController->SetLayoutDirection( layoutDirection );
778 Layout::Engine& engine = mController->GetLayoutEngine();
779 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
782 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
784 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
788 case StyleChange::DEFAULT_FONT_CHANGE:
790 // Property system did not set the font so should update it.
791 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
792 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
793 mController->UpdateAfterFontChange( newFont );
797 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
799 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
803 case StyleChange::THEME_CHANGE:
805 // Nothing to do, let control base class handle this
810 // Up call to Control
811 Control::OnStyleChange( styleManager, change );
814 Vector3 TextLabel::GetNaturalSize()
817 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
819 Vector3 naturalSize = mController->GetNaturalSize();
820 naturalSize.width += ( padding.start + padding.end );
821 naturalSize.height += ( padding.top + padding.bottom );
826 float TextLabel::GetHeightForWidth( float width )
829 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
831 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
834 void TextLabel::OnPropertySet( Property::Index index, const Property::Value& propertyValue )
836 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
840 case Toolkit::TextLabel::Property::TEXT_COLOR:
842 const Vector4& textColor = propertyValue.Get< Vector4 >();
843 if( mController->GetDefaultColor() != textColor )
845 mController->SetDefaultColor( textColor );
846 mTextUpdateNeeded = true;
852 Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
858 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
860 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
863 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
865 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
867 if( mController->IsTextFitEnabled() )
869 mController->FitPointSizeforLayout( contentSize );
870 mController->SetTextFitContentSize( contentSize );
873 // Support Right-To-Left
874 Dali::LayoutDirection::Type layoutDirection;
875 if( mController->IsMatchSystemLanguageDirection() )
877 layoutDirection = static_cast<Dali::LayoutDirection::Type>( DevelWindow::Get( Self() ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
881 layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
883 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
885 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
886 || mTextUpdateNeeded )
888 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
891 TextVisual::EnableRendererUpdate( mVisual );
893 // Support Right-To-Left of padding
894 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
896 std::swap( padding.start, padding.end );
899 // Calculate the size of the visual that can fit the text
900 Size layoutSize = mController->GetTextModel()->GetLayoutSize();
901 layoutSize.x = contentSize.x;
903 const Vector2& shadowOffset = mController->GetTextModel()->GetShadowOffset();
904 if ( shadowOffset.y > Math::MACHINE_EPSILON_1 )
906 layoutSize.y += shadowOffset.y;
909 float outlineWidth = mController->GetTextModel()->GetOutlineWidth();
910 layoutSize.y += outlineWidth * 2.0f;
911 layoutSize.y = std::min( layoutSize.y, contentSize.y );
913 // Calculate the offset for vertical alignment only, as the layout engine will do the horizontal alignment.
914 Vector2 alignmentOffset;
915 alignmentOffset.x = 0.0f;
916 alignmentOffset.y = ( contentSize.y - layoutSize.y ) * VERTICAL_ALIGNMENT_TABLE[mController->GetVerticalAlignment()];
918 Property::Map visualTransform;
919 visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, layoutSize )
920 .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
921 .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( padding.start, padding.top ) + alignmentOffset )
922 .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
923 .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
924 .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
925 mVisual.SetTransformAndSize( visualTransform, size );
927 if ( mController->IsAutoScrollEnabled() )
929 SetUpAutoScrolling();
932 mTextUpdateNeeded = false;
936 void TextLabel::RequestTextRelayout()
939 // Signal that a Relayout may be needed
942 void TextLabel::SetUpAutoScrolling()
944 const Size& controlSize = mController->GetView().GetControlSize();
945 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.
946 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
948 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n",
949 textNaturalSize.x,textNaturalSize.y , controlSize.x,controlSize.y );
951 if ( !mTextScroller )
953 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
955 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
956 mTextScroller = Text::TextScroller::New( *this );
959 // Calculate the actual gap before scrolling wraps.
960 int textPadding = std::max( controlSize.x - textNaturalSize.x, 0.0f );
961 float wrapGap = std::max( mTextScroller->GetGap(), textPadding );
962 Vector2 textureSize = textNaturalSize + Vector2(wrapGap, 0.0f); // Add the gap as a part of the texture
964 // Create a texture of the text for scrolling
965 Size verifiedSize = textureSize;
966 const int maxTextureSize = Dali::GetMaxTextureSize();
968 //if the texture size width exceed maxTextureSize, modify the visual model size and enabled the ellipsis
969 bool actualellipsis = mController->IsTextElideEnabled();
970 if( verifiedSize.width > maxTextureSize )
972 verifiedSize.width = maxTextureSize;
973 if( textNaturalSize.width > maxTextureSize )
975 mController->SetTextElideEnabled( true );
977 GetHeightForWidth( maxTextureSize );
978 wrapGap = std::max( maxTextureSize - textNaturalSize.width, 0.0f );
981 Text::TypesetterPtr typesetter = Text::Typesetter::New( mController->GetTextModel() );
983 PixelData data = typesetter->Render( verifiedSize, mController->GetTextDirection(), Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888 ); // ignore the horizontal alignment
984 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D,
985 data.GetPixelFormat(),
988 texture.Upload( data );
990 TextureSet textureSet = TextureSet::New();
991 textureSet.SetTexture( 0u, texture );
993 // Filter mode needs to be set to linear to produce better quality while scaling.
994 Sampler sampler = Sampler::New();
995 sampler.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
996 sampler.SetWrapMode( Dali::WrapMode::DEFAULT, Dali::WrapMode::REPEAT, Dali::WrapMode::DEFAULT ); // Wrap the texture in the x direction
997 textureSet.SetSampler( 0u, sampler );
999 // Set parameters for scrolling
1000 Renderer renderer = static_cast<Internal::Visual::Base&>( GetImplementation( mVisual ) ).GetRenderer();
1001 mTextScroller->SetParameters( Self(), renderer, textureSet, controlSize, verifiedSize, wrapGap, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment() );
1002 mController->SetTextElideEnabled( actualellipsis );
1005 void TextLabel::ScrollingFinished()
1007 // Pure Virtual from TextScroller Interface
1008 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
1009 mController->SetAutoScrollEnabled( false );
1010 RequestTextRelayout();
1013 TextLabel::TextLabel()
1014 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1015 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1016 mTextUpdateNeeded( false )
1020 TextLabel::~TextLabel()
1024 } // namespace Internal
1026 } // namespace Toolkit