From: Agnelo Vaz Date: Tue, 25 Aug 2015 15:56:11 +0000 (+0100) Subject: System font family change to update font in TextField X-Git-Tag: dali_1.1.2~17^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=785904f5477a648bc0005dcbb39bd3a85077e32d System font family change to update font in TextField * StyleManager has an API to GetDefaultFontFamily * StyleManager to store DefaultFontFamly from StyleMonitor when system font changes. * TextField to Update Text Model after Default font changes. - Currently editing text changes but not the Inactive Placeholder Signed-off-by: Agnelo Vaz Change-Id: I6d3f070e7ec57fea9815348ddce998563b392a95 --- diff --git a/dali-toolkit/devel-api/styling/style-manager.cpp b/dali-toolkit/devel-api/styling/style-manager.cpp index b3a0028..19e2f1f 100644 --- a/dali-toolkit/devel-api/styling/style-manager.cpp +++ b/dali-toolkit/devel-api/styling/style-manager.cpp @@ -58,6 +58,11 @@ void StyleManager::SetOrientation( Orientation orientation ) GetImpl(*this).SetOrientation( orientation ); } +std::string StyleManager::GetDefaultFontFamily() const +{ + return GetImpl(*this).GetDefaultFontFamily(); +} + Orientation StyleManager::GetOrientation() { return GetImpl(*this).GetOrientation(); diff --git a/dali-toolkit/devel-api/styling/style-manager.h b/dali-toolkit/devel-api/styling/style-manager.h index a568bba..a1596e1 100644 --- a/dali-toolkit/devel-api/styling/style-manager.h +++ b/dali-toolkit/devel-api/styling/style-manager.h @@ -115,6 +115,12 @@ public: Orientation GetOrientation(); /** + * @brief Retrieves the default font family. + * @return The default font family. + */ + std::string GetDefaultFontFamily() const; + + /** * @brief Make a request to set the theme JSON file to one that exists in the Toolkit package. * * Multiple requests per event processing cycle can be made, but only the final one will be acted diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index 10d87a7..eeb7fa5 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -149,6 +149,9 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr { Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n"); + + if( textField ) { TextField& impl( GetImpl( textField ) ); @@ -210,7 +213,7 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr if( impl.mController->GetDefaultFontFamily() != fontFamily ) { - impl.mController->SetDefaultFontFamily( fontFamily ); + impl.mController->SetDefaultFontFamily( fontFamily, true ); // "true" as SetProperty means user defined font so don't change when system font changes. } } break; @@ -929,12 +932,10 @@ void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange:: { case StyleChange::DEFAULT_FONT_CHANGE: { - DALI_LOG_INFO( gLogFilter, Debug::General, "TextField::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE\n"); - if ( mController->GetDefaultFontFamily() == "" ) - { - // Property system did not set the font so should update it. - // todo instruct text-controller to update model - } + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n"); + std::string newFont = styleManager.GetDefaultFontFamily(); + // Property system did not set the font so should update it. + mController->UpdateAfterFontChange( newFont ); break; } @@ -969,6 +970,8 @@ float TextField::GetHeightForWidth( float width ) void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container ) { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n"); + if( mController->Relayout( size ) || !mRenderer ) { diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp index 81a5c97..ce08f89 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -151,7 +151,7 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr if( impl.mController->GetDefaultFontFamily() != fontFamily ) { - impl.mController->SetDefaultFontFamily( fontFamily ); + impl.mController->SetDefaultFontFamily( fontFamily, true ); } } break; diff --git a/dali-toolkit/internal/styling/style-manager-impl.cpp b/dali-toolkit/internal/styling/style-manager-impl.cpp index 08d61fd..41f20e3 100644 --- a/dali-toolkit/internal/styling/style-manager-impl.cpp +++ b/dali-toolkit/internal/styling/style-manager-impl.cpp @@ -100,6 +100,7 @@ Toolkit::StyleManager StyleManager::Get() StyleManager::StyleManager() : mOrientationDegrees( 0 ), // Portrait mDefaultFontSize( -1 ), + mDefaultFontFamily(""), mThemeFile( DEFAULT_THEME ), mFeedbackStyle( NULL ) { @@ -155,6 +156,11 @@ void StyleManager::SetOrientation( Orientation orientation ) } } +std::string StyleManager::GetDefaultFontFamily() const +{ + return mDefaultFontFamily; +} + Orientation StyleManager::GetOrientation() { return mOrientation; @@ -417,6 +423,7 @@ void StyleManager::StyleMonitorChange( StyleMonitor styleMonitor, StyleChange::T { case StyleChange::DEFAULT_FONT_CHANGE: { + mDefaultFontFamily = styleMonitor.GetDefaultFontFamily(); break; } diff --git a/dali-toolkit/internal/styling/style-manager-impl.h b/dali-toolkit/internal/styling/style-manager-impl.h index 86c6d4c..ab5e24d 100644 --- a/dali-toolkit/internal/styling/style-manager-impl.h +++ b/dali-toolkit/internal/styling/style-manager-impl.h @@ -81,6 +81,11 @@ public: Orientation GetOrientation(); /** + * @copydoc Toolkit::StyleManager::GetDefaultFontFamily + */ + std::string GetDefaultFontFamily() const; + + /** * @copydoc Toolkit::StyleManager::SetStyleConstant */ void SetStyleConstant( const std::string& key, const Property::Value& value ); @@ -254,6 +259,8 @@ private: int mDefaultFontSize; ///< Logical size, not a point-size + std::string mDefaultFontFamily; + std::string mThemeFile; ///< The full path of the current theme file Property::Map mThemeBuilderConstants; ///< Contants to give the theme builder diff --git a/dali-toolkit/internal/text/multi-language-support-impl.cpp b/dali-toolkit/internal/text/multi-language-support-impl.cpp index d730c9e..bb33981 100644 --- a/dali-toolkit/internal/text/multi-language-support-impl.cpp +++ b/dali-toolkit/internal/text/multi-language-support-impl.cpp @@ -363,7 +363,7 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, // Copy the fonts set by application developers. const Length numberOfFontRuns = fonts.Count(); - const Vector definedFonts = fonts; + const Vector userSetFonts = fonts; fonts.Clear(); // Traverse the characters and validate/set the fonts. @@ -386,8 +386,8 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); // Iterators of the font and script runs. - Vector::ConstIterator fontRunIt = definedFonts.Begin(); - Vector::ConstIterator fontRunEndIt = definedFonts.End(); + Vector::ConstIterator fontRunIt = userSetFonts.Begin(); + Vector::ConstIterator fontRunEndIt = userSetFonts.End(); Vector::ConstIterator scriptRunIt = scripts.Begin(); Vector::ConstIterator scriptRunEndIt = scripts.End(); diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index 5054e8b..e60fe37 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -21,6 +21,7 @@ // EXTERNAL INCLUDES #include #include +#include // INTERNAL INCLUDES #include @@ -174,7 +175,9 @@ struct ModifyEvent struct FontDefaults { FontDefaults() - : mDefaultPointSize(0.0f), + : mDefaultFontFamily(""), + mDefaultFontStyle(""), + mDefaultPointSize(0.0f), mFontId(0u) { } @@ -214,7 +217,8 @@ struct Controller::Impl mAlignmentOffset(), mOperationsPending( NO_OPERATION ), mMaximumNumberOfCharacters( 50 ), - mRecalculateNaturalSize( true ) + mRecalculateNaturalSize( true ), + mUserDefinedFontFamily( false) { mLogicalModel = LogicalModel::New(); mVisualModel = VisualModel::New(); @@ -482,7 +486,9 @@ struct Controller::Impl Vector2 mAlignmentOffset; ///< Vertical and horizontal offset of the whole text inside the control due to alignment. OperationsMask mOperationsPending; ///< Operations pending to be done to layout the text. Length mMaximumNumberOfCharacters; ///< Maximum number of characters that can be inserted. + bool mRecalculateNaturalSize:1; ///< Whether the natural size needs to be recalculated. + bool mUserDefinedFontFamily:1; ///< Whether the Font family was Set by the user instead of being left as sytem default }; } // namespace Text diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 86f0090..41344ac 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -74,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(); @@ -223,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 ) { @@ -231,7 +233,7 @@ void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily ) } mImpl->mFontDefaults->mDefaultFontFamily = defaultFontFamily; - + mImpl->mUserDefinedFontFamily = userDefined; // Clear the font-specific data ClearFontData(); @@ -316,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; diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index 99c2ab0..fa4f966 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -178,8 +178,9 @@ public: * @brief Set the default font family. * * @param[in] defaultFontFamily The default font family. + * @param[in] userDefined If set by the user */ - void SetDefaultFontFamily( const std::string& defaultFontFamily ); + void SetDefaultFontFamily( const std::string& defaultFontFamily, bool userDefined ); /** * @brief Retrieve the default font family. @@ -217,6 +218,12 @@ public: float GetDefaultPointSize() const; /** + * @ brief Update the text after a font change + * @param[in] newDefaultFont The new font to change to + */ + void UpdateAfterFontChange( std::string& newDefaultFont ); + + /** * @brief Set the text color * * @param textColor The text color