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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
OLD | NEW |