| Index: ui/gfx/font_render_params_win.cc
|
| diff --git a/ui/gfx/font_render_params_win.cc b/ui/gfx/font_render_params_win.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..675de1f77d78acb3bf9552a0489500292c6231e7
|
| --- /dev/null
|
| +++ b/ui/gfx/font_render_params_win.cc
|
| @@ -0,0 +1,80 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "ui/gfx/font_render_params.h"
|
| +
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/memory/singleton.h"
|
| +#include "ui/gfx/win/singleton_hwnd.h"
|
| +
|
| +namespace gfx {
|
| +
|
| +namespace {
|
| +
|
| +// Caches font render params and updates them on system notifications.
|
| +class CachedFontRenderParams : public gfx::SingletonHwnd::Observer {
|
| + public:
|
| + static CachedFontRenderParams* GetInstance() {
|
| + return Singleton<CachedFontRenderParams>::get();
|
| + }
|
| +
|
| + const FontRenderParams& GetParams() {
|
| + if (params_)
|
| + return *params_;
|
| +
|
| + params_.reset(new FontRenderParams());
|
| + params_->antialiasing = false;
|
| + params_->subpixel_positioning = false;
|
| + params_->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE;
|
| +
|
| + BOOL enabled = false;
|
| + if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &enabled, 0) && enabled) {
|
| + params_->antialiasing = true;
|
| + params_->subpixel_positioning = true;
|
| +
|
| + UINT type = 0;
|
| + if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &type, 0) &&
|
| + type == FE_FONTSMOOTHINGCLEARTYPE) {
|
| + params_->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB;
|
| + }
|
| + }
|
| + gfx::SingletonHwnd::GetInstance()->AddObserver(this);
|
| + return *params_;
|
| + }
|
| +
|
| + private:
|
| + friend struct DefaultSingletonTraits<CachedFontRenderParams>;
|
| +
|
| + CachedFontRenderParams() {}
|
| + virtual ~CachedFontRenderParams() {
|
| + // Can't remove the SingletonHwnd observer here since SingletonHwnd may have
|
| + // been destroyed already (both singletons).
|
| + }
|
| +
|
| + virtual void OnWndProc(HWND hwnd,
|
| + UINT message,
|
| + WPARAM wparam,
|
| + LPARAM lparam) OVERRIDE {
|
| + if (message == WM_SETTINGCHANGE) {
|
| + params_.reset();
|
| + gfx::SingletonHwnd::GetInstance()->RemoveObserver(this);
|
| + }
|
| + }
|
| +
|
| + scoped_ptr<FontRenderParams> params_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(CachedFontRenderParams);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +const FontRenderParams& GetDefaultFontRenderParams() {
|
| + return CachedFontRenderParams::GetInstance()->GetParams();
|
| +}
|
| +
|
| +const FontRenderParams& GetDefaultWebKitFontRenderParams() {
|
| + return GetDefaultFontRenderParams();
|
| +}
|
| +
|
| +} // namespace gfx
|
|
|