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

Side by Side Diff: ui/gfx/render_text_mac.mm

Issue 1914443002: Revert of RenderTextMac: Cache the SkTypeface on the TextRun (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/render_text_mac.h ('k') | no next file » | 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/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
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 skia::RefPtr<SkTypeface> CreateSkiaTypeface(const gfx::Font& font, int style) {
70 gfx::Font font_with_style = font.Derive(0, style);
71 if (!font_with_style.GetNativeFont())
72 return nullptr;
73 return skia::AdoptRef(SkCreateTypefaceFromCTFont(
74 static_cast<CTFontRef>(font_with_style.GetNativeFont())));
75 }
76
77 } // namespace internal
78
67 RenderTextMac::RenderTextMac() : common_baseline_(0), runs_valid_(false) {} 79 RenderTextMac::RenderTextMac() : common_baseline_(0), runs_valid_(false) {}
68 80
69 RenderTextMac::~RenderTextMac() {} 81 RenderTextMac::~RenderTextMac() {}
70 82
71 std::unique_ptr<RenderText> RenderTextMac::CreateInstanceOfSameType() const { 83 std::unique_ptr<RenderText> RenderTextMac::CreateInstanceOfSameType() const {
72 return base::WrapUnique(new RenderTextMac); 84 return base::WrapUnique(new RenderTextMac);
73 } 85 }
74 86
75 bool RenderTextMac::MultilineSupported() const { 87 bool RenderTextMac::MultilineSupported() const {
76 return false; 88 return false;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 ApplyFadeEffects(renderer); 205 ApplyFadeEffects(renderer);
194 ApplyTextShadows(renderer); 206 ApplyTextShadows(renderer);
195 207
196 for (size_t i = 0; i < runs_.size(); ++i) { 208 for (size_t i = 0; i < runs_.size(); ++i) {
197 const TextRun& run = runs_[i]; 209 const TextRun& run = runs_[i];
198 renderer->SetForegroundColor(run.foreground); 210 renderer->SetForegroundColor(run.foreground);
199 211
200 CTFontRef ct_font = static_cast<CTFontRef>(run.font.GetNativeFont()); 212 CTFontRef ct_font = static_cast<CTFontRef>(run.font.GetNativeFont());
201 renderer->SetTextSize(CTFontGetSize(ct_font)); 213 renderer->SetTextSize(CTFontGetSize(ct_font));
202 214
203 // The painter adds its own ref. So don't |release()| it from the ref ptr in 215 int font_style = Font::NORMAL;
204 // TextRun. 216 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(ct_font);
205 renderer->SetTypeface(run.typeface.get()); 217 if (traits & kCTFontBoldTrait)
218 font_style |= Font::BOLD;
219 if (traits & kCTFontItalicTrait)
220 font_style |= Font::ITALIC;
221 renderer->SetFontWithStyle(run.font, font_style);
206 222
207 renderer->DrawPosText(&run.glyph_positions[0], &run.glyphs[0], 223 renderer->DrawPosText(&run.glyph_positions[0], &run.glyphs[0],
208 run.glyphs.size()); 224 run.glyphs.size());
209 renderer->DrawDecorations(run.origin.x(), run.origin.y(), run.width, 225 renderer->DrawDecorations(run.origin.x(), run.origin.y(), run.width,
210 run.underline, run.strike, run.diagonal_strike); 226 run.underline, run.strike, run.diagonal_strike);
211 } 227 }
212 228
213 renderer->EndDiagonalStrike(); 229 renderer->EndDiagonalStrike();
214 } 230 }
215 231
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 point->set(x + SkDoubleToScalar(positions_ptr[glyph].x), 410 point->set(x + SkDoubleToScalar(positions_ptr[glyph].x),
395 y + SkDoubleToScalar(positions_ptr[glyph].y)); 411 y + SkDoubleToScalar(positions_ptr[glyph].y));
396 } 412 }
397 413
398 // TODO(asvitkine): Style boundaries are not necessarily per-run. Handle 414 // TODO(asvitkine): Style boundaries are not necessarily per-run. Handle
399 // this better. Also, support strike and diagonal_strike. 415 // this better. Also, support strike and diagonal_strike.
400 CFDictionaryRef attributes = CTRunGetAttributes(ct_run); 416 CFDictionaryRef attributes = CTRunGetAttributes(ct_run);
401 CTFontRef ct_font = base::mac::GetValueFromDictionary<CTFontRef>( 417 CTFontRef ct_font = base::mac::GetValueFromDictionary<CTFontRef>(
402 attributes, kCTFontAttributeName); 418 attributes, kCTFontAttributeName);
403 run->font = Font(static_cast<NSFont*>(ct_font)); 419 run->font = Font(static_cast<NSFont*>(ct_font));
404 run->typeface.reset(SkCreateTypefaceFromCTFont(ct_font));
405 420
406 const CGColorRef foreground = base::mac::GetValueFromDictionary<CGColorRef>( 421 const CGColorRef foreground = base::mac::GetValueFromDictionary<CGColorRef>(
407 attributes, kCTForegroundColorAttributeName); 422 attributes, kCTForegroundColorAttributeName);
408 if (foreground) 423 if (foreground)
409 run->foreground = skia::CGColorRefToSkColor(foreground); 424 run->foreground = skia::CGColorRefToSkColor(foreground);
410 425
411 const CFNumberRef underline = 426 const CFNumberRef underline =
412 base::mac::GetValueFromDictionary<CFNumberRef>( 427 base::mac::GetValueFromDictionary<CFNumberRef>(
413 attributes, kCTUnderlineStyleAttributeName); 428 attributes, kCTUnderlineStyleAttributeName);
414 CTUnderlineStyle value = kCTUnderlineStyleNone; 429 CTUnderlineStyle value = kCTUnderlineStyleNone;
415 if (underline && CFNumberGetValue(underline, kCFNumberSInt32Type, &value)) 430 if (underline && CFNumberGetValue(underline, kCFNumberSInt32Type, &value))
416 run->underline = (value == kCTUnderlineStyleSingle); 431 run->underline = (value == kCTUnderlineStyleSingle);
417 432
418 run_origin.offset(run_width, 0); 433 run_origin.offset(run_width, 0);
419 } 434 }
420 runs_valid_ = true; 435 runs_valid_ = true;
421 } 436 }
422 437
423 void RenderTextMac::InvalidateStyle() { 438 void RenderTextMac::InvalidateStyle() {
424 line_.reset(); 439 line_.reset();
425 attributes_.reset(); 440 attributes_.reset();
426 runs_.clear(); 441 runs_.clear();
427 runs_valid_ = false; 442 runs_valid_ = false;
428 } 443 }
429 444
430 } // namespace gfx 445 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698