<!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>[203092] 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/203092">203092</a></dd>
<dt>Author</dt> <dd>mmaxfield@apple.com</dd>
<dt>Date</dt> <dd>2016-07-11 16:23:56 -0700 (Mon, 11 Jul 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Honor the second argument to FontFaceSet.load and FontFaceSet.check
https://bugs.webkit.org/show_bug.cgi?id=159607
&lt;rdar://problem/27284902&gt;

Reviewed by Zalan Bujtas.

Source/WebCore:

This second argument is used in conjunction with the unicode-range CSS property, so that
loading from a FontFaceSet only loads the fonts which actually match the characters given.
Previously, we hadn't implemented proper support for this unicode-range property, but now
that we have implemented it, we should honor this second argument.

Test: fast/text/unicode-range-javascript.html

* css/CSSFontFace.cpp:
(WebCore::CSSFontFace::rangesMatchCodePoint):
* css/CSSFontFace.h:
* css/CSSFontFaceSet.cpp:
(WebCore::codePointsFromString):
(WebCore::CSSFontFaceSet::matchingFaces):

LayoutTests:

* fast/text/font-face-set-document-expected.txt:
* fast/text/font-face-set-document.html:
* fast/text/font-face-set-javascript-expected.txt:
* fast/text/font-face-set-javascript.html:
* fast/text/unicode-range-javascript-expected.txt: Added.
* fast/text/unicode-range-javascript.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfasttextfontfacesetdocumentexpectedtxt">trunk/LayoutTests/fast/text/font-face-set-document-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfasttextfontfacesetdocumenthtml">trunk/LayoutTests/fast/text/font-face-set-document.html</a></li>
<li><a href="#trunkLayoutTestsfasttextfontfacesetjavascriptexpectedtxt">trunk/LayoutTests/fast/text/font-face-set-javascript-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfasttextfontfacesetjavascripthtml">trunk/LayoutTests/fast/text/font-face-set-javascript.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecssCSSFontFacecpp">trunk/Source/WebCore/css/CSSFontFace.cpp</a></li>
<li><a href="#trunkSourceWebCorecssCSSFontFaceh">trunk/Source/WebCore/css/CSSFontFace.h</a></li>
<li><a href="#trunkSourceWebCorecssCSSFontFaceSetcpp">trunk/Source/WebCore/css/CSSFontFaceSet.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfasttextunicoderangejavascriptexpectedtxt">trunk/LayoutTests/fast/text/unicode-range-javascript-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfasttextunicoderangejavascripthtml">trunk/LayoutTests/fast/text/unicode-range-javascript.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (203091 => 203092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-07-11 23:18:41 UTC (rev 203091)
+++ trunk/LayoutTests/ChangeLog        2016-07-11 23:23:56 UTC (rev 203092)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2016-07-11  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
+
+        Honor the second argument to FontFaceSet.load and FontFaceSet.check
+        https://bugs.webkit.org/show_bug.cgi?id=159607
+        &lt;rdar://problem/27284902&gt;
+
+        Reviewed by Zalan Bujtas.
+
+        * fast/text/font-face-set-document-expected.txt:
+        * fast/text/font-face-set-document.html:
+        * fast/text/font-face-set-javascript-expected.txt:
+        * fast/text/font-face-set-javascript.html:
+        * fast/text/unicode-range-javascript-expected.txt: Added.
+        * fast/text/unicode-range-javascript.html: Added.
+
</ins><span class="cx"> 2016-07-11  Nan Wang  &lt;n_wang@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         AX: Crash when backspacing in number field with spin button
</span></span></pre></div>
<a id="trunkLayoutTestsfasttextfontfacesetdocumentexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/text/font-face-set-document-expected.txt (203091 => 203092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/font-face-set-document-expected.txt        2016-07-11 23:18:41 UTC (rev 203091)
+++ trunk/LayoutTests/fast/text/font-face-set-document-expected.txt        2016-07-11 23:23:56 UTC (rev 203092)
</span><span class="lines">@@ -12,9 +12,8 @@
</span><span class="cx"> PASS object.done is true
</span><span class="cx"> PASS document.getElementById(&quot;testElement&quot;).offsetWidth is not originalWidth
</span><span class="cx"> PASS document.getElementById(&quot;testElement&quot;).offsetWidth is originalWidth
</span><del>-PASS object.length is 2
</del><ins>+PASS object.length is 1
</ins><span class="cx"> PASS object[0].family is &quot;MyFont3&quot;
</span><del>-PASS object[1].family is &quot;MyFont3&quot;
</del><span class="cx"> PASS document.getElementById(&quot;testElement&quot;).offsetWidth is not originalWidth
</span><span class="cx"> PASS document.getElementById(&quot;testElement&quot;).offsetWidth is originalWidth
</span><span class="cx"> PASS successfullyParsed is true
</span></span></pre></div>
<a id="trunkLayoutTestsfasttextfontfacesetdocumenthtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/text/font-face-set-document.html (203091 => 203092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/font-face-set-document.html        2016-07-11 23:18:41 UTC (rev 203091)
+++ trunk/LayoutTests/fast/text/font-face-set-document.html        2016-07-11 23:23:56 UTC (rev 203092)
</span><span class="lines">@@ -76,9 +76,8 @@
</span><span class="cx">         return document.fonts.load(&quot;50px MyFont3&quot;);
</span><span class="cx">     }).then(function(x) {
</span><span class="cx">         object = x;
</span><del>-        shouldBe(&quot;object.length&quot;, &quot;2&quot;);
</del><ins>+        shouldBe(&quot;object.length&quot;, &quot;1&quot;);
</ins><span class="cx">         shouldBeEqualToString(&quot;object[0].family&quot;, &quot;MyFont3&quot;);
</span><del>-        shouldBeEqualToString(&quot;object[1].family&quot;, &quot;MyFont3&quot;);
</del><span class="cx">         object = undefined;
</span><span class="cx">         appliedFont = new FontFace(&quot;AppliedFont&quot;, &quot;url(\&quot;../../resources/Ahem.otf\&quot;)&quot;, {});
</span><span class="cx">         document.fonts.add(appliedFont);
</span></span></pre></div>
<a id="trunkLayoutTestsfasttextfontfacesetjavascriptexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/text/font-face-set-javascript-expected.txt (203091 => 203092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/font-face-set-javascript-expected.txt        2016-07-11 23:18:41 UTC (rev 203091)
+++ trunk/LayoutTests/fast/text/font-face-set-javascript-expected.txt        2016-07-11 23:23:56 UTC (rev 203092)
</span><span class="lines">@@ -45,7 +45,7 @@
</span><span class="cx"> PASS fontFaceSet.status is &quot;loaded&quot;
</span><span class="cx"> PASS fontFaceSet.status is &quot;loaded&quot;
</span><span class="cx"> PASS item is [fontFace3]
</span><del>-PASS item is [fontFace3, fontFace4]
</del><ins>+PASS item is [fontFace3]
</ins><span class="cx"> PASS item is fontFaceSet
</span><span class="cx"> PASS fontFaceSet.status is &quot;loaded&quot;
</span><span class="cx"> PASS fontFaceSet.status is &quot;loading&quot;
</span></span></pre></div>
<a id="trunkLayoutTestsfasttextfontfacesetjavascripthtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/text/font-face-set-javascript.html (203091 => 203092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/font-face-set-javascript.html        2016-07-11 23:18:41 UTC (rev 203091)
+++ trunk/LayoutTests/fast/text/font-face-set-javascript.html        2016-07-11 23:23:56 UTC (rev 203092)
</span><span class="lines">@@ -126,7 +126,7 @@
</span><span class="cx">     finishJSTest();
</span><span class="cx"> }).then(function(arg) {
</span><span class="cx">     item = arg;
</span><del>-    shouldBe(&quot;item&quot;, &quot;[fontFace3, fontFace4]&quot;);
</del><ins>+    shouldBe(&quot;item&quot;, &quot;[fontFace3]&quot;);
</ins><span class="cx">     fontFaceSet.add(fontFace4);
</span><span class="cx">     fontFaceSet.load(&quot;16px family3&quot;);
</span><span class="cx">     return fontFaceSet.ready;
</span></span></pre></div>
<a id="trunkLayoutTestsfasttextunicoderangejavascriptexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/unicode-range-javascript-expected.txt (0 => 203092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/unicode-range-javascript-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/text/unicode-range-javascript-expected.txt        2016-07-11 23:23:56 UTC (rev 203092)
</span><span class="lines">@@ -0,0 +1,17 @@
</span><ins>+This test makes sure that the second argument to FontFaceSet.load() and FontFaceSet.check() is honored.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+PASS faces.length is 1
+PASS faces[0].unicodeRange is &quot;U+41-41&quot;
+PASS document.fonts.check('14px WebFont', 'A') is true
+PASS faces.length is 1
+PASS faces[0].family is &quot;WebFont&quot;
+PASS faces[0].unicodeRange is &quot;U+41-41&quot;
+PASS document.fonts.check('14px WebFont3', 'A') is false
+PASS document.fonts.check('14px WebFont3', 'A') is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfasttextunicoderangejavascripthtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/unicode-range-javascript.html (0 => 203092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/unicode-range-javascript.html                                (rev 0)
+++ trunk/LayoutTests/fast/text/unicode-range-javascript.html        2016-07-11 23:23:56 UTC (rev 203092)
</span><span class="lines">@@ -0,0 +1,78 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+if (window.testRunner)
+    testRunner.dumpAsText();
+if (window.internals) {
+    internals.clearMemoryCache();
+    internals.invalidateFontCache();
+}
+&lt;/script&gt;
+&lt;style&gt;
+@font-face {
+        font-family: WebFont;
+        src: url(&quot;../../resources/Ahem.ttf&quot;) format(&quot;truetype&quot;);
+        unicode-range: U+42;
+}
+@font-face {
+    font-family: WebFont;
+    src: url(&quot;../../resources/Ahem.otf&quot;) format(&quot;opentype&quot;);
+    unicode-range: U+41;
+}
+@font-face {
+    font-family: WebFont2;
+    src: url(&quot;../../resources/Ahem.otf&quot;) format(&quot;opentype&quot;);
+    unicode-range: U+41-42;
+}
+@font-face {
+    font-family: WebFont3;
+    src: url(&quot;notafont.ttf&quot;) format(&quot;truetype&quot;);
+    unicode-range: U+42;
+}
+@font-face {
+    font-family: WebFont3;
+    src: url(&quot;../../resources/Ahem.woff&quot;) format(&quot;woff&quot;);
+    unicode-range: U+41;
+}
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;script&gt;
+self.jsTestIsAsync = true;
+
+description(&quot;This test makes sure that the second argument to FontFaceSet.load() and FontFaceSet.check() is honored.&quot;);
+
+function failure() {
+    testFailed(&quot;Promise should not fail.&quot;);
+    finishJSTest();
+}
+
+var faces;
+document.fonts.load(&quot;14px WebFont&quot;, &quot;A&quot;).then(function(facesArgument) {
+    faces = facesArgument;
+    shouldBe(&quot;faces.length&quot;, &quot;1&quot;);
+    shouldBeEqualToString(&quot;faces[0].unicodeRange&quot;, &quot;U+41-41&quot;);
+    shouldBeTrue(&quot;document.fonts.check('14px WebFont', 'A')&quot;);
+    return document.fonts.load(&quot;14px WebFont, WebFont2&quot;, &quot;A&quot;);
+}, failure).then(function(facesArgument) {
+    faces = facesArgument;
+    shouldBe(&quot;faces.length&quot;, &quot;1&quot;);
+    shouldBeEqualToString(&quot;faces[0].family&quot;, &quot;WebFont&quot;);
+    shouldBeEqualToString(&quot;faces[0].unicodeRange&quot;, &quot;U+41-41&quot;);
+    shouldBeFalse(&quot;document.fonts.check('14px WebFont3', 'A')&quot;);
+    for (let f of document.fonts) {
+        if (f.family == &quot;WebFont3&quot; &amp;&amp; f.unicodeRange == &quot;U+41-41&quot;)
+            return f.load();
+    }
+    testFailed(&quot;Should find font.&quot;);
+    finishJSTest();
+}, failure).then(function(face) {
+    shouldBeTrue(&quot;document.fonts.check('14px WebFont3', 'A')&quot;);
+    finishJSTest();
+}, failure);
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&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 (203091 => 203092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-07-11 23:18:41 UTC (rev 203091)
+++ trunk/Source/WebCore/ChangeLog        2016-07-11 23:23:56 UTC (rev 203092)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2016-07-11  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
+
+        Honor the second argument to FontFaceSet.load and FontFaceSet.check
+        https://bugs.webkit.org/show_bug.cgi?id=159607
+        &lt;rdar://problem/27284902&gt;
+
+        Reviewed by Zalan Bujtas.
+
+        This second argument is used in conjunction with the unicode-range CSS property, so that
+        loading from a FontFaceSet only loads the fonts which actually match the characters given.
+        Previously, we hadn't implemented proper support for this unicode-range property, but now
+        that we have implemented it, we should honor this second argument.
+
+        Test: fast/text/unicode-range-javascript.html
+
+        * css/CSSFontFace.cpp:
+        (WebCore::CSSFontFace::rangesMatchCodePoint):
+        * css/CSSFontFace.h:
+        * css/CSSFontFaceSet.cpp:
+        (WebCore::codePointsFromString):
+        (WebCore::CSSFontFaceSet::matchingFaces):
+
</ins><span class="cx"> 2016-07-11  Zalan Bujtas  &lt;zalan@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unable to edit fields or drag to select text in Dashboard widgets.
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSFontFacecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSFontFace.cpp (203091 => 203092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSFontFace.cpp        2016-07-11 23:18:41 UTC (rev 203091)
+++ trunk/Source/WebCore/css/CSSFontFace.cpp        2016-07-11 23:23:56 UTC (rev 203092)
</span><span class="lines">@@ -370,6 +370,18 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool CSSFontFace::rangesMatchCodePoint(UChar32 character) const
+{
+    if (m_ranges.isEmpty())
+        return true;
+
+    for (auto&amp; range : m_ranges) {
+        if (range.from &lt;= character &amp;&amp; character &lt;= range.to)
+            return true;
+    }
+    return false;
+}
+
</ins><span class="cx"> void CSSFontFace::fontLoadEventOccurred()
</span><span class="cx"> {
</span><span class="cx">     Ref&lt;CSSFontFace&gt; protectedThis(*this);
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSFontFaceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSFontFace.h (203091 => 203092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSFontFace.h        2016-07-11 23:18:41 UTC (rev 203091)
+++ trunk/Source/WebCore/css/CSSFontFace.h        2016-07-11 23:23:56 UTC (rev 203092)
</span><span class="lines">@@ -133,6 +133,8 @@
</span><span class="cx">         UChar32 to;
</span><span class="cx">     };
</span><span class="cx"> 
</span><ins>+    bool rangesMatchCodePoint(UChar32) const;
+
</ins><span class="cx">     // We don't guarantee that the FontFace wrapper will be the same every time you ask for it.
</span><span class="cx">     Ref&lt;FontFace&gt; wrapper();
</span><span class="cx">     void setWrapper(FontFace&amp;);
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSFontFaceSetcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSFontFaceSet.cpp (203091 => 203092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSFontFaceSet.cpp        2016-07-11 23:18:41 UTC (rev 203091)
+++ trunk/Source/WebCore/css/CSSFontFaceSet.cpp        2016-07-11 23:23:56 UTC (rev 203092)
</span><span class="lines">@@ -308,8 +308,24 @@
</span><span class="cx">     return static_cast&lt;FontTraitsMask&gt;(static_cast&lt;unsigned&gt;(styleMask) | static_cast&lt;unsigned&gt;(weightMask));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-Vector&lt;std::reference_wrapper&lt;CSSFontFace&gt;&gt; CSSFontFaceSet::matchingFaces(const String&amp; font, const String&amp;, ExceptionCode&amp; ec)
</del><ins>+static HashSet&lt;UChar32&gt; codePointsFromString(StringView stringView)
</ins><span class="cx"> {
</span><ins>+    HashSet&lt;UChar32&gt; result;
+    auto graphemeClusters = stringView.graphemeClusters();
+    for (auto cluster : graphemeClusters) {
+        ASSERT(cluster.length() &gt; 0);
+        UChar32 character = 0;
+        if (cluster.is8Bit())
+            character = cluster[0];
+        else
+            U16_GET(cluster.characters16(), 0, 0, cluster.length(), character);
+        result.add(character);
+    }
+    return result;
+}
+
+Vector&lt;std::reference_wrapper&lt;CSSFontFace&gt;&gt; CSSFontFaceSet::matchingFaces(const String&amp; font, const String&amp; string, ExceptionCode&amp; ec)
+{
</ins><span class="cx">     Vector&lt;std::reference_wrapper&lt;CSSFontFace&gt;&gt; result;
</span><span class="cx">     auto style = MutableStyleProperties::create();
</span><span class="cx">     auto parseResult = CSSParser::parseValue(style, CSSPropertyFont, font, true, CSSStrictMode, nullptr);
</span><span class="lines">@@ -334,21 +350,37 @@
</span><span class="cx">     CSSValueList&amp; familyList = downcast&lt;CSSValueList&gt;(*family);
</span><span class="cx"> 
</span><span class="cx">     HashSet&lt;AtomicString&gt; uniqueFamilies;
</span><ins>+    Vector&lt;AtomicString&gt; familyOrder;
</ins><span class="cx">     for (auto&amp; family : familyList) {
</span><span class="cx">         const CSSPrimitiveValue&amp; primitive = downcast&lt;CSSPrimitiveValue&gt;(family.get());
</span><span class="cx">         if (!primitive.isFontFamily())
</span><span class="cx">             continue;
</span><del>-        uniqueFamilies.add(primitive.fontFamily().familyName);
</del><ins>+        if (uniqueFamilies.add(primitive.fontFamily().familyName).isNewEntry)
+            familyOrder.append(primitive.fontFamily().familyName);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    for (auto&amp; family : uniqueFamilies) {
-        CSSSegmentedFontFace* faces = getFontFace(fontTraitsMask, family);
-        if (!faces)
-            continue;
-        for (auto&amp; constituentFace : faces-&gt;constituentFaces())
-            result.append(constituentFace.get());
</del><ins>+    HashSet&lt;CSSFontFace*&gt; resultConstituents;
+    for (auto codePoint : codePointsFromString(string)) {
+        bool found = false;
+        for (auto&amp; family : familyOrder) {
+            CSSSegmentedFontFace* faces = getFontFace(fontTraitsMask, family);
+            if (!faces)
+                continue;
+            for (auto&amp; constituentFace : faces-&gt;constituentFaces()) {
+                if (constituentFace-&gt;rangesMatchCodePoint(codePoint)) {
+                    resultConstituents.add(constituentFace.ptr());
+                    found = true;
+                    break;
+                }
+            }
+            if (found)
+                break;
+        }
</ins><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    for (auto* constituent : resultConstituents)
+        result.append(*constituent);
+
</ins><span class="cx">     return result;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>