Changeset 254506 in webkit


Ignore:
Timestamp:
Jan 14, 2020 6:40:12 AM (4 years ago)
Author:
clopez@igalia.com
Message:

[Freetype] Support for the -webkit-font-smoothing CSS property
https://bugs.webkit.org/show_bug.cgi?id=54763

Reviewed by Simon Fraser.

Source/WebCore:

Pass the smoothing preference defined on the CSS style, so its
taken into account when drawing the font. If the CSS doesn't
specify any preference then it behaves like before this patch
(it tries to automatically antialias the font, if supported).

This patch sets the antialiasing value at drawing time without
affecting the font, like the Mac/iOS ports do. This approach is
maybe less efficient than taking into account the antialiasing
value when the font platform data its created, but its a better
fit for the current cross-platform code.
I did some benchmarks (see the bug above if you are curious) and
I was unable to prove this method is less efficient than setting
the antialising value when the font platform data is created.

Test: platform/gtk/fonts/webkit-font-smoothing.html

  • platform/graphics/cairo/CairoOperations.cpp:

(WebCore::Cairo::drawGlyphsToContext):
(WebCore::Cairo::drawGlyphsShadow):
(WebCore::Cairo::drawGlyphs):

  • platform/graphics/cairo/CairoOperations.h:
  • platform/graphics/cairo/CairoUtilities.cpp:
  • platform/graphics/cairo/CairoUtilities.h:
  • platform/graphics/cairo/FontCairo.cpp:

(WebCore::FontCascade::drawGlyphs):

  • platform/graphics/cairo/GraphicsContextImplCairo.cpp:

(WebCore::GraphicsContextImplCairo::drawGlyphs):

  • platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp:

(Nicosia::CairoOperationRecorder::drawGlyphs):

LayoutTests:

Add a regression test. This test is specific for platform gtk because
it depends on the custom fonts.conf file that its used for GTK layout
tests.

  • platform/gtk/TestExpectations:
  • platform/gtk/fast/css/font-smoothing-expected.png:
  • platform/gtk/fonts/webkit-font-smoothing-expected.html: Added.
  • platform/gtk/fonts/webkit-font-smoothing.html: Added.
  • platform/wpe/TestExpectations:
  • platform/wpe/fast/css/font-smoothing-expected.png: Added.
Location:
trunk
Files:
3 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r254505 r254506  
     12020-01-14  Carlos Alberto Lopez Perez  <clopez@igalia.com>
     2
     3        [Freetype] Support for the -webkit-font-smoothing CSS property
     4        https://bugs.webkit.org/show_bug.cgi?id=54763
     5
     6        Reviewed by Simon Fraser.
     7
     8        Add a regression test. This test is specific for platform gtk because
     9        it depends on the custom fonts.conf file that its used for GTK layout
     10        tests.
     11
     12        * platform/gtk/TestExpectations:
     13        * platform/gtk/fast/css/font-smoothing-expected.png:
     14        * platform/gtk/fonts/webkit-font-smoothing-expected.html: Added.
     15        * platform/gtk/fonts/webkit-font-smoothing.html: Added.
     16        * platform/wpe/TestExpectations:
     17        * platform/wpe/fast/css/font-smoothing-expected.png: Added.
     18
    1192020-01-14  youenn fablet  <youenn@apple.com>
    220
  • trunk/LayoutTests/platform/gtk/TestExpectations

    r254486 r254506  
    815815webkit.org/b/142270 fast/canvas/canvas-ellipse-zero-lineto.html [ Failure ]
    816816
    817 webkit.org/b/142819 fast/text/baseline-inline-block.html [ ImageOnlyFailure ]
    818 
    819817# This feature is only enabled on Mac and iOS right now
    820818contentfiltering [ Skip ]
     
    12061204webkit.org/b/206002 http/wpt/css/css-highlight-api/highlight-text-replace.html [ ImageOnlyFailure ]
    12071205webkit.org/b/206002 http/wpt/css/css-highlight-api/highlight-text.html [ ImageOnlyFailure ]
     1206
     1207webkit.org/b/205186 compositing/contents-format/subpixel-antialiased-text.html [ ImageOnlyFailure ]
     1208webkit.org/b/205187 fast/text/font-antialiasing-save-restore.html [ ImageOnlyFailure ]
    12081209
    12091210#////////////////////////////////////////////////////////////////////////////////////////
  • trunk/LayoutTests/platform/wpe/TestExpectations

    r254486 r254506  
    505505webkit.org/b/200165 imported/w3c/web-platform-tests/websockets/cookies/007.html [ Failure ]
    506506webkit.org/b/200165 imported/w3c/web-platform-tests/websockets/cookies/004.html [ Failure ]
     507
     508webkit.org/b/205186 compositing/contents-format/subpixel-antialiased-text.html [ ImageOnlyFailure ]
     509webkit.org/b/205187 fast/text/font-antialiasing-save-restore.html [ ImageOnlyFailure ]
    507510
    508511#////////////////////////////////////////////////////////////////////////////////////////
  • trunk/Source/WebCore/ChangeLog

    r254505 r254506  
     12020-01-14  Carlos Alberto Lopez Perez  <clopez@igalia.com>
     2
     3        [Freetype] Support for the -webkit-font-smoothing CSS property
     4        https://bugs.webkit.org/show_bug.cgi?id=54763
     5
     6        Reviewed by Simon Fraser.
     7
     8        Pass the smoothing preference defined on the CSS style, so its
     9        taken into account when drawing the font. If the CSS doesn't
     10        specify any preference then it behaves like before this patch
     11        (it tries to automatically antialias the font, if supported).
     12
     13        This patch sets the antialiasing value at drawing time without
     14        affecting the font, like the Mac/iOS ports do. This approach is
     15        maybe less efficient than taking into account the antialiasing
     16        value when the font platform data its created, but its a better
     17        fit for the current cross-platform code.
     18        I did some benchmarks (see the bug above if you are curious) and
     19        I was unable to prove this method is less efficient than setting
     20        the antialising value when the font platform data is created.
     21
     22        Test: platform/gtk/fonts/webkit-font-smoothing.html
     23
     24        * platform/graphics/cairo/CairoOperations.cpp:
     25        (WebCore::Cairo::drawGlyphsToContext):
     26        (WebCore::Cairo::drawGlyphsShadow):
     27        (WebCore::Cairo::drawGlyphs):
     28        * platform/graphics/cairo/CairoOperations.h:
     29        * platform/graphics/cairo/CairoUtilities.cpp:
     30        * platform/graphics/cairo/CairoUtilities.h:
     31        * platform/graphics/cairo/FontCairo.cpp:
     32        (WebCore::FontCascade::drawGlyphs):
     33        * platform/graphics/cairo/GraphicsContextImplCairo.cpp:
     34        (WebCore::GraphicsContextImplCairo::drawGlyphs):
     35        * platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp:
     36        (Nicosia::CairoOperationRecorder::drawGlyphs):
     37
    1382020-01-14  youenn fablet  <youenn@apple.com>
    239
  • trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp

    r253359 r254506  
    3636#if USE(CAIRO)
    3737
     38#include "CairoUniquePtr.h"
    3839#include "CairoUtilities.h"
    3940#include "DrawErrorUnderline.h"
     
    307308}
    308309
    309 static void drawGlyphsToContext(cairo_t* context, cairo_scaled_font_t* scaledFont, double syntheticBoldOffset, const Vector<cairo_glyph_t>& glyphs)
     310static void drawGlyphsToContext(cairo_t* context, cairo_scaled_font_t* scaledFont, double syntheticBoldOffset, const Vector<cairo_glyph_t>& glyphs, FontSmoothingMode fontSmoothingMode)
    310311{
    311312    cairo_matrix_t originalTransform;
     
    314315
    315316    cairo_set_scaled_font(context, scaledFont);
     317
     318    // The scaled font defaults to FontSmoothingMode::AutoSmoothing. Only override antialiasing settings if its not auto.
     319    if (fontSmoothingMode != FontSmoothingMode::AutoSmoothing) {
     320        CairoUniquePtr<cairo_font_options_t> fontOptionsSmoothing(cairo_font_options_copy(getDefaultCairoFontOptions()));
     321        switch (fontSmoothingMode) {
     322        case FontSmoothingMode::Antialiased:
     323            cairo_font_options_set_antialias(fontOptionsSmoothing.get(), CAIRO_ANTIALIAS_GRAY);
     324            break;
     325        case FontSmoothingMode::SubpixelAntialiased:
     326            cairo_font_options_set_antialias(fontOptionsSmoothing.get(), CAIRO_ANTIALIAS_SUBPIXEL);
     327            break;
     328        case FontSmoothingMode::NoSmoothing:
     329            cairo_font_options_set_antialias(fontOptionsSmoothing.get(), CAIRO_ANTIALIAS_NONE);
     330            break;
     331        default:
     332            ASSERT_NOT_REACHED();
     333        }
     334        cairo_set_font_options(context, fontOptionsSmoothing.get());
     335    }
     336
    316337    cairo_show_glyphs(context, glyphs.data(), glyphs.size());
    317338
     
    324345}
    325346
    326 static void drawGlyphsShadow(PlatformContextCairo& platformContext, const ShadowState& shadowState, TextDrawingModeFlags textDrawingMode, const FloatSize& shadowOffset, const Color& shadowColor, const FloatPoint& point, cairo_scaled_font_t* scaledFont, double syntheticBoldOffset, const Vector<cairo_glyph_t>& glyphs)
     347static void drawGlyphsShadow(PlatformContextCairo& platformContext, const ShadowState& shadowState, TextDrawingModeFlags textDrawingMode, const FloatSize& shadowOffset, const Color& shadowColor, const FloatPoint& point, cairo_scaled_font_t* scaledFont, double syntheticBoldOffset, const Vector<cairo_glyph_t>& glyphs, FontSmoothingMode fontSmoothingMode)
    327348{
    328349    ShadowBlur shadow({ shadowState.blur, shadowState.blur }, shadowState.offset, shadowState.color, shadowState.ignoreTransforms);
     
    337358        cairo_translate(context, shadowOffset.width(), shadowOffset.height());
    338359        setSourceRGBAFromColor(context, shadowColor);
    339         drawGlyphsToContext(context, scaledFont, syntheticBoldOffset, glyphs);
     360        drawGlyphsToContext(context, scaledFont, syntheticBoldOffset, glyphs, fontSmoothingMode);
    340361
    341362        cairo_restore(context);
     
    348369
    349370    shadow.drawShadowLayer(State::getCTM(platformContext), State::getClipBounds(platformContext), fontExtentsRect,
    350         [scaledFont, syntheticBoldOffset, &glyphs](GraphicsContext& shadowContext)
     371        [scaledFont, syntheticBoldOffset, &glyphs, fontSmoothingMode](GraphicsContext& shadowContext)
    351372        {
    352             drawGlyphsToContext(shadowContext.platformContext()->cr(), scaledFont, syntheticBoldOffset, glyphs);
     373            drawGlyphsToContext(shadowContext.platformContext()->cr(), scaledFont, syntheticBoldOffset, glyphs, fontSmoothingMode);
    353374        },
    354375        [&platformContext, &shadowState](ImageBuffer& layerImage, const FloatPoint& layerOrigin, const FloatSize& layerSize)
     
    837858}
    838859
    839 void drawGlyphs(PlatformContextCairo& platformContext, const FillSource& fillSource, const StrokeSource& strokeSource, const ShadowState& shadowState, const FloatPoint& point, cairo_scaled_font_t* scaledFont, double syntheticBoldOffset, const Vector<cairo_glyph_t>& glyphs, float xOffset, TextDrawingModeFlags textDrawingMode, float strokeThickness, const FloatSize& shadowOffset, const Color& shadowColor)
    840 {
    841     drawGlyphsShadow(platformContext, shadowState, textDrawingMode, shadowOffset, shadowColor, point, scaledFont, syntheticBoldOffset, glyphs);
     860void drawGlyphs(PlatformContextCairo& platformContext, const FillSource& fillSource, const StrokeSource& strokeSource, const ShadowState& shadowState, const FloatPoint& point, cairo_scaled_font_t* scaledFont, double syntheticBoldOffset, const Vector<cairo_glyph_t>& glyphs, float xOffset, TextDrawingModeFlags textDrawingMode, float strokeThickness, const FloatSize& shadowOffset, const Color& shadowColor, FontSmoothingMode fontSmoothingMode)
     861{
     862    drawGlyphsShadow(platformContext, shadowState, textDrawingMode, shadowOffset, shadowColor, point, scaledFont, syntheticBoldOffset, glyphs, fontSmoothingMode);
    842863
    843864    cairo_t* cr = platformContext.cr();
     
    846867    if (textDrawingMode & TextModeFill) {
    847868        prepareForFilling(cr, fillSource, AdjustPatternForGlobalAlpha);
    848         drawGlyphsToContext(cr, scaledFont, syntheticBoldOffset, glyphs);
     869        drawGlyphsToContext(cr, scaledFont, syntheticBoldOffset, glyphs, fontSmoothingMode);
    849870    }
    850871
  • trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h

    r252965 r254506  
    137137void clearRect(PlatformContextCairo&, const FloatRect&);
    138138
    139 void drawGlyphs(PlatformContextCairo&, const FillSource&, const StrokeSource&, const ShadowState&, const FloatPoint&, cairo_scaled_font_t*, double, const Vector<cairo_glyph_t>&, float, TextDrawingModeFlags, float, const FloatSize&, const Color&);
     139void drawGlyphs(PlatformContextCairo&, const FillSource&, const StrokeSource&, const ShadowState&, const FloatPoint&, cairo_scaled_font_t*, double, const Vector<cairo_glyph_t>&, float, TextDrawingModeFlags, float, const FloatSize&, const Color&, FontSmoothingMode);
    140140
    141141void drawNativeImage(PlatformContextCairo&, cairo_surface_t*, const FloatRect&, const FloatRect&, const ImagePaintingOptions&, float, const ShadowState&);
  • trunk/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp

    r254502 r254506  
    5757namespace WebCore {
    5858
    59 #if USE(FREETYPE) && !PLATFORM(GTK)
     59#if USE(CAIRO) && !PLATFORM(GTK)
    6060const cairo_font_options_t* getDefaultCairoFontOptions()
    6161{
  • trunk/Source/WebCore/platform/graphics/cairo/CairoUtilities.h

    r254502 r254506  
    7171    FT_Face m_ftFace { nullptr };
    7272};
     73#endif
    7374
     75#if USE(CAIRO)
    7476const cairo_font_options_t* getDefaultCairoFontOptions();
    7577#endif
  • trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp

    r254190 r254506  
    5050
    5151void FontCascade::drawGlyphs(GraphicsContext& context, const Font& font, const GlyphBuffer& glyphBuffer,
    52     unsigned from, unsigned numGlyphs, const FloatPoint& point, FontSmoothingMode)
     52    unsigned from, unsigned numGlyphs, const FloatPoint& point, FontSmoothingMode fontSmoothingMode)
    5353{
    5454    if (!font.platformData().size())
     
    7777    Cairo::drawGlyphs(*context.platformContext(), Cairo::FillSource(state), Cairo::StrokeSource(state),
    7878        Cairo::ShadowState(state), point, scaledFont, syntheticBoldOffset, glyphs, xOffset,
    79         state.textDrawingMode, state.strokeThickness, state.shadowOffset, state.shadowColor);
     79        state.textDrawingMode, state.strokeThickness, state.shadowOffset, state.shadowColor,
     80        fontSmoothingMode);
    8081}
    8182
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.cpp

    r254190 r254506  
    234234void GraphicsContextImplCairo::drawGlyphs(const Font& font, const GlyphBuffer& glyphBuffer, unsigned from, unsigned numGlyphs, const FloatPoint& point, FontSmoothingMode fontSmoothing)
    235235{
    236     UNUSED_PARAM(fontSmoothing);
    237236    if (!font.platformData().size())
    238237        return;
     
    259258    Cairo::drawGlyphs(m_platformContext, Cairo::FillSource(state), Cairo::StrokeSource(state),
    260259        Cairo::ShadowState(state), point, scaledFont, syntheticBoldOffset, glyphs, xOffset,
    261         state.textDrawingMode, state.strokeThickness, state.shadowOffset, state.shadowColor);
     260        state.textDrawingMode, state.strokeThickness, state.shadowOffset, state.shadowColor,
     261        fontSmoothing);
    262262}
    263263
  • trunk/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp

    r249217 r254506  
    494494void CairoOperationRecorder::drawGlyphs(const Font& font, const GlyphBuffer& glyphBuffer, unsigned from, unsigned numGlyphs, const FloatPoint& point, FontSmoothingMode fontSmoothing)
    495495{
    496     struct DrawGlyphs final : PaintingOperation, OperationData<Cairo::FillSource, Cairo::StrokeSource, Cairo::ShadowState, FloatPoint, RefPtr<cairo_scaled_font_t>, float, Vector<cairo_glyph_t>, float, TextDrawingModeFlags, float, FloatSize, Color> {
     496    struct DrawGlyphs final : PaintingOperation, OperationData<Cairo::FillSource, Cairo::StrokeSource, Cairo::ShadowState, FloatPoint, RefPtr<cairo_scaled_font_t>, float, Vector<cairo_glyph_t>, float, TextDrawingModeFlags, float, FloatSize, Color, FontSmoothingMode> {
    497497        virtual ~DrawGlyphs() = default;
    498498
     
    500500        {
    501501            Cairo::drawGlyphs(contextForReplay(replayer), arg<0>(), arg<1>(), arg<2>(), arg<3>(), arg<4>().get(),
    502                 arg<5>(), arg<6>(), arg<7>(), arg<8>(), arg<9>(), arg<10>(), arg<11>());
     502                arg<5>(), arg<6>(), arg<7>(), arg<8>(), arg<9>(), arg<10>(), arg<11>(), arg<12>());
    503503        }
    504504
     
    509509    };
    510510
    511     UNUSED_PARAM(fontSmoothing);
    512511    if (!font.platformData().size())
    513512        return;
     
    532531        RefPtr<cairo_scaled_font_t>(font.platformData().scaledFont()),
    533532        font.syntheticBoldOffset(), WTFMove(glyphs), xOffset, state.textDrawingMode,
    534         state.strokeThickness, state.shadowOffset, state.shadowColor));
     533        state.strokeThickness, state.shadowOffset, state.shadowColor, fontSmoothing));
    535534}
    536535
Note: See TracChangeset for help on using the changeset viewer.