Title: [177078] trunk
Revision
177078
Author
mrobin...@webkit.org
Date
2014-12-10 10:37:39 -0800 (Wed, 10 Dec 2014)

Log Message

[GTK] Add support for text-decoration-skip
https://bugs.webkit.org/show_bug.cgi?id=131540

Reviewed by Gustavo Noronha Silva.

Source/WebCore:

No new tests. This is covered by existing layout tests.

* platform/graphics/cairo/FontCairo.cpp:
(WebCore::GlyphIterationState): Added this class, a modified version of the Mac
port's implementation.
(WebCore::Font::dashesForIntersectionsWithRect): Ditto.
* platform/graphics/cairo/FontCairoHarfbuzzNG.cpp:
(WebCore::Font::getGlyphsAndAdvancesForComplexText): Added an implementation for
HarfBuzz that just fills out the GlyphBuffer, but does not render it.
(WebCore::Font::drawComplexText): Use the new getGlyphsAndAdvancesForComplexText
in a similar way to the Mac port.
* platform/graphics/harfbuzz/HarfBuzzShaper.cpp:
(WebCore::HarfBuzzShaper::fillGlyphBufferFromHarfBuzzRun): We need to pass the current
character index to GlyphBuffer:add since it's used by dashesForIntersectionsWithRect
and otherwise it will be uninitialized when we try to access it.

Source/WTF:

* wtf/Platform.h: Enable text decoration skip by default.

LayoutTests:

* platform/gtk/TestExpectations: Unskip a test relying on text-decoration-skip
and skip a new test that has a newly exposed, but unrelated issue.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (177077 => 177078)


--- trunk/LayoutTests/ChangeLog	2014-12-10 18:15:13 UTC (rev 177077)
+++ trunk/LayoutTests/ChangeLog	2014-12-10 18:37:39 UTC (rev 177078)
@@ -1,3 +1,13 @@
+2014-12-10  Martin Robinson  <mrobin...@igalia.com>
+
+        [GTK] Add support for text-decoration-skip
+        https://bugs.webkit.org/show_bug.cgi?id=131540
+
+        Reviewed by Gustavo Noronha Silva.
+
+        * platform/gtk/TestExpectations: Unskip a test relying on text-decoration-skip
+        and skip a new test that has a newly exposed, but unrelated issue.
+
 2014-12-10  Carlos Alberto Lopez Perez  <clo...@igalia.com>
 
         [GTK] Unreviewed GTK gardening.

Modified: trunk/LayoutTests/platform/gtk/TestExpectations (177077 => 177078)


--- trunk/LayoutTests/platform/gtk/TestExpectations	2014-12-10 18:15:13 UTC (rev 177077)
+++ trunk/LayoutTests/platform/gtk/TestExpectations	2014-12-10 18:37:39 UTC (rev 177078)
@@ -1969,6 +1969,7 @@
 webkit.org/b/124504 fast/text/break-word-pre-wrap.html [ ImageOnlyFailure ]
 
 webkit.org/b/124507 fast/css3-text/css3-text-decoration/text-decoration-skip/text-decoration-skip-ink.html [ ImageOnlyFailure ]
+webkit.org/b/139486 fast/css3-text/css3-text-decoration/text-decoration-skip/decoration-skip-crash-fallback-svg.html [ ImageOnlyFailure ]
 
 webkit.org/b/124509 media/video-controls-captions-trackmenu-hide-on-click-outside.html [ Failure ]
 webkit.org/b/124509 media/video-controls-captions-trackmenu-hide-on-click.html [ Failure ]
@@ -2112,8 +2113,6 @@
 
 webkit.org/b/131501 fast/css3-text/css3-text-decoration/text-decoration-skip/glyph-inside-underline.html [ ImageOnlyFailure ]
 
-webkit.org/b/131540 fast/css3-text/css3-text-decoration/text-decoration-skip/text-decoration-skip-ink-svg.html [ ImageOnlyFailure ]
-
 webkit.org/b/130971 media/track/track-remove-track.html [ Timeout ]
 
 webkit.org/b/117756 media/track/media-element-enqueue-event-crash.html [ Timeout Pass Crash ]

Modified: trunk/Source/WTF/ChangeLog (177077 => 177078)


--- trunk/Source/WTF/ChangeLog	2014-12-10 18:15:13 UTC (rev 177077)
+++ trunk/Source/WTF/ChangeLog	2014-12-10 18:37:39 UTC (rev 177078)
@@ -1,3 +1,12 @@
+2014-12-10  Martin Robinson  <mrobin...@igalia.com>
+
+        [GTK] Add support for text-decoration-skip
+        https://bugs.webkit.org/show_bug.cgi?id=131540
+
+        Reviewed by Gustavo Noronha Silva.
+
+        * wtf/Platform.h: Enable text decoration skip by default.
+
 2014-12-09  David Kilzer  <ddkil...@apple.com>
 
         Switch from using PLATFORM_NAME to SDK selectors in ANGLE, bmalloc, gtest, _javascript_Core, WTF

Modified: trunk/Source/WTF/wtf/Platform.h (177077 => 177078)


--- trunk/Source/WTF/wtf/Platform.h	2014-12-10 18:15:13 UTC (rev 177077)
+++ trunk/Source/WTF/wtf/Platform.h	2014-12-10 18:37:39 UTC (rev 177078)
@@ -1056,6 +1056,7 @@
 #if PLATFORM(GTK) || PLATFORM(EFL)
 #undef ENABLE_OPENTYPE_VERTICAL
 #define ENABLE_OPENTYPE_VERTICAL 1
+#define ENABLE_CSS3_TEXT_DECORATION_SKIP_INK 1
 #endif
 
 #if PLATFORM(COCOA)

Modified: trunk/Source/WebCore/ChangeLog (177077 => 177078)


--- trunk/Source/WebCore/ChangeLog	2014-12-10 18:15:13 UTC (rev 177077)
+++ trunk/Source/WebCore/ChangeLog	2014-12-10 18:37:39 UTC (rev 177078)
@@ -1,3 +1,26 @@
+2014-12-10  Martin Robinson  <mrobin...@igalia.com>
+
+        [GTK] Add support for text-decoration-skip
+        https://bugs.webkit.org/show_bug.cgi?id=131540
+
+        Reviewed by Gustavo Noronha Silva.
+
+        No new tests. This is covered by existing layout tests.
+
+        * platform/graphics/cairo/FontCairo.cpp:
+        (WebCore::GlyphIterationState): Added this class, a modified version of the Mac
+        port's implementation.
+        (WebCore::Font::dashesForIntersectionsWithRect): Ditto.
+        * platform/graphics/cairo/FontCairoHarfbuzzNG.cpp:
+        (WebCore::Font::getGlyphsAndAdvancesForComplexText): Added an implementation for
+        HarfBuzz that just fills out the GlyphBuffer, but does not render it.
+        (WebCore::Font::drawComplexText): Use the new getGlyphsAndAdvancesForComplexText
+        in a similar way to the Mac port.
+        * platform/graphics/harfbuzz/HarfBuzzShaper.cpp:
+        (WebCore::HarfBuzzShaper::fillGlyphBufferFromHarfBuzzRun): We need to pass the current
+        character index to GlyphBuffer:add since it's used by dashesForIntersectionsWithRect
+        and otherwise it will be uninitialized when we try to access it.
+
 2014-12-10  Andreas Kling  <akl...@apple.com>
 
         REGRESSION(r177048) 11 failures on layout tests fast/selectors.

Modified: trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp (177077 => 177078)


--- trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp	2014-12-10 18:15:13 UTC (rev 177077)
+++ trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp	2014-12-10 18:37:39 UTC (rev 177078)
@@ -4,6 +4,7 @@
  * Copyright (C) 2007, 2008 Alp Toker <a...@atoker.com>
  * Copyright (C) 2009 Dirk Schulze <k...@webkit.org>
  * Copyright (C) 2010 Holger Hans Peter Freyther
+ * Copyright (C) 2014 Igalia S.L.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -38,6 +39,7 @@
 #include "ImageBuffer.h"
 #include "Pattern.h"
 #include "PlatformContextCairo.h"
+#include "PlatformPathCairo.h"
 #include "ShadowBlur.h"
 #include "SimpleFontData.h"
 
@@ -136,4 +138,221 @@
     cairo_restore(cr);
 }
 
+#if ENABLE(CSS3_TEXT_DECORATION_SKIP_INK)
+struct GlyphIterationState {
+    GlyphIterationState(FloatPoint startingPoint, FloatPoint currentPoint, float centerOfLine, float minX, float maxX)
+        : startingPoint(startingPoint)
+        , currentPoint(currentPoint)
+        , centerOfLine(centerOfLine)
+        , minX(minX)
+        , maxX(maxX)
+    {
+    }
+    FloatPoint startingPoint;
+    FloatPoint currentPoint;
+    float centerOfLine;
+    float minX;
+    float maxX;
+};
+
+static bool findIntersectionPoint(float y, FloatPoint p1, FloatPoint p2, float& x)
+{
+    x = p1.x() + (y - p1.y()) * (p2.x() - p1.x()) / (p2.y() - p1.y());
+    return (p1.y() < y && p2.y() > y) || (p1.y() > y && p2.y() < y);
 }
+
+static void updateX(GlyphIterationState& state, float x)
+{
+    state.minX = std::min(state.minX, x);
+    state.maxX = std::max(state.maxX, x);
+}
+
+// This function is called by Path::apply and is therefore invoked for each contour in a glyph. This
+// function models each contours as a straight line and calculates the intersections between each
+// pseudo-contour and the vertical center of the underline found in GlyphIterationState::centerOfLine.
+// It keeps track of the leftmost and rightmost intersection in  GlyphIterationState::minX and 
+// GlyphIterationState::maxX.
+static void findPathIntersections(void* stateAsVoidPointer, const PathElement* element)
+{
+    auto& state = *static_cast<GlyphIterationState*>(stateAsVoidPointer);
+    bool doIntersection = false;
+    FloatPoint point = FloatPoint();
+    switch (element->type) {
+    case PathElementMoveToPoint:
+        state.startingPoint = element->points[0];
+        state.currentPoint = element->points[0];
+        break;
+    case PathElementAddLineToPoint:
+        doIntersection = true;
+        point = element->points[0];
+        break;
+    case PathElementAddQuadCurveToPoint:
+        doIntersection = true;
+        point = element->points[1];
+        break;
+    case PathElementAddCurveToPoint:
+        doIntersection = true;
+        point = element->points[2];
+        break;
+    case PathElementCloseSubpath:
+        doIntersection = true;
+        point = state.startingPoint;
+        break;
+    }
+
+    if (!doIntersection)
+        return;
+
+    float x;
+    if (findIntersectionPoint(state.centerOfLine, state.currentPoint, point, x))
+        updateX(state, x);
+
+    state.currentPoint = point;
+}
+
+class CairoGlyphToPathTranslator final : public GlyphToPathTranslator {
+public:
+    CairoGlyphToPathTranslator(const TextRun& textRun, const GlyphBuffer& glyphBuffer, const FloatPoint& textOrigin)
+        : m_index(0)
+        , m_textRun(textRun)
+        , m_glyphBuffer(glyphBuffer)
+        , m_fontData(glyphBuffer.fontDataAt(m_index))
+        , m_translation(AffineTransform().translate(textOrigin.x(), textOrigin.y()))
+    {
+        moveToNextValidGlyph();
+    }
+private:
+    virtual bool containsMorePaths() override
+    {
+        return m_index != m_glyphBuffer.size();
+    }
+    virtual Path path() override;
+    virtual std::pair<float, float> extents() override;
+    virtual GlyphUnderlineType underlineType() override;
+    virtual void advance() override;
+    void moveToNextValidGlyph();
+
+    int m_index;
+    const TextRun& m_textRun;
+    const GlyphBuffer& m_glyphBuffer;
+    const SimpleFontData* m_fontData;
+    AffineTransform m_translation;
+};
+
+Path CairoGlyphToPathTranslator::path()
+{
+    Path path;
+    path.ensurePlatformPath();
+
+    cairo_glyph_t cairoGlyph;
+    cairoGlyph.index = m_glyphBuffer.glyphAt(m_index);
+    cairo_set_scaled_font(path.platformPath()->context(), m_fontData->platformData().scaledFont());
+    cairo_glyph_path(path.platformPath()->context(), &cairoGlyph, 1);
+
+    float syntheticBoldOffset = m_fontData->syntheticBoldOffset();
+    if (syntheticBoldOffset) {
+        cairo_translate(path.platformPath()->context(), syntheticBoldOffset, 0);
+        cairo_show_glyphs(path.platformPath()->context(), &cairoGlyph, 1);
+    }
+
+    path.transform(m_translation);
+    return path;
+}
+
+std::pair<float, float> CairoGlyphToPathTranslator::extents()
+{
+    FloatPoint beginning = m_translation.mapPoint(FloatPoint());
+    FloatSize end = m_translation.mapSize(m_glyphBuffer.advanceAt(m_index));
+    return std::make_pair(static_cast<float>(beginning.x()), static_cast<float>(beginning.x() + end.width()));
+}
+
+GlyphToPathTranslator::GlyphUnderlineType CairoGlyphToPathTranslator::underlineType()
+{
+    return computeUnderlineType(m_textRun, m_glyphBuffer, m_index);
+}
+
+void CairoGlyphToPathTranslator::moveToNextValidGlyph()
+{
+    if (!m_fontData->isSVGFont())
+        return;
+    advance();
+}
+
+void CairoGlyphToPathTranslator::advance()
+{
+    do {
+        GlyphBufferAdvance advance = m_glyphBuffer.advanceAt(m_index);
+        m_translation = m_translation.translate(advance.width(), advance.height());
+        ++m_index;
+        if (m_index >= m_glyphBuffer.size())
+            break;
+        m_fontData = m_glyphBuffer.fontDataAt(m_index);
+    } while (m_fontData->isSVGFont() && m_index < m_glyphBuffer.size());
+}
+
+DashArray Font::dashesForIntersectionsWithRect(const TextRun& run, const FloatPoint& textOrigin, const FloatRect& lineExtents) const
+{
+    if (loadingCustomFonts())
+        return DashArray();
+
+    GlyphBuffer glyphBuffer;
+    glyphBuffer.saveOffsetsInString();
+    float deltaX;
+    if (codePath(run) != Font::Complex)
+        deltaX = getGlyphsAndAdvancesForSimpleText(run, 0, run.length(), glyphBuffer);
+    else
+        deltaX = getGlyphsAndAdvancesForComplexText(run, 0, run.length(), glyphBuffer);
+
+    if (!glyphBuffer.size())
+        return DashArray();
+
+    // FIXME: Handle SVG + non-SVG interleaved runs. https://bugs.webkit.org/show_bug.cgi?id=133778
+    const SimpleFontData* fontData = glyphBuffer.fontDataAt(0);
+    std::unique_ptr<GlyphToPathTranslator> translator;
+    bool isSVG = false;
+    FloatPoint origin = FloatPoint(textOrigin.x() + deltaX, textOrigin.y());
+    if (!fontData->isSVGFont())
+        translator = std::make_unique<CairoGlyphToPathTranslator>(run, glyphBuffer, origin);
+    else {
+        TextRun::RenderingContext* renderingContext = run.renderingContext();
+        if (!renderingContext)
+            return DashArray();
+        translator = renderingContext->createGlyphToPathTranslator(*fontData, &run, glyphBuffer, 0, glyphBuffer.size(), origin);
+        isSVG = true;
+    }
+    DashArray result;
+    for (int index = 0; translator->containsMorePaths(); ++index, translator->advance()) {
+        float centerOfLine = lineExtents.y() + (lineExtents.height() / 2);
+        GlyphIterationState info = GlyphIterationState(FloatPoint(), FloatPoint(), centerOfLine, lineExtents.x() + lineExtents.width(), lineExtents.x());
+        const SimpleFontData* localFontData = glyphBuffer.fontDataAt(index);
+        if (!localFontData || (!isSVG && localFontData->isSVGFont()) || (isSVG && localFontData != fontData)) {
+            // The advances will get all messed up if we do anything other than bail here.
+            result.clear();
+            break;
+        }
+        switch (translator->underlineType()) {
+        case GlyphToPathTranslator::GlyphUnderlineType::SkipDescenders: {
+            Path path = translator->path();
+            path.apply(&info, &findPathIntersections);
+            if (info.minX < info.maxX) {
+                result.append(info.minX - lineExtents.x());
+                result.append(info.maxX - lineExtents.x());
+            }
+            break;
+        }
+        case GlyphToPathTranslator::GlyphUnderlineType::SkipGlyph: {
+            std::pair<float, float> extents = translator->extents();
+            result.append(extents.first - lineExtents.x());
+            result.append(extents.second - lineExtents.x());
+            break;
+        }
+        case GlyphToPathTranslator::GlyphUnderlineType::DrawOverGlyph:
+            // Nothing to do
+            break;
+        }
+    }
+    return result;
+}
+#endif
+
+}

Modified: trunk/Source/WebCore/platform/graphics/cairo/FontCairoHarfbuzzNG.cpp (177077 => 177078)


--- trunk/Source/WebCore/platform/graphics/cairo/FontCairoHarfbuzzNG.cpp	2014-12-10 18:15:13 UTC (rev 177077)
+++ trunk/Source/WebCore/platform/graphics/cairo/FontCairoHarfbuzzNG.cpp	2014-12-10 18:37:39 UTC (rev 177078)
@@ -38,20 +38,36 @@
 
 namespace WebCore {
 
-float Font::drawComplexText(GraphicsContext* context, const TextRun& run, const FloatPoint& point, int, int) const
+
+float Font::getGlyphsAndAdvancesForComplexText(const TextRun& run, int, int, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot /* forTextEmphasis */) const
 {
-    GlyphBuffer glyphBuffer;
     HarfBuzzShaper shaper(this, run);
-    if (shaper.shape(&glyphBuffer)) {
-        FloatPoint startPoint = point;
-        float startX = startPoint.x();
-        drawGlyphBuffer(context, run, glyphBuffer, startPoint);
-        return startPoint.x() - startX;
+    if (!shaper.shape(&glyphBuffer)) {
+        LOG_ERROR("Shaper couldn't shape glyphBuffer.");
+        return 0;
     }
-    LOG_ERROR("Shaper couldn't shape glyphBuffer.");
+
+    // FIXME: Mac returns an initial advance here.
     return 0;
 }
+float Font::drawComplexText(GraphicsContext* context, const TextRun& run, const FloatPoint& point, int from, int to) const
+{
+    // This glyph buffer holds our glyphs + advances + font data for each glyph.
+    GlyphBuffer glyphBuffer;
 
+    float startX = point.x() + getGlyphsAndAdvancesForComplexText(run, from, to, glyphBuffer);
+
+    // We couldn't generate any glyphs for the run. Give up.
+    if (glyphBuffer.isEmpty())
+        return 0;
+
+    // Draw the glyph buffer now at the starting point returned in startX.
+    FloatPoint startPoint(startX, point.y());
+    drawGlyphBuffer(context, run, glyphBuffer, startPoint);
+
+    return startPoint.x() - startX;
+}
+
 void Font::drawEmphasisMarksForComplexText(GraphicsContext* /* context */, const TextRun& /* run */, const AtomicString& /* mark */, const FloatPoint& /* point */, int /* from */, int /* to */) const
 {
     notImplemented();

Modified: trunk/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp (177077 => 177078)


--- trunk/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp	2014-12-10 18:15:13 UTC (rev 177077)
+++ trunk/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp	2014-12-10 18:37:39 UTC (rev 177078)
@@ -579,10 +579,10 @@
             if (currentCharacterIndex > m_run.length())
                 m_startOffset.move(glyphAdvanceX, glyphAdvanceY);
             else
-                glyphBuffer->add(glyphs[i], currentRun->fontData(), createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY));
+                glyphBuffer->add(glyphs[i], currentRun->fontData(), createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY), currentCharacterIndex);
         } else {
             if (currentCharacterIndex < m_run.length())
-                glyphBuffer->add(glyphs[i], currentRun->fontData(), createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY));
+                glyphBuffer->add(glyphs[i], currentRun->fontData(), createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY), currentCharacterIndex);
         }
     }
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to