<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[177078] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/177078">177078</a></dd>
<dt>Author</dt> <dd>mrobinson@webkit.org</dd>
<dt>Date</dt> <dd>2014-12-10 10:37:39 -0800 (Wed, 10 Dec 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[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.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformgtkTestExpectations">trunk/LayoutTests/platform/gtk/TestExpectations</a></li>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfPlatformh">trunk/Source/WTF/wtf/Platform.h</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscairoFontCairocpp">trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscairoFontCairoHarfbuzzNGcpp">trunk/Source/WebCore/platform/graphics/cairo/FontCairoHarfbuzzNG.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsharfbuzzHarfBuzzShapercpp">trunk/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (177077 => 177078)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-12-10 18:15:13 UTC (rev 177077)
+++ trunk/LayoutTests/ChangeLog        2014-12-10 18:37:39 UTC (rev 177078)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2014-12-10  Martin Robinson  &lt;mrobinson@igalia.com&gt;
+
+        [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.
+
</ins><span class="cx"> 2014-12-10  Carlos Alberto Lopez Perez  &lt;clopez@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GTK] Unreviewed GTK gardening.
</span></span></pre></div>
<a id="trunkLayoutTestsplatformgtkTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/gtk/TestExpectations (177077 => 177078)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1969,6 +1969,7 @@
</span><span class="cx"> webkit.org/b/124504 fast/text/break-word-pre-wrap.html [ ImageOnlyFailure ]
</span><span class="cx"> 
</span><span class="cx"> webkit.org/b/124507 fast/css3-text/css3-text-decoration/text-decoration-skip/text-decoration-skip-ink.html [ ImageOnlyFailure ]
</span><ins>+webkit.org/b/139486 fast/css3-text/css3-text-decoration/text-decoration-skip/decoration-skip-crash-fallback-svg.html [ ImageOnlyFailure ]
</ins><span class="cx"> 
</span><span class="cx"> webkit.org/b/124509 media/video-controls-captions-trackmenu-hide-on-click-outside.html [ Failure ]
</span><span class="cx"> webkit.org/b/124509 media/video-controls-captions-trackmenu-hide-on-click.html [ Failure ]
</span><span class="lines">@@ -2112,8 +2113,6 @@
</span><span class="cx"> 
</span><span class="cx"> webkit.org/b/131501 fast/css3-text/css3-text-decoration/text-decoration-skip/glyph-inside-underline.html [ ImageOnlyFailure ]
</span><span class="cx"> 
</span><del>-webkit.org/b/131540 fast/css3-text/css3-text-decoration/text-decoration-skip/text-decoration-skip-ink-svg.html [ ImageOnlyFailure ]
-
</del><span class="cx"> webkit.org/b/130971 media/track/track-remove-track.html [ Timeout ]
</span><span class="cx"> 
</span><span class="cx"> webkit.org/b/117756 media/track/media-element-enqueue-event-crash.html [ Timeout Pass Crash ]
</span></span></pre></div>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (177077 => 177078)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,12 @@
</span><ins>+2014-12-10  Martin Robinson  &lt;mrobinson@igalia.com&gt;
+
+        [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.
+
</ins><span class="cx"> 2014-12-09  David Kilzer  &lt;ddkilzer@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Switch from using PLATFORM_NAME to SDK selectors in ANGLE, bmalloc, gtest, JavaScriptCore, WTF
</span></span></pre></div>
<a id="trunkSourceWTFwtfPlatformh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/Platform.h (177077 => 177078)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1056,6 +1056,7 @@
</span><span class="cx"> #if PLATFORM(GTK) || PLATFORM(EFL)
</span><span class="cx"> #undef ENABLE_OPENTYPE_VERTICAL
</span><span class="cx"> #define ENABLE_OPENTYPE_VERTICAL 1
</span><ins>+#define ENABLE_CSS3_TEXT_DECORATION_SKIP_INK 1
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA)
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (177077 => 177078)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2014-12-10  Martin Robinson  &lt;mrobinson@igalia.com&gt;
+
+        [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.
+
</ins><span class="cx"> 2014-12-10  Andreas Kling  &lt;akling@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         REGRESSION(r177048) 11 failures on layout tests fast/selectors.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscairoFontCairocpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp (177077 => 177078)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -4,6 +4,7 @@
</span><span class="cx">  * Copyright (C) 2007, 2008 Alp Toker &lt;alp@atoker.com&gt;
</span><span class="cx">  * Copyright (C) 2009 Dirk Schulze &lt;krit@webkit.org&gt;
</span><span class="cx">  * Copyright (C) 2010 Holger Hans Peter Freyther
</span><ins>+ * Copyright (C) 2014 Igalia S.L.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -38,6 +39,7 @@
</span><span class="cx"> #include &quot;ImageBuffer.h&quot;
</span><span class="cx"> #include &quot;Pattern.h&quot;
</span><span class="cx"> #include &quot;PlatformContextCairo.h&quot;
</span><ins>+#include &quot;PlatformPathCairo.h&quot;
</ins><span class="cx"> #include &quot;ShadowBlur.h&quot;
</span><span class="cx"> #include &quot;SimpleFontData.h&quot;
</span><span class="cx"> 
</span><span class="lines">@@ -136,4 +138,221 @@
</span><span class="cx">     cairo_restore(cr);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#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&amp; x)
+{
+    x = p1.x() + (y - p1.y()) * (p2.x() - p1.x()) / (p2.y() - p1.y());
+    return (p1.y() &lt; y &amp;&amp; p2.y() &gt; y) || (p1.y() &gt; y &amp;&amp; p2.y() &lt; y);
</ins><span class="cx"> }
</span><ins>+
+static void updateX(GlyphIterationState&amp; 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&amp; state = *static_cast&lt;GlyphIterationState*&gt;(stateAsVoidPointer);
+    bool doIntersection = false;
+    FloatPoint point = FloatPoint();
+    switch (element-&gt;type) {
+    case PathElementMoveToPoint:
+        state.startingPoint = element-&gt;points[0];
+        state.currentPoint = element-&gt;points[0];
+        break;
+    case PathElementAddLineToPoint:
+        doIntersection = true;
+        point = element-&gt;points[0];
+        break;
+    case PathElementAddQuadCurveToPoint:
+        doIntersection = true;
+        point = element-&gt;points[1];
+        break;
+    case PathElementAddCurveToPoint:
+        doIntersection = true;
+        point = element-&gt;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&amp; textRun, const GlyphBuffer&amp; glyphBuffer, const FloatPoint&amp; 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&lt;float, float&gt; extents() override;
+    virtual GlyphUnderlineType underlineType() override;
+    virtual void advance() override;
+    void moveToNextValidGlyph();
+
+    int m_index;
+    const TextRun&amp; m_textRun;
+    const GlyphBuffer&amp; 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()-&gt;context(), m_fontData-&gt;platformData().scaledFont());
+    cairo_glyph_path(path.platformPath()-&gt;context(), &amp;cairoGlyph, 1);
+
+    float syntheticBoldOffset = m_fontData-&gt;syntheticBoldOffset();
+    if (syntheticBoldOffset) {
+        cairo_translate(path.platformPath()-&gt;context(), syntheticBoldOffset, 0);
+        cairo_show_glyphs(path.platformPath()-&gt;context(), &amp;cairoGlyph, 1);
+    }
+
+    path.transform(m_translation);
+    return path;
+}
+
+std::pair&lt;float, float&gt; CairoGlyphToPathTranslator::extents()
+{
+    FloatPoint beginning = m_translation.mapPoint(FloatPoint());
+    FloatSize end = m_translation.mapSize(m_glyphBuffer.advanceAt(m_index));
+    return std::make_pair(static_cast&lt;float&gt;(beginning.x()), static_cast&lt;float&gt;(beginning.x() + end.width()));
+}
+
+GlyphToPathTranslator::GlyphUnderlineType CairoGlyphToPathTranslator::underlineType()
+{
+    return computeUnderlineType(m_textRun, m_glyphBuffer, m_index);
+}
+
+void CairoGlyphToPathTranslator::moveToNextValidGlyph()
+{
+    if (!m_fontData-&gt;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 &gt;= m_glyphBuffer.size())
+            break;
+        m_fontData = m_glyphBuffer.fontDataAt(m_index);
+    } while (m_fontData-&gt;isSVGFont() &amp;&amp; m_index &lt; m_glyphBuffer.size());
+}
+
+DashArray Font::dashesForIntersectionsWithRect(const TextRun&amp; run, const FloatPoint&amp; textOrigin, const FloatRect&amp; 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&lt;GlyphToPathTranslator&gt; translator;
+    bool isSVG = false;
+    FloatPoint origin = FloatPoint(textOrigin.x() + deltaX, textOrigin.y());
+    if (!fontData-&gt;isSVGFont())
+        translator = std::make_unique&lt;CairoGlyphToPathTranslator&gt;(run, glyphBuffer, origin);
+    else {
+        TextRun::RenderingContext* renderingContext = run.renderingContext();
+        if (!renderingContext)
+            return DashArray();
+        translator = renderingContext-&gt;createGlyphToPathTranslator(*fontData, &amp;run, glyphBuffer, 0, glyphBuffer.size(), origin);
+        isSVG = true;
+    }
+    DashArray result;
+    for (int index = 0; translator-&gt;containsMorePaths(); ++index, translator-&gt;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 &amp;&amp; localFontData-&gt;isSVGFont()) || (isSVG &amp;&amp; localFontData != fontData)) {
+            // The advances will get all messed up if we do anything other than bail here.
+            result.clear();
+            break;
+        }
+        switch (translator-&gt;underlineType()) {
+        case GlyphToPathTranslator::GlyphUnderlineType::SkipDescenders: {
+            Path path = translator-&gt;path();
+            path.apply(&amp;info, &amp;findPathIntersections);
+            if (info.minX &lt; info.maxX) {
+                result.append(info.minX - lineExtents.x());
+                result.append(info.maxX - lineExtents.x());
+            }
+            break;
+        }
+        case GlyphToPathTranslator::GlyphUnderlineType::SkipGlyph: {
+            std::pair&lt;float, float&gt; extents = translator-&gt;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
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscairoFontCairoHarfbuzzNGcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cairo/FontCairoHarfbuzzNG.cpp (177077 => 177078)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -38,20 +38,36 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-float Font::drawComplexText(GraphicsContext* context, const TextRun&amp; run, const FloatPoint&amp; point, int, int) const
</del><ins>+
+float Font::getGlyphsAndAdvancesForComplexText(const TextRun&amp; run, int, int, GlyphBuffer&amp; glyphBuffer, ForTextEmphasisOrNot /* forTextEmphasis */) const
</ins><span class="cx"> {
</span><del>-    GlyphBuffer glyphBuffer;
</del><span class="cx">     HarfBuzzShaper shaper(this, run);
</span><del>-    if (shaper.shape(&amp;glyphBuffer)) {
-        FloatPoint startPoint = point;
-        float startX = startPoint.x();
-        drawGlyphBuffer(context, run, glyphBuffer, startPoint);
-        return startPoint.x() - startX;
</del><ins>+    if (!shaper.shape(&amp;glyphBuffer)) {
+        LOG_ERROR(&quot;Shaper couldn't shape glyphBuffer.&quot;);
+        return 0;
</ins><span class="cx">     }
</span><del>-    LOG_ERROR(&quot;Shaper couldn't shape glyphBuffer.&quot;);
</del><ins>+
+    // FIXME: Mac returns an initial advance here.
</ins><span class="cx">     return 0;
</span><span class="cx"> }
</span><ins>+float Font::drawComplexText(GraphicsContext* context, const TextRun&amp; run, const FloatPoint&amp; point, int from, int to) const
+{
+    // This glyph buffer holds our glyphs + advances + font data for each glyph.
+    GlyphBuffer glyphBuffer;
</ins><span class="cx"> 
</span><ins>+    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;
+}
+
</ins><span class="cx"> void Font::drawEmphasisMarksForComplexText(GraphicsContext* /* context */, const TextRun&amp; /* run */, const AtomicString&amp; /* mark */, const FloatPoint&amp; /* point */, int /* from */, int /* to */) const
</span><span class="cx"> {
</span><span class="cx">     notImplemented();
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsharfbuzzHarfBuzzShapercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp (177077 => 177078)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -579,10 +579,10 @@
</span><span class="cx">             if (currentCharacterIndex &gt; m_run.length())
</span><span class="cx">                 m_startOffset.move(glyphAdvanceX, glyphAdvanceY);
</span><span class="cx">             else
</span><del>-                glyphBuffer-&gt;add(glyphs[i], currentRun-&gt;fontData(), createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY));
</del><ins>+                glyphBuffer-&gt;add(glyphs[i], currentRun-&gt;fontData(), createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY), currentCharacterIndex);
</ins><span class="cx">         } else {
</span><span class="cx">             if (currentCharacterIndex &lt; m_run.length())
</span><del>-                glyphBuffer-&gt;add(glyphs[i], currentRun-&gt;fontData(), createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY));
</del><ins>+                glyphBuffer-&gt;add(glyphs[i], currentRun-&gt;fontData(), createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY), currentCharacterIndex);
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>