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> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/win/scoped_hdc.h" | 17 #include "base/win/scoped_hdc.h" |
18 #include "base/win/scoped_select_object.h" | 18 #include "base/win/scoped_select_object.h" |
19 #include "base/win/win_util.h" | 19 #include "base/win/win_util.h" |
20 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
21 #include "ui/gfx/font.h" | 21 #include "ui/gfx/font.h" |
| 22 #include "ui/gfx/font_list.h" |
22 #include "ui/gfx/win/scoped_set_map_mode.h" | 23 #include "ui/gfx/win/scoped_set_map_mode.h" |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 // If the tmWeight field of a TEXTMETRIC structure has a value >= this, the | 27 // If the tmWeight field of a TEXTMETRIC structure has a value >= this, the |
27 // font is bold. | 28 // font is bold. |
28 const int kTextMetricWeightBold = 700; | 29 const int kTextMetricWeightBold = 700; |
29 | 30 |
30 // Returns the minimum font size, using the minimum size callback, if set. | 31 // Returns the minimum font size, using the minimum size callback, if set. |
31 int GetMinimumFontSize() { | 32 int GetMinimumFontSize() { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 148 |
148 int PlatformFontWin::GetAverageCharacterWidth() const { | 149 int PlatformFontWin::GetAverageCharacterWidth() const { |
149 return font_ref_->ave_char_width(); | 150 return font_ref_->ave_char_width(); |
150 } | 151 } |
151 | 152 |
152 int PlatformFontWin::GetStringWidth(const base::string16& text) const { | 153 int PlatformFontWin::GetStringWidth(const base::string16& text) const { |
153 return Canvas::GetStringWidth(text, | 154 return Canvas::GetStringWidth(text, |
154 Font(const_cast<PlatformFontWin*>(this))); | 155 Font(const_cast<PlatformFontWin*>(this))); |
155 } | 156 } |
156 | 157 |
| 158 float PlatformFontWin::GetStringWidthF(const base::string16& text) const { |
| 159 return Canvas::GetStringWidthF( |
| 160 text, FontList(Font(const_cast<PlatformFontWin*>(this)))); |
| 161 } |
| 162 |
157 int PlatformFontWin::GetExpectedTextWidth(int length) const { | 163 int PlatformFontWin::GetExpectedTextWidth(int length) const { |
158 return length * std::min(font_ref_->GetDluBaseX(), | 164 return length * std::min(font_ref_->GetDluBaseX(), |
159 GetAverageCharacterWidth()); | 165 GetAverageCharacterWidth()); |
160 } | 166 } |
161 | 167 |
162 int PlatformFontWin::GetStyle() const { | 168 int PlatformFontWin::GetStyle() const { |
163 return font_ref_->style(); | 169 return font_ref_->style(); |
164 } | 170 } |
165 | 171 |
166 std::string PlatformFontWin::GetFontName() const { | 172 std::string PlatformFontWin::GetFontName() const { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 return new PlatformFontWin(native_font); | 330 return new PlatformFontWin(native_font); |
325 } | 331 } |
326 | 332 |
327 // static | 333 // static |
328 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 334 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
329 int font_size) { | 335 int font_size) { |
330 return new PlatformFontWin(font_name, font_size); | 336 return new PlatformFontWin(font_name, font_size); |
331 } | 337 } |
332 | 338 |
333 } // namespace gfx | 339 } // namespace gfx |
OLD | NEW |