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)
86 mFontClient = TextAbstraction::FontClient::Get();
87 GetSystemDefaultFontFamily(mFontClient, mDefaultFontFamily);
88 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "StyleMonitor::StyleMonitor::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str());
89 mDefaultFontSize = mFontClient.GetDefaultFontSize();
92 StyleMonitor::~StyleMonitor()
96 void StyleMonitor::StyleChanged(StyleChange::Type styleChange)
100 case StyleChange::DEFAULT_FONT_CHANGE:
104 mFontClient.ResetSystemDefaults();
105 GetSystemDefaultFontFamily(mFontClient, mDefaultFontFamily);
107 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "StyleMonitor::StyleChanged::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str());
111 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
113 mDefaultFontSize = mFontClient.GetDefaultFontSize();
117 case StyleChange::THEME_CHANGE:
123 EmitStyleChangeSignal(styleChange);
126 std::string StyleMonitor::GetDefaultFontFamily() const
128 return mDefaultFontFamily;
131 std::string StyleMonitor::GetDefaultFontStyle() const
133 return mDefaultFontStyle;
136 int StyleMonitor::GetDefaultFontSize() const
138 return mDefaultFontSize;
141 const std::string& StyleMonitor::GetTheme() const
143 return mUserDefinedThemeFilePath;
146 void StyleMonitor::SetTheme(const std::string& path)
148 mUserDefinedThemeFilePath = path;
149 EmitStyleChangeSignal(StyleChange::THEME_CHANGE);
152 bool StyleMonitor::LoadThemeFile(const std::string& filename, std::string& output)
156 std::streampos bufferSize = 0;
157 Dali::Vector<char> fileBuffer;
158 if(Dali::FileLoader::ReadFile(filename, bufferSize, fileBuffer, FileLoader::FileType::BINARY))
160 output.assign(&fileBuffer[0], bufferSize);
167 Dali::StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
169 return mStyleChangeSignal;
172 void StyleMonitor::EmitStyleChangeSignal(StyleChange::Type styleChange)
174 if(!mStyleChangeSignal.Empty())
176 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "StyleMonitor::EmitStyleChangeSignal\n");
177 Dali::StyleMonitor handle(this);
178 mStyleChangeSignal.Emit(handle, styleChange);
182 } // namespace Adaptor
184 } // namespace Internal