Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: ui/gfx/platform_font_win.cc

Issue 11087016: Create font with DEFAULT_CHARSET instead of ANSI_CHARSET. (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/gfx/render_text_win.cc » ('j') | ui/gfx/render_text_win.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/gfx/platform_font_win.h" 5 #include "ui/gfx/platform_font_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <math.h> 8 #include <math.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 Font PlatformFontWin::DeriveFontWithHeight(int height, int style) { 91 Font PlatformFontWin::DeriveFontWithHeight(int height, int style) {
92 DCHECK_GE(height, 0); 92 DCHECK_GE(height, 0);
93 if (GetHeight() == height && GetStyle() == style) 93 if (GetHeight() == height && GetStyle() == style)
94 return Font(this); 94 return Font(this);
95 95
96 // CreateFontIndirect() doesn't return the largest size for the given height 96 // CreateFontIndirect() doesn't return the largest size for the given height
97 // when decreasing the height. Iterate to find it. 97 // when decreasing the height. Iterate to find it.
98 if (GetHeight() > height) { 98 if (GetHeight() > height) {
99 const int min_font_size = GetMinimumFontSize(); 99 const int min_font_size = GetMinimumFontSize();
100 Font font = DeriveFont(-1, style); 100 Font font = DeriveFont(-1, style);
101 while (font.GetHeight() > height && font.GetFontSize() != min_font_size) { 101 int font_height = font.GetHeight();
102 int font_size = font.GetFontSize();
103 while (font_height > height && font_size != min_font_size) {
102 font = font.DeriveFont(-1, style); 104 font = font.DeriveFont(-1, style);
105 if (font_height == font.GetHeight() && font_size == font.GetFontSize())
106 break;
107 font_height = font.GetHeight();
108 font_size = font.GetFontSize();
103 } 109 }
104 return font; 110 return font;
105 } 111 }
106 112
107 LOGFONT font_info; 113 LOGFONT font_info;
108 GetObject(GetNativeFont(), sizeof(LOGFONT), &font_info); 114 GetObject(GetNativeFont(), sizeof(LOGFONT), &font_info);
109 font_info.lfHeight = height; 115 font_info.lfHeight = height;
110 SetLogFontStyle(style, &font_info); 116 SetLogFontStyle(style, &font_info);
111 117
112 HFONT hfont = CreateFontIndirect(&font_info); 118 HFONT hfont = CreateFontIndirect(&font_info);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 // Font, private: 191 // Font, private:
186 192
187 void PlatformFontWin::InitWithCopyOfHFONT(HFONT hfont) { 193 void PlatformFontWin::InitWithCopyOfHFONT(HFONT hfont) {
188 DCHECK(hfont); 194 DCHECK(hfont);
189 LOGFONT font_info; 195 LOGFONT font_info;
190 GetObject(hfont, sizeof(LOGFONT), &font_info); 196 GetObject(hfont, sizeof(LOGFONT), &font_info);
191 font_ref_ = CreateHFontRef(CreateFontIndirect(&font_info)); 197 font_ref_ = CreateHFontRef(CreateFontIndirect(&font_info));
192 } 198 }
193 199
194 void PlatformFontWin::InitWithFontNameAndSize(const std::string& font_name, 200 void PlatformFontWin::InitWithFontNameAndSize(const std::string& font_name,
195 int font_size) { 201 int font_size) {
Vitaly Buka (NO REVIEWS) 2012/10/09 06:09:42 This also fixes hang and makes visible work. I sti
196 HFONT hf = ::CreateFont(-font_size, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 202 HFONT hf = ::CreateFont(-font_size, 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, 0,
msw 2012/10/12 20:50:57 MSDN indicates that this picks a char set "based o
Vitaly Buka (NO REVIEWS) 2012/10/12 21:11:33 I guess with ANSI_CHARSET it's consistent in sense
197 UTF8ToUTF16(font_name).c_str()); 203 0, 0, 0, UTF8ToUTF16(font_name).c_str());
198 font_ref_ = CreateHFontRef(hf); 204 font_ref_ = CreateHFontRef(hf);
199 } 205 }
200 206
201 // static 207 // static
202 PlatformFontWin::HFontRef* PlatformFontWin::GetBaseFontRef() { 208 PlatformFontWin::HFontRef* PlatformFontWin::GetBaseFontRef() {
203 if (base_font_ref_ == NULL) { 209 if (base_font_ref_ == NULL) {
204 NONCLIENTMETRICS metrics; 210 NONCLIENTMETRICS metrics;
205 base::win::GetNonClientMetrics(&metrics); 211 base::win::GetNonClientMetrics(&metrics);
206 212
207 if (adjust_font_callback) 213 if (adjust_font_callback)
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 return new PlatformFontWin(native_font); 315 return new PlatformFontWin(native_font);
310 } 316 }
311 317
312 // static 318 // static
313 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, 319 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name,
314 int font_size) { 320 int font_size) {
315 return new PlatformFontWin(font_name, font_size); 321 return new PlatformFontWin(font_name, font_size);
316 } 322 }
317 323
318 } // namespace gfx 324 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/render_text_win.cc » ('j') | ui/gfx/render_text_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698