OLD | NEW |
---|---|
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/render_text_mac.h" | 5 #include "ui/gfx/render_text_mac.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 #include <ApplicationServices/ApplicationServices.h> | 8 #include <ApplicationServices/ApplicationServices.h> |
9 #include <CoreText/CoreText.h> | 9 #include <CoreText/CoreText.h> |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <cmath> | 12 #include <cmath> |
13 #include <utility> | 13 #include <utility> |
14 | 14 |
15 #include "base/mac/foundation_util.h" | 15 #include "base/mac/foundation_util.h" |
16 #include "base/mac/mac_util.h" | 16 #include "base/mac/mac_util.h" |
17 #include "base/mac/scoped_cftyperef.h" | 17 #include "base/mac/scoped_cftyperef.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/memory/ptr_util.h" | 19 #include "base/memory/ptr_util.h" |
20 #include "base/strings/sys_string_conversions.h" | 20 #include "base/strings/sys_string_conversions.h" |
21 #include "skia/ext/skia_utils_mac.h" | 21 #include "skia/ext/skia_utils_mac.h" |
22 #include "third_party/skia/include/ports/SkTypeface_mac.h" | 22 #include "third_party/skia/include/ports/SkTypeface_mac.h" |
tapted
2016/09/21 04:06:56
remove?
karandeepb
2016/09/22 08:17:39
Removed render_text_harfbuzz_mac.mm. So this is no
| |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 // This function makes a copy of |font| with the given symbolic traits. On OSX | 26 // This function makes a copy of |font| with the given symbolic traits. On OSX |
27 // 10.11, CTFontCreateCopyWithSymbolicTraits has the right behavior but | 27 // 10.11, CTFontCreateCopyWithSymbolicTraits has the right behavior but |
28 // CTFontCreateWithFontDescriptor does not. The opposite holds true for OSX | 28 // CTFontCreateWithFontDescriptor does not. The opposite holds true for OSX |
29 // 10.10. | 29 // 10.10. |
30 base::ScopedCFTypeRef<CTFontRef> CopyFontWithSymbolicTraits(CTFontRef font, | 30 base::ScopedCFTypeRef<CTFontRef> CopyFontWithSymbolicTraits(CTFontRef font, |
31 int sym_traits) { | 31 int sym_traits) { |
32 if (base::mac::IsAtLeastOS10_11()) { | 32 if (base::mac::IsAtLeastOS10_11()) { |
(...skipping 24 matching lines...) Expand all Loading... | |
57 base::ScopedCFTypeRef<CTFontDescriptorRef> desc( | 57 base::ScopedCFTypeRef<CTFontDescriptorRef> desc( |
58 CTFontDescriptorCreateWithAttributes(attributes)); | 58 CTFontDescriptorCreateWithAttributes(attributes)); |
59 return base::ScopedCFTypeRef<CTFontRef>( | 59 return base::ScopedCFTypeRef<CTFontRef>( |
60 CTFontCreateWithFontDescriptor(desc, 0.0, nullptr)); | 60 CTFontCreateWithFontDescriptor(desc, 0.0, nullptr)); |
61 } | 61 } |
62 | 62 |
63 } // namespace | 63 } // namespace |
64 | 64 |
65 namespace gfx { | 65 namespace gfx { |
66 | 66 |
67 namespace internal { | |
68 | |
69 // Note: this is only used by RenderTextHarfbuzz. | |
70 sk_sp<SkTypeface> CreateSkiaTypeface(const Font& font, | |
71 bool italic, | |
72 Font::Weight weight) { | |
73 const Font::FontStyle style = italic ? Font::ITALIC : Font::NORMAL; | |
74 Font font_with_style = font.Derive(0, style, weight); | |
75 if (!font_with_style.GetNativeFont()) | |
76 return nullptr; | |
77 | |
78 return sk_sp<SkTypeface>(SkCreateTypefaceFromCTFont( | |
79 base::mac::NSToCFCast(font_with_style.GetNativeFont()))); | |
80 } | |
81 | |
82 } // namespace internal | |
83 | |
84 RenderTextMac::RenderTextMac() : common_baseline_(0), runs_valid_(false) {} | 67 RenderTextMac::RenderTextMac() : common_baseline_(0), runs_valid_(false) {} |
85 | 68 |
86 RenderTextMac::~RenderTextMac() {} | 69 RenderTextMac::~RenderTextMac() {} |
87 | 70 |
88 std::unique_ptr<RenderText> RenderTextMac::CreateInstanceOfSameType() const { | 71 std::unique_ptr<RenderText> RenderTextMac::CreateInstanceOfSameType() const { |
89 return base::WrapUnique(new RenderTextMac); | 72 return base::WrapUnique(new RenderTextMac); |
90 } | 73 } |
91 | 74 |
92 bool RenderTextMac::MultilineSupported() const { | 75 bool RenderTextMac::MultilineSupported() const { |
93 return false; | 76 return false; |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 runs_valid_ = true; | 424 runs_valid_ = true; |
442 } | 425 } |
443 | 426 |
444 void RenderTextMac::InvalidateStyle() { | 427 void RenderTextMac::InvalidateStyle() { |
445 line_.reset(); | 428 line_.reset(); |
446 attributes_.reset(); | 429 attributes_.reset(); |
447 runs_.clear(); | 430 runs_.clear(); |
448 runs_valid_ = false; | 431 runs_valid_ = false; |
449 } | 432 } |
450 | 433 |
434 bool RenderTextMac::GetStyledStringForRange( | |
435 const Range& range, | |
436 NSMutableAttributedString* str) const { | |
437 // TODO(karandeepb): This is not invoked on any codepath currently. Style the | |
438 // returned string if need be. | |
439 if (obscured()) | |
440 return false; | |
441 | |
442 [[str mutableString] | |
443 setString:base::SysUTF16ToNSString(GetTextFromRange(range))]; | |
444 return true; | |
445 } | |
446 | |
451 } // namespace gfx | 447 } // namespace gfx |
OLD | NEW |