OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/gfx/font_render_params.h" |
| 6 |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/memory/singleton.h" |
| 9 #include "ui/gfx/win/singleton_hwnd.h" |
| 10 |
| 11 namespace gfx { |
| 12 |
| 13 namespace { |
| 14 |
| 15 // Caches font render params and updates them on system notifications. |
| 16 class CachedFontRenderParams : public gfx::SingletonHwnd::Observer { |
| 17 public: |
| 18 static CachedFontRenderParams* GetInstance() { |
| 19 return Singleton<CachedFontRenderParams>::get(); |
| 20 } |
| 21 |
| 22 const FontRenderParams& GetParams() { |
| 23 if (params_) |
| 24 return *params_; |
| 25 |
| 26 params_.reset(new FontRenderParams()); |
| 27 params_->antialiasing = false; |
| 28 params_->subpixel_positioning = false; |
| 29 params_->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE; |
| 30 |
| 31 BOOL enabled = false; |
| 32 if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &enabled, 0) && enabled) { |
| 33 params_->antialiasing = true; |
| 34 params_->subpixel_positioning = true; |
| 35 |
| 36 UINT type = 0; |
| 37 if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &type, 0) && |
| 38 type == FE_FONTSMOOTHINGCLEARTYPE) { |
| 39 params_->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB; |
| 40 } |
| 41 } |
| 42 gfx::SingletonHwnd::GetInstance()->AddObserver(this); |
| 43 return *params_; |
| 44 } |
| 45 |
| 46 private: |
| 47 friend struct DefaultSingletonTraits<CachedFontRenderParams>; |
| 48 |
| 49 CachedFontRenderParams() {} |
| 50 virtual ~CachedFontRenderParams() { |
| 51 // Can't remove the SingletonHwnd observer here since SingletonHwnd may have |
| 52 // been destroyed already (both singletons). |
| 53 } |
| 54 |
| 55 virtual void OnWndProc(HWND hwnd, |
| 56 UINT message, |
| 57 WPARAM wparam, |
| 58 LPARAM lparam) OVERRIDE { |
| 59 if (message == WM_SETTINGCHANGE) { |
| 60 params_.reset(); |
| 61 gfx::SingletonHwnd::GetInstance()->RemoveObserver(this); |
| 62 } |
| 63 } |
| 64 |
| 65 scoped_ptr<FontRenderParams> params_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(CachedFontRenderParams); |
| 68 }; |
| 69 |
| 70 } // namespace |
| 71 |
| 72 const FontRenderParams& GetDefaultFontRenderParams() { |
| 73 return CachedFontRenderParams::GetInstance()->GetParams(); |
| 74 } |
| 75 |
| 76 const FontRenderParams& GetDefaultWebKitFontRenderParams() { |
| 77 return GetDefaultFontRenderParams(); |
| 78 } |
| 79 |
| 80 } // namespace gfx |
OLD | NEW |