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

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: 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
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/SkRefCnt.h"
28 #include "third_party/skia/include/core/SkTypeface.h" 29 #include "third_party/skia/include/core/SkTypeface.h"
29 #include "ui/gfx/canvas.h" 30 #include "ui/gfx/canvas.h"
30 #include "ui/gfx/font.h" 31 #include "ui/gfx/font.h"
31 #include "ui/gfx/font_render_params.h" 32 #include "ui/gfx/font_render_params.h"
32 #include "ui/gfx/win/scoped_set_map_mode.h" 33 #include "ui/gfx/win/scoped_set_map_mode.h"
33 34
34 namespace { 35 namespace {
35 36
36 // If the tmWeight field of a TEXTMETRIC structure has a value >= this, the 37 // If the tmWeight field of a TEXTMETRIC structure has a value >= this, the
37 // font is bold. 38 // font is bold.
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 direct_write_factory_, 577 direct_write_factory_,
577 dwrite_font.Receive()); 578 dwrite_font.Receive());
578 if (FAILED(hr)) { 579 if (FAILED(hr)) {
579 CHECK(false); 580 CHECK(false);
580 return nullptr; 581 return nullptr;
581 } 582 }
582 583
583 DWRITE_FONT_METRICS dwrite_font_metrics = {0}; 584 DWRITE_FONT_METRICS dwrite_font_metrics = {0};
584 dwrite_font->GetMetrics(&dwrite_font_metrics); 585 dwrite_font->GetMetrics(&dwrite_font_metrics);
585 586
586 skia::RefPtr<SkTypeface> skia_face = skia::AdoptRef( 587 sk_sp<SkTypeface> skia_face(
587 SkTypeface::CreateFromName( 588 SkTypeface::CreateFromName(
588 base::SysWideToUTF8(font_info.lfFaceName).c_str(), 589 base::SysWideToUTF8(font_info.lfFaceName).c_str(),
589 static_cast<SkTypeface::Style>(skia_style))); 590 static_cast<SkTypeface::Style>(skia_style)));
590 591
591 gfx::FontRenderParams font_params = 592 gfx::FontRenderParams font_params =
592 gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), nullptr); 593 gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), nullptr);
593 SkFontHost::SetSubpixelOrder( 594 SkFontHost::SetSubpixelOrder(
594 gfx::FontRenderParams::SubpixelRenderingToSkiaLCDOrder( 595 gfx::FontRenderParams::SubpixelRenderingToSkiaLCDOrder(
595 font_params.subpixel_rendering)); 596 font_params.subpixel_rendering));
596 SkFontHost::SetSubpixelOrientation( 597 SkFontHost::SetSubpixelOrientation(
597 gfx::FontRenderParams::SubpixelRenderingToSkiaLCDOrientation( 598 gfx::FontRenderParams::SubpixelRenderingToSkiaLCDOrientation(
598 font_params.subpixel_rendering)); 599 font_params.subpixel_rendering));
599 600
600 SkPaint paint; 601 SkPaint paint;
601 paint.setAntiAlias(font_params.antialiasing); 602 paint.setAntiAlias(font_params.antialiasing);
602 paint.setTypeface(skia_face.get()); 603 paint.setTypeface(skia_face);
f(malita) 2016/05/04 15:49:57 std::move(skia_face)
tomhudson 2016/05/04 16:51:54 Done.
603 paint.setTextSize(-font_info.lfHeight); 604 paint.setTextSize(-font_info.lfHeight);
604 SkPaint::FontMetrics skia_metrics; 605 SkPaint::FontMetrics skia_metrics;
605 paint.getFontMetrics(&skia_metrics); 606 paint.getFontMetrics(&skia_metrics);
606 607
607 // The calculations below are similar to those in the CreateHFontRef 608 // The calculations below are similar to those in the CreateHFontRef
608 // function. The height, baseline and cap height are rounded up to ensure 609 // function. The height, baseline and cap height are rounded up to ensure
609 // that they match up closely with GDI. 610 // that they match up closely with GDI.
610 const int height = std::ceil(skia_metrics.fDescent - skia_metrics.fAscent); 611 const int height = std::ceil(skia_metrics.fDescent - skia_metrics.fAscent);
611 const int baseline = std::max<int>(1, std::ceil(-skia_metrics.fAscent)); 612 const int baseline = std::max<int>(1, std::ceil(-skia_metrics.fAscent));
612 const int cap_height = std::ceil(paint.getTextSize() * 613 const int cap_height = std::ceil(paint.getTextSize() *
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 return new PlatformFontWin(native_font); 725 return new PlatformFontWin(native_font);
725 } 726 }
726 727
727 // static 728 // static
728 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, 729 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name,
729 int font_size) { 730 int font_size) {
730 return new PlatformFontWin(font_name, font_size); 731 return new PlatformFontWin(font_name, font_size);
731 } 732 }
732 733
733 } // namespace gfx 734 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698