OLD | NEW |
---|---|
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 if (font_height == font.GetHeight() && font_size == font.GetFontSize()) | 105 if (font_height == font.GetHeight() && font_size == font.GetFontSize()) |
106 break; | 106 break; |
107 font_height = font.GetHeight(); | 107 font_height = font.GetHeight(); |
108 font_size = font.GetFontSize(); | 108 font_size = font.GetFontSize(); |
109 } | 109 } |
110 return font; | 110 return font; |
111 } | 111 } |
112 | 112 |
113 LOGFONT font_info; | 113 LOGFONT font_info; |
114 GetObject(GetNativeFont(), sizeof(LOGFONT), &font_info); | 114 GetObject(GetNativeFont(), sizeof(LOGFONT), &font_info); |
115 font_info.lfHeight = height; | |
116 SetLogFontStyle(style, &font_info); | 115 SetLogFontStyle(style, &font_info); |
117 | 116 |
118 HFONT hfont = CreateFontIndirect(&font_info); | 117 HFONT hfont = CreateFontIndirect(&font_info); |
119 return Font(new PlatformFontWin(CreateHFontRef(hfont))); | 118 Font best_font(new PlatformFontWin(CreateHFontRef(hfont))); |
119 int best_font_height = best_font.GetHeight(); | |
120 | |
121 while (best_font_height <= height) { | |
122 Font font = best_font.Derive(1, style); | |
123 int font_height = font.GetHeight(); | |
124 if (font_height > height) { | |
Alexei Svitkine (slow)
2014/04/25 15:56:14
I'm not sure this if is needed, since the loop sho
Tomasz Moniuszko
2014/05/08 14:08:17
The reason for this fix is that GetTextMetrics ret
Alexei Svitkine (slow)
2014/05/09 21:17:50
I see, that makes sense since we iterate down in o
Tomasz Moniuszko
2014/05/29 10:46:40
Done.
Test results for 100k repeats with differen
Alexei Svitkine (slow)
2014/05/29 21:13:34
Seems like a sizeable-enough win to do the optimiz
| |
125 break; | |
126 } | |
127 best_font = font; | |
128 best_font_height = font_height; | |
129 } | |
130 | |
131 return best_font; | |
120 } | 132 } |
121 | 133 |
122 //////////////////////////////////////////////////////////////////////////////// | 134 //////////////////////////////////////////////////////////////////////////////// |
123 // PlatformFontWin, PlatformFont implementation: | 135 // PlatformFontWin, PlatformFont implementation: |
124 | 136 |
125 Font PlatformFontWin::DeriveFont(int size_delta, int style) const { | 137 Font PlatformFontWin::DeriveFont(int size_delta, int style) const { |
126 LOGFONT font_info; | 138 LOGFONT font_info; |
127 GetObject(GetNativeFont(), sizeof(LOGFONT), &font_info); | 139 GetObject(GetNativeFont(), sizeof(LOGFONT), &font_info); |
128 const int requested_font_size = font_ref_->requested_font_size(); | 140 const int requested_font_size = font_ref_->requested_font_size(); |
129 font_info.lfHeight = AdjustFontSize(-requested_font_size, size_delta); | 141 font_info.lfHeight = AdjustFontSize(-requested_font_size, size_delta); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 return new PlatformFontWin(native_font); | 334 return new PlatformFontWin(native_font); |
323 } | 335 } |
324 | 336 |
325 // static | 337 // static |
326 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 338 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
327 int font_size) { | 339 int font_size) { |
328 return new PlatformFontWin(font_name, font_size); | 340 return new PlatformFontWin(font_name, font_size); |
329 } | 341 } |
330 | 342 |
331 } // namespace gfx | 343 } // namespace gfx |
OLD | NEW |