| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 // locale. | 48 // locale. |
| 49 if (abs(lf_height) < min_font_size) { | 49 if (abs(lf_height) < min_font_size) { |
| 50 return lf_height < 0 ? -min_font_size : min_font_size; | 50 return lf_height < 0 ? -min_font_size : min_font_size; |
| 51 } else { | 51 } else { |
| 52 return lf_height; | 52 return lf_height; |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 // Sets style properties on |font_info| based on |font_style|. | 56 // Sets style properties on |font_info| based on |font_style|. |
| 57 void SetLogFontStyle(int font_style, LOGFONT* font_info) { | 57 void SetLogFontStyle(int font_style, LOGFONT* font_info) { |
| 58 font_info->lfUnderline = (font_style & gfx::Font::UNDERLINED) != 0; | 58 font_info->lfUnderline = (font_style & gfx::Font::UNDERLINE) != 0; |
| 59 font_info->lfItalic = (font_style & gfx::Font::ITALIC) != 0; | 59 font_info->lfItalic = (font_style & gfx::Font::ITALIC) != 0; |
| 60 font_info->lfWeight = (font_style & gfx::Font::BOLD) ? FW_BOLD : FW_NORMAL; | 60 font_info->lfWeight = (font_style & gfx::Font::BOLD) ? FW_BOLD : FW_NORMAL; |
| 61 } | 61 } |
| 62 | 62 |
| 63 } // namespace | 63 } // namespace |
| 64 | 64 |
| 65 namespace gfx { | 65 namespace gfx { |
| 66 | 66 |
| 67 // static | 67 // static |
| 68 PlatformFontWin::HFontRef* PlatformFontWin::base_font_ref_; | 68 PlatformFontWin::HFontRef* PlatformFontWin::base_font_ref_; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 235 |
| 236 const int height = std::max<int>(1, font_metrics.tmHeight); | 236 const int height = std::max<int>(1, font_metrics.tmHeight); |
| 237 const int baseline = std::max<int>(1, font_metrics.tmAscent); | 237 const int baseline = std::max<int>(1, font_metrics.tmAscent); |
| 238 const int ave_char_width = std::max<int>(1, font_metrics.tmAveCharWidth); | 238 const int ave_char_width = std::max<int>(1, font_metrics.tmAveCharWidth); |
| 239 const int font_size = | 239 const int font_size = |
| 240 std::max<int>(1, font_metrics.tmHeight - font_metrics.tmInternalLeading); | 240 std::max<int>(1, font_metrics.tmHeight - font_metrics.tmInternalLeading); |
| 241 int style = 0; | 241 int style = 0; |
| 242 if (font_metrics.tmItalic) | 242 if (font_metrics.tmItalic) |
| 243 style |= Font::ITALIC; | 243 style |= Font::ITALIC; |
| 244 if (font_metrics.tmUnderlined) | 244 if (font_metrics.tmUnderlined) |
| 245 style |= Font::UNDERLINED; | 245 style |= Font::UNDERLINE; |
| 246 if (font_metrics.tmWeight >= kTextMetricWeightBold) | 246 if (font_metrics.tmWeight >= kTextMetricWeightBold) |
| 247 style |= Font::BOLD; | 247 style |= Font::BOLD; |
| 248 | 248 |
| 249 return new HFontRef(font, font_size, height, baseline, ave_char_width, style); | 249 return new HFontRef(font, font_size, height, baseline, ave_char_width, style); |
| 250 } | 250 } |
| 251 | 251 |
| 252 PlatformFontWin::PlatformFontWin(HFontRef* hfont_ref) : font_ref_(hfont_ref) { | 252 PlatformFontWin::PlatformFontWin(HFontRef* hfont_ref) : font_ref_(hfont_ref) { |
| 253 } | 253 } |
| 254 | 254 |
| 255 //////////////////////////////////////////////////////////////////////////////// | 255 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 return new PlatformFontWin(native_font); | 315 return new PlatformFontWin(native_font); |
| 316 } | 316 } |
| 317 | 317 |
| 318 // static | 318 // static |
| 319 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 319 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
| 320 int font_size) { | 320 int font_size) { |
| 321 return new PlatformFontWin(font_name, font_size); | 321 return new PlatformFontWin(font_name, font_size); |
| 322 } | 322 } |
| 323 | 323 |
| 324 } // namespace gfx | 324 } // namespace gfx |
| OLD | NEW |