2 * Copyright (c) 2006, 2007, 2008, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "public/platform/Platform.h"
34 #include "SkTypeface.h"
35 #include "platform/LayoutTestSupport.h"
36 #include "platform/RuntimeEnabledFeatures.h"
37 #include "platform/fonts/harfbuzz/FontPlatformDataHarfBuzz.h"
38 #include "public/platform/linux/WebFontInfo.h"
39 #include "public/platform/linux/WebFontRenderStyle.h"
40 #include "public/platform/linux/WebSandboxSupport.h"
44 static SkPaint::Hinting skiaHinting = SkPaint::kNormal_Hinting;
45 static bool useSkiaAutoHint = true;
46 static bool useSkiaBitmaps = true;
47 static bool useSkiaAntiAlias = true;
48 static bool useSkiaSubpixelRendering = false;
50 void FontPlatformData::setHinting(SkPaint::Hinting hinting)
52 skiaHinting = hinting;
55 void FontPlatformData::setAutoHint(bool useAutoHint)
57 useSkiaAutoHint = useAutoHint;
60 void FontPlatformData::setUseBitmaps(bool useBitmaps)
62 useSkiaBitmaps = useBitmaps;
65 void FontPlatformData::setAntiAlias(bool useAntiAlias)
67 useSkiaAntiAlias = useAntiAlias;
70 void FontPlatformData::setSubpixelRendering(bool useSubpixelRendering)
72 useSkiaSubpixelRendering = useSubpixelRendering;
75 void FontPlatformData::setupPaint(SkPaint* paint, GraphicsContext*) const
77 paint->setAntiAlias(m_style.useAntiAlias);
78 paint->setHinting(static_cast<SkPaint::Hinting>(m_style.hintStyle));
79 paint->setEmbeddedBitmapText(m_style.useBitmaps);
80 paint->setAutohinted(m_style.useAutoHint);
81 if (m_style.useAntiAlias)
82 paint->setLCDRenderText(m_style.useSubpixelRendering);
84 // TestRunner specifically toggles the subpixel positioning flag.
85 if (RuntimeEnabledFeatures::subpixelFontScalingEnabled()
86 && paint->getHinting() != SkPaint::kFull_Hinting
87 && !isRunningLayoutTest())
88 paint->setSubpixelText(true);
90 paint->setSubpixelText(m_style.useSubpixelPositioning);
92 const float ts = m_textSize >= 0 ? m_textSize : 12;
93 paint->setTextSize(SkFloatToScalar(ts));
94 paint->setTypeface(m_typeface.get());
95 paint->setFakeBoldText(m_syntheticBold);
96 paint->setTextSkewX(m_syntheticItalic ? -SK_Scalar1 / 4 : 0);
100 static inline void getRenderStyleForStrike(FontRenderStyle& fontRenderStyle, const char* font, int sizeAndStyle)
102 blink::WebFontRenderStyle style;
108 style.setDefaults(); // It's probably a webfont. Take the system defaults.
109 else if (blink::Platform::current()->sandboxSupport())
110 blink::Platform::current()->sandboxSupport()->getRenderStyleForStrike(font, sizeAndStyle, &style);
112 blink::WebFontInfo::renderStyleForStrike(font, sizeAndStyle, &style);
115 style.toFontRenderStyle(&fontRenderStyle);
118 void FontPlatformData::querySystemForRenderStyle(bool useSkiaSubpixelPositioning)
120 getRenderStyleForStrike(m_style, m_family.data(), (((int)m_textSize) << 2) | (m_typeface->style() & 3));
122 // Fix FontRenderStyle::NoPreference to actual styles.
123 if (m_style.useAntiAlias == FontRenderStyle::NoPreference)
124 m_style.useAntiAlias = useSkiaAntiAlias;
126 if (!m_style.useHinting)
127 m_style.hintStyle = SkPaint::kNo_Hinting;
128 else if (m_style.useHinting == FontRenderStyle::NoPreference)
129 m_style.hintStyle = skiaHinting;
131 if (m_style.useBitmaps == FontRenderStyle::NoPreference)
132 m_style.useBitmaps = useSkiaBitmaps;
133 if (m_style.useAutoHint == FontRenderStyle::NoPreference)
134 m_style.useAutoHint = useSkiaAutoHint;
135 if (m_style.useAntiAlias == FontRenderStyle::NoPreference)
136 m_style.useAntiAlias = useSkiaAntiAlias;
137 if (m_style.useSubpixelRendering == FontRenderStyle::NoPreference)
138 m_style.useSubpixelRendering = useSkiaSubpixelRendering;
140 // TestRunner specifically toggles the subpixel positioning flag.
141 if (m_style.useSubpixelPositioning == FontRenderStyle::NoPreference
142 || isRunningLayoutTest())
143 m_style.useSubpixelPositioning = useSkiaSubpixelPositioning;
146 bool FontPlatformData::defaultUseSubpixelPositioning()
148 return FontDescription::subpixelPositioning();
151 } // namespace WebCore