Fix the problem that the font does not change because the font cache of the multi-language-support and text-controller does not disappear when the language is changed.
Change-Id: Ib6afee3101d87cd09a1a0c9af5c9f33b16bf84cb
DALI_TEST_EQUALS(DEFAULT_FONTS_REMAIN_COUNT, defaultFontsPerScript->mFonts.size(), TEST_LOCATION);
END_TEST;
+}
+
+int UtcDaliTextMultiLanguageLocaleChange(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliTextMultiLanguageLocaleChange");
+
+ Adaptor &adaptor = application.GetAdaptor();
+ MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get();
+
+ std::string newLocale = "multi_TEST";
+ adaptor.LocaleChangedSignal().Emit(newLocale);
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS(newLocale.data(), GetImplementation(multilanguageSupport).GetLocale(), TEST_LOCATION);
+
+ END_TEST;
}
\ No newline at end of file
END_TEST;
}
+
+int UtcDaliTextLabelLocaleChange(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliTextLabelLocaleChange ");
+
+ Adaptor &adaptor = application.GetAdaptor();
+ TextLabel textLabel = TextLabel::New();
+ application.GetScene().Add(textLabel);
+
+ application.SendNotification();
+ application.Render();
+
+ std::string newLocale = "label_TEST";
+ adaptor.LocaleChangedSignal().Emit(newLocale);
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS(newLocale.data(), GetImpl(textLabel).GetLocale(), TEST_LOCATION);
+
+ END_TEST;
+}
\ No newline at end of file
Dali::Adaptor::AdaptorSignalType& ResizedSignal();
Dali::Adaptor::AdaptorSignalType& LanguageChangedSignal();
Dali::Adaptor::WindowCreatedSignalType& WindowCreatedSignal();
+ Dali::Adaptor::LocaleChangedSignalType& LocaleChangedSignal();
static Adaptor& GetImpl( Dali::Adaptor& adaptor ) { return *adaptor.mImpl; }
static const Adaptor& GetImpl( const Dali::Adaptor& adaptor ) { return *adaptor.mImpl; }
Dali::Adaptor::AdaptorSignalType mResizedSignal;
Dali::Adaptor::AdaptorSignalType mLanguageChangedSignal;
Dali::Adaptor::WindowCreatedSignalType mWindowCreatedSignal;
+ Dali::Adaptor::LocaleChangedSignalType mLocaleChangedSignal;
TestApplication* mTestApplication;
};
return mMainWindow;
}
+ Dali::Adaptor& GetAdaptor()
+ {
+ return *mAdaptor;
+ }
+
private:
Dali::Window mMainWindow;
std::unique_ptr< Adaptor > mAdaptor;
#include <dali/devel-api/adaptor-framework/image-loading.h>
#include <dali/devel-api/common/stage.h>
#include <dali/devel-api/object/property-helper-devel.h>
+#include <dali/integration-api/adaptor-framework/adaptor.h>
#include <dali/integration-api/debug.h>
#include <dali/public-api/common/dali-common.h>
#include <dali/public-api/object/type-registry-helper.h>
self.LayoutDirectionChangedSignal().Connect(this, &TextLabel::OnLayoutDirectionChanged);
+ if(Dali::Adaptor::IsAvailable())
+ {
+ Dali::Adaptor::Get().LocaleChangedSignal().Connect(this, &TextLabel::OnLocaleChanged);
+ }
+
Layout::Engine& engine = mController->GetLayoutEngine();
engine.SetCursorWidth(0u); // Do not layout space for the cursor.
mController->ChangedLayoutDirection();
}
+void TextLabel::OnLocaleChanged(std::string locale)
+{
+ if(mLocale != locale)
+ {
+ mLocale = locale;
+ mController->ResetFontAndStyleData();
+ }
+}
+
+std::string TextLabel::GetLocale()
+{
+ return mLocale;
+}
+
void TextLabel::EmitTextFitChangedSignal()
{
Dali::Toolkit::TextLabel handle(GetOwner());
: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour)),
mRenderingBackend(DEFAULT_RENDERING_BACKEND),
mTextUpdateNeeded(false),
- mLastAutoScrollEnabled(false)
+ mLastAutoScrollEnabled(false),
+ mLocale(std::string())
{
}
*/
bool IsTextFitArrayEnabled() const;
+ /**
+ * @brief Gets the locale.
+ */
+ std::string GetLocale();
+
private: // From Control
/**
* @copydoc Control::OnInitialize()
void OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type);
/**
+ * @brief Callback function for when the locale is changed.
+ * @param[in] locale The new system locale.
+ */
+ void OnLocaleChanged(std::string locale);
+
+ /**
* @brief Emits TextFitChanged signal.
*/
void EmitTextFitChangedSignal();
Toolkit::DevelTextLabel::AnchorClickedSignalType mAnchorClickedSignal;
Toolkit::DevelTextLabel::TextFitChangedSignalType mTextFitChangedSignal;
+ std::string mLocale;
+
int mRenderingBackend;
bool mTextUpdateNeeded : 1;
bool mLastAutoScrollEnabled : 1;
#include <dali-toolkit/devel-api/styling/style-manager-devel.h>
#include <dali-toolkit/internal/text/controller/text-controller.h>
#include <dali-toolkit/internal/text/input-style.h>
+#include <dali-toolkit/internal/text/multi-language-support.h>
#include <dali-toolkit/internal/text/text-model.h>
#include <dali-toolkit/internal/text/text-view.h>
#include <dali-toolkit/public-api/styling/style-manager.h>
}
/**
+ * @copydoc Text::Controller::ResetFontAndStyleData()
+ */
+ void ResetFontAndStyleData()
+ {
+ ClearFontData();
+ ClearStyleData();
+ RequestRelayout();
+ }
+
+ /**
* @brief Helper to move the cursor, grab handle etc.
*/
bool ProcessInputEvents();
mImpl->mIsLayoutDirectionChanged = true;
}
+void Controller::ResetFontAndStyleData()
+{
+ mImpl->ResetFontAndStyleData();
+}
+
void Controller::SetMatchLayoutDirection(DevelText::MatchLayoutDirection type)
{
mImpl->mModel->mMatchLayoutDirection = type;
void ChangedLayoutDirection();
/**
+ * @brief Clear font and style data.
+ */
+ void ResetFontAndStyleData();
+
+ /**
* @brief Retrieves if showing real text or not.
* @return The value of showing real text.
*/
// EXTERNAL INCLUDES
#include <dali/devel-api/common/singleton-service.h>
#include <dali/devel-api/text-abstraction/font-client.h>
+#include <dali/integration-api/adaptor-framework/adaptor.h>
#include <dali/integration-api/debug.h>
#include <dali/integration-api/trace.h>
MultilanguageSupport::MultilanguageSupport()
: mDefaultFontPerScriptCache(),
- mValidFontsPerScriptCache()
+ mValidFontsPerScriptCache(),
+ mLocale(std::string())
{
// Initializes the default font cache to zero (invalid font).
// Reserves space to cache the default fonts and access them with the script as an index.
// Initializes the valid fonts cache to NULL (no valid fonts).
// Reserves space to cache the valid fonts and access them with the script as an index.
mValidFontsPerScriptCache.Resize(TextAbstraction::GetNumberOfScripts(), NULL);
+
+ if(Dali::Adaptor::IsAvailable())
+ {
+ Dali::Adaptor::Get().LocaleChangedSignal().Connect(this, &MultilanguageSupport::OnLocaleChanged);
+ }
}
MultilanguageSupport::~MultilanguageSupport()
}
}
+void MultilanguageSupport::OnLocaleChanged(std::string locale)
+{
+ if(mLocale != locale)
+ {
+ mLocale = locale;
+ ClearCache();
+ }
+}
+
+void MultilanguageSupport::ClearCache()
+{
+ mDefaultFontPerScriptCache.Clear();
+ mValidFontsPerScriptCache.Clear();
+
+ mDefaultFontPerScriptCache.Resize(TextAbstraction::GetNumberOfScripts(), NULL);
+ mValidFontsPerScriptCache.Resize(TextAbstraction::GetNumberOfScripts(), NULL);
+}
+
+std::string MultilanguageSupport::GetLocale()
+{
+ return mLocale;
+}
+
Text::MultilanguageSupport MultilanguageSupport::Get()
{
Text::MultilanguageSupport multilanguageSupportHandle;
// EXTERNAL INCLUDES
#include <dali/public-api/object/base-object.h>
+#include <dali/public-api/signals/connection-tracker.h>
// INTERNAL INCLUDES
#include <dali-toolkit/internal/text/multi-language-support.h>
/**
* @brief Multi-language support implementation. @see Text::MultilanguageSupport.
*/
-class MultilanguageSupport : public BaseObject
+class MultilanguageSupport : public BaseObject, public ConnectionTracker
{
public:
/**
Length numberOfCharacters,
Vector<FontRun>& fonts);
+ /**
+ * @brief Callback function for when the locale is changed.
+ * @param[in] locale The new system locale.
+ */
+ void OnLocaleChanged(std::string locale);
+
+ /**
+ * @brief Clear font caches when locale changed.
+ */
+ void ClearCache();
+
+ /**
+ * @brief Gets the locale.
+ */
+ std::string GetLocale();
+
private:
Vector<DefaultFonts*> mDefaultFontPerScriptCache; ///< Caches default fonts for a script.
Vector<ValidateFontsPerScript*> mValidFontsPerScriptCache; ///< Caches valid fonts for a script.
+ std::string mLocale;
+
//Methods
/**