OLD | NEW |
(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/linux/FontRenderStyle.h" |
| 6 |
| 7 #include "platform/LayoutTestSupport.h" |
| 8 #include "platform/fonts/FontDescription.h" |
| 9 #include "public/platform/Platform.h" |
| 10 #include "public/platform/linux/WebFontRenderStyle.h" |
| 11 #include "public/platform/linux/WebSandboxSupport.h" |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 namespace { |
| 16 |
| 17 SkPaint::Hinting skiaHinting = SkPaint::kNormal_Hinting; |
| 18 bool useSkiaAutoHint = true; |
| 19 bool useSkiaBitmaps = true; |
| 20 bool useSkiaAntiAlias = true; |
| 21 bool useSkiaSubpixelRendering = false; |
| 22 |
| 23 } // namespace |
| 24 |
| 25 // static |
| 26 void FontRenderStyle::setHinting(SkPaint::Hinting hinting) |
| 27 { |
| 28 skiaHinting = hinting; |
| 29 } |
| 30 |
| 31 // static |
| 32 void FontRenderStyle::setAutoHint(bool useAutoHint) |
| 33 { |
| 34 useSkiaAutoHint = useAutoHint; |
| 35 } |
| 36 |
| 37 // static |
| 38 void FontRenderStyle::setUseBitmaps(bool useBitmaps) |
| 39 { |
| 40 useSkiaBitmaps = useBitmaps; |
| 41 } |
| 42 |
| 43 // static |
| 44 void FontRenderStyle::setAntiAlias(bool useAntiAlias) |
| 45 { |
| 46 useSkiaAntiAlias = useAntiAlias; |
| 47 } |
| 48 |
| 49 // static |
| 50 void FontRenderStyle::setSubpixelRendering(bool useSubpixelRendering) |
| 51 { |
| 52 useSkiaSubpixelRendering = useSubpixelRendering; |
| 53 } |
| 54 |
| 55 // static |
| 56 FontRenderStyle FontRenderStyle::querySystem(const CString& family, float textSi
ze, SkTypeface::Style typefaceStyle) |
| 57 { |
| 58 WebFontRenderStyle style; |
| 59 #if OS(ANDROID) |
| 60 style.setDefaults(); |
| 61 #else |
| 62 // If the font name is missing (i.e. probably a web font) or the sandbox is
disabled, use the system defaults. |
| 63 if (!family.length() || !Platform::current()->sandboxSupport()) { |
| 64 style.setDefaults(); |
| 65 } else { |
| 66 const int sizeAndStyle = (((int)textSize) << 2) | (typefaceStyle & 3); |
| 67 Platform::current()->sandboxSupport()->getWebFontRenderStyleForStrike(fa
mily.data(), sizeAndStyle, &style); |
| 68 } |
| 69 #endif |
| 70 |
| 71 FontRenderStyle result; |
| 72 style.toFontRenderStyle(&result); |
| 73 |
| 74 // Fix FontRenderStyle::NoPreference to actual styles. |
| 75 if (result.useAntiAlias == FontRenderStyle::NoPreference) |
| 76 result.useAntiAlias = useSkiaAntiAlias; |
| 77 |
| 78 if (!result.useHinting) |
| 79 result.hintStyle = SkPaint::kNo_Hinting; |
| 80 else if (result.useHinting == FontRenderStyle::NoPreference) |
| 81 result.hintStyle = skiaHinting; |
| 82 |
| 83 if (result.useBitmaps == FontRenderStyle::NoPreference) |
| 84 result.useBitmaps = useSkiaBitmaps; |
| 85 if (result.useAutoHint == FontRenderStyle::NoPreference) |
| 86 result.useAutoHint = useSkiaAutoHint; |
| 87 if (result.useAntiAlias == FontRenderStyle::NoPreference) |
| 88 result.useAntiAlias = useSkiaAntiAlias; |
| 89 if (result.useSubpixelRendering == FontRenderStyle::NoPreference) |
| 90 result.useSubpixelRendering = useSkiaSubpixelRendering; |
| 91 |
| 92 // TestRunner specifically toggles the subpixel positioning flag. |
| 93 if (result.useSubpixelPositioning == FontRenderStyle::NoPreference |
| 94 || LayoutTestSupport::isRunningLayoutTest()) |
| 95 result.useSubpixelPositioning = FontDescription::subpixelPositioning(); |
| 96 |
| 97 return result; |
| 98 } |
| 99 |
| 100 void FontRenderStyle::applyToPaint(SkPaint& paint, float deviceScaleFactor) cons
t |
| 101 { |
| 102 paint.setAntiAlias(useAntiAlias); |
| 103 paint.setHinting(static_cast<SkPaint::Hinting>(hintStyle)); |
| 104 paint.setEmbeddedBitmapText(useBitmaps); |
| 105 paint.setAutohinted(useAutoHint); |
| 106 if (useAntiAlias) |
| 107 paint.setLCDRenderText(useSubpixelRendering); |
| 108 |
| 109 // Do not enable subpixel text on low-dpi if full hinting is requested. |
| 110 bool useSubpixelText = (paint.getHinting() != SkPaint::kFull_Hinting || devi
ceScaleFactor > 1.0f); |
| 111 |
| 112 // TestRunner specifically toggles the subpixel positioning flag. |
| 113 if (useSubpixelText && !LayoutTestSupport::isRunningLayoutTest()) |
| 114 paint.setSubpixelText(true); |
| 115 else |
| 116 paint.setSubpixelText(useSubpixelPositioning); |
| 117 } |
| 118 |
| 119 } // namespace blink |
OLD | NEW |