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

Unified Diff: ui/gfx/render_text.cc

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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/render_text.h ('k') | ui/gfx/render_text_harfbuzz.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text.cc
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index 7019918df3959526af5504e2f57a75ee02ec8cd5..29b2e8e3bf1d795b4d60b92b3a2dba1370814ac9 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -90,6 +90,16 @@
return baseline + std::max(min_shift, std::min(max_shift, baseline_shift));
}
+#if !defined(OS_MACOSX)
+// Converts |Font::FontStyle| flags to |SkTypeface::Style| flags.
+SkTypeface::Style ConvertFontStyleToSkiaTypefaceStyle(int font_style) {
+ int skia_style = SkTypeface::kNormal;
+ skia_style |= (font_style & Font::BOLD) ? SkTypeface::kBold : 0;
+ skia_style |= (font_style & Font::ITALIC) ? SkTypeface::kItalic : 0;
+ return static_cast<SkTypeface::Style>(skia_style);
+}
+#endif
+
int round(float value) {
return static_cast<int>(floor(value + 0.5f));
}
@@ -247,6 +257,18 @@
paint_.setTextSize(size);
}
+void SkiaTextRenderer::SetFontWithStyle(const Font& font, int style) {
+ skia::RefPtr<SkTypeface> typeface = CreateSkiaTypeface(font, style);
+ if (typeface) {
+ // |paint_| adds its own ref. So don't |release()| it from the ref ptr here.
+ SetTypeface(typeface.get());
+
+ // Enable fake bold text if bold style is needed but new typeface does not
+ // have it.
+ paint_.setFakeBoldText((style & Font::BOLD) && !typeface->isBold());
+ }
+}
+
void SkiaTextRenderer::SetForegroundColor(SkColor foreground) {
paint_.setColor(foreground);
}
@@ -400,6 +422,14 @@
Line::Line(const Line& other) = default;
Line::~Line() {}
+
+#if !defined(OS_MACOSX)
+skia::RefPtr<SkTypeface> CreateSkiaTypeface(const gfx::Font& font, int style) {
+ SkTypeface::Style skia_style = ConvertFontStyleToSkiaTypefaceStyle(style);
+ return skia::AdoptRef(
+ SkTypeface::CreateFromName(font.GetFontName().c_str(), skia_style));
+}
+#endif
void ApplyRenderParams(const FontRenderParams& params,
bool subpixel_rendering_suppressed,
« no previous file with comments | « ui/gfx/render_text.h ('k') | ui/gfx/render_text_harfbuzz.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698