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