OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windowsx.h> | 7 #include <windowsx.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <iterator> | 9 #include <iterator> |
10 | 10 |
11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/win/i18n.h" | 14 #include "base/win/i18n.h" |
15 #include "base/win/windows_version.h" | 15 #include "base/win/windows_version.h" |
16 #include "grit/app_locale_settings.h" | 16 #include "grit/app_locale_settings.h" |
17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/gfx/display.h" | 18 #include "ui/gfx/display.h" |
19 #include "ui/gfx/win/dpi.h" | 19 #include "ui/gfx/win/dpi.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 void AdjustLogFont(const string16& font_family, | 23 void AdjustLogFont(const base::string16& font_family, |
24 double font_size_scaler, | 24 double font_size_scaler, |
25 double dpi_scale, | 25 double dpi_scale, |
26 LOGFONT* logfont) { | 26 LOGFONT* logfont) { |
27 DCHECK(font_size_scaler > 0); | 27 DCHECK(font_size_scaler > 0); |
28 font_size_scaler = std::max(std::min(font_size_scaler, 2.0), 0.7); | 28 font_size_scaler = std::max(std::min(font_size_scaler, 2.0), 0.7); |
29 // Font metrics are computed in pixels and scale in high-DPI mode. | 29 // Font metrics are computed in pixels and scale in high-DPI mode. |
30 // Normalized by the DPI scale factor in order to work in DIP with | 30 // Normalized by the DPI scale factor in order to work in DIP with |
31 // Views/Aura. Call with dpi_scale=1 to keep the size in pixels. | 31 // Views/Aura. Call with dpi_scale=1 to keep the size in pixels. |
32 font_size_scaler /= dpi_scale; | 32 font_size_scaler /= dpi_scale; |
33 logfont->lfHeight = static_cast<long>(font_size_scaler * | 33 logfont->lfHeight = static_cast<long>(font_size_scaler * |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 106 |
107 bool IsLocaleSupportedByOS(const std::string& locale) { | 107 bool IsLocaleSupportedByOS(const std::string& locale) { |
108 // Block Amharic on Windows XP unless 'Abyssinica SIL' font is present. | 108 // Block Amharic on Windows XP unless 'Abyssinica SIL' font is present. |
109 // On Win XP, no Ethiopic/Amahric font is availabel out of box. We hard-coded | 109 // On Win XP, no Ethiopic/Amahric font is availabel out of box. We hard-coded |
110 // 'Abyssinica SIL' in the resource bundle to use in the UI. Check | 110 // 'Abyssinica SIL' in the resource bundle to use in the UI. Check |
111 // for its presence to determine whether or not to support Amharic UI on XP. | 111 // for its presence to determine whether or not to support Amharic UI on XP. |
112 return (base::win::GetVersion() >= base::win::VERSION_VISTA || | 112 return (base::win::GetVersion() >= base::win::VERSION_VISTA || |
113 !LowerCaseEqualsASCII(locale, "am") || IsFontPresent(L"Abyssinica SIL")); | 113 !LowerCaseEqualsASCII(locale, "am") || IsFontPresent(L"Abyssinica SIL")); |
114 } | 114 } |
115 | 115 |
116 bool NeedOverrideDefaultUIFont(string16* override_font_family, | 116 bool NeedOverrideDefaultUIFont(base::string16* override_font_family, |
117 double* font_size_scaler) { | 117 double* font_size_scaler) { |
118 // This is rather simple-minded to deal with the UI font size | 118 // This is rather simple-minded to deal with the UI font size |
119 // issue for some Indian locales (ml, bn, hi) for which | 119 // issue for some Indian locales (ml, bn, hi) for which |
120 // the default Windows fonts are too small to be legible. For those | 120 // the default Windows fonts are too small to be legible. For those |
121 // locales, IDS_UI_FONT_FAMILY is set to an actual font family to | 121 // locales, IDS_UI_FONT_FAMILY is set to an actual font family to |
122 // use while for other locales, it's set to 'default'. | 122 // use while for other locales, it's set to 'default'. |
123 | 123 |
124 // XP and Vista or later have different font size issues and | 124 // XP and Vista or later have different font size issues and |
125 // we need separate ui font specifications. | 125 // we need separate ui font specifications. |
126 int ui_font_family_id = IDS_UI_FONT_FAMILY; | 126 int ui_font_family_id = IDS_UI_FONT_FAMILY; |
127 int ui_font_size_scaler_id = IDS_UI_FONT_SIZE_SCALER; | 127 int ui_font_size_scaler_id = IDS_UI_FONT_SIZE_SCALER; |
128 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | 128 if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
129 ui_font_family_id = IDS_UI_FONT_FAMILY_XP; | 129 ui_font_family_id = IDS_UI_FONT_FAMILY_XP; |
130 ui_font_size_scaler_id = IDS_UI_FONT_SIZE_SCALER_XP; | 130 ui_font_size_scaler_id = IDS_UI_FONT_SIZE_SCALER_XP; |
131 } | 131 } |
132 | 132 |
133 string16 ui_font_family = GetStringUTF16(ui_font_family_id); | 133 base::string16 ui_font_family = GetStringUTF16(ui_font_family_id); |
134 int scaler100; | 134 int scaler100; |
135 if (!base::StringToInt(l10n_util::GetStringUTF16(ui_font_size_scaler_id), | 135 if (!base::StringToInt(l10n_util::GetStringUTF16(ui_font_size_scaler_id), |
136 &scaler100)) | 136 &scaler100)) |
137 return false; | 137 return false; |
138 | 138 |
139 // We use the OS default in two cases: | 139 // We use the OS default in two cases: |
140 // 1) The resource bundle has 'default' and '100' for font family and | 140 // 1) The resource bundle has 'default' and '100' for font family and |
141 // font scaler. | 141 // font scaler. |
142 // 2) The resource bundle is not available for some reason and | 142 // 2) The resource bundle is not available for some reason and |
143 // ui_font_family is empty. | 143 // ui_font_family is empty. |
(...skipping 10 matching lines...) Expand all Loading... |
154 void AdjustUIFont(LOGFONT* logfont) { | 154 void AdjustUIFont(LOGFONT* logfont) { |
155 double dpi_scale = gfx::GetDPIScale(); | 155 double dpi_scale = gfx::GetDPIScale(); |
156 if (gfx::Display::HasForceDeviceScaleFactor()) { | 156 if (gfx::Display::HasForceDeviceScaleFactor()) { |
157 // If the scale is forced, we don't need to adjust it here. | 157 // If the scale is forced, we don't need to adjust it here. |
158 dpi_scale = 1.0; | 158 dpi_scale = 1.0; |
159 } | 159 } |
160 AdjustUIFontForDIP(dpi_scale, logfont); | 160 AdjustUIFontForDIP(dpi_scale, logfont); |
161 } | 161 } |
162 | 162 |
163 void AdjustUIFontForDIP(float dpi_scale, LOGFONT* logfont) { | 163 void AdjustUIFontForDIP(float dpi_scale, LOGFONT* logfont) { |
164 string16 ui_font_family = L"default"; | 164 base::string16 ui_font_family = L"default"; |
165 double ui_font_size_scaler = 1; | 165 double ui_font_size_scaler = 1; |
166 if (NeedOverrideDefaultUIFont(&ui_font_family, &ui_font_size_scaler) || | 166 if (NeedOverrideDefaultUIFont(&ui_font_family, &ui_font_size_scaler) || |
167 dpi_scale != 1) { | 167 dpi_scale != 1) { |
168 AdjustLogFont(ui_font_family, ui_font_size_scaler, dpi_scale, logfont); | 168 AdjustLogFont(ui_font_family, ui_font_size_scaler, dpi_scale, logfont); |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 void AdjustUIFontForWindow(HWND hwnd) { | 172 void AdjustUIFontForWindow(HWND hwnd) { |
173 string16 ui_font_family; | 173 base::string16 ui_font_family; |
174 double ui_font_size_scaler; | 174 double ui_font_size_scaler; |
175 if (NeedOverrideDefaultUIFont(&ui_font_family, &ui_font_size_scaler)) { | 175 if (NeedOverrideDefaultUIFont(&ui_font_family, &ui_font_size_scaler)) { |
176 LOGFONT logfont; | 176 LOGFONT logfont; |
177 if (GetObject(GetWindowFont(hwnd), sizeof(logfont), &logfont)) { | 177 if (GetObject(GetWindowFont(hwnd), sizeof(logfont), &logfont)) { |
178 double dpi_scale = 1; | 178 double dpi_scale = 1; |
179 AdjustLogFont(ui_font_family, ui_font_size_scaler, dpi_scale, &logfont); | 179 AdjustLogFont(ui_font_family, ui_font_size_scaler, dpi_scale, &logfont); |
180 HFONT hfont = CreateFontIndirect(&logfont); | 180 HFONT hfont = CreateFontIndirect(&logfont); |
181 if (hfont) | 181 if (hfont) |
182 SetWindowFont(hwnd, hfont, FALSE); | 182 SetWindowFont(hwnd, hfont, FALSE); |
183 } | 183 } |
(...skipping 11 matching lines...) Expand all Loading... |
195 } else { | 195 } else { |
196 NOTREACHED() << "Failed to determine the UI language for locale override."; | 196 NOTREACHED() << "Failed to determine the UI language for locale override."; |
197 } | 197 } |
198 } | 198 } |
199 | 199 |
200 const std::vector<std::string>& GetLocaleOverrides() { | 200 const std::vector<std::string>& GetLocaleOverrides() { |
201 return override_locale_holder.Get().value(); | 201 return override_locale_holder.Get().value(); |
202 } | 202 } |
203 | 203 |
204 } // namespace l10n_util | 204 } // namespace l10n_util |
OLD | NEW |