| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/common/l10n_util.h" | |
| 6 #include "chrome/common/l10n_util_win.h" | |
| 7 | |
| 8 #include <algorithm> | |
| 9 #include <windowsx.h> | |
| 10 | |
| 11 #include "base/string_util.h" | |
| 12 #include "base/win_util.h" | |
| 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 | |
| 39 namespace l10n_util { | |
| 40 | |
| 41 int GetExtendedStyles() { | |
| 42 return GetTextDirection() == LEFT_TO_RIGHT ? 0 : | |
| 43 WS_EX_LAYOUTRTL | WS_EX_RTLREADING; | |
| 44 } | |
| 45 | |
| 46 int GetExtendedTooltipStyles() { | |
| 47 return GetTextDirection() == LEFT_TO_RIGHT ? 0 : WS_EX_LAYOUTRTL; | |
| 48 } | |
| 49 | |
| 50 void HWNDSetRTLLayout(HWND hwnd) { | |
| 51 DWORD ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE); | |
| 52 | |
| 53 // We don't have to do anything if the style is already set for the HWND. | |
| 54 if (!(ex_style & WS_EX_LAYOUTRTL)) { | |
| 55 ex_style |= WS_EX_LAYOUTRTL; | |
| 56 ::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style); | |
| 57 | |
| 58 // Right-to-left layout changes are not applied to the window immediately | |
| 59 // so we should make sure a WM_PAINT is sent to the window by invalidating | |
| 60 // the entire window rect. | |
| 61 ::InvalidateRect(hwnd, NULL, true); | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 bool IsLocaleSupportedByOS(const std::wstring& locale) { | |
| 66 // Block Oriya on Windows XP. | |
| 67 return !(LowerCaseEqualsASCII(locale, "or") && | |
| 68 win_util::GetWinVersion() < win_util::WINVERSION_VISTA); | |
| 69 } | |
| 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 | |
| 75 // the default Windows fonts are too small to be legible. For those | |
| 76 // locales, IDS_UI_FONT_FAMILY is set to an actual font family to | |
| 77 // use while for other locales, it's set to 'default'. | |
| 78 | |
| 79 // XP and Vista or later have different font size issues and | |
| 80 // we need separate ui font specifications. | |
| 81 int ui_font_family_id = IDS_UI_FONT_FAMILY; | |
| 82 int ui_font_size_scaler_id = IDS_UI_FONT_SIZE_SCALER; | |
| 83 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) { | |
| 84 ui_font_family_id = IDS_UI_FONT_FAMILY_XP; | |
| 85 ui_font_size_scaler_id = IDS_UI_FONT_SIZE_SCALER_XP; | |
| 86 } | |
| 87 | |
| 88 std::wstring ui_font_family = GetString(ui_font_family_id); | |
| 89 int scaler100 = StringToInt(l10n_util::GetString(ui_font_size_scaler_id)); | |
| 90 if (ui_font_family == L"default" && scaler100 == 100) | |
| 91 return false; | |
| 92 if (override_font_family && font_size_scaler) { | |
| 93 override_font_family->swap(ui_font_family); | |
| 94 *font_size_scaler = scaler100 / 100.0; | |
| 95 } | |
| 96 return true; | |
| 97 } | |
| 98 | |
| 99 void AdjustUIFont(LOGFONT* logfont) { | |
| 100 std::wstring ui_font_family; | |
| 101 double ui_font_size_scaler; | |
| 102 if (NeedOverrideDefaultUIFont(&ui_font_family, &ui_font_size_scaler)) | |
| 103 AdjustLogFont(ui_font_family, ui_font_size_scaler, logfont); | |
| 104 } | |
| 105 | |
| 106 void AdjustUIFontForWindow(HWND hwnd) { | |
| 107 std::wstring ui_font_family; | |
| 108 double ui_font_size_scaler; | |
| 109 if (NeedOverrideDefaultUIFont(&ui_font_family, &ui_font_size_scaler)) { | |
| 110 LOGFONT logfont; | |
| 111 if (GetObject(GetWindowFont(hwnd), sizeof(logfont), &logfont)) { | |
| 112 AdjustLogFont(ui_font_family, ui_font_size_scaler, &logfont); | |
| 113 HFONT hfont = CreateFontIndirect(&logfont); | |
| 114 if (hfont) | |
| 115 SetWindowFont(hwnd, hfont, FALSE); | |
| 116 } | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 } // namespace l10n_util | |
| OLD | NEW |