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

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

Issue 1939143002: Remove all uses of skia::RefPtr and stale includes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix bad rebase Created 4 years, 7 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/platform_font_linux.cc ('k') | ui/gfx/render_text.h » ('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 <windows.h> 7 #include <windows.h>
8 #include <dwrite.h> 8 #include <dwrite.h>
9 #include <limits.h> 9 #include <limits.h>
10 #include <math.h> 10 #include <math.h>
11 #include <stdint.h> 11 #include <stdint.h>
12 #include <wchar.h> 12 #include <wchar.h>
13 13
14 #include <algorithm> 14 #include <algorithm>
15 15
16 #include "base/debug/alias.h" 16 #include "base/debug/alias.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/strings/string16.h" 19 #include "base/strings/string16.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/strings/sys_string_conversions.h" 21 #include "base/strings/sys_string_conversions.h"
22 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
23 #include "base/win/scoped_comptr.h" 23 #include "base/win/scoped_comptr.h"
24 #include "base/win/scoped_gdi_object.h" 24 #include "base/win/scoped_gdi_object.h"
25 #include "base/win/scoped_hdc.h" 25 #include "base/win/scoped_hdc.h"
26 #include "base/win/scoped_select_object.h" 26 #include "base/win/scoped_select_object.h"
27 #include "base/win/win_util.h" 27 #include "base/win/win_util.h"
28 #include "third_party/skia/include/core/SkFontLCDConfig.h" 28 #include "third_party/skia/include/core/SkFontLCDConfig.h"
29 #include "third_party/skia/include/core/SkRefCnt.h"
29 #include "third_party/skia/include/core/SkTypeface.h" 30 #include "third_party/skia/include/core/SkTypeface.h"
30 #include "ui/gfx/canvas.h" 31 #include "ui/gfx/canvas.h"
31 #include "ui/gfx/font.h" 32 #include "ui/gfx/font.h"
32 #include "ui/gfx/font_render_params.h" 33 #include "ui/gfx/font_render_params.h"
33 #include "ui/gfx/win/scoped_set_map_mode.h" 34 #include "ui/gfx/win/scoped_set_map_mode.h"
34 35
35 namespace { 36 namespace {
36 37
37 // If the tmWeight field of a TEXTMETRIC structure has a value >= this, the 38 // If the tmWeight field of a TEXTMETRIC structure has a value >= this, the
38 // font is bold. 39 // font is bold.
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 direct_write_factory_, 578 direct_write_factory_,
578 dwrite_font.Receive()); 579 dwrite_font.Receive());
579 if (FAILED(hr)) { 580 if (FAILED(hr)) {
580 CHECK(false); 581 CHECK(false);
581 return nullptr; 582 return nullptr;
582 } 583 }
583 584
584 DWRITE_FONT_METRICS dwrite_font_metrics = {0}; 585 DWRITE_FONT_METRICS dwrite_font_metrics = {0};
585 dwrite_font->GetMetrics(&dwrite_font_metrics); 586 dwrite_font->GetMetrics(&dwrite_font_metrics);
586 587
587 skia::RefPtr<SkTypeface> skia_face = skia::AdoptRef( 588 sk_sp<SkTypeface> skia_face(
588 SkTypeface::CreateFromName( 589 SkTypeface::CreateFromName(
589 base::SysWideToUTF8(font_info.lfFaceName).c_str(), 590 base::SysWideToUTF8(font_info.lfFaceName).c_str(),
590 static_cast<SkTypeface::Style>(skia_style))); 591 static_cast<SkTypeface::Style>(skia_style)));
591 592
592 gfx::FontRenderParams font_params = 593 gfx::FontRenderParams font_params =
593 gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), nullptr); 594 gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), nullptr);
594 SkFontLCDConfig::SetSubpixelOrder( 595 SkFontLCDConfig::SetSubpixelOrder(
595 gfx::FontRenderParams::SubpixelRenderingToSkiaLCDOrder( 596 gfx::FontRenderParams::SubpixelRenderingToSkiaLCDOrder(
596 font_params.subpixel_rendering)); 597 font_params.subpixel_rendering));
597 SkFontLCDConfig::SetSubpixelOrientation( 598 SkFontLCDConfig::SetSubpixelOrientation(
598 gfx::FontRenderParams::SubpixelRenderingToSkiaLCDOrientation( 599 gfx::FontRenderParams::SubpixelRenderingToSkiaLCDOrientation(
599 font_params.subpixel_rendering)); 600 font_params.subpixel_rendering));
600 601
601 SkPaint paint; 602 SkPaint paint;
602 paint.setAntiAlias(font_params.antialiasing); 603 paint.setAntiAlias(font_params.antialiasing);
603 paint.setTypeface(skia_face.get()); 604 paint.setTypeface(std::move(skia_face));
604 paint.setTextSize(-font_info.lfHeight); 605 paint.setTextSize(-font_info.lfHeight);
605 SkPaint::FontMetrics skia_metrics; 606 SkPaint::FontMetrics skia_metrics;
606 paint.getFontMetrics(&skia_metrics); 607 paint.getFontMetrics(&skia_metrics);
607 608
608 // The calculations below are similar to those in the CreateHFontRef 609 // The calculations below are similar to those in the CreateHFontRef
609 // function. The height, baseline and cap height are rounded up to ensure 610 // function. The height, baseline and cap height are rounded up to ensure
610 // that they match up closely with GDI. 611 // that they match up closely with GDI.
611 const int height = std::ceil(skia_metrics.fDescent - skia_metrics.fAscent); 612 const int height = std::ceil(skia_metrics.fDescent - skia_metrics.fAscent);
612 const int baseline = std::max<int>(1, std::ceil(-skia_metrics.fAscent)); 613 const int baseline = std::max<int>(1, std::ceil(-skia_metrics.fAscent));
613 const int cap_height = std::ceil(paint.getTextSize() * 614 const int cap_height = std::ceil(paint.getTextSize() *
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 return new PlatformFontWin(native_font); 726 return new PlatformFontWin(native_font);
726 } 727 }
727 728
728 // static 729 // static
729 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, 730 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name,
730 int font_size) { 731 int font_size) {
731 return new PlatformFontWin(font_name, font_size); 732 return new PlatformFontWin(font_name, font_size);
732 } 733 }
733 734
734 } // namespace gfx 735 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/platform_font_linux.cc ('k') | ui/gfx/render_text.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698