<!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>[174325] trunk/Source/WebCore</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/174325">174325</a></dd>
<dt>Author</dt> <dd>mmaxfield@apple.com</dd>
<dt>Date</dt> <dd>2014-10-04 23:34:07 -0700 (Sat, 04 Oct 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[SVG -&gt; OTF Converter] Arabic forms are not substituted correctly
https://bugs.webkit.org/show_bug.cgi?id=137092

Reviewed by Darin Adler.

Tests: svg/W3C-SVG-1.1/fonts-glyph-02-t.svg
       svg/custom/glyph-selection-arabic-forms.svg

* svg/SVGToOTFFontConversion.cpp:
(WebCore::SVGToOTFFontConverter::appendArabicReplacementSubtable): Invoked for each of the three
Arabic form substitutions.
(WebCore::SVGToOTFFontConverter::appendGSUBTable): OpenType &quot;Advanced Typographic Table&quot;:
&quot;Glyph substitution data&quot;
(WebCore::SVGToOTFFontConverter::SVGToOTFFontConverter): Re-order the m_codepointsToIndicesMap
to prefer isolated forms of glyphs.
(WebCore::SVGToOTFFontConverter::convertSVGToOTFFont): Append the GSUB table.
(WebCore::calculateChecksum): Deleted.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoresvgSVGToOTFFontConversioncpp">trunk/Source/WebCore/svg/SVGToOTFFontConversion.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (174324 => 174325)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-10-04 22:24:21 UTC (rev 174324)
+++ trunk/Source/WebCore/ChangeLog        2014-10-05 06:34:07 UTC (rev 174325)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2014-10-04  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
+
+        [SVG -&gt; OTF Converter] Arabic forms are not substituted correctly
+        https://bugs.webkit.org/show_bug.cgi?id=137092
+
+        Reviewed by Darin Adler.
+
+        Tests: svg/W3C-SVG-1.1/fonts-glyph-02-t.svg
+               svg/custom/glyph-selection-arabic-forms.svg
+
+        * svg/SVGToOTFFontConversion.cpp:
+        (WebCore::SVGToOTFFontConverter::appendArabicReplacementSubtable): Invoked for each of the three
+        Arabic form substitutions.
+        (WebCore::SVGToOTFFontConverter::appendGSUBTable): OpenType &quot;Advanced Typographic Table&quot;:
+        &quot;Glyph substitution data&quot;
+        (WebCore::SVGToOTFFontConverter::SVGToOTFFontConverter): Re-order the m_codepointsToIndicesMap
+        to prefer isolated forms of glyphs.
+        (WebCore::SVGToOTFFontConverter::convertSVGToOTFFont): Append the GSUB table.
+        (WebCore::calculateChecksum): Deleted.
+
</ins><span class="cx"> 2014-10-04  Dhi Aurrahman  &lt;diorahman@rockybars.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Implement Element.closest() API
</span></span></pre></div>
<a id="trunkSourceWebCoresvgSVGToOTFFontConversioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/svg/SVGToOTFFontConversion.cpp (174324 => 174325)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/svg/SVGToOTFFontConversion.cpp        2014-10-04 22:24:21 UTC (rev 174324)
+++ trunk/Source/WebCore/svg/SVGToOTFFontConversion.cpp        2014-10-05 06:34:07 UTC (rev 174325)
</span><span class="lines">@@ -134,6 +134,7 @@
</span><span class="cx">     typedef void (SVGToOTFFontConverter::*FontAppendingFunction)();
</span><span class="cx">     void appendTable(const char identifier[4], FontAppendingFunction);
</span><span class="cx">     void appendCMAPTable();
</span><ins>+    void appendGSUBTable();
</ins><span class="cx">     void appendHEADTable();
</span><span class="cx">     void appendHHEATable();
</span><span class="cx">     void appendHMTXTable();
</span><span class="lines">@@ -160,6 +161,8 @@
</span><span class="cx">     template&lt;typename T&gt; size_t appendKERNSubtable(bool (T::*buildKerningPair)(SVGKerningPair&amp;) const, uint16_t coverage);
</span><span class="cx">     size_t finishAppendingKERNSubtable(Vector&lt;KerningData&gt;, uint16_t coverage);
</span><span class="cx"> 
</span><ins>+    void appendArabicReplacementSubtable(size_t subtableRecordLocation, const char arabicForm[]);
+
</ins><span class="cx">     Vector&lt;GlyphData&gt; m_glyphs;
</span><span class="cx">     HashMap&lt;String, Glyph&gt; m_glyphNameToIndexMap; // SVG 1.1: &quot;It is recommended that glyph names be unique within a font.&quot;
</span><span class="cx">     HashMap&lt;String, Vector&lt;Glyph, 1&gt;&gt; m_codepointsToIndicesMap;
</span><span class="lines">@@ -558,6 +561,119 @@
</span><span class="cx">         m_result.appendVector(glyph.charString);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void SVGToOTFFontConverter::appendArabicReplacementSubtable(size_t subtableRecordLocation, const char arabicForm[])
+{
+    Vector&lt;std::pair&lt;Glyph, Glyph&gt;&gt; arabicFinalReplacements;
+    for (auto&amp; pair : m_codepointsToIndicesMap) {
+        for (auto glyphIndex : pair.value) {
+            auto&amp; glyph = m_glyphs[glyphIndex];
+            if (glyph.glyphElement &amp;&amp; equalIgnoringCase(glyph.glyphElement-&gt;fastGetAttribute(SVGNames::arabic_formAttr), arabicForm))
+                arabicFinalReplacements.append(std::make_pair(pair.value[0], glyphIndex));
+        }
+    }
+    if (arabicFinalReplacements.size() &gt; std::numeric_limits&lt;uint16_t&gt;::max())
+        arabicFinalReplacements.clear();
+
+    overwrite16(subtableRecordLocation + 6, m_result.size() - subtableRecordLocation);
+    auto subtableLocation = m_result.size();
+    append16(2); // Format 2
+    append16(0); // Placeholder for offset to coverage table, relative to beginning of substitution table
+    append16(arabicFinalReplacements.size()); // GlyphCount
+    for (auto&amp; pair : arabicFinalReplacements)
+        append16(pair.second);
+
+    overwrite16(subtableLocation + 2, m_result.size() - subtableLocation);
+    append16(1); // CoverageFormat
+    append16(arabicFinalReplacements.size()); // GlyphCount
+    for (auto&amp; pair : arabicFinalReplacements)
+        append16(pair.first);
+}
+
+void SVGToOTFFontConverter::appendGSUBTable()
+{
+    auto tableLocation = m_result.size();
+    auto headerSize = 10;
+
+    append32(0x00010000); // Version
+    append16(headerSize); // Offset to ScriptList
+    auto featureListOffsetLocation = m_result.size();
+    append16(0); // Placeholder for FeatureList offset
+    auto lookupListOffsetLocation = m_result.size();
+    append16(0); // Placeholder for LookupList offset
+    ASSERT(tableLocation + headerSize == m_result.size());
+
+    // ScriptList
+    auto scriptListLocation = m_result.size();
+    append16(1); // Number of ScriptRecords
+    append32BitCode(&quot;arab&quot;);
+    append16(m_result.size() + 2 - scriptListLocation); // Offset of Script table, relative to beginning of ScriptList
+
+    auto scriptTableLocation = m_result.size();
+    auto sizeOfEmptyScriptTable = 4;
+    append16(sizeOfEmptyScriptTable); // Offset of default language system table, relative to beginning of Script table
+    append16(0); // Number of following language system tables
+    ASSERT_UNUSED(scriptTableLocation, scriptTableLocation + sizeOfEmptyScriptTable == m_result.size());
+
+    append16(0); // LookupOrder &quot;= NULL ... reserved&quot;
+    append16(0); // First feature is required
+    uint16_t featureCount = 4;
+    append16(4); // FeatureCount
+    for (uint16_t i = 0; i &lt; featureCount; ++i)
+        append16(i); // Index of our feature into the FeatureList
+
+    // FeatureList
+    overwrite16(featureListOffsetLocation, m_result.size() - tableLocation);
+    auto featureListLocation = m_result.size();
+    size_t featureListSize = 2 + 6 * featureCount;
+    size_t featureTableSize = 6;
+    append16(featureCount); // FeatureCount
+    append32BitCode(&quot;fina&quot;);
+    append16(featureListSize + featureTableSize * 0); // Offset of feature table, relative to beginning of FeatureList table
+    append32BitCode(&quot;medi&quot;);
+    append16(featureListSize + featureTableSize * 1); // Offset of feature table, relative to beginning of FeatureList table
+    append32BitCode(&quot;init&quot;);
+    append16(featureListSize + featureTableSize * 2); // Offset of feature table, relative to beginning of FeatureList table
+    append32BitCode(&quot;rlig&quot;);
+    append16(featureListSize + featureTableSize * 3); // Offset of feature table, relative to beginning of FeatureList table
+    ASSERT_UNUSED(featureListLocation, featureListLocation + featureListSize == m_result.size());
+
+    for (unsigned i = 0; i &lt; featureCount; ++i) {
+        auto featureTableStart = m_result.size();
+        append16(0); // FeatureParams &quot;= NULL ... reserved&quot;
+        append16(1); // LookupCount
+        append16(i); // LookupListIndex
+        ASSERT_UNUSED(featureTableStart, featureTableStart + featureTableSize == m_result.size());
+    }
+
+    // LookupList
+    overwrite16(lookupListOffsetLocation, m_result.size() - tableLocation);
+    auto lookupListLocation = m_result.size();
+    append16(featureCount); // LookupCount
+    for (unsigned i = 0; i &lt; featureCount; ++i)
+        append16(0); // Placeholder for offset to feature table, relative to beginning of LookupList
+    size_t subtableRecordLocations[featureCount];
+    for (unsigned i = 0; i &lt; featureCount; ++i) {
+        subtableRecordLocations[i] = m_result.size();
+        overwrite16(lookupListLocation + 2 + 2 * i, m_result.size() - lookupListLocation);
+        append16(i == 3 ? 3 : 1); // Type 1: &quot;Replace one glyph with one glyph&quot; / Type 3: &quot;Replace one glyph with one of many glyphs&quot;
+        append16(0); // LookupFlag
+        append16(1); // SubTableCount
+        append16(0); // Placeholder for offset to subtable, relative to beginning of Lookup table
+    }
+
+    appendArabicReplacementSubtable(subtableRecordLocations[0], &quot;terminal&quot;);
+    appendArabicReplacementSubtable(subtableRecordLocations[1], &quot;medial&quot;);
+    appendArabicReplacementSubtable(subtableRecordLocations[2], &quot;initial&quot;);
+
+    // Manually append empty &quot;rlig&quot; subtable
+    overwrite16(subtableRecordLocations[3] + 6, m_result.size() - subtableRecordLocations[3]);
+    append16(1); // Format 1
+    append16(6); // offset to coverage table, relative to beginning of substitution table
+    append16(0); // AlternateSetCount
+    append16(1); // CoverageFormat
+    append16(0); // GlyphCount
+}
+
</ins><span class="cx"> void SVGToOTFFontConverter::appendVORGTable()
</span><span class="cx"> {
</span><span class="cx">     append16(1); // Major version
</span><span class="lines">@@ -972,8 +1088,14 @@
</span><span class="cx">             if (!glyphName.isNull())
</span><span class="cx">                 m_glyphNameToIndexMap.add(glyphName, i);
</span><span class="cx">         }
</span><del>-        if (m_codepointsToIndicesMap.isValidKey(glyph.codepoints))
-            m_codepointsToIndicesMap.add(glyph.codepoints, Vector&lt;Glyph&gt;()).iterator-&gt;value.append(i);
</del><ins>+        if (m_codepointsToIndicesMap.isValidKey(glyph.codepoints)) {
+            auto&amp; glyphVector = m_codepointsToIndicesMap.add(glyph.codepoints, Vector&lt;Glyph&gt;()).iterator-&gt;value;
+            // Prefer isolated arabic forms
+            if (glyph.glyphElement &amp;&amp; equalIgnoringCase(glyph.glyphElement-&gt;fastGetAttribute(SVGNames::arabic_formAttr), &quot;isolated&quot;))
+                glyphVector.insert(0, i);
+            else
+                glyphVector.append(i);
+        }
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // FIXME: Handle commas.
</span><span class="lines">@@ -1050,7 +1172,7 @@
</span><span class="cx">     if (m_glyphs.isEmpty())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    uint16_t numTables = 13;
</del><ins>+    uint16_t numTables = 14;
</ins><span class="cx">     uint16_t roundedNumTables = roundDownToPowerOfTwo(numTables);
</span><span class="cx">     uint16_t searchRange = roundedNumTables * 16; // searchRange: &quot;(Maximum power of 2 &lt;= numTables) x 16.&quot;
</span><span class="cx"> 
</span><span class="lines">@@ -1070,6 +1192,7 @@
</span><span class="cx">         m_result.append(0);
</span><span class="cx"> 
</span><span class="cx">     appendTable(&quot;CFF &quot;, &amp;SVGToOTFFontConverter::appendCFFTable);
</span><ins>+    appendTable(&quot;GSUB&quot;, &amp;SVGToOTFFontConverter::appendGSUBTable);
</ins><span class="cx">     appendTable(&quot;OS/2&quot;, &amp;SVGToOTFFontConverter::appendOS2Table);
</span><span class="cx">     appendTable(&quot;VORG&quot;, &amp;SVGToOTFFontConverter::appendVORGTable);
</span><span class="cx">     appendTable(&quot;cmap&quot;, &amp;SVGToOTFFontConverter::appendCMAPTable);
</span></span></pre>
</div>
</div>

</body>
</html>