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"
16 // Caches font render params and updates them on system notifications.
17 class CachedFontRenderParams
: public gfx::SingletonHwnd::Observer
{
19 static CachedFontRenderParams
* GetInstance() {
20 return Singleton
<CachedFontRenderParams
>::get();
23 const FontRenderParams
& GetParams() {
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
;
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();
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);
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
,
63 LPARAM lparam
) override
{
64 if (message
== WM_SETTINGCHANGE
) {
66 gfx::SingletonHwnd::GetInstance()->RemoveObserver(this);
70 scoped_ptr
<FontRenderParams
> params_
;
72 DISALLOW_COPY_AND_ASSIGN(CachedFontRenderParams
);
77 FontRenderParams
GetFontRenderParams(const FontRenderParamsQuery
& query
,
78 std::string
* family_out
) {
81 // Customized font rendering settings are not supported, only defaults.
82 return CachedFontRenderParams::GetInstance()->GetParams();