Merge "Size negotiation patch 1: Remove actor SetPreferredSize" into tizen
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / text-actor-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/actors/text-actor-impl.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/public-api/text/text-actor-parameters.h>
24 #include <dali/integration-api/platform-abstraction.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/internal/common/core-impl.h>
27 #include <dali/internal/event/actor-attachments/text-attachment-impl.h>
28 #include <dali/internal/event/common/property-helper.h>
29 #include <dali/internal/event/text/font-impl.h>
30 #include <dali/internal/event/text/text-impl.h>
31 #include <dali/internal/event/text/utf8-impl.h>
32
33 namespace Dali
34 {
35
36 namespace Internal
37 {
38
39 namespace
40 {
41
42 // Properties
43
44 //              Name                       Type   writable animatable constraint-input  enum for index-checking
45 DALI_PROPERTY_TABLE_BEGIN
46 DALI_PROPERTY( "text",                     STRING,    true,    false,   true,   Dali::TextActor::Property::TEXT                     )
47 DALI_PROPERTY( "font",                     STRING,    true,    false,   true,   Dali::TextActor::Property::FONT                     )
48 DALI_PROPERTY( "font-style",               STRING,    true,    false,   true,   Dali::TextActor::Property::FONT_STYLE               )
49 DALI_PROPERTY( "outline-enable",           BOOLEAN,   true,    false,   true,   Dali::TextActor::Property::OUTLINE_ENABLE           )
50 DALI_PROPERTY( "outline-color",            VECTOR4,   true,    false,   true,   Dali::TextActor::Property::OUTLINE_COLOR            )
51 DALI_PROPERTY( "outline-thickness-width",  VECTOR2,   true,    false,   true,   Dali::TextActor::Property::OUTLINE_THICKNESS_WIDTH  )
52 DALI_PROPERTY( "smooth-edge",              FLOAT,     true,    false,   true,   Dali::TextActor::Property::SMOOTH_EDGE              )
53 DALI_PROPERTY( "glow-enable",              BOOLEAN,   true,    false,   true,   Dali::TextActor::Property::GLOW_ENABLE              )
54 DALI_PROPERTY( "glow-color",               VECTOR4,   true,    false,   true,   Dali::TextActor::Property::GLOW_COLOR               )
55 DALI_PROPERTY( "glow-intensity",           FLOAT,     true,    false,   true,   Dali::TextActor::Property::GLOW_INTENSITY           )
56 DALI_PROPERTY( "shadow-enable",            BOOLEAN,   true,    false,   true,   Dali::TextActor::Property::SHADOW_ENABLE            )
57 DALI_PROPERTY( "shadow-color",             VECTOR4,   true,    false,   true,   Dali::TextActor::Property::SHADOW_COLOR             )
58 DALI_PROPERTY( "shadow-offset",            VECTOR2,   true,    false,   true,   Dali::TextActor::Property::SHADOW_OFFSET            )
59 DALI_PROPERTY( "italics-angle",            FLOAT,     true,    false,   true,   Dali::TextActor::Property::ITALICS_ANGLE            )
60 DALI_PROPERTY( "underline",                BOOLEAN,   true,    false,   true,   Dali::TextActor::Property::UNDERLINE                )
61 DALI_PROPERTY( "weight",                   INTEGER,   true,    false,   true,   Dali::TextActor::Property::WEIGHT                   )
62 DALI_PROPERTY( "font-detection-automatic", BOOLEAN,   true,    false,   true,   Dali::TextActor::Property::FONT_DETECTION_AUTOMATIC )
63 DALI_PROPERTY( "gradient-color",           VECTOR4,   true,    false,   true,   Dali::TextActor::Property::GRADIENT_COLOR           )
64 DALI_PROPERTY( "gradient-start-point",     VECTOR2,   true,    false,   true,   Dali::TextActor::Property::GRADIENT_START_POINT     )
65 DALI_PROPERTY( "gradient-end-point",       VECTOR2,   true,    false,   true,   Dali::TextActor::Property::GRADIENT_END_POINT       )
66 DALI_PROPERTY( "shadow-size",              FLOAT,     true,    false,   true,   Dali::TextActor::Property::SHADOW_SIZE              )
67 DALI_PROPERTY( "text-color",               VECTOR4,   true,    false,   true,   Dali::TextActor::Property::TEXT_COLOR               )
68 DALI_PROPERTY_TABLE_END( DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX )
69
70 // Signals
71
72 const char* const SIGNAL_TEXT_LOADING_FINISHED = "text-loading-finished";
73
74 BaseHandle Create()
75 {
76   return Dali::TextActor::New();
77 }
78
79 TypeRegistration mType( typeid( Dali::TextActor ), typeid( Dali::RenderableActor ), Create );
80
81 SignalConnectorType s1( mType, SIGNAL_TEXT_LOADING_FINISHED, &TextActor::DoConnectSignal );
82
83 }
84
85 TextActorPtr TextActor::New( const Integration::TextArray& utfCodes, const TextActorParameters& parameters )
86 {
87   // first stage construction
88   TextActorPtr actor ( new TextActor( parameters.IsAutomaticFontDetectionEnabled() ) );
89
90   const TextStyle& style = parameters.GetTextStyle();
91
92   FontPointer fontPtr( Font::New(style.GetFontName(), style.GetFontStyle(), style.GetFontPointSize() ) );
93
94   // Second-phase construction
95   actor->Initialize();
96
97   //create the attachment
98   actor->mTextAttachment = TextAttachment::New( actor->GetEventThreadServices(), *actor->mNode, Integration::TextArray(), fontPtr );
99   actor->Attach(*actor->mTextAttachment);
100
101   // Note: SetTextStyle() MUST be called before SetText(), to ensure
102   //       that a single ResourceRequest for the glyphs is made. Calling
103   //       them in the wrong order will issue two requests.
104   actor->SetTextStyle( style, DONT_REQUEST_NEW_TEXT );
105
106   actor->SetText( utfCodes );
107
108   return actor;
109 }
110
111 TextActor::TextActor(bool fontDetection)
112 : RenderableActor(),
113   mLoadingState(Dali::ResourceLoading),
114   mUsingNaturalSize(true),
115   mInternalSetSize(false),
116   mFontDetection(fontDetection),
117   mObserving(false)
118 {
119 }
120
121 void TextActor::OnInitialize()
122 {
123 }
124
125 TextActor::~TextActor()
126 {
127   StopObservingTextLoads();
128 }
129
130 const std::string TextActor::GetText() const
131 {
132   const Integration::TextArray& utfCodes = mTextAttachment->GetText();
133
134   std::string text;
135
136   const std::size_t length = utfCodes.Count();
137   // minimize allocations for ascii strings
138   text.reserve( length );
139
140   for (unsigned int i = 0; i < length; ++i)
141   {
142     unsigned char utf8Data[4];
143     unsigned int utf8Length;
144
145     utf8Length = UTF8Write(utfCodes[i], utf8Data);
146
147     text.append(reinterpret_cast<const char*>(utf8Data), utf8Length);
148   }
149
150   return text;
151 }
152
153 Font* TextActor::GetFont() const
154 {
155   return &mTextAttachment->GetFont();
156 }
157
158 void TextActor::SetToNaturalSize()
159 {
160   // ignore size set by application
161   mUsingNaturalSize = true;
162   TextChanged(); // this will calculate natural size
163 }
164
165 void TextActor::StopObservingTextLoads()
166 {
167   if( mObserving )
168   {
169     mTextAttachment->GetFont().RemoveObserver( *this );
170     mObserving = false;
171   }
172 }
173
174 void TextActor::StartObservingTextLoads()
175 {
176   if( !mObserving )
177   {
178     mTextAttachment->GetFont().AddObserver( *this );
179     mObserving = true;
180   }
181 }
182
183 void TextActor::SetText(const Integration::TextArray& utfCodes)
184 {
185   StopObservingTextLoads();
186
187   // assign the new text
188   mTextAttachment->SetText(utfCodes);
189
190   if( mFontDetection )
191   {
192     // first check if the provided font supports the text
193     //
194     if( !mTextAttachment->GetFont().AllGlyphsSupported(utfCodes) )
195     {
196       // auto-detect font
197       // @todo GetFamilyForText should return font name and style
198       const std::string fontName = Font::GetFamilyForText(utfCodes);
199
200       // use previous formatting
201       Internal::Font& font = mTextAttachment->GetFont();
202
203       Dali::Font fontNew = Dali::Font::New( Dali::FontParameters( fontName, font.GetStyle(), PointSize(font.GetPointSize() ) ) );
204
205       SetFont( GetImplementation(fontNew), DONT_REQUEST_NEW_TEXT );
206     }
207   }
208
209   TextChanged();
210 }
211
212 void TextActor::SetFont(Font& font, TextRequestMode mode )
213 {
214   StopObservingTextLoads();
215
216   if( mode == REQUEST_NEW_TEXT )
217   {
218     // set the new font
219     mTextAttachment->SetFont( font );
220
221     // request text for new font
222     TextChanged();
223   }
224   else
225   {
226     // just set the font
227     mTextAttachment->SetFont( font );
228   }
229 }
230
231 Vector3 TextActor::GetNaturalSize() const
232 {
233   Vector2 naturalSize( mTextAttachment->GetNaturalTextSize() );
234   return Vector3( naturalSize.width, naturalSize.height, CalculateSizeZ( naturalSize ) );
235 }
236
237 void TextActor::OnSizeSet(const Vector3& targetSize)
238 {
239   if( !mInternalSetSize )
240   {
241     // after size is once set by application we no longer use the natural size
242     mUsingNaturalSize = false;
243   }
244 }
245
246 void TextActor::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
247 {
248   // after size has been animated by application we no longer use the natural size
249   mUsingNaturalSize = false;
250 }
251
252 RenderableAttachment& TextActor::GetRenderableAttachment() const
253 {
254   DALI_ASSERT_DEBUG( mTextAttachment );
255   return *mTextAttachment;
256 }
257
258 void TextActor::SetGradientColor( const Vector4& color )
259 {
260   mTextAttachment->SetGradient( color, mTextAttachment->GetGradientStartPoint(), mTextAttachment->GetGradientEndPoint() );
261 }
262
263 const Vector4& TextActor::GetGradientColor() const
264 {
265   return mTextAttachment->GetGradientColor();
266 }
267
268 void TextActor::SetGradientStartPoint( const Vector2& position )
269 {
270   mTextAttachment->SetGradient( mTextAttachment->GetGradientColor(), position, mTextAttachment->GetGradientEndPoint() );
271 }
272
273 const Vector2& TextActor::GetGradientStartPoint() const
274 {
275   return mTextAttachment->GetGradientStartPoint();
276 }
277
278 void TextActor::SetGradientEndPoint( const Vector2& position )
279 {
280   mTextAttachment->SetGradient( mTextAttachment->GetGradientColor(), mTextAttachment->GetGradientStartPoint(), position );
281 }
282
283 const Vector2& TextActor::GetGradientEndPoint() const
284 {
285   return mTextAttachment->GetGradientEndPoint();
286 }
287
288 void TextActor::SetGradient( const Vector4& color, const Vector2& startPoint, const Vector2& endPoint )
289 {
290   mTextAttachment->SetGradient( color, startPoint, endPoint );
291 }
292
293 void TextActor::SetTextStyle( const TextStyle& style, TextRequestMode mode )
294 {
295   // Set font.
296   const Font& font = mTextAttachment->GetFont();
297
298   // Determine the font name/style/size that Font would create.
299   // Then compare this to the existing font (which has been validated by Font).
300
301   std::string resolvedFontName = style.GetFontName();
302   std::string resolvedFontStyle = style.GetFontStyle();
303   float resolvedFontPointSize = style.GetFontPointSize();
304   bool resolvedFontFamilyDefault(false);
305   bool resolvedFontPointSizeDefault(false);
306
307   Font::ValidateFontRequest( resolvedFontName,
308                              resolvedFontStyle,
309                              resolvedFontPointSize,
310                              resolvedFontFamilyDefault,
311                              resolvedFontPointSizeDefault );
312
313   // Now compare to existing font used to see if a font change is necessary.
314   if( ( font.GetName() != resolvedFontName ) ||
315       ( font.GetStyle() != resolvedFontStyle ) ||
316       ( fabsf(font.GetPointSize() - resolvedFontPointSize) >= GetRangedEpsilon(font.GetPointSize(), resolvedFontPointSize) ) )
317   {
318     // Create font with original request (so font can determine if family and/or point size is default)
319     SetFont( *(Font::New( style.GetFontName(), style.GetFontStyle(), style.GetFontPointSize() ) ), mode );
320   }
321
322   // Set color.
323   if( !style.IsTextColorDefault() )
324   {
325     SetTextColor( style.GetTextColor() );
326   }
327   else
328   {
329     mTextAttachment->ResetTextColor();
330   }
331
332   // Italics
333   if( !style.IsItalicsDefault() )
334   {
335     SetItalics( style.IsItalicsEnabled() ? Radian( style.GetItalicsAngle() ) : Radian( 0.0f ) );
336   }
337   else
338   {
339     mTextAttachment->ResetItalics();
340   }
341
342   // Underline
343   if( !style.IsUnderlineDefault() )
344   {
345     SetUnderline( style.IsUnderlineEnabled(), style.GetUnderlineThickness(), style.GetUnderlinePosition() );
346   }
347   else
348   {
349     mTextAttachment->ResetUnderline();
350   }
351
352   // Shadow
353   if( !style.IsShadowDefault() )
354   {
355     SetShadow( style.IsShadowEnabled(), style.GetShadowColor(), style.GetShadowOffset(), style.GetShadowSize() );
356   }
357   else
358   {
359     mTextAttachment->ResetShadow();
360   }
361
362   // Glow
363   if( !style.IsGlowDefault() )
364   {
365     SetGlow( style.IsGlowEnabled(), style.GetGlowColor(), style.GetGlowIntensity() );
366   }
367   else
368   {
369     mTextAttachment->ResetGlow();
370   }
371
372   // Soft Smooth edge.
373   if( !style.IsSmoothEdgeDefault() )
374   {
375     SetSmoothEdge( style.GetSmoothEdge() );
376   }
377   else
378   {
379     mTextAttachment->ResetSmoothEdge();
380   }
381
382   // Outline
383   if( !style.IsOutlineDefault() )
384   {
385     SetOutline( style.IsOutlineEnabled(), style.GetOutlineColor(), style.GetOutlineThickness() );
386   }
387   else
388   {
389     mTextAttachment->ResetOutline();
390   }
391
392   // Weight
393   if( !style.IsFontWeightDefault() )
394   {
395     SetWeight( style.GetWeight() );
396   }
397   else
398   {
399     mTextAttachment->ResetWeight();
400   }
401
402   //Gradient
403   if( !style.IsGradientDefault() )
404   {
405     if( style.IsGradientEnabled() )
406     {
407       SetGradient( style.GetGradientColor(), style.GetGradientStartPoint(), style.GetGradientEndPoint() );
408     }
409     else
410     {
411       SetGradient( TextStyle::DEFAULT_GRADIENT_COLOR, TextStyle::DEFAULT_GRADIENT_START_POINT, TextStyle::DEFAULT_GRADIENT_END_POINT );
412     }
413   }
414   else
415   {
416     mTextAttachment->ResetGradient();
417   }
418   TextChanged();
419 }
420
421 TextStyle TextActor::GetTextStyle() const
422 {
423   TextStyle textStyle;
424   mTextAttachment->GetTextStyle( textStyle );
425
426   return textStyle;
427 }
428
429 void TextActor::SetTextColor(const Vector4& color)
430 {
431   mTextAttachment->SetTextColor( color );
432 }
433
434 Vector4 TextActor::GetTextColor() const
435 {
436   return mTextAttachment->GetTextColor();
437 }
438
439 void TextActor::SetSmoothEdge( float smoothEdge )
440 {
441   mTextAttachment->SetSmoothEdge(smoothEdge);
442 }
443
444 void TextActor::SetOutline( bool enable, const Vector4& color, const Vector2& offset )
445 {
446   mTextAttachment->SetOutline(enable, color, offset);
447 }
448
449 void TextActor::SetGlow( bool enable, const Vector4& color, float intensity )
450 {
451   mTextAttachment->SetGlow(enable, color, intensity);
452 }
453
454 void TextActor::SetShadow( bool enable, const Vector4& color, const Vector2& offset, float size )
455 {
456   mTextAttachment->SetShadow(enable, color, offset, size);
457 }
458
459 void TextActor::SetItalics( Radian angle )
460 {
461   mTextAttachment->SetItalics( angle );
462
463   TextChanged();
464 }
465
466 bool TextActor::GetItalics() const
467 {
468   return mTextAttachment->GetItalics();
469 }
470
471 Radian TextActor::GetItalicsAngle() const
472 {
473   return mTextAttachment->GetItalicsAngle();
474 }
475
476 void TextActor::SetUnderline( bool enable, float thickness, float position )
477 {
478   mTextAttachment->SetUnderline( enable, thickness, position );
479
480   TextChanged();
481 }
482
483 bool TextActor::GetUnderline() const
484 {
485   return mTextAttachment->GetUnderline();
486 }
487
488 float TextActor::GetUnderlineThickness() const
489 {
490   return mTextAttachment->GetUnderlineThickness();
491 }
492
493 float TextActor::GetUnderlinePosition() const
494 {
495   return mTextAttachment->GetUnderlinePosition();
496 }
497
498 void TextActor::SetWeight( TextStyle::Weight weight )
499 {
500   mTextAttachment->SetWeight( weight );
501 }
502
503 TextStyle::Weight TextActor::GetWeight() const
504 {
505   return mTextAttachment->GetWeight();
506 }
507
508 void TextActor::SetFontDetectionAutomatic(bool value)
509 {
510   mFontDetection = value;
511 }
512
513 bool TextActor::IsFontDetectionAutomatic() const
514 {
515   return mFontDetection;
516 }
517
518 bool TextActor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
519 {
520   bool connected( true );
521   TextActor* textActor = dynamic_cast<TextActor*>(object);
522
523   if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_LOADING_FINISHED ) )
524   {
525     textActor->TextAvailableSignal().Connect( tracker, functor );
526   }
527   else
528   {
529     // signalName does not match any signal
530     connected = false;
531   }
532
533   return connected;
534 }
535
536 void TextActor::TextLoaded()
537 {
538   // if the text is loaded, trigger the loaded finished signal
539   CheckTextLoadState();
540 }
541
542 void TextActor::TextChanged()
543 {
544   // this will tell the text attachment to act on any text or font changes
545   mTextAttachment->TextChanged();
546
547   // check the loading state
548   bool loaded = CheckTextLoadState();
549   if( ! loaded)
550   {
551     mLoadingState = Dali::ResourceLoading;
552
553     StartObservingTextLoads();
554   }
555   // the text natural size is calculated synchronously above, when TextChanged() is called
556   if (mUsingNaturalSize)
557   {
558     mInternalSetSize = true; // to know we're internally setting size
559     SetSize( mTextAttachment->GetNaturalTextSize() );
560     mInternalSetSize = false;
561   }
562 }
563
564 bool TextActor::CheckTextLoadState()
565 {
566   if( mTextAttachment->IsTextLoaded() )
567   {
568     mLoadingState = Dali::ResourceLoadingSucceeded;
569
570     StopObservingTextLoads();
571
572     // emit text available signal
573
574     mLoadingFinished.Emit( Dali::TextActor( this ) );
575
576     return true;
577   }
578
579   // text not loaded
580   return false;
581 }
582
583 unsigned int TextActor::GetDefaultPropertyCount() const
584 {
585   return RenderableActor::GetDefaultPropertyCount() + DEFAULT_PROPERTY_COUNT;
586 }
587
588 void TextActor::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
589 {
590   RenderableActor::GetDefaultPropertyIndices( indices ); // RenderableActor class properties
591
592   indices.reserve( indices.size() + DEFAULT_PROPERTY_COUNT );
593
594   int index = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
595   for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i, ++index )
596   {
597     indices.push_back( index );
598   }
599 }
600
601 const char* TextActor::GetDefaultPropertyName( Property::Index index ) const
602 {
603   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
604   {
605     return RenderableActor::GetDefaultPropertyName(index) ;
606   }
607
608   index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
609   if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
610   {
611     return DEFAULT_PROPERTY_DETAILS[index].name;
612   }
613
614   // Index out-of-bounds.
615   return NULL;
616 }
617
618 Property::Index TextActor::GetDefaultPropertyIndex(const std::string& name) const
619 {
620   Property::Index index = Property::INVALID_INDEX;
621
622   // Look for name in default properties
623   for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
624   {
625     if( 0 == strcmp( name.c_str(), DEFAULT_PROPERTY_DETAILS[i].name ) ) // Don't want to convert rhs to string
626     {
627       index = i + DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
628       break;
629     }
630   }
631
632   // If not found, check in base class
633   if( Property::INVALID_INDEX == index )
634   {
635     index = RenderableActor::GetDefaultPropertyIndex( name );
636   }
637
638   return index;
639 }
640
641 bool TextActor::IsDefaultPropertyWritable( Property::Index index ) const
642 {
643   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
644   {
645     return RenderableActor::IsDefaultPropertyWritable( index ) ;
646   }
647
648   return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX ].writable;
649 }
650
651 bool TextActor::IsDefaultPropertyAnimatable( Property::Index index ) const
652 {
653   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
654   {
655     return RenderableActor::IsDefaultPropertyAnimatable( index ) ;
656   }
657
658   return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX ].animatable;
659 }
660
661 bool TextActor::IsDefaultPropertyAConstraintInput( Property::Index index ) const
662 {
663   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
664   {
665     return RenderableActor::IsDefaultPropertyAConstraintInput( index );
666   }
667   return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX ].constraintInput;
668 }
669
670 Property::Type TextActor::GetDefaultPropertyType( Property::Index index ) const
671 {
672   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
673   {
674     return RenderableActor::GetDefaultPropertyType( index ) ;
675   }
676
677   index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
678   if( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
679   {
680     return DEFAULT_PROPERTY_DETAILS[index].type;
681   }
682
683   // index out-of-bounds
684   return Property::NONE;
685 }
686
687 void TextActor::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
688 {
689   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
690   {
691     RenderableActor::SetDefaultProperty( index, propertyValue ) ;
692   }
693   else
694   {
695     switch(index)
696     {
697       case Dali::TextActor::Property::TEXT:
698       {
699         SetText( GetTextArray( Dali::Text( propertyValue.Get<std::string>() ) ) );
700         break;
701       }
702       case Dali::TextActor::Property::FONT:
703       {
704         SetFont( *Font::New( propertyValue.Get<std::string>(),
705                            mTextAttachment->GetFont().GetStyle(),
706                            PointSize( mTextAttachment->GetFont().GetPointSize() ) ) );
707         break;
708       }
709       case Dali::TextActor::Property::FONT_STYLE:
710       {
711         SetFont( *Font::New( mTextAttachment->GetFont().GetName(),
712                            propertyValue.Get<std::string>(),
713                            PointSize( mTextAttachment->GetFont().GetPointSize() ) ) );
714         break;
715       }
716       case Dali::TextActor::Property::OUTLINE_ENABLE:
717       {
718         Vector4 color;
719         Vector2 thickness;
720         mTextAttachment->GetOutlineParams( color, thickness );
721         mTextAttachment->SetOutline( propertyValue.Get<bool>(), color, thickness );
722         break;
723       }
724       case Dali::TextActor::Property::OUTLINE_COLOR:
725       {
726         Vector4 color;
727         Vector2 thickness;
728         mTextAttachment->GetOutlineParams( color, thickness );
729         mTextAttachment->SetOutline( mTextAttachment->GetOutline(), propertyValue.Get<Vector4>(), thickness );
730         break;
731       }
732       case Dali::TextActor::Property::OUTLINE_THICKNESS_WIDTH:
733       {
734         Vector4 color;
735         Vector2 thickness;
736         mTextAttachment->GetOutlineParams( color, thickness );
737         mTextAttachment->SetOutline( mTextAttachment->GetOutline(), color, propertyValue.Get<Vector2>() );
738         break;
739       }
740       case Dali::TextActor::Property::SMOOTH_EDGE:
741       {
742         mTextAttachment->SetSmoothEdge( propertyValue.Get<float>());
743         break;
744       }
745       case Dali::TextActor::Property::GLOW_ENABLE:
746       {
747         Vector4 color;
748         float intensity;
749         mTextAttachment->GetGlowParams( color, intensity );
750         mTextAttachment->SetGlow( propertyValue.Get<bool>(), color, intensity );
751         break;
752       }
753       case Dali::TextActor::Property::GLOW_COLOR:
754       {
755         Vector4 color;
756         float intensity;
757         mTextAttachment->GetGlowParams( color, intensity );
758         mTextAttachment->SetGlow( mTextAttachment->GetGlow(), propertyValue.Get<Vector4>(), intensity );
759         break;
760       }
761       case Dali::TextActor::Property::GLOW_INTENSITY:
762       {
763         Vector4 color;
764         float intensity;
765         mTextAttachment->GetGlowParams( color, intensity );
766         mTextAttachment->SetGlow(mTextAttachment->GetGlow(), color, propertyValue.Get<float>());
767         break;
768       }
769       case Dali::TextActor::Property::SHADOW_ENABLE:
770       {
771         Vector4 color;
772         Vector2 offset;
773         float size;
774         mTextAttachment->GetShadowParams( color, offset, size );
775         mTextAttachment->SetShadow( propertyValue.Get<bool>(), color, offset, size );
776         break;
777       }
778       case Dali::TextActor::Property::SHADOW_COLOR:
779       {
780         Vector4 color;
781         Vector2 offset;
782         float size;
783         mTextAttachment->GetShadowParams( color, offset, size );
784         mTextAttachment->SetShadow( mTextAttachment->GetShadow(), propertyValue.Get<Vector4>(), offset, size );
785         break;
786       }
787       case Dali::TextActor::Property::SHADOW_OFFSET:
788       {
789         Vector4 color;
790         Vector2 offset;
791         float size;
792         mTextAttachment->GetShadowParams( color, offset, size );
793         mTextAttachment->SetShadow( mTextAttachment->GetShadow(), color, propertyValue.Get<Vector2>(), size );
794         break;
795       }
796       case Dali::TextActor::Property::SHADOW_SIZE:
797       {
798         Vector4 color;
799         Vector2 offset;
800         float size;
801         mTextAttachment->GetShadowParams( color, offset, size );
802         mTextAttachment->SetShadow( mTextAttachment->GetShadow(), color, offset, propertyValue.Get<float>() );
803         break;
804       }
805       case Dali::TextActor::Property::ITALICS_ANGLE:
806       {
807         SetItalics( Radian( propertyValue.Get<float>() ) ) ;
808         break;
809       }
810       case Dali::TextActor::Property::UNDERLINE:
811       {
812         SetUnderline( propertyValue.Get<bool>(), 0.f, 0.f ) ;
813         break;
814       }
815       case Dali::TextActor::Property::WEIGHT:
816       {
817         mTextAttachment->SetWeight( static_cast<TextStyle::Weight>( propertyValue.Get<int>() ) ) ;
818         break;
819       }
820       case Dali::TextActor::Property::FONT_DETECTION_AUTOMATIC:
821       {
822         mFontDetection = propertyValue.Get<bool>()  ;
823         break;
824       }
825       case Dali::TextActor::Property::GRADIENT_COLOR:
826       {
827         mTextAttachment->SetGradient( propertyValue.Get<Vector4>(), mTextAttachment->GetGradientStartPoint(), mTextAttachment->GetGradientEndPoint() );
828         break;
829       }
830       case Dali::TextActor::Property::GRADIENT_START_POINT:
831       {
832         mTextAttachment->SetGradient( mTextAttachment->GetGradientColor(), propertyValue.Get<Vector2>(), mTextAttachment->GetGradientEndPoint() );
833         break;
834       }
835       case Dali::TextActor::Property::GRADIENT_END_POINT:
836       {
837         mTextAttachment->SetGradient( mTextAttachment->GetGradientColor(), mTextAttachment->GetGradientStartPoint(), propertyValue.Get<Vector2>() );
838         break;
839       }
840       case Dali::TextActor::Property::TEXT_COLOR:
841       {
842         mTextAttachment->SetTextColor( propertyValue.Get<Vector4>() );
843         break;
844       }
845       default:
846       {
847         DALI_LOG_WARNING( "Unknown text set property (%d)\n", index );
848         break;
849       }
850     } // switch(index)
851
852   } // else
853 }
854
855 Property::Value TextActor::GetDefaultProperty( Property::Index index ) const
856 {
857   Property::Value ret ;
858   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
859   {
860     ret = RenderableActor::GetDefaultProperty( index ) ;
861   }
862   else
863   {
864     switch( index )
865     {
866       case Dali::TextActor::Property::TEXT:
867       {
868         ret = GetText();
869         break;
870       }
871       case Dali::TextActor::Property::FONT:
872       {
873         ret = mTextAttachment->GetFont().GetName();
874         break;
875       }
876       case Dali::TextActor::Property::FONT_STYLE:
877       {
878         ret = mTextAttachment->GetFont().GetStyle();
879         break;
880       }
881       case Dali::TextActor::Property::OUTLINE_ENABLE:
882       {
883         ret = mTextAttachment->GetOutline();
884         break;
885       }
886       case Dali::TextActor::Property::OUTLINE_COLOR:
887       {
888         Vector4 color;
889         Vector2 thickness;
890         mTextAttachment->GetOutlineParams( color, thickness );
891         ret = color;
892         break;
893       }
894       case Dali::TextActor::Property::OUTLINE_THICKNESS_WIDTH:
895       {
896         Vector4 color;
897         Vector2 thickness;
898         mTextAttachment->GetOutlineParams( color, thickness );
899         ret = thickness;
900         break;
901       }
902       case Dali::TextActor::Property::SMOOTH_EDGE:
903       {
904         ret = mTextAttachment->GetSmoothEdge();
905         break;
906       }
907       case Dali::TextActor::Property::GLOW_ENABLE:
908       {
909         ret = mTextAttachment->GetGlow();
910         break;
911       }
912       case Dali::TextActor::Property::GLOW_COLOR:
913       {
914         Vector4 color;
915         float intensity( 0.0f );
916         mTextAttachment->GetGlowParams( color, intensity );
917         ret  = color;
918         break;
919       }
920       case Dali::TextActor::Property::GLOW_INTENSITY:
921       {
922         Vector4 color;
923         float intensity( 0.0f );
924         mTextAttachment->GetGlowParams( color, intensity );
925         ret = intensity;
926         break;
927       }
928       case Dali::TextActor::Property::SHADOW_ENABLE:
929       {
930         ret = mTextAttachment->GetShadow();
931         break;
932       }
933       case Dali::TextActor::Property::SHADOW_COLOR:
934       {
935         Vector4 color;
936         Vector2 offset;
937         float size;
938         mTextAttachment->GetShadowParams( color, offset, size );
939         ret = color;
940         break;
941       }
942       case Dali::TextActor::Property::SHADOW_OFFSET:
943       {
944         Vector4 color;
945         Vector2 offset;
946         float size;
947         mTextAttachment->GetShadowParams( color, offset, size );
948         ret = offset;
949         break;
950       }
951       case Dali::TextActor::Property::SHADOW_SIZE:
952       {
953         Vector4 color;
954         Vector2 offset;
955         float size;
956         mTextAttachment->GetShadowParams( color, offset, size );
957         ret = size;
958         break;
959       }
960       case Dali::TextActor::Property::ITALICS_ANGLE:
961       {
962         ret = static_cast<float>( mTextAttachment->GetItalics() ) ;
963         break;
964       }
965       case Dali::TextActor::Property::UNDERLINE:
966       {
967         ret = mTextAttachment->GetUnderline() ;
968         break;
969       }
970       case Dali::TextActor::Property::WEIGHT:
971       {
972         ret = static_cast<int>( mTextAttachment->GetWeight() );
973         break;
974       }
975       case Dali::TextActor::Property::FONT_DETECTION_AUTOMATIC:
976       {
977         ret = mFontDetection;
978         break;
979       }
980       case Dali::TextActor::Property::GRADIENT_COLOR:
981       {
982         ret = mTextAttachment->GetGradientColor();
983         break;
984       }
985       case Dali::TextActor::Property::GRADIENT_START_POINT:
986       {
987         ret = mTextAttachment->GetGradientStartPoint();
988         break;
989       }
990       case Dali::TextActor::Property::GRADIENT_END_POINT:
991       {
992         ret = mTextAttachment->GetGradientEndPoint();
993         break;
994       }
995       case Dali::TextActor::Property::TEXT_COLOR:
996       {
997         ret = mTextAttachment->GetTextColor();
998         break;
999       }
1000       default:
1001       {
1002         DALI_LOG_WARNING( "Unknown text set property (%d)\n", index );
1003         break;
1004       }
1005     } // switch(index)
1006   } // if from base class
1007
1008   return ret ;
1009 }
1010
1011 } // namespace Internal
1012
1013 } // namespace Dali