| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright (c) 2006, 2007, 2008, Google Inc. All rights reserved. | 2  * Copyright (c) 2006, 2007, 2008, Google Inc. All rights reserved. | 
| 3  * | 3  * | 
| 4  * Redistribution and use in source and binary forms, with or without | 4  * Redistribution and use in source and binary forms, with or without | 
| 5  * modification, are permitted provided that the following conditions are | 5  * modification, are permitted provided that the following conditions are | 
| 6  * met: | 6  * met: | 
| 7  * | 7  * | 
| 8  *     * Redistributions of source code must retain the above copyright | 8  *     * Redistributions of source code must retain the above copyright | 
| 9  * notice, this list of conditions and the following disclaimer. | 9  * notice, this list of conditions and the following disclaimer. | 
| 10  *     * Redistributions in binary form must reproduce the above | 10  *     * Redistributions in binary form must reproduce the above | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
| 22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 
| 23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 
| 24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
| 25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
| 26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
| 27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| 29  */ | 29  */ | 
| 30 | 30 | 
| 31 #include "public/platform/Platform.h" | 31 #include "platform/fonts/FontPlatformData.h" | 
| 32 | 32 | 
| 33 #include "SkTypeface.h" | 33 #include "SkTypeface.h" | 
| 34 #include "platform/LayoutTestSupport.h" |  | 
| 35 #include "platform/RuntimeEnabledFeatures.h" |  | 
| 36 #include "platform/fonts/FontPlatformData.h" |  | 
| 37 #include "platform/graphics/GraphicsContext.h" |  | 
| 38 #include "public/platform/linux/WebFontRenderStyle.h" |  | 
| 39 #include "public/platform/linux/WebSandboxSupport.h" |  | 
| 40 | 34 | 
| 41 namespace blink { | 35 namespace blink { | 
| 42 | 36 | 
| 43 static SkPaint::Hinting skiaHinting = SkPaint::kNormal_Hinting; |  | 
| 44 static bool useSkiaAutoHint = true; |  | 
| 45 static bool useSkiaBitmaps = true; |  | 
| 46 static bool useSkiaAntiAlias = true; |  | 
| 47 static bool useSkiaSubpixelRendering = false; |  | 
| 48 |  | 
| 49 void FontPlatformData::setHinting(SkPaint::Hinting hinting) |  | 
| 50 { |  | 
| 51     skiaHinting = hinting; |  | 
| 52 } |  | 
| 53 |  | 
| 54 void FontPlatformData::setAutoHint(bool useAutoHint) |  | 
| 55 { |  | 
| 56     useSkiaAutoHint = useAutoHint; |  | 
| 57 } |  | 
| 58 |  | 
| 59 void FontPlatformData::setUseBitmaps(bool useBitmaps) |  | 
| 60 { |  | 
| 61     useSkiaBitmaps = useBitmaps; |  | 
| 62 } |  | 
| 63 |  | 
| 64 void FontPlatformData::setAntiAlias(bool useAntiAlias) |  | 
| 65 { |  | 
| 66     useSkiaAntiAlias = useAntiAlias; |  | 
| 67 } |  | 
| 68 |  | 
| 69 void FontPlatformData::setSubpixelRendering(bool useSubpixelRendering) |  | 
| 70 { |  | 
| 71     useSkiaSubpixelRendering = useSubpixelRendering; |  | 
| 72 } |  | 
| 73 |  | 
| 74 void FontPlatformData::setupPaint(SkPaint* paint, float deviceScaleFactor, const
      Font*) const | 37 void FontPlatformData::setupPaint(SkPaint* paint, float deviceScaleFactor, const
      Font*) const | 
| 75 { | 38 { | 
| 76     paint->setAntiAlias(m_style.useAntiAlias); | 39     m_style.applyToPaint(*paint, deviceScaleFactor); | 
| 77     paint->setHinting(static_cast<SkPaint::Hinting>(m_style.hintStyle)); |  | 
| 78     paint->setEmbeddedBitmapText(m_style.useBitmaps); |  | 
| 79     paint->setAutohinted(m_style.useAutoHint); |  | 
| 80     if (m_style.useAntiAlias) |  | 
| 81         paint->setLCDRenderText(m_style.useSubpixelRendering); |  | 
| 82 |  | 
| 83     // Do not enable subpixel text on low-dpi if full hinting is requested. |  | 
| 84     bool useSubpixelText = (paint->getHinting() != SkPaint::kFull_Hinting || dev
     iceScaleFactor > 1.0f); |  | 
| 85 |  | 
| 86     // TestRunner specifically toggles the subpixel positioning flag. |  | 
| 87     if (useSubpixelText && !LayoutTestSupport::isRunningLayoutTest()) |  | 
| 88         paint->setSubpixelText(true); |  | 
| 89     else |  | 
| 90         paint->setSubpixelText(m_style.useSubpixelPositioning); |  | 
| 91 | 40 | 
| 92     const float ts = m_textSize >= 0 ? m_textSize : 12; | 41     const float ts = m_textSize >= 0 ? m_textSize : 12; | 
| 93     paint->setTextSize(SkFloatToScalar(ts)); | 42     paint->setTextSize(SkFloatToScalar(ts)); | 
| 94     paint->setTypeface(m_typeface.get()); | 43     paint->setTypeface(m_typeface.get()); | 
| 95     paint->setFakeBoldText(m_syntheticBold); | 44     paint->setFakeBoldText(m_syntheticBold); | 
| 96     paint->setTextSkewX(m_syntheticItalic ? -SK_Scalar1 / 4 : 0); | 45     paint->setTextSkewX(m_syntheticItalic ? -SK_Scalar1 / 4 : 0); | 
| 97 } | 46 } | 
| 98 | 47 | 
| 99 void FontPlatformData::querySystemForRenderStyle() |  | 
| 100 { |  | 
| 101     WebFontRenderStyle style; |  | 
| 102 #if OS(ANDROID) |  | 
| 103     style.setDefaults(); |  | 
| 104 #else |  | 
| 105     // If the font name is missing (i.e. probably a web font) or the sandbox is 
     disabled, use the system defaults. |  | 
| 106     if (!m_family.length() || !Platform::current()->sandboxSupport()) { |  | 
| 107         style.setDefaults(); |  | 
| 108     } else { |  | 
| 109         const int sizeAndStyle = (((int)m_textSize) << 2) | (m_typeface->style()
      & 3); |  | 
| 110         Platform::current()->sandboxSupport()->getWebFontRenderStyleForStrike(m_
     family.data(), sizeAndStyle, &style); |  | 
| 111     } |  | 
| 112 #endif |  | 
| 113     style.toFontRenderStyle(&m_style); |  | 
| 114 |  | 
| 115     // Fix FontRenderStyle::NoPreference to actual styles. |  | 
| 116     if (m_style.useAntiAlias == FontRenderStyle::NoPreference) |  | 
| 117         m_style.useAntiAlias = useSkiaAntiAlias; |  | 
| 118 |  | 
| 119     if (!m_style.useHinting) |  | 
| 120         m_style.hintStyle = SkPaint::kNo_Hinting; |  | 
| 121     else if (m_style.useHinting == FontRenderStyle::NoPreference) |  | 
| 122         m_style.hintStyle = skiaHinting; |  | 
| 123 |  | 
| 124     if (m_style.useBitmaps == FontRenderStyle::NoPreference) |  | 
| 125         m_style.useBitmaps = useSkiaBitmaps; |  | 
| 126     if (m_style.useAutoHint == FontRenderStyle::NoPreference) |  | 
| 127         m_style.useAutoHint = useSkiaAutoHint; |  | 
| 128     if (m_style.useAntiAlias == FontRenderStyle::NoPreference) |  | 
| 129         m_style.useAntiAlias = useSkiaAntiAlias; |  | 
| 130     if (m_style.useSubpixelRendering == FontRenderStyle::NoPreference) |  | 
| 131         m_style.useSubpixelRendering = useSkiaSubpixelRendering; |  | 
| 132 |  | 
| 133     // TestRunner specifically toggles the subpixel positioning flag. |  | 
| 134     if (m_style.useSubpixelPositioning == FontRenderStyle::NoPreference |  | 
| 135         || LayoutTestSupport::isRunningLayoutTest()) |  | 
| 136         m_style.useSubpixelPositioning = FontDescription::subpixelPositioning(); |  | 
| 137 } |  | 
| 138 |  | 
| 139 } // namespace blink | 48 } // namespace blink | 
| OLD | NEW | 
|---|