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

Side by Side 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, 7 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "platform/fonts/FontRenderStyle.h"
6
7 #include "platform/fonts/FontDescription.h"
8 #include "platform/LayoutTestSupport.h"
9 #include "wtf/text/WTFString.h"
10 #include "public/platform/linux/WebFontRenderStyle.h"
11 #include "public/platform/Platform.h"
12 #include "public/platform/linux/WebSandboxSupport.h"
13
14 namespace blink {
15
16 static SkPaint::Hinting skiaHinting = SkPaint::kNormal_Hinting;
17 static bool useSkiaAutoHint = true;
18 static bool useSkiaBitmaps = true;
19 static bool useSkiaAntiAlias = true;
20 static bool useSkiaSubpixelRendering = false;
21
22 void FontRenderStyle::setHinting(SkPaint::Hinting hinting)
23 {
24 skiaHinting = hinting;
25 }
26
27 void FontRenderStyle::setAutoHint(bool useAutoHint)
28 {
29 useSkiaAutoHint = useAutoHint;
30 }
31
32 void FontRenderStyle::setUseBitmaps(bool useBitmaps)
33 {
34 useSkiaBitmaps = useBitmaps;
35 }
36
37 void FontRenderStyle::setAntiAlias(bool useAntiAlias)
38 {
39 useSkiaAntiAlias = useAntiAlias;
40 }
41
42 void FontRenderStyle::setSubpixelRendering(bool useSubpixelRendering)
43 {
44 useSkiaSubpixelRendering = useSubpixelRendering;
45 }
46
47 void FontRenderStyle::apply(SkPaint* paint, float deviceScaleFactor) const
48 {
49 paint->setAntiAlias(useAntiAlias);
50 paint->setHinting(static_cast<SkPaint::Hinting>(hintStyle));
51 paint->setEmbeddedBitmapText(useBitmaps);
52 paint->setAutohinted(useAutoHint);
53 if (useAntiAlias)
54 paint->setLCDRenderText(useSubpixelRendering);
55
56 // Do not enable subpixel text on low-dpi if full hinting is requested.
57 bool useSubpixelText = (paint->getHinting() != SkPaint::kFull_Hinting || dev iceScaleFactor > 1.0f);
58
59 // TestRunner specifically toggles the subpixel positioning flag.
60 if (useSubpixelText && !LayoutTestSupport::isRunningLayoutTest())
61 paint->setSubpixelText(true);
62 else
63 paint->setSubpixelText(useSubpixelPositioning);
64 }
65
66 void FontRenderStyle::querySystemForRenderStyle(WTF::String family, float textSi ze, SkTypeface::Style typefaceStyle)
67 {
68 WebFontRenderStyle style;
69 #if OS(ANDROID)
70 style.setDefaults();
71 #else
72 // If the font name is missing (i.e. probably a web font) or the sandbox is disabled, use the system defaults.
73 if (!family.length() || !Platform::current()->sandboxSupport()) {
74 style.setDefaults();
75 } else {
76 const int sizeAndStyle = (((int)textSize) << 2) | (typefaceStyle & 3);
77 Platform::current()->sandboxSupport()->getWebFontRenderStyleForStrike(fa mily.utf8().data(), sizeAndStyle, &style);
78 }
79 #endif
80 style.toFontRenderStyle(this);
81
82 // Fix FontRenderStyle::NoPreference to actual styles.
83 if (useAntiAlias == FontRenderStyle::NoPreference)
84 useAntiAlias = useSkiaAntiAlias;
85
86 if (!useHinting)
87 hintStyle = SkPaint::kNo_Hinting;
88 else if (useHinting == FontRenderStyle::NoPreference)
89 hintStyle = skiaHinting;
90
91 if (useBitmaps == FontRenderStyle::NoPreference)
92 useBitmaps = useSkiaBitmaps;
93 if (useAutoHint == FontRenderStyle::NoPreference)
94 useAutoHint = useSkiaAutoHint;
95 if (useAntiAlias == FontRenderStyle::NoPreference)
96 useAntiAlias = useSkiaAntiAlias;
97 if (useSubpixelRendering == FontRenderStyle::NoPreference)
98 useSubpixelRendering = useSkiaSubpixelRendering;
99
100 // TestRunner specifically toggles the subpixel positioning flag.
101 if (useSubpixelPositioning == FontRenderStyle::NoPreference
102 || LayoutTestSupport::isRunningLayoutTest())
103 useSubpixelPositioning = FontDescription::subpixelPositioning();
104 }
105
106 } // namespace blink
OLDNEW
« 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