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

Unified Diff: ui/gfx/render_text_mac.mm

Issue 1919123002: RenderTextMac: Cache the SkTypeface on the TextRun [reland] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes, and a test, but somewhat orthogonal 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/render_text_mac.h ('k') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text_mac.mm
diff --git a/ui/gfx/render_text_mac.mm b/ui/gfx/render_text_mac.mm
index f1c7299af209198be595064a33796efe5d70d5ee..915f51f927a75e665124221256000cce10843102 100644
--- a/ui/gfx/render_text_mac.mm
+++ b/ui/gfx/render_text_mac.mm
@@ -66,12 +66,14 @@ namespace gfx {
namespace internal {
-skia::RefPtr<SkTypeface> CreateSkiaTypeface(const gfx::Font& font, int style) {
+// Note: this is only used by RenderTextHarfbuzz.
+sk_sp<SkTypeface> CreateSkiaTypeface(const gfx::Font& font, int style) {
gfx::Font font_with_style = font.Derive(0, style);
if (!font_with_style.GetNativeFont())
return nullptr;
- return skia::AdoptRef(SkCreateTypefaceFromCTFont(
- static_cast<CTFontRef>(font_with_style.GetNativeFont())));
+
+ return sk_sp<SkTypeface>(SkCreateTypefaceFromCTFont(
+ base::mac::NSToCFCast(font_with_style.GetNativeFont())));
}
} // namespace internal
@@ -212,13 +214,9 @@ void RenderTextMac::DrawVisualText(internal::SkiaTextRenderer* renderer) {
CTFontRef ct_font = static_cast<CTFontRef>(run.font.GetNativeFont());
renderer->SetTextSize(CTFontGetSize(ct_font));
- int font_style = Font::NORMAL;
- CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(ct_font);
- if (traits & kCTFontBoldTrait)
- font_style |= Font::BOLD;
- if (traits & kCTFontItalicTrait)
- font_style |= Font::ITALIC;
- renderer->SetFontWithStyle(run.font, font_style);
+ // The painter adds its own ref. So don't |release()| it from the ref ptr in
+ // TextRun.
+ renderer->SetTypeface(run.typeface.get());
renderer->DrawPosText(&run.glyph_positions[0], &run.glyphs[0],
run.glyphs.size());
@@ -417,6 +415,7 @@ void RenderTextMac::ComputeRuns() {
CTFontRef ct_font = base::mac::GetValueFromDictionary<CTFontRef>(
attributes, kCTFontAttributeName);
run->font = Font(static_cast<NSFont*>(ct_font));
+ run->typeface.reset(SkCreateTypefaceFromCTFont(ct_font));
const CGColorRef foreground = base::mac::GetValueFromDictionary<CGColorRef>(
attributes, kCTForegroundColorAttributeName);
« no previous file with comments | « ui/gfx/render_text_mac.h ('k') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698