Move FontDefaults Declaration/Definition as it's needed by the TextInput.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.cpp
index 219d8e5..591dbaf 100644 (file)
@@ -70,6 +70,31 @@ namespace Toolkit
 namespace Text
 {
 
+struct Controller::FontDefaults
+{
+  FontDefaults()
+  : mDefaultPointSize(0.0f),
+    mFontId(0u)
+  {
+  }
+
+  FontId GetFontId( TextAbstraction::FontClient& fontClient )
+  {
+    if( !mFontId )
+    {
+      Dali::TextAbstraction::PointSize26Dot6 pointSize = mDefaultPointSize*64;
+      mFontId = fontClient.GetFontId( mDefaultFontFamily, mDefaultFontStyle, pointSize );
+    }
+
+    return mFontId;
+  }
+
+  std::string mDefaultFontFamily;
+  std::string mDefaultFontStyle;
+  float mDefaultPointSize;
+  FontId mFontId;
+};
+
 struct Controller::TextInput
 {
   // Used to queue input events until DoRelayout()
@@ -245,7 +270,7 @@ struct Controller::TextInput
       float yPosition = event.p3.mFloat - alignmentOffset.y;
       float height(0.0f);
       GetClosestCursorPosition( mPrimaryCursorPosition, xPosition, yPosition, height );
-      mDecorator->SetPosition( PRIMARY_CURSOR, xPosition, yPosition, height );
+      mDecorator->SetPosition( PRIMARY_CURSOR, xPosition, yPosition, height, height ); // TODO: To be fixed in the next patch.
       mUpdateCursorPosition = false;
 
       mDecoratorUpdated = true;
@@ -325,7 +350,8 @@ struct Controller::TextInput
 
       GetClosestCursorPosition( mPrimaryCursorPosition, xPosition, yPosition, height );
 
-      mDecorator->SetPosition( PRIMARY_CURSOR, xPosition, yPosition, height );
+      mDecorator->SetPosition( PRIMARY_CURSOR, xPosition, yPosition, height, height ); // TODO: To be fixed in the next patch.
+
       //mDecorator->HidePopup();
       ChangeState ( EDITING );
       mDecoratorUpdated = true;
@@ -359,7 +385,7 @@ struct Controller::TextInput
 
       // TODO - multi-line selection
       const Vector<LineRun>& lines = mVisualModel->mLines;
-      float height = lines.Count() ? lines[0].lineSize.height : 0.0f;
+      float height = lines.Count() ? lines[0].ascender + -lines[0].descender : 0.0f;
 
       mDecorator->SetPosition( PRIMARY_SELECTION_HANDLE,   primaryX,   0.0f, height );
       mDecorator->SetPosition( SECONDARY_SELECTION_HANDLE, secondaryX, 0.0f, height );
@@ -438,7 +464,8 @@ struct Controller::TextInput
     const Vector<LineRun>& lines = mVisualModel->mLines;
     for( float totalHeight = 0; lineIndex < lines.Count(); ++lineIndex )
     {
-      totalHeight += lines[lineIndex].lineSize.height;
+      const LineRun& lineRun = lines[lineIndex];
+      totalHeight += lineRun.ascender + -lineRun.descender;
       if( y < totalHeight )
       {
         return lineIndex;
@@ -515,7 +542,7 @@ struct Controller::TextInput
     }
     visualY = 0.0f;
 
-    height = line.lineSize.height;
+    height = line.ascender + -line.descender;
   }
 
   void UpdateCursorPosition()
@@ -559,13 +586,14 @@ struct Controller::TextInput
         lastGlyph = (lineRuns[lineIndex].glyphIndex + lineRuns[lineIndex].numberOfGlyphs);
         if( cursorGlyph < lastGlyph )
         {
-          height = lineRuns[lineIndex].lineSize.height;
+          const LineRun& lineRun = lineRuns[lineIndex];
+          height = lineRun.ascender + -lineRun.descender;
           break;
         }
       }
     }
 
-    mDecorator->SetPosition( PRIMARY_CURSOR, visualX, visualY, height );
+    mDecorator->SetPosition( PRIMARY_CURSOR, visualX, visualY, height, height ); // TODO: To be fixed in the next patch.
     mDecoratorUpdated = true;
   }
 
@@ -602,31 +630,6 @@ struct Controller::TextInput
   bool mUpdateCursorPosition       : 1; ///< True if the visual position of the cursor must be recalculated
 };
 
-struct Controller::FontDefaults
-{
-  FontDefaults()
-  : mDefaultPointSize(0.0f),
-    mFontId(0u)
-  {
-  }
-
-  FontId GetFontId( TextAbstraction::FontClient& fontClient )
-  {
-    if( !mFontId )
-    {
-      Dali::TextAbstraction::PointSize26Dot6 pointSize = mDefaultPointSize*64;
-      mFontId = fontClient.GetFontId( mDefaultFontFamily, mDefaultFontStyle, pointSize );
-    }
-
-    return mFontId;
-  }
-
-  std::string mDefaultFontFamily;
-  std::string mDefaultFontStyle;
-  float mDefaultPointSize;
-  FontId mFontId;
-};
-
 struct Controller::Impl
 {
   Impl( ControlInterface& controlInterface )
@@ -651,9 +654,11 @@ struct Controller::Impl
 
     mView.SetVisualModel( mVisualModel );
 
-    // Set the shadow properties to default
+    // Set the text properties to default
+    mVisualModel->SetTextColor( Color::WHITE );
     mVisualModel->SetShadowOffset( Vector2::ZERO );
     mVisualModel->SetShadowColor( Vector4::ZERO );
+    mVisualModel->SetUnderlineEnabled( false );
   }
 
   ~Impl()
@@ -849,6 +854,11 @@ void Controller::GetDefaultFonts( Vector<FontRun>& fonts, Length numberOfCharact
   }
 }
 
+const Vector4& Controller::GetTextColor() const
+{
+  return mImpl->mVisualModel->GetTextColor();
+}
+
 const Vector2& Controller::GetShadowOffset() const
 {
   return mImpl->mVisualModel->GetShadowOffset();
@@ -859,6 +869,21 @@ const Vector4& Controller::GetShadowColor() const
   return mImpl->mVisualModel->GetShadowColor();
 }
 
+const Vector4& Controller::GetUnderlineColor() const
+{
+  return mImpl->mVisualModel->GetUnderlineColor();
+}
+
+bool Controller::IsUnderlineEnabled() const
+{
+  return mImpl->mVisualModel->IsUnderlineEnabled();
+}
+
+void Controller::SetTextColor( const Vector4& textColor )
+{
+  mImpl->mVisualModel->SetTextColor( textColor );
+}
+
 void Controller::SetShadowOffset( const Vector2& shadowOffset )
 {
   mImpl->mVisualModel->SetShadowOffset( shadowOffset );
@@ -869,6 +894,16 @@ void Controller::SetShadowColor( const Vector4& shadowColor )
   mImpl->mVisualModel->SetShadowColor( shadowColor );
 }
 
+void Controller::SetUnderlineColor( const Vector4& color )
+{
+  mImpl->mVisualModel->SetUnderlineColor( color );
+}
+
+void Controller::SetUnderlineEnabled( bool enabled )
+{
+  mImpl->mVisualModel->SetUnderlineEnabled( enabled );
+}
+
 void Controller::EnableTextInput( DecoratorPtr decorator )
 {
   if( !mImpl->mTextInput )