12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/l10n/l10n_util_win.h"
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <windows.h>
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/win/win_util.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/platform_test.h"
12d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/gfx/win/dpi.h"
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)typedef PlatformTest L10nUtilWinTest;
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(L10nUtilWinTest, TestDPIScaling) {
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Baseline font for comparison.
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  NONCLIENTMETRICS metrics;
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::win::GetNonClientMetrics(&metrics);
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  LOGFONT lf = metrics.lfMessageFont;
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  l10n_util::AdjustUIFont(&lf);
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int size = lf.lfHeight;
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  float rounding = size < 0 ? -0.5f : 0.5f;
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Test that font size is properly normalized for DIP. In high-DPI mode, the
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // font metrics are scaled based on the DPI scale factor. For Windows 8, 140%
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // and 180% font scaling are supported. Simulate size normalization for a DPI-
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // aware process by manually scaling up the font and checking that it returns
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // to the expected size.
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  lf.lfHeight = static_cast<int>(1.4 * size + rounding);
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  l10n_util::AdjustUIFontForDIP(1.4f, &lf);
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_NEAR(size, lf.lfHeight, 1);
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  lf.lfHeight = static_cast<int>(1.8 * size + rounding);
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  l10n_util::AdjustUIFontForDIP(1.8f, &lf);
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_NEAR(size, lf.lfHeight, 1);
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}