Merge "Fixes some alignment issues." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.cpp
index e3b29bd..47afc96 100644 (file)
@@ -38,6 +38,7 @@ namespace
 #endif
 
 const float MAX_FLOAT = std::numeric_limits<float>::max();
+const unsigned int POINTS_PER_INCH = 72;
 
 const std::string EMPTY_STRING("");
 
@@ -73,6 +74,8 @@ void Controller::EnableTextInput( DecoratorPtr decorator )
 
 void Controller::SetText( const std::string& text )
 {
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
+
   // Remove the previously set text
   ResetText();
 
@@ -222,7 +225,7 @@ int Controller::GetMaximumNumberOfCharacters()
   return mImpl->mMaximumNumberOfCharacters;
 }
 
-void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
+void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily, bool userDefined )
 {
   if( !mImpl->mFontDefaults )
   {
@@ -230,7 +233,7 @@ void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
   }
 
   mImpl->mFontDefaults->mDefaultFontFamily = defaultFontFamily;
-
+  mImpl->mUserDefinedFontFamily = userDefined;
   // Clear the font-specific data
   ClearFontData();
 
@@ -287,6 +290,15 @@ void Controller::SetDefaultPointSize( float pointSize )
 
   mImpl->mFontDefaults->mDefaultPointSize = pointSize;
 
+  unsigned int horizontalDpi( 0u );
+  unsigned int verticalDpi( 0u );
+  mImpl->mFontClient.GetDpi( horizontalDpi, verticalDpi );
+
+  // Adjust the metrics if the fixed-size font should be down-scaled
+  int maxEmojiSize( pointSize/POINTS_PER_INCH * verticalDpi );
+  DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultPointSize %p setting MaxEmojiSize %d\n", this, maxEmojiSize );
+  mImpl->mMetrics->SetMaxEmojiSize( maxEmojiSize );
+
   // Clear the font-specific data
   ClearFontData();
 
@@ -306,6 +318,23 @@ float Controller::GetDefaultPointSize() const
   return 0.0f;
 }
 
+void Controller::UpdateAfterFontChange( std::string& newDefaultFont )
+{
+  DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange");
+
+  ClearFontData();
+
+  if ( !mImpl->mUserDefinedFontFamily ) // If user defined font then should not update when system font changes
+  {
+    DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
+    mImpl->mFontDefaults->mDefaultFontFamily=newDefaultFont;
+    mImpl->UpdateModel( ALL_OPERATIONS );
+    mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
+    mImpl->mRecalculateNaturalSize = true;
+    mImpl->RequestRelayout();
+  }
+}
+
 void Controller::SetTextColor( const Vector4& textColor )
 {
   mImpl->mTextColor = textColor;
@@ -641,11 +670,24 @@ bool Controller::Relayout( const Size& size )
   // Do not re-do any operation until something changes.
   mImpl->mOperationsPending = NO_OPERATION;
 
+  // Keep the current offset and alignment as it will be used to update the decorator's positions.
+  Vector2 offset;
+  if( mImpl->mEventData )
+  {
+    offset = mImpl->mAlignmentOffset + mImpl->mEventData->mScrollPosition;
+  }
+
   // After doing the text layout, the alignment offset to place the actor in the desired position can be calculated.
   CalculateTextAlignment( size );
 
   if( mImpl->mEventData )
   {
+    // If there is a nex size, the scroll position needs to be clamped.
+    mImpl->ClampHorizontalScroll( layoutSize );
+
+    // Update the decorator's positions.
+    mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mAlignmentOffset + mImpl->mEventData->mScrollPosition - offset );
+
     // Move the cursor, grab handle etc.
     updated = mImpl->ProcessInputEvents() || updated;
   }