OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/base/l10n/l10n_util_win.h" | 5 #include "ui/base/l10n/l10n_util_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/win/win_util.h" | 9 #include "base/win/win_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
12 #include "ui/gfx/dpi_win.h" | 12 #include "ui/gfx/win/dpi.h" |
13 | 13 |
14 typedef PlatformTest L10nUtilWinTest; | 14 typedef PlatformTest L10nUtilWinTest; |
15 | 15 |
16 TEST_F(L10nUtilWinTest, TestDPIScaling) { | 16 TEST_F(L10nUtilWinTest, TestDPIScaling) { |
17 // Baseline font for comparison. | 17 // Baseline font for comparison. |
18 NONCLIENTMETRICS metrics; | 18 NONCLIENTMETRICS metrics; |
19 base::win::GetNonClientMetrics(&metrics); | 19 base::win::GetNonClientMetrics(&metrics); |
20 LOGFONT lf = metrics.lfMessageFont; | 20 LOGFONT lf = metrics.lfMessageFont; |
21 l10n_util::AdjustUIFont(&lf); | 21 l10n_util::AdjustUIFont(&lf); |
22 int size = lf.lfHeight; | 22 int size = lf.lfHeight; |
23 float rounding = size < 0 ? -0.5f : 0.5f; | 23 float rounding = size < 0 ? -0.5f : 0.5f; |
24 | 24 |
25 // Test that font size is properly normalized for DIP. In high-DPI mode, the | 25 // Test that font size is properly normalized for DIP. In high-DPI mode, the |
26 // font metrics are scaled based on the DPI scale factor. For Windows 8, 140% | 26 // font metrics are scaled based on the DPI scale factor. For Windows 8, 140% |
27 // and 180% font scaling are supported. Simulate size normalization for a DPI- | 27 // and 180% font scaling are supported. Simulate size normalization for a DPI- |
28 // aware process by manually scaling up the font and checking that it returns | 28 // aware process by manually scaling up the font and checking that it returns |
29 // to the expected size. | 29 // to the expected size. |
30 lf.lfHeight = static_cast<int>(1.4 * size + rounding); | 30 lf.lfHeight = static_cast<int>(1.4 * size + rounding); |
31 l10n_util::AdjustUIFontForDIP(1.4f, &lf); | 31 l10n_util::AdjustUIFontForDIP(1.4f, &lf); |
32 EXPECT_NEAR(size, lf.lfHeight, 1); | 32 EXPECT_NEAR(size, lf.lfHeight, 1); |
33 | 33 |
34 lf.lfHeight = static_cast<int>(1.8 * size + rounding); | 34 lf.lfHeight = static_cast<int>(1.8 * size + rounding); |
35 l10n_util::AdjustUIFontForDIP(1.8f, &lf); | 35 l10n_util::AdjustUIFontForDIP(1.8f, &lf); |
36 EXPECT_NEAR(size, lf.lfHeight, 1); | 36 EXPECT_NEAR(size, lf.lfHeight, 1); |
37 } | 37 } |
OLD | NEW |