Chromium Code Reviews| 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 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 // function. The height, baseline and cap height are rounded up to ensure | 502 // function. The height, baseline and cap height are rounded up to ensure |
| 503 // that they match up closely with GDI. | 503 // that they match up closely with GDI. |
| 504 const int height = std::ceil(skia_metrics.fDescent - skia_metrics.fAscent); | 504 const int height = std::ceil(skia_metrics.fDescent - skia_metrics.fAscent); |
| 505 const int baseline = std::max<int>(1, std::ceil(-skia_metrics.fAscent)); | 505 const int baseline = std::max<int>(1, std::ceil(-skia_metrics.fAscent)); |
| 506 const int cap_height = std::ceil(paint.getTextSize() * | 506 const int cap_height = std::ceil(paint.getTextSize() * |
| 507 static_cast<double>(dwrite_font_metrics.capHeight) / | 507 static_cast<double>(dwrite_font_metrics.capHeight) / |
| 508 dwrite_font_metrics.designUnitsPerEm); | 508 dwrite_font_metrics.designUnitsPerEm); |
| 509 | 509 |
| 510 // The metrics retrieved from skia don't have the average character width. In | 510 // The metrics retrieved from skia don't have the average character width. In |
| 511 // any case if we get the average character width from skia then use that or | 511 // any case if we get the average character width from skia then use that or |
| 512 // use the text extent technique as documented by microsoft. See | 512 // the average character width in the TEXTMETRIC structure. |
| 513 // GetAverageCharWidthInDialogUnits for details. | 513 // TODO(ananta) |
|
Alexei Svitkine (slow)
2015/01/29 20:52:10
Nit:
Usually, there's a : after the TODO(name) an
ananta
2015/01/29 21:04:58
Done.
| |
| 514 // Investigate whether it is possible to retrieve this value from | |
| 515 // DirectWrite. | |
| 514 const int ave_char_width = | 516 const int ave_char_width = |
| 515 skia_metrics.fAvgCharWidth == 0 ? | 517 skia_metrics.fAvgCharWidth == 0 ? font_metrics.tmAveCharWidth |
| 516 HFontRef::GetAverageCharWidthInDialogUnits(gdi_font) | |
| 517 : skia_metrics.fAvgCharWidth; | 518 : skia_metrics.fAvgCharWidth; |
| 518 | 519 |
| 519 int style = 0; | 520 int style = 0; |
| 520 if (skia_style & SkTypeface::kItalic) | 521 if (skia_style & SkTypeface::kItalic) |
| 521 style |= Font::ITALIC; | 522 style |= Font::ITALIC; |
| 522 if (font_info.lfUnderline) | 523 if (font_info.lfUnderline) |
| 523 style |= Font::UNDERLINE; | 524 style |= Font::UNDERLINE; |
| 524 if (font_info.lfWeight >= kTextMetricWeightBold) | 525 if (font_info.lfWeight >= kTextMetricWeightBold) |
| 525 style |= Font::BOLD; | 526 style |= Font::BOLD; |
| 526 return new HFontRef(gdi_font, -font_info.lfHeight, height, baseline, | 527 return new HFontRef(gdi_font, -font_info.lfHeight, height, baseline, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 610 return new PlatformFontWin(native_font); | 611 return new PlatformFontWin(native_font); |
| 611 } | 612 } |
| 612 | 613 |
| 613 // static | 614 // static |
| 614 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 615 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
| 615 int font_size) { | 616 int font_size) { |
| 616 return new PlatformFontWin(font_name, font_size); | 617 return new PlatformFontWin(font_name, font_size); |
| 617 } | 618 } |
| 618 | 619 |
| 619 } // namespace gfx | 620 } // namespace gfx |
| OLD | NEW |