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/win/dpi.h" | |
13 | 12 |
14 typedef PlatformTest L10nUtilWinTest; | 13 typedef PlatformTest L10nUtilWinTest; |
15 | 14 |
16 TEST_F(L10nUtilWinTest, TestDPIScaling) { | 15 TEST_F(L10nUtilWinTest, TestDPIScaling) { |
17 // Baseline font for comparison. | 16 // Baseline font for comparison. |
18 NONCLIENTMETRICS_XP metrics; | 17 NONCLIENTMETRICS_XP metrics; |
19 base::win::GetNonClientMetrics(&metrics); | 18 base::win::GetNonClientMetrics(&metrics); |
20 LOGFONT lf = metrics.lfMessageFont; | 19 LOGFONT lf = metrics.lfMessageFont; |
21 l10n_util::AdjustUIFont(&lf); | 20 l10n_util::AdjustUIFont(&lf); |
22 int size = lf.lfHeight; | 21 int size = lf.lfHeight; |
23 float rounding = size < 0 ? -0.5f : 0.5f; | 22 float rounding = size < 0 ? -0.5f : 0.5f; |
24 | 23 |
25 // Test that font size is properly normalized for DIP. In high-DPI mode, the | 24 // 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% | 25 // 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- | 26 // 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 | 27 // aware process by manually scaling up the font and checking that it returns |
29 // to the expected size. | 28 // to the expected size. |
30 lf.lfHeight = static_cast<int>(1.4 * size + rounding); | 29 lf.lfHeight = static_cast<int>(1.4 * size + rounding); |
31 l10n_util::AdjustUIFontForDIP(1.4f, &lf); | 30 l10n_util::AdjustUIFontForDIP(1.4f, &lf); |
32 EXPECT_NEAR(size, lf.lfHeight, 1); | 31 EXPECT_NEAR(size, lf.lfHeight, 1); |
33 | 32 |
34 lf.lfHeight = static_cast<int>(1.8 * size + rounding); | 33 lf.lfHeight = static_cast<int>(1.8 * size + rounding); |
35 l10n_util::AdjustUIFontForDIP(1.8f, &lf); | 34 l10n_util::AdjustUIFontForDIP(1.8f, &lf); |
36 EXPECT_NEAR(size, lf.lfHeight, 1); | 35 EXPECT_NEAR(size, lf.lfHeight, 1); |
37 } | 36 } |
OLD | NEW |