OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/common/l10n_util.h" | 5 #include "chrome/common/l10n_util.h" |
6 #include "chrome/common/l10n_util_win.h" | 6 #include "chrome/common/l10n_util_win.h" |
7 | 7 |
| 8 #include <algorithm> |
| 9 #include <windowsx.h> |
| 10 |
| 11 #include "base/string_util.h" |
8 #include "base/win_util.h" | 12 #include "base/win_util.h" |
9 | 13 |
| 14 #include "grit/locale_settings.h" |
| 15 |
| 16 namespace { |
| 17 |
| 18 void AdjustLogFont(const std::wstring& font_family, |
| 19 double font_size_scaler, |
| 20 LOGFONT* logfont) { |
| 21 DCHECK(font_size_scaler > 0); |
| 22 font_size_scaler = std::max(std::min(font_size_scaler, 2.0), 0.7); |
| 23 logfont->lfHeight = static_cast<long>(font_size_scaler * |
| 24 static_cast<double>(abs(logfont->lfHeight)) + 0.5) * |
| 25 (logfont->lfHeight > 0 ? 1 : -1); |
| 26 |
| 27 // TODO(jungshik): We may want to check the existence of the font. |
| 28 // If it's not installed, we shouldn't adjust the font. |
| 29 if (font_family != L"default") { |
| 30 int name_len = std::min(static_cast<int>(font_family.size()), |
| 31 LF_FACESIZE -1); |
| 32 memcpy(logfont->lfFaceName, font_family.data(), name_len * sizeof(WORD)); |
| 33 logfont->lfFaceName[name_len] = 0; |
| 34 } |
| 35 } |
| 36 |
| 37 } // namespace |
| 38 |
10 namespace l10n_util { | 39 namespace l10n_util { |
11 | 40 |
12 int GetExtendedStyles() { | 41 int GetExtendedStyles() { |
13 return GetTextDirection() == LEFT_TO_RIGHT ? 0 : | 42 return GetTextDirection() == LEFT_TO_RIGHT ? 0 : |
14 WS_EX_LAYOUTRTL | WS_EX_RTLREADING; | 43 WS_EX_LAYOUTRTL | WS_EX_RTLREADING; |
15 } | 44 } |
16 | 45 |
17 int GetExtendedTooltipStyles() { | 46 int GetExtendedTooltipStyles() { |
18 return GetTextDirection() == LEFT_TO_RIGHT ? 0 : WS_EX_LAYOUTRTL; | 47 return GetTextDirection() == LEFT_TO_RIGHT ? 0 : WS_EX_LAYOUTRTL; |
19 } | 48 } |
(...skipping 12 matching lines...) Expand all Loading... |
32 ::InvalidateRect(hwnd, NULL, true); | 61 ::InvalidateRect(hwnd, NULL, true); |
33 } | 62 } |
34 } | 63 } |
35 | 64 |
36 bool IsLocaleSupportedByOS(const std::wstring& locale) { | 65 bool IsLocaleSupportedByOS(const std::wstring& locale) { |
37 // Block Oriya on Windows XP. | 66 // Block Oriya on Windows XP. |
38 return !(LowerCaseEqualsASCII(locale, "or") && | 67 return !(LowerCaseEqualsASCII(locale, "or") && |
39 win_util::GetWinVersion() < win_util::WINVERSION_VISTA); | 68 win_util::GetWinVersion() < win_util::WINVERSION_VISTA); |
40 } | 69 } |
41 | 70 |
| 71 bool NeedOverrideDefaultUIFont(std::wstring* override_font_family, |
| 72 double* font_size_scaler) { |
| 73 // This is rather simple-minded to deal with the UI font size |
| 74 // issue for some Indian locales (ml, bn, hi) for which the default |
| 75 // Windows fonts are too small to be legible. For those locales, |
| 76 // IDS_UI_FONT_FAMILY is set to an actual font family to use while |
| 77 // for other locales, it's set to 'default'. |
| 78 std::wstring ui_font_family = GetString(IDS_UI_FONT_FAMILY); |
| 79 int scaler100 = StringToInt(l10n_util::GetString(IDS_UI_FONT_SIZE_SCALER)); |
| 80 if (ui_font_family == L"default" && scaler100 == 100) |
| 81 return false; |
| 82 if (override_font_family && font_size_scaler) { |
| 83 override_font_family->swap(ui_font_family); |
| 84 *font_size_scaler = scaler100 / 100.0; |
| 85 } |
| 86 return true; |
| 87 } |
| 88 |
| 89 void AdjustUIFont(LOGFONT* logfont) { |
| 90 std::wstring ui_font_family; |
| 91 double ui_font_size_scaler; |
| 92 if (NeedOverrideDefaultUIFont(&ui_font_family, &ui_font_size_scaler)) |
| 93 AdjustLogFont(ui_font_family, ui_font_size_scaler, logfont); |
| 94 } |
| 95 |
| 96 void AdjustUIFontForWindow(HWND hwnd) { |
| 97 std::wstring ui_font_family; |
| 98 double ui_font_size_scaler; |
| 99 if (NeedOverrideDefaultUIFont(&ui_font_family, &ui_font_size_scaler)) { |
| 100 LOGFONT logfont; |
| 101 if (GetObject(GetWindowFont(hwnd), sizeof(logfont), &logfont)) { |
| 102 AdjustLogFont(ui_font_family, ui_font_size_scaler, &logfont); |
| 103 HFONT hfont = CreateFontIndirect(&logfont); |
| 104 if (hfont) |
| 105 SetWindowFont(hwnd, hfont, FALSE); |
| 106 } |
| 107 } |
| 108 } |
| 109 |
42 } // namespace l10n_util | 110 } // namespace l10n_util |
OLD | NEW |