| 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/command_line.h" |
| 9 #include "base/win/win_util.h" | 10 #include "base/win/win_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "testing/platform_test.h" | 12 #include "testing/platform_test.h" |
| 13 #include "ui/display/display.h" |
| 14 #include "ui/display/display_switches.h" |
| 15 #include "ui/display/win/screen_win.h" |
| 12 | 16 |
| 13 typedef PlatformTest L10nUtilWinTest; | 17 typedef PlatformTest L10nUtilWinTest; |
| 14 | 18 |
| 15 TEST_F(L10nUtilWinTest, TestDPIScaling) { | 19 TEST_F(L10nUtilWinTest, TestDPIScaling) { |
| 16 // Baseline font for comparison. | 20 // Baseline font for comparison. |
| 17 NONCLIENTMETRICS_XP metrics; | 21 NONCLIENTMETRICS_XP metrics; |
| 18 base::win::GetNonClientMetrics(&metrics); | 22 base::win::GetNonClientMetrics(&metrics); |
| 19 LOGFONT lf = metrics.lfMessageFont; | 23 LOGFONT lf = metrics.lfMessageFont; |
| 20 l10n_util::AdjustUIFont(&lf); | 24 l10n_util::AdjustUIFont(&lf); |
| 21 int size = lf.lfHeight; | 25 int size = lf.lfHeight; |
| 22 float rounding = size < 0 ? -0.5f : 0.5f; | 26 float rounding = size < 0 ? -0.5f : 0.5f; |
| 23 | 27 |
| 24 // Test that font size is properly normalized for DIP. In high-DPI mode, the | 28 // Test that font size is properly normalized for DIP. In high-DPI mode, the |
| 25 // font metrics are scaled based on the DPI scale factor. For Windows 8, 140% | 29 // font metrics are scaled based on the DPI scale factor. For Windows 8, 140% |
| 26 // and 180% font scaling are supported. Simulate size normalization for a DPI- | 30 // and 180% font scaling are supported. Simulate size normalization for a DPI- |
| 27 // aware process by manually scaling up the font and checking that it returns | 31 // aware process by manually scaling up the font and checking that it returns |
| 28 // to the expected size. | 32 // to the expected size. |
| 29 lf.lfHeight = static_cast<int>(1.4 * size + rounding); | 33 lf.lfHeight = static_cast<int>(1.4 * size + rounding); |
| 30 l10n_util::AdjustUIFontForDIP(1.4f, &lf); | 34 l10n_util::AdjustUIFontForDIP(1.4f, &lf); |
| 31 EXPECT_NEAR(size, lf.lfHeight, 1); | 35 EXPECT_NEAR(size, lf.lfHeight, 1); |
| 32 | 36 |
| 33 lf.lfHeight = static_cast<int>(1.8 * size + rounding); | 37 lf.lfHeight = static_cast<int>(1.8 * size + rounding); |
| 34 l10n_util::AdjustUIFontForDIP(1.8f, &lf); | 38 l10n_util::AdjustUIFontForDIP(1.8f, &lf); |
| 35 EXPECT_NEAR(size, lf.lfHeight, 1); | 39 EXPECT_NEAR(size, lf.lfHeight, 1); |
| 36 } | 40 } |
| 41 |
| 42 // Test for crbug.com/675933. Since font size is a Windows metric we need to |
| 43 // normalize to DIPs based on the real device scale factor, not the forced one. |
| 44 TEST_F(L10nUtilWinTest, TestForcedScaling) { |
| 45 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 46 switches::kForceDeviceScaleFactor, "4"); |
| 47 display::Display::ResetForceDeviceScaleFactorForTesting(); |
| 48 |
| 49 NONCLIENTMETRICS_XP metrics; |
| 50 base::win::GetNonClientMetrics(&metrics); |
| 51 LOGFONT lf = metrics.lfMessageFont; |
| 52 |
| 53 // Set the font size to an arbitrary value and make sure it comes through |
| 54 // correctly on the other end. |
| 55 constexpr int test_font_size = 18; |
| 56 lf.lfHeight = test_font_size; |
| 57 l10n_util::AdjustUIFont(&lf); |
| 58 EXPECT_EQ(test_font_size / display::win::ScreenWin::GetSystemScaleFactor(), |
| 59 lf.lfHeight); |
| 60 } |
| OLD | NEW |