Chromium Code Reviews| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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; | 115 font_info.lfHeight = height; |
| 116 SetLogFontStyle(style, &font_info); | 116 SetLogFontStyle(style, &font_info); |
| 117 | 117 |
| 118 HFONT hfont = CreateFontIndirect(&font_info); | 118 HFONT hfont = CreateFontIndirect(&font_info); |
| 119 return Font(new PlatformFontWin(CreateHFontRef(hfont))); | 119 Font best_font(new PlatformFontWin(CreateHFontRef(hfont))); |
| 120 int best_font_height = best_font.GetHeight(); | |
| 121 | |
| 122 while (best_font_height <= height) { | |
|
msw
2014/05/29 21:34:41
Is it possible (and more efficient) to first guess
| |
| 123 Font font = best_font.Derive(1, style); | |
| 124 int font_height = font.GetHeight(); | |
| 125 if (font_height > height) { | |
| 126 break; | |
| 127 } | |
| 128 best_font = font; | |
| 129 best_font_height = font_height; | |
| 130 } | |
| 131 | |
| 132 return best_font; | |
| 120 } | 133 } |
| 121 | 134 |
| 122 //////////////////////////////////////////////////////////////////////////////// | 135 //////////////////////////////////////////////////////////////////////////////// |
| 123 // PlatformFontWin, PlatformFont implementation: | 136 // PlatformFontWin, PlatformFont implementation: |
| 124 | 137 |
| 125 Font PlatformFontWin::DeriveFont(int size_delta, int style) const { | 138 Font PlatformFontWin::DeriveFont(int size_delta, int style) const { |
| 126 LOGFONT font_info; | 139 LOGFONT font_info; |
| 127 GetObject(GetNativeFont(), sizeof(LOGFONT), &font_info); | 140 GetObject(GetNativeFont(), sizeof(LOGFONT), &font_info); |
| 128 const int requested_font_size = font_ref_->requested_font_size(); | 141 const int requested_font_size = font_ref_->requested_font_size(); |
| 129 font_info.lfHeight = AdjustFontSize(-requested_font_size, size_delta); | 142 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); | 335 return new PlatformFontWin(native_font); |
| 323 } | 336 } |
| 324 | 337 |
| 325 // static | 338 // static |
| 326 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 339 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
| 327 int font_size) { | 340 int font_size) { |
| 328 return new PlatformFontWin(font_name, font_size); | 341 return new PlatformFontWin(font_name, font_size); |
| 329 } | 342 } |
| 330 | 343 |
| 331 } // namespace gfx | 344 } // namespace gfx |
| OLD | NEW |