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