| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "base/win/win_util.h" | 15 #include "base/win/win_util.h" |
| 16 #include "ui/gfx/canvas_skia.h" | |
| 17 #include "ui/gfx/font.h" | 16 #include "ui/gfx/font.h" |
| 18 | 17 |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 21 // If the tmWeight field of a TEXTMETRIC structure has a value >= this, the | 20 // If the tmWeight field of a TEXTMETRIC structure has a value >= this, the |
| 22 // font is bold. | 21 // font is bold. |
| 23 const int kTextMetricWeightBold = 700; | 22 const int kTextMetricWeightBold = 700; |
| 24 | 23 |
| 25 // Returns either minimum font allowed for a current locale or | 24 // Returns either minimum font allowed for a current locale or |
| 26 // lf_height + size_delta value. | 25 // lf_height + size_delta value. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 94 } |
| 96 | 95 |
| 97 int PlatformFontWin::GetBaseline() const { | 96 int PlatformFontWin::GetBaseline() const { |
| 98 return font_ref_->baseline(); | 97 return font_ref_->baseline(); |
| 99 } | 98 } |
| 100 | 99 |
| 101 int PlatformFontWin::GetAverageCharacterWidth() const { | 100 int PlatformFontWin::GetAverageCharacterWidth() const { |
| 102 return font_ref_->ave_char_width(); | 101 return font_ref_->ave_char_width(); |
| 103 } | 102 } |
| 104 | 103 |
| 105 int PlatformFontWin::GetStringWidth(const string16& text) const { | |
| 106 int width = 0, height = 0; | |
| 107 CanvasSkia::SizeStringInt(text, Font(const_cast<PlatformFontWin*>(this)), | |
| 108 &width, &height, gfx::Canvas::NO_ELLIPSIS); | |
| 109 return width; | |
| 110 } | |
| 111 | |
| 112 int PlatformFontWin::GetExpectedTextWidth(int length) const { | 104 int PlatformFontWin::GetExpectedTextWidth(int length) const { |
| 113 return length * std::min(font_ref_->dlu_base_x(), GetAverageCharacterWidth()); | 105 return length * std::min(font_ref_->dlu_base_x(), GetAverageCharacterWidth()); |
| 114 } | 106 } |
| 115 | 107 |
| 116 int PlatformFontWin::GetStyle() const { | 108 int PlatformFontWin::GetStyle() const { |
| 117 return font_ref_->style(); | 109 return font_ref_->style(); |
| 118 } | 110 } |
| 119 | 111 |
| 120 std::string PlatformFontWin::GetFontName() const { | 112 std::string PlatformFontWin::GetFontName() const { |
| 121 return font_ref_->font_name(); | 113 return font_ref_->font_name(); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 return new PlatformFontWin(native_font); | 241 return new PlatformFontWin(native_font); |
| 250 } | 242 } |
| 251 | 243 |
| 252 // static | 244 // static |
| 253 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 245 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
| 254 int font_size) { | 246 int font_size) { |
| 255 return new PlatformFontWin(font_name, font_size); | 247 return new PlatformFontWin(font_name, font_size); |
| 256 } | 248 } |
| 257 | 249 |
| 258 } // namespace gfx | 250 } // namespace gfx |
| OLD | NEW |