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/singleton_hwnd.h"
15 // Caches font render params and updates them on system notifications.
16 class CachedFontRenderParams
: public gfx::SingletonHwnd::Observer
{
18 static CachedFontRenderParams
* GetInstance() {
19 return Singleton
<CachedFontRenderParams
>::get();
22 const FontRenderParams
& GetParams() {
26 params_
.reset(new FontRenderParams());
27 params_
->antialiasing
= false;
28 params_
->subpixel_positioning
= false;
29 params_
->autohinter
= false;
30 params_
->use_bitmaps
= false;
31 params_
->hinting
= FontRenderParams::HINTING_MEDIUM
;
32 params_
->subpixel_rendering
= FontRenderParams::SUBPIXEL_RENDERING_NONE
;
35 if (SystemParametersInfo(SPI_GETFONTSMOOTHING
, 0, &enabled
, 0) && enabled
) {
36 params_
->antialiasing
= true;
37 params_
->subpixel_positioning
= true;
40 if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE
, 0, &type
, 0) &&
41 type
== FE_FONTSMOOTHINGCLEARTYPE
) {
42 params_
->subpixel_rendering
= FontRenderParams::SUBPIXEL_RENDERING_RGB
;
45 gfx::SingletonHwnd::GetInstance()->AddObserver(this);
50 friend struct DefaultSingletonTraits
<CachedFontRenderParams
>;
52 CachedFontRenderParams() {}
53 virtual ~CachedFontRenderParams() {
54 // Can't remove the SingletonHwnd observer here since SingletonHwnd may have
55 // been destroyed already (both singletons).
58 virtual void OnWndProc(HWND hwnd
,
61 LPARAM lparam
) override
{
62 if (message
== WM_SETTINGCHANGE
) {
64 gfx::SingletonHwnd::GetInstance()->RemoveObserver(this);
68 scoped_ptr
<FontRenderParams
> params_
;
70 DISALLOW_COPY_AND_ASSIGN(CachedFontRenderParams
);
75 FontRenderParams
GetFontRenderParams(const FontRenderParamsQuery
& query
,
76 std::string
* family_out
) {
79 // Customized font rendering settings are not supported, only defaults.
80 return CachedFontRenderParams::GetInstance()->GetParams();