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

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

Issue 844083002: Get all font unittests running with DirectWrite on Windows 7+ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reworded comment Created 5 years, 11 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 | « ui/gfx/font_list_unittest.cc ('k') | 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 int font_size = font.GetFontSize(); 223 int font_size = font.GetFontSize();
224 while (font_height > height && font_size != min_font_size) { 224 while (font_height > height && font_size != min_font_size) {
225 font = font.Derive(-1, style); 225 font = font.Derive(-1, style);
226 if (font_height == font.GetHeight() && font_size == font.GetFontSize()) 226 if (font_height == font.GetHeight() && font_size == font.GetFontSize())
227 break; 227 break;
228 font_height = font.GetHeight(); 228 font_height = font.GetHeight();
229 font_size = font.GetFontSize(); 229 font_size = font.GetFontSize();
230 } 230 }
231 return font; 231 return font;
232 } 232 }
233 233 // We derive a font with a size delta of 0 initially, i.e the derived font
msw 2015/01/12 21:30:55 Is this necessary given the early return at lines
msw 2015/01/12 21:30:55 nit: add a blank line above.
ananta 2015/01/12 22:14:15 Done.
ananta 2015/01/12 22:14:15 The function has changed.
ananta 2015/01/12 22:14:15 Removed the comment. The function has changed a bi
234 LOGFONT font_info; 234 // starts off with the height of the current font instance.
235 GetObject(GetNativeFont(), sizeof(LOGFONT), &font_info); 235 // This is to ensure that we honor the contract of this function which is
236 font_info.lfHeight = height; 236 // to return a font with with height less than or equal to the desired
237 SetLogFontStyle(style, &font_info); 237 // height.
238 238 Font font = DeriveFont(0, style);
239 HFONT hfont = CreateFontIndirect(&font_info); 239 while (font.GetHeight() < height) {
240 return DeriveWithCorrectedSize(hfont); 240 Font derived_font = font.Derive(1, style);
msw 2015/01/12 21:30:55 I'm curious about the performance impact here, but
ananta 2015/01/12 22:14:15 Done. Removed the starting 2 lines which check for
241 if (derived_font.GetHeight() > height)
242 break;
243 font = derived_font;
244 }
245 return font;
241 } 246 }
242 247
243 //////////////////////////////////////////////////////////////////////////////// 248 ////////////////////////////////////////////////////////////////////////////////
244 // PlatformFontWin, PlatformFont implementation: 249 // PlatformFontWin, PlatformFont implementation:
245 250
246 Font PlatformFontWin::DeriveFont(int size_delta, int style) const { 251 Font PlatformFontWin::DeriveFont(int size_delta, int style) const {
247 LOGFONT font_info; 252 LOGFONT font_info;
248 GetObject(GetNativeFont(), sizeof(LOGFONT), &font_info); 253 GetObject(GetNativeFont(), sizeof(LOGFONT), &font_info);
249 const int requested_font_size = font_ref_->requested_font_size(); 254 const int requested_font_size = font_ref_->requested_font_size();
250 font_info.lfHeight = AdjustFontSize(-requested_font_size, size_delta); 255 font_info.lfHeight = AdjustFontSize(-requested_font_size, size_delta);
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 SkPaint paint; 516 SkPaint paint;
512 paint.setAntiAlias(!!antialiasing); 517 paint.setAntiAlias(!!antialiasing);
513 paint.setTypeface(skia_face.get()); 518 paint.setTypeface(skia_face.get());
514 paint.setTextSize(-font_info.lfHeight); 519 paint.setTextSize(-font_info.lfHeight);
515 SkPaint::FontMetrics skia_metrics; 520 SkPaint::FontMetrics skia_metrics;
516 paint.getFontMetrics(&skia_metrics); 521 paint.getFontMetrics(&skia_metrics);
517 522
518 // The calculations below are similar to those in the CreateHFontRef 523 // The calculations below are similar to those in the CreateHFontRef
519 // function. The height, baseline and cap height are rounded up to ensure 524 // function. The height, baseline and cap height are rounded up to ensure
520 // that they match up closely with GDI. 525 // that they match up closely with GDI.
521 const int height = std::ceil( 526 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)); 527 const int baseline = std::max<int>(1, std::ceil(-skia_metrics.fAscent));
524 const int cap_height = std::ceil(paint.getTextSize() * 528 const int cap_height = std::ceil(paint.getTextSize() *
525 static_cast<double>(dwrite_font_metrics.capHeight) / 529 static_cast<double>(dwrite_font_metrics.capHeight) /
526 dwrite_font_metrics.designUnitsPerEm); 530 dwrite_font_metrics.designUnitsPerEm);
527 531
528 // The metrics retrieved from skia don't have the average character width. In 532 // 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 533 // 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 534 // use the text extent technique as documented by microsoft. See
531 // GetAverageCharWidthInDialogUnits for details. 535 // GetAverageCharWidthInDialogUnits for details.
532 const int ave_char_width = 536 const int ave_char_width =
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 return new PlatformFontWin(native_font); 624 return new PlatformFontWin(native_font);
621 } 625 }
622 626
623 // static 627 // static
624 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, 628 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name,
625 int font_size) { 629 int font_size) {
626 return new PlatformFontWin(font_name, font_size); 630 return new PlatformFontWin(font_name, font_size);
627 } 631 }
628 632
629 } // namespace gfx 633 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/font_list_unittest.cc ('k') | ui/gfx/platform_font_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698