2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/styling/common/style-monitor-impl.h>
22 #include <dali/devel-api/adaptor-framework/file-loader.h>
23 #include <dali/devel-api/common/singleton-service.h>
24 #include <dali/integration-api/debug.h>
25 #include <dali/public-api/object/type-registry.h>
28 #include <dali/internal/adaptor/common/adaptor-impl.h>
38 #if defined(DEBUG_ENABLED)
39 Dali::Integration::Log::Filter* gLogFilter = Dali::Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_STYLE_MONITOR");
43 * Use font client to get the system default font family
44 * @param[in] fontClient handle to font client
45 * @param[out] fontFamily string representing font family
47 void GetSystemDefaultFontFamily(TextAbstraction::FontClient& fontClient, std::string& fontFamily)
49 TextAbstraction::FontDescription defaultFontDescription;
52 fontClient.GetDefaultPlatformFontDescription(defaultFontDescription);
53 fontFamily = defaultFontDescription.family;
57 } // unnamed namespace
59 Dali::StyleMonitor StyleMonitor::Get()
61 Dali::StyleMonitor styleMonitor;
63 Dali::SingletonService service(SingletonService::Get());
66 // Check whether the singleton is already created
67 Dali::BaseHandle handle = service.GetSingleton(typeid(Dali::StyleMonitor));
70 // If so, downcast the handle
71 styleMonitor = Dali::StyleMonitor(dynamic_cast<StyleMonitor*>(handle.GetObjectPtr()));
75 styleMonitor = Dali::StyleMonitor(new StyleMonitor());
76 service.Register(typeid(styleMonitor), styleMonitor);
83 StyleMonitor::StyleMonitor()
84 : mDefaultFontSize(-1)
88 StyleMonitor::~StyleMonitor()
92 bool StyleMonitor::EnsureFontClientCreated()
96 mFontClient = TextAbstraction::FontClient::Get();
97 GetSystemDefaultFontFamily(mFontClient, mDefaultFontFamily);
98 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "StyleMonitor::StyleMonitor::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str());
99 mDefaultFontSize = mFontClient.GetDefaultFontSize();
102 return mFontClient != nullptr ? true : false;
105 void StyleMonitor::StyleChanged(StyleChange::Type styleChange)
109 case StyleChange::DEFAULT_FONT_CHANGE:
111 if(EnsureFontClientCreated())
113 mFontClient.ResetSystemDefaults();
114 GetSystemDefaultFontFamily(mFontClient, mDefaultFontFamily);
116 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "StyleMonitor::StyleChanged::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str());
120 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
122 if(EnsureFontClientCreated())
124 mDefaultFontSize = mFontClient.GetDefaultFontSize();
129 case StyleChange::THEME_CHANGE:
135 EmitStyleChangeSignal(styleChange);
138 std::string StyleMonitor::GetDefaultFontFamily() const
140 return mDefaultFontFamily;
143 std::string StyleMonitor::GetDefaultFontStyle() const
145 return mDefaultFontStyle;
148 int StyleMonitor::GetDefaultFontSize() const
150 return mDefaultFontSize;
153 const std::string& StyleMonitor::GetTheme() const
155 return mUserDefinedThemeFilePath;
158 void StyleMonitor::SetTheme(const std::string& path)
160 mUserDefinedThemeFilePath = path;
161 EmitStyleChangeSignal(StyleChange::THEME_CHANGE);
164 bool StyleMonitor::LoadThemeFile(const std::string& filename, std::string& output)
168 std::streampos bufferSize = 0;
169 Dali::Vector<char> fileBuffer;
170 if(Dali::FileLoader::ReadFile(filename, bufferSize, fileBuffer, FileLoader::FileType::BINARY))
172 output.assign(&fileBuffer[0], bufferSize);
179 Dali::StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
181 return mStyleChangeSignal;
184 void StyleMonitor::EmitStyleChangeSignal(StyleChange::Type styleChange)
186 if(!mStyleChangeSignal.Empty())
188 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "StyleMonitor::EmitStyleChangeSignal\n");
189 Dali::StyleMonitor handle(this);
190 mStyleChangeSignal.Emit(handle, styleChange);
194 } // namespace Adaptor
196 } // namespace Internal