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

Unified Diff: third_party/WebKit/Source/platform/fonts/FontRenderStyle.cpp

Issue 1931393002: Introduce typeface cache in blink::FontCache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wip: others 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
Index: third_party/WebKit/Source/platform/fonts/FontRenderStyle.cpp
diff --git a/third_party/WebKit/Source/platform/fonts/FontRenderStyle.cpp b/third_party/WebKit/Source/platform/fonts/FontRenderStyle.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..e1432deae14a13820f2eafdffc3f9b6d9bb19ff6
--- /dev/null
+++ b/third_party/WebKit/Source/platform/fonts/FontRenderStyle.cpp
@@ -0,0 +1,106 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "platform/fonts/FontRenderStyle.h"
+
+#include "platform/fonts/FontDescription.h"
+#include "platform/LayoutTestSupport.h"
+#include "wtf/text/WTFString.h"
+#include "public/platform/linux/WebFontRenderStyle.h"
+#include "public/platform/Platform.h"
+#include "public/platform/linux/WebSandboxSupport.h"
+
+namespace blink {
+
+static SkPaint::Hinting skiaHinting = SkPaint::kNormal_Hinting;
+static bool useSkiaAutoHint = true;
+static bool useSkiaBitmaps = true;
+static bool useSkiaAntiAlias = true;
+static bool useSkiaSubpixelRendering = false;
+
+void FontRenderStyle::setHinting(SkPaint::Hinting hinting)
+{
+ skiaHinting = hinting;
+}
+
+void FontRenderStyle::setAutoHint(bool useAutoHint)
+{
+ useSkiaAutoHint = useAutoHint;
+}
+
+void FontRenderStyle::setUseBitmaps(bool useBitmaps)
+{
+ useSkiaBitmaps = useBitmaps;
+}
+
+void FontRenderStyle::setAntiAlias(bool useAntiAlias)
+{
+ useSkiaAntiAlias = useAntiAlias;
+}
+
+void FontRenderStyle::setSubpixelRendering(bool useSubpixelRendering)
+{
+ useSkiaSubpixelRendering = useSubpixelRendering;
+}
+
+void FontRenderStyle::apply(SkPaint* paint, float deviceScaleFactor) const
+{
+ paint->setAntiAlias(useAntiAlias);
+ paint->setHinting(static_cast<SkPaint::Hinting>(hintStyle));
+ paint->setEmbeddedBitmapText(useBitmaps);
+ paint->setAutohinted(useAutoHint);
+ if (useAntiAlias)
+ paint->setLCDRenderText(useSubpixelRendering);
+
+ // Do not enable subpixel text on low-dpi if full hinting is requested.
+ bool useSubpixelText = (paint->getHinting() != SkPaint::kFull_Hinting || deviceScaleFactor > 1.0f);
+
+ // TestRunner specifically toggles the subpixel positioning flag.
+ if (useSubpixelText && !LayoutTestSupport::isRunningLayoutTest())
+ paint->setSubpixelText(true);
+ else
+ paint->setSubpixelText(useSubpixelPositioning);
+}
+
+void FontRenderStyle::querySystemForRenderStyle(WTF::String family, float textSize, SkTypeface::Style typefaceStyle)
+{
+ WebFontRenderStyle style;
+#if OS(ANDROID)
+ style.setDefaults();
+#else
+ // If the font name is missing (i.e. probably a web font) or the sandbox is disabled, use the system defaults.
+ if (!family.length() || !Platform::current()->sandboxSupport()) {
+ style.setDefaults();
+ } else {
+ const int sizeAndStyle = (((int)textSize) << 2) | (typefaceStyle & 3);
+ Platform::current()->sandboxSupport()->getWebFontRenderStyleForStrike(family.utf8().data(), sizeAndStyle, &style);
+ }
+#endif
+ style.toFontRenderStyle(this);
+
+ // Fix FontRenderStyle::NoPreference to actual styles.
+ if (useAntiAlias == FontRenderStyle::NoPreference)
+ useAntiAlias = useSkiaAntiAlias;
+
+ if (!useHinting)
+ hintStyle = SkPaint::kNo_Hinting;
+ else if (useHinting == FontRenderStyle::NoPreference)
+ hintStyle = skiaHinting;
+
+ if (useBitmaps == FontRenderStyle::NoPreference)
+ useBitmaps = useSkiaBitmaps;
+ if (useAutoHint == FontRenderStyle::NoPreference)
+ useAutoHint = useSkiaAutoHint;
+ if (useAntiAlias == FontRenderStyle::NoPreference)
+ useAntiAlias = useSkiaAntiAlias;
+ if (useSubpixelRendering == FontRenderStyle::NoPreference)
+ useSubpixelRendering = useSkiaSubpixelRendering;
+
+ // TestRunner specifically toggles the subpixel positioning flag.
+ if (useSubpixelPositioning == FontRenderStyle::NoPreference
+ || LayoutTestSupport::isRunningLayoutTest())
+ useSubpixelPositioning = FontDescription::subpixelPositioning();
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/FontRenderStyle.h ('k') | third_party/WebKit/Source/platform/fonts/SimpleFontData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698