Commit 08526340 authored by ananta's avatar ananta Committed by Commit bot

For DirectWrite font metrics use the average character width from the TEXTMETRIC structure.

Currently we fetch the average character width from the GetTextExtentPoint32 API for DirectWrite as skia
does not return this value. The width returned by the GetTextExtentPoint32 API is 1 px larger than the one
reported by the TEXTMETRIC structure causing some dialogs like the bookmark editor to display much larger than that
with GDI.

We now use the average character width from the TEXTMETRIC structure while reporting back the metrics for DirectWrite
fonts. Longer term fix is to find out a way to calculate this from DirectWrite. Does not appear to be straigthforward.
Added a TODO to that effect in the code.

BUG=434588
TEST=Updated the PlatformFontWinTest.Metrics_SkiaVersusGDI test to validate the average character widths.
For manual test, launch Chrome and open the bookmark
editor on Windows 7+. Observe that the window size is larger than the window size when using GDI for fonts.

Review URL: https://codereview.chromium.org/875303003

Cr-Commit-Position: refs/heads/master@{#313801}
parent cd189c1c
...@@ -509,11 +509,11 @@ PlatformFontWin::HFontRef* PlatformFontWin::CreateHFontRefFromSkia( ...@@ -509,11 +509,11 @@ PlatformFontWin::HFontRef* PlatformFontWin::CreateHFontRefFromSkia(
// The metrics retrieved from skia don't have the average character width. In // The metrics retrieved from skia don't have the average character width. In
// any case if we get the average character width from skia then use that or // any case if we get the average character width from skia then use that or
// use the text extent technique as documented by microsoft. See // the average character width in the TEXTMETRIC structure.
// GetAverageCharWidthInDialogUnits for details. // TODO(ananta): Investigate whether it is possible to retrieve this value
// from DirectWrite.
const int ave_char_width = const int ave_char_width =
skia_metrics.fAvgCharWidth == 0 ? skia_metrics.fAvgCharWidth == 0 ? font_metrics.tmAveCharWidth
HFontRef::GetAverageCharWidthInDialogUnits(gdi_font)
: skia_metrics.fAvgCharWidth; : skia_metrics.fAvgCharWidth;
int style = 0; int style = 0;
......
...@@ -150,6 +150,7 @@ TEST(PlatformFontWinTest, Metrics_SkiaVersusGDI) { ...@@ -150,6 +150,7 @@ TEST(PlatformFontWinTest, Metrics_SkiaVersusGDI) {
EXPECT_EQ(h_font_gdi->font_size(), h_font_skia->font_size()); EXPECT_EQ(h_font_gdi->font_size(), h_font_skia->font_size());
EXPECT_EQ(h_font_gdi->style(), h_font_skia->style()); EXPECT_EQ(h_font_gdi->style(), h_font_skia->style());
EXPECT_EQ(h_font_gdi->font_name(), h_font_skia->font_name()); EXPECT_EQ(h_font_gdi->font_name(), h_font_skia->font_name());
EXPECT_EQ(h_font_gdi->ave_char_width(), h_font_skia->ave_char_width());
EXPECT_LE(abs(h_font_gdi->cap_height() - h_font_skia->cap_height()), 1); EXPECT_LE(abs(h_font_gdi->cap_height() - h_font_skia->cap_height()), 1);
EXPECT_LE(abs(h_font_gdi->baseline() - h_font_skia->baseline()), 1); EXPECT_LE(abs(h_font_gdi->baseline() - h_font_skia->baseline()), 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment