Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Side by Side Diff: ui/gfx/platform_font_win.cc

Issue 875303003: For DirectWrite font metrics use the average character width from the TEXTMETRIC structure. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed comment Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/gfx/platform_font_win_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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): Investigate whether it is possible to retrieve this value
514 // from DirectWrite.
514 const int ave_char_width = 515 const int ave_char_width =
515 skia_metrics.fAvgCharWidth == 0 ? 516 skia_metrics.fAvgCharWidth == 0 ? font_metrics.tmAveCharWidth
516 HFontRef::GetAverageCharWidthInDialogUnits(gdi_font)
517 : skia_metrics.fAvgCharWidth; 517 : skia_metrics.fAvgCharWidth;
518 518
519 int style = 0; 519 int style = 0;
520 if (skia_style & SkTypeface::kItalic) 520 if (skia_style & SkTypeface::kItalic)
521 style |= Font::ITALIC; 521 style |= Font::ITALIC;
522 if (font_info.lfUnderline) 522 if (font_info.lfUnderline)
523 style |= Font::UNDERLINE; 523 style |= Font::UNDERLINE;
524 if (font_info.lfWeight >= kTextMetricWeightBold) 524 if (font_info.lfWeight >= kTextMetricWeightBold)
525 style |= Font::BOLD; 525 style |= Font::BOLD;
526 return new HFontRef(gdi_font, -font_info.lfHeight, height, baseline, 526 return new HFontRef(gdi_font, -font_info.lfHeight, height, baseline,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 return new PlatformFontWin(native_font); 610 return new PlatformFontWin(native_font);
611 } 611 }
612 612
613 // static 613 // static
614 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, 614 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name,
615 int font_size) { 615 int font_size) {
616 return new PlatformFontWin(font_name, font_size); 616 return new PlatformFontWin(font_name, font_size);
617 } 617 }
618 618
619 } // namespace gfx 619 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/platform_font_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698