| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <dwrite.h> | 8 #include <dwrite.h> |
| 9 #include <math.h> | 9 #include <math.h> |
| 10 #include <windows.h> | 10 #include <windows.h> |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 SkPaint paint; | 511 SkPaint paint; |
| 512 paint.setAntiAlias(!!antialiasing); | 512 paint.setAntiAlias(!!antialiasing); |
| 513 paint.setTypeface(skia_face.get()); | 513 paint.setTypeface(skia_face.get()); |
| 514 paint.setTextSize(-font_info.lfHeight); | 514 paint.setTextSize(-font_info.lfHeight); |
| 515 SkPaint::FontMetrics skia_metrics; | 515 SkPaint::FontMetrics skia_metrics; |
| 516 paint.getFontMetrics(&skia_metrics); | 516 paint.getFontMetrics(&skia_metrics); |
| 517 | 517 |
| 518 // The calculations below are similar to those in the CreateHFontRef | 518 // The calculations below are similar to those in the CreateHFontRef |
| 519 // function. The height, baseline and cap height are rounded up to ensure | 519 // function. The height, baseline and cap height are rounded up to ensure |
| 520 // that they match up closely with GDI. | 520 // that they match up closely with GDI. |
| 521 const int height = std::ceil( | 521 const int height = std::ceil(skia_metrics.fDescent - skia_metrics.fAscent); |
| 522 skia_metrics.fDescent - skia_metrics.fAscent + skia_metrics.fLeading); | |
| 523 const int baseline = std::max<int>(1, std::ceil(-skia_metrics.fAscent)); | 522 const int baseline = std::max<int>(1, std::ceil(-skia_metrics.fAscent)); |
| 524 const int cap_height = std::ceil(paint.getTextSize() * | 523 const int cap_height = std::ceil(paint.getTextSize() * |
| 525 static_cast<double>(dwrite_font_metrics.capHeight) / | 524 static_cast<double>(dwrite_font_metrics.capHeight) / |
| 526 dwrite_font_metrics.designUnitsPerEm); | 525 dwrite_font_metrics.designUnitsPerEm); |
| 527 | 526 |
| 528 // The metrics retrieved from skia don't have the average character width. In | 527 // The metrics retrieved from skia don't have the average character width. In |
| 529 // any case if we get the average character width from skia then use that or | 528 // any case if we get the average character width from skia then use that or |
| 530 // use the text extent technique as documented by microsoft. See | 529 // use the text extent technique as documented by microsoft. See |
| 531 // GetAverageCharWidthInDialogUnits for details. | 530 // GetAverageCharWidthInDialogUnits for details. |
| 532 const int ave_char_width = | 531 const int ave_char_width = |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 return new PlatformFontWin(native_font); | 619 return new PlatformFontWin(native_font); |
| 621 } | 620 } |
| 622 | 621 |
| 623 // static | 622 // static |
| 624 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 623 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
| 625 int font_size) { | 624 int font_size) { |
| 626 return new PlatformFontWin(font_name, font_size); | 625 return new PlatformFontWin(font_name, font_size); |
| 627 } | 626 } |
| 628 | 627 |
| 629 } // namespace gfx | 628 } // namespace gfx |
| OLD | NEW |