<!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>[166603] 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/166603">166603</a></dd>
<dt>Author</dt> <dd>mmaxfield@apple.com</dd>
<dt>Date</dt> <dd>2014-04-01 13:05:08 -0700 (Tue, 01 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>svg/text/text-overflow-ellipsis-svgfont-kerning-ligatures.html and svg/css/font-face-crash.html frequently assert in ComplexTextController::offsetForPosition
https://bugs.webkit.org/show_bug.cgi?id=119747

Reviewed by Simon Fraser.

Source/WebCore:

Even though kerning and ligatures currently don't work with the
simple text path, messing those up is better than creating null
CTRun and CTLine objects.

Rather than calling the badly-named renderingContext() function on TextRun objects
to determine if they are drawn with an SVG font, this patch creates a wrapper function
with a better name and uses that instead.

Test: svg/text/svg-font-hittest.html

* platform/graphics/Font.cpp:
(WebCore::isDrawnWithSVGFont): Wrapper around renderingContext()
(WebCore::Font::drawText): Use wrapper function
(WebCore::Font::drawEmphasisMarks): Use wrapper function
(WebCore::Font::width): Use wrapper function
(WebCore::Font::selectionRectForText): Use wrapper function
(WebCore::Font::offsetForPosition): If we are using an SVG font, use the simple path
instead of the complex one
(WebCore::Font::codePath): Use wrapper function
* platform/graphics/cocoa/FontPlatformDataCocoa.mm:
(WebCore::FontPlatformData::ctFont):

LayoutTests:

Clicking on SVG text used to cause a ComplexTextController to be built
around the SVG text (which is incorrect and would crash). This test
does just that and makes sure there is no crash.

* svg/text/resources/Litherum.svg: Added.
* svg/text/svg-font-hittest-expected.txt: Added.
* svg/text/svg-font-hittest.html: Added.
* LayoutTests/platform/mac/TestExpectations: Unskipped tests</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformmacTestExpectations">trunk/LayoutTests/platform/mac/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsFontcpp">trunk/Source/WebCore/platform/graphics/Font.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscocoaFontPlatformDataCocoamm">trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestssvgtextresourcesLitherumsvg">trunk/LayoutTests/svg/text/resources/Litherum.svg</a></li>
<li><a href="#trunkLayoutTestssvgtextsvgfonthittestexpectedtxt">trunk/LayoutTests/svg/text/svg-font-hittest-expected.txt</a></li>
<li><a href="#trunkLayoutTestssvgtextsvgfonthittesthtml">trunk/LayoutTests/svg/text/svg-font-hittest.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (166602 => 166603)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-04-01 19:53:04 UTC (rev 166602)
+++ trunk/LayoutTests/ChangeLog        2014-04-01 20:05:08 UTC (rev 166603)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2014-04-01  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
+
+        svg/text/text-overflow-ellipsis-svgfont-kerning-ligatures.html and svg/css/font-face-crash.html frequently assert in ComplexTextController::offsetForPosition
+        https://bugs.webkit.org/show_bug.cgi?id=119747
+
+        Reviewed by Simon Fraser.
+
+        Clicking on SVG text used to cause a ComplexTextController to be built
+        around the SVG text (which is incorrect and would crash). This test
+        does just that and makes sure there is no crash.
+
+        * svg/text/resources/Litherum.svg: Added.
+        * svg/text/svg-font-hittest-expected.txt: Added.
+        * svg/text/svg-font-hittest.html: Added.
+        * LayoutTests/platform/mac/TestExpectations: Unskipped tests
+
</ins><span class="cx"> 2014-04-01  Daniel Bates  &lt;dabates@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         RenderQuote must destroy remaining text renderer before first letter renderer
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac/TestExpectations (166602 => 166603)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac/TestExpectations        2014-04-01 19:53:04 UTC (rev 166602)
+++ trunk/LayoutTests/platform/mac/TestExpectations        2014-04-01 20:05:08 UTC (rev 166603)
</span><span class="lines">@@ -1319,9 +1319,6 @@
</span><span class="cx"> webkit.org/b/122040 animations/combo-transform-translate+scale.html [ Pass Failure ]
</span><span class="cx"> webkit.org/b/128379 animations/suspend-resume-animation.html [ Pass Failure ]
</span><span class="cx"> 
</span><del>-webkit.org/b/119747 [ Debug ] svg/text/text-overflow-ellipsis-svgfont-kerning-ligatures.html [ Skip ]
-webkit.org/b/119747 [ Debug ] svg/css/font-face-crash.html [ Skip ]
-
</del><span class="cx"> # Regressions in svg/clip-path
</span><span class="cx"> webkit.org/b/128499 svg/clip-path/clip-path-content-use-005.svg [ ImageOnlyFailure ]
</span><span class="cx"> webkit.org/b/128499 svg/clip-path/clip-path-precision-001.svg [ ImageOnlyFailure ]
</span></span></pre></div>
<a id="trunkLayoutTestssvgtextresourcesLitherumsvg"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/svg/text/resources/Litherum.svg (0 => 166603)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/svg/text/resources/Litherum.svg                                (rev 0)
+++ trunk/LayoutTests/svg/text/resources/Litherum.svg        2014-04-01 20:05:08 UTC (rev 166603)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+&lt;?xml version=&quot;1.0&quot; standalone=&quot;no&quot;?&gt;
+&lt;!DOCTYPE svg PUBLIC &quot;-//W3C//DTD SVG 1.1//EN&quot; &quot;http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd&quot; &gt;
+&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;
+&lt;metadata&gt;&lt;/metadata&gt;
+&lt;defs&gt;
+&lt;font id=&quot;Litherum&quot; horiz-adv-x=&quot;1024&quot;&gt;
+&lt;font-face units-per-em=&quot;14&quot; ascent=&quot;14&quot; descent=&quot;-7&quot;/&gt;
+&lt;glyph unicode=&quot;|&quot; horiz-adv-x=&quot;14&quot; d=&quot;M5 -7v21h4v-21z&quot;/&gt;
+&lt;/font&gt;
+&lt;/defs&gt;
+&lt;/svg&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestssvgtextsvgfonthittestexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/svg/text/svg-font-hittest-expected.txt (0 => 166603)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/svg/text/svg-font-hittest-expected.txt                                (rev 0)
+++ trunk/LayoutTests/svg/text/svg-font-hittest-expected.txt        2014-04-01 20:05:08 UTC (rev 166603)
</span><span class="lines">@@ -0,0 +1,3 @@
</span><ins>+This code triggers the glyph hit-testing code, which should not crash when a glyph is drawn with SVG fonts.
+Pass
+|
</ins></span></pre></div>
<a id="trunkLayoutTestssvgtextsvgfonthittesthtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/svg/text/svg-font-hittest.html (0 => 166603)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/svg/text/svg-font-hittest.html                                (rev 0)
+++ trunk/LayoutTests/svg/text/svg-font-hittest.html        2014-04-01 20:05:08 UTC (rev 166603)
</span><span class="lines">@@ -0,0 +1,37 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;style&gt;
+@font-face {
+    font-family: 'Litherum';
+    src: url(&quot;./resources/Litherum.svg&quot;) format(svg)
+}
+#p {
+    font: 1000px 'Litherum';
+}
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;test()&quot;&gt;
+This code triggers the glyph hit-testing code, which should not
+crash when a glyph is drawn with SVG fonts.
+&lt;div id=&quot;result&quot;&gt;&lt;/div&gt;
+&lt;div id=&quot;p&quot;&gt;|&lt;/div&gt;
+&lt;script&gt;
+function test() {
+    if (document.caretRangeFromPoint(400, 300))
+        document.getElementById(&quot;result&quot;).innerText = &quot;Pass&quot;;
+    else
+        document.getElementById(&quot;result&quot;).innerText = &quot;Fail&quot;;
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+}
+// Force layout, so that fonts begin to load before the document finishes loading, and thus delay the load event.
+document.body.offsetTop;
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (166602 => 166603)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-04-01 19:53:04 UTC (rev 166602)
+++ trunk/Source/WebCore/ChangeLog        2014-04-01 20:05:08 UTC (rev 166603)
</span><span class="lines">@@ -1,3 +1,32 @@
</span><ins>+2014-04-01  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
+
+        svg/text/text-overflow-ellipsis-svgfont-kerning-ligatures.html and svg/css/font-face-crash.html frequently assert in ComplexTextController::offsetForPosition
+        https://bugs.webkit.org/show_bug.cgi?id=119747
+
+        Reviewed by Simon Fraser.
+
+        Even though kerning and ligatures currently don't work with the
+        simple text path, messing those up is better than creating null
+        CTRun and CTLine objects.
+
+        Rather than calling the badly-named renderingContext() function on TextRun objects
+        to determine if they are drawn with an SVG font, this patch creates a wrapper function
+        with a better name and uses that instead.
+
+        Test: svg/text/svg-font-hittest.html
+
+        * platform/graphics/Font.cpp:
+        (WebCore::isDrawnWithSVGFont): Wrapper around renderingContext()
+        (WebCore::Font::drawText): Use wrapper function
+        (WebCore::Font::drawEmphasisMarks): Use wrapper function
+        (WebCore::Font::width): Use wrapper function
+        (WebCore::Font::selectionRectForText): Use wrapper function
+        (WebCore::Font::offsetForPosition): If we are using an SVG font, use the simple path
+        instead of the complex one
+        (WebCore::Font::codePath): Use wrapper function
+        * platform/graphics/cocoa/FontPlatformDataCocoa.mm:
+        (WebCore::FontPlatformData::ctFont):
+
</ins><span class="cx"> 2014-04-01  Daniel Bates  &lt;dabates@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         RenderQuote must destroy remaining text renderer before first letter renderer
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFontcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Font.cpp (166602 => 166603)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/Font.cpp        2014-04-01 19:53:04 UTC (rev 166602)
+++ trunk/Source/WebCore/platform/graphics/Font.cpp        2014-04-01 20:05:08 UTC (rev 166603)
</span><span class="lines">@@ -63,6 +63,11 @@
</span><span class="cx">     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+static bool isDrawnWithSVGFont(const TextRun&amp; run)
+{
+    return run.renderingContext();
+}
+
</ins><span class="cx"> static bool useBackslashAsYenSignForFamily(const AtomicString&amp; family)
</span><span class="cx"> {
</span><span class="cx">     if (family.isEmpty())
</span><span class="lines">@@ -336,7 +341,7 @@
</span><span class="cx"> 
</span><span class="cx">     CodePath codePathToUse = codePath(run);
</span><span class="cx">     // FIXME: Use the fast code path once it handles partial runs with kerning and ligatures. See http://webkit.org/b/100050
</span><del>-    if (codePathToUse != Complex &amp;&amp; typesettingFeatures() &amp;&amp; (from || to != run.length()) &amp;&amp; !run.renderingContext())
</del><ins>+    if (codePathToUse != Complex &amp;&amp; typesettingFeatures() &amp;&amp; (from || to != run.length()) &amp;&amp; !isDrawnWithSVGFont(run))
</ins><span class="cx">         codePathToUse = Complex;
</span><span class="cx"> 
</span><span class="cx">     if (codePathToUse != Complex)
</span><span class="lines">@@ -355,7 +360,7 @@
</span><span class="cx"> 
</span><span class="cx">     CodePath codePathToUse = codePath(run);
</span><span class="cx">     // FIXME: Use the fast code path once it handles partial runs with kerning and ligatures. See http://webkit.org/b/100050
</span><del>-    if (codePathToUse != Complex &amp;&amp; typesettingFeatures() &amp;&amp; (from || to != run.length()) &amp;&amp; !run.renderingContext())
</del><ins>+    if (codePathToUse != Complex &amp;&amp; typesettingFeatures() &amp;&amp; (from || to != run.length()) &amp;&amp; !isDrawnWithSVGFont(run))
</ins><span class="cx">         codePathToUse = Complex;
</span><span class="cx"> 
</span><span class="cx">     if (codePathToUse != Complex)
</span><span class="lines">@@ -400,8 +405,8 @@
</span><span class="cx"> float Font::width(const TextRun&amp; run, int&amp; charsConsumed, String&amp; glyphName) const
</span><span class="cx"> {
</span><span class="cx"> #if ENABLE(SVG_FONTS)
</span><del>-    if (TextRun::RenderingContext* renderingContext = run.renderingContext())
-        return renderingContext-&gt;floatWidthUsingSVGFont(*this, run, charsConsumed, glyphName);
</del><ins>+    if (isDrawnWithSVGFont(run))
+        return run.renderingContext()-&gt;floatWidthUsingSVGFont(*this, run, charsConsumed, glyphName);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     charsConsumed = run.length();
</span><span class="lines">@@ -508,7 +513,7 @@
</span><span class="cx"> 
</span><span class="cx">     CodePath codePathToUse = codePath(run);
</span><span class="cx">     // FIXME: Use the fast code path once it handles partial runs with kerning and ligatures. See http://webkit.org/b/100050
</span><del>-    if (codePathToUse != Complex &amp;&amp; typesettingFeatures() &amp;&amp; (from || to != run.length()) &amp;&amp; !run.renderingContext())
</del><ins>+    if (codePathToUse != Complex &amp;&amp; typesettingFeatures() &amp;&amp; (from || to != run.length()) &amp;&amp; !isDrawnWithSVGFont(run))
</ins><span class="cx">         codePathToUse = Complex;
</span><span class="cx"> 
</span><span class="cx">     if (codePathToUse != Complex)
</span><span class="lines">@@ -520,7 +525,7 @@
</span><span class="cx"> int Font::offsetForPosition(const TextRun&amp; run, float x, bool includePartialGlyphs) const
</span><span class="cx"> {
</span><span class="cx">     // FIXME: Use the fast code path once it handles partial runs with kerning and ligatures. See http://webkit.org/b/100050
</span><del>-    if (codePath(run) != Complex &amp;&amp; !typesettingFeatures())
</del><ins>+    if (codePath(run) != Complex &amp;&amp; (!typesettingFeatures() || isDrawnWithSVGFont(run)))
</ins><span class="cx">         return offsetForPositionForSimpleText(run, x, includePartialGlyphs);
</span><span class="cx"> 
</span><span class="cx">     return offsetForPositionForComplexText(run, x, includePartialGlyphs);
</span><span class="lines">@@ -587,7 +592,7 @@
</span><span class="cx">         return s_codePath;
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(SVG_FONTS)
</span><del>-    if (run.renderingContext())
</del><ins>+    if (isDrawnWithSVGFont(run))
</ins><span class="cx">         return Simple;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscocoaFontPlatformDataCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm (166602 => 166603)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm        2014-04-01 19:53:04 UTC (rev 166602)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm        2014-04-01 20:05:08 UTC (rev 166603)
</span><span class="lines">@@ -308,6 +308,7 @@
</span><span class="cx">     if (m_CTFont)
</span><span class="cx">         return m_CTFont.get();
</span><span class="cx"> 
</span><ins>+    ASSERT(m_cgFont.get());
</ins><span class="cx"> #if !PLATFORM(IOS)
</span><span class="cx">     m_CTFont = toCTFontRef(m_font);
</span><span class="cx">     if (m_CTFont) {
</span><span class="lines">@@ -319,10 +320,8 @@
</span><span class="cx">         else
</span><span class="cx">             fontDescriptor = cascadeToLastResortFontDescriptor();
</span><span class="cx">         m_CTFont = adoptCF(CTFontCreateCopyWithAttributes(m_CTFont.get(), m_size, 0, fontDescriptor));
</span><del>-    } else {
-        ASSERT(m_cgFont.get());
</del><ins>+    } else
</ins><span class="cx">         m_CTFont = adoptCF(CTFontCreateWithGraphicsFont(m_cgFont.get(), m_size, 0, cascadeToLastResortFontDescriptor()));
</span><del>-    }
</del><span class="cx"> #else
</span><span class="cx">     // Apple Color Emoji size is adjusted (and then re-adjusted by Core Text) and capped.
</span><span class="cx">     CGFloat size = !m_isEmoji ? m_size : m_size &lt;= 15 ? 4 * (m_size + 2) / static_cast&lt;CGFloat&gt;(5) : 16;
</span></span></pre>
</div>
</div>

</body>
</html>