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

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

Issue 1406403007: Eliminate HICON leaks caused by creating icons from bitmap image. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years 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/path_win_unittest.cc ('k') | ui/native_theme/native_theme_win.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 <dwrite.h> 7 #include <dwrite.h>
8 #include <math.h> 8 #include <math.h>
9 #include <wchar.h> 9 #include <wchar.h>
10 #include <windows.h> 10 #include <windows.h>
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 if (FAILED(hr)) { 123 if (FAILED(hr)) {
124 CHECK(false); 124 CHECK(false);
125 return hr; 125 return hr;
126 } 126 }
127 127
128 // We try to find a matching font by triggering DirectWrite to substitute the 128 // We try to find a matching font by triggering DirectWrite to substitute the
129 // font passed in with a matching font (FontSubstitutes registry key) 129 // font passed in with a matching font (FontSubstitutes registry key)
130 // If this succeeds we return the matched font. 130 // If this succeeds we return the matched font.
131 base::win::ScopedGDIObject<HFONT> font(::CreateFontIndirect(font_info)); 131 base::win::ScopedGDIObject<HFONT> font(::CreateFontIndirect(font_info));
132 base::win::ScopedGetDC screen_dc(NULL); 132 base::win::ScopedGetDC screen_dc(NULL);
133 base::win::ScopedSelectObject scoped_font(screen_dc, font); 133 base::win::ScopedSelectObject scoped_font(screen_dc, font.get());
134 134
135 base::win::ScopedComPtr<IDWriteFontFace> font_face; 135 base::win::ScopedComPtr<IDWriteFontFace> font_face;
136 hr = gdi_interop->CreateFontFaceFromHdc(screen_dc, font_face.Receive()); 136 hr = gdi_interop->CreateFontFaceFromHdc(screen_dc, font_face.Receive());
137 if (FAILED(hr)) 137 if (FAILED(hr))
138 return hr; 138 return hr;
139 139
140 LOGFONT converted_font = {0}; 140 LOGFONT converted_font = {0};
141 hr = gdi_interop->ConvertFontFaceToLOGFONT(font_face.get(), &converted_font); 141 hr = gdi_interop->ConvertFontFaceToLOGFONT(font_face.get(), &converted_font);
142 if (SUCCEEDED(hr)) { 142 if (SUCCEEDED(hr)) {
143 hr = font_collection->GetFontFromFontFace(font_face.get(), dwrite_font); 143 hr = font_collection->GetFontFromFontFace(font_face.get(), dwrite_font);
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 446
447 // static 447 // static
448 int PlatformFontWin::GetFontSize(const LOGFONT& font_info) { 448 int PlatformFontWin::GetFontSize(const LOGFONT& font_info) {
449 if (font_info.lfHeight < 0) 449 if (font_info.lfHeight < 0)
450 return -font_info.lfHeight; 450 return -font_info.lfHeight;
451 451
452 base::win::ScopedGetDC screen_dc(NULL); 452 base::win::ScopedGetDC screen_dc(NULL);
453 base::win::ScopedGDIObject<HFONT> font(CreateFontIndirect(&font_info)); 453 base::win::ScopedGDIObject<HFONT> font(CreateFontIndirect(&font_info));
454 454
455 TEXTMETRIC font_metrics = {0}; 455 TEXTMETRIC font_metrics = {0};
456 PlatformFontWin::GetTextMetricsForFont(screen_dc, font, &font_metrics); 456 PlatformFontWin::GetTextMetricsForFont(screen_dc, font.get(), &font_metrics);
457 return font_metrics.tmAscent; 457 return font_metrics.tmAscent;
458 } 458 }
459 459
460 //////////////////////////////////////////////////////////////////////////////// 460 ////////////////////////////////////////////////////////////////////////////////
461 // Font, private: 461 // Font, private:
462 462
463 void PlatformFontWin::InitWithCopyOfHFONT(HFONT hfont) { 463 void PlatformFontWin::InitWithCopyOfHFONT(HFONT hfont) {
464 DCHECK(hfont); 464 DCHECK(hfont);
465 LOGFONT font_info; 465 LOGFONT font_info;
466 GetObject(hfont, sizeof(LOGFONT), &font_info); 466 GetObject(hfont, sizeof(LOGFONT), &font_info);
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 return new PlatformFontWin(native_font); 722 return new PlatformFontWin(native_font);
723 } 723 }
724 724
725 // static 725 // static
726 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, 726 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name,
727 int font_size) { 727 int font_size) {
728 return new PlatformFontWin(font_name, font_size); 728 return new PlatformFontWin(font_name, font_size);
729 } 729 }
730 730
731 } // namespace gfx 731 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/path_win_unittest.cc ('k') | ui/native_theme/native_theme_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698