base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / ui / gfx / font_render_params_win.cc
blob9f8409c4eb146996fe2c2714819401e76bb6c848
1 // Copyright 2014 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.
5 #include "ui/gfx/font_render_params.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/singleton.h"
9 #include "ui/gfx/win/direct_write.h"
10 #include "ui/gfx/win/singleton_hwnd.h"
12 namespace gfx {
14 namespace {
16 // Caches font render params and updates them on system notifications.
17 class CachedFontRenderParams : public gfx::SingletonHwnd::Observer {
18 public:
19 static CachedFontRenderParams* GetInstance() {
20 return Singleton<CachedFontRenderParams>::get();
23 const FontRenderParams& GetParams() {
24 if (params_)
25 return *params_;
27 params_.reset(new FontRenderParams());
28 params_->antialiasing = false;
29 params_->subpixel_positioning = false;
30 params_->autohinter = false;
31 params_->use_bitmaps = false;
32 params_->hinting = FontRenderParams::HINTING_MEDIUM;
33 params_->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE;
35 BOOL enabled = false;
36 if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &enabled, 0) && enabled) {
37 params_->antialiasing = true;
38 // GDI does not support subpixel positioning.
39 params_->subpixel_positioning = win::IsDirectWriteEnabled();
41 UINT type = 0;
42 if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &type, 0) &&
43 type == FE_FONTSMOOTHINGCLEARTYPE) {
44 params_->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB;
47 gfx::SingletonHwnd::GetInstance()->AddObserver(this);
48 return *params_;
51 private:
52 friend struct DefaultSingletonTraits<CachedFontRenderParams>;
54 CachedFontRenderParams() {}
55 virtual ~CachedFontRenderParams() {
56 // Can't remove the SingletonHwnd observer here since SingletonHwnd may have
57 // been destroyed already (both singletons).
60 virtual void OnWndProc(HWND hwnd,
61 UINT message,
62 WPARAM wparam,
63 LPARAM lparam) override {
64 if (message == WM_SETTINGCHANGE) {
65 params_.reset();
66 gfx::SingletonHwnd::GetInstance()->RemoveObserver(this);
70 scoped_ptr<FontRenderParams> params_;
72 DISALLOW_COPY_AND_ASSIGN(CachedFontRenderParams);
75 } // namespace
77 FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query,
78 std::string* family_out) {
79 if (family_out)
80 NOTIMPLEMENTED();
81 // Customized font rendering settings are not supported, only defaults.
82 return CachedFontRenderParams::GetInstance()->GetParams();
85 } // namespace gfx