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(bool for_web_contents
) {
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 // Subpixel positioning is not yet implemented for UI. crbug.com/389649
38 params_
->subpixel_positioning
= for_web_contents
;
41 if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE
, 0, &type
, 0) &&
42 type
== FE_FONTSMOOTHINGCLEARTYPE
) {
43 params_
->subpixel_rendering
= FontRenderParams::SUBPIXEL_RENDERING_RGB
;
46 gfx::SingletonHwnd::GetInstance()->AddObserver(this);
51 friend struct DefaultSingletonTraits
<CachedFontRenderParams
>;
53 CachedFontRenderParams() {}
54 virtual ~CachedFontRenderParams() {
55 // Can't remove the SingletonHwnd observer here since SingletonHwnd may have
56 // been destroyed already (both singletons).
59 virtual void OnWndProc(HWND hwnd
,
62 LPARAM lparam
) OVERRIDE
{
63 if (message
== WM_SETTINGCHANGE
) {
65 gfx::SingletonHwnd::GetInstance()->RemoveObserver(this);
69 scoped_ptr
<FontRenderParams
> params_
;
71 DISALLOW_COPY_AND_ASSIGN(CachedFontRenderParams
);
76 FontRenderParams
GetFontRenderParams(const FontRenderParamsQuery
& query
,
77 std::string
* family_out
) {
78 // Customized font rendering settings are not supported, only defaults.
79 if (!query
.is_empty() || family_out
)
81 return CachedFontRenderParams::GetInstance()->GetParams(
82 query
.for_web_contents
);