<!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>[178180] 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/178180">178180</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2015-01-09 11:33:40 -0800 (Fri, 09 Jan 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>FontCache should only deal with SimpleFontData
https://bugs.webkit.org/show_bug.cgi?id=140293

Reviewed by Andreas Kling.

FontCache::fontForFamilyAtIndex hands out FontData objects and calls to FontSelector. That sort
of code does not belong to the cache layer. Move the functionality up to FontGlyphs.

* platform/graphics/Font.cpp:
(WebCore::Font::operator==):
(WebCore::Font::drawText):
(WebCore::Font::drawEmphasisMarks):
(WebCore::Font::isLoadingCustomFonts):
* platform/graphics/Font.h:
(WebCore::Font::loadingCustomFonts): Deleted.
* platform/graphics/FontCache.cpp:
(WebCore::FontCache::similarFontPlatformData):

    Generic null implementation to reduce #ifs.

(WebCore::FontCache::fontForFamilyAtIndex): Deleted.
* platform/graphics/FontCache.h:

    Unfriend FontGlyphs.

* platform/graphics/FontGlyphs.cpp:
(WebCore::FontGlyphs::FontGlyphs):
(WebCore::FontGlyphs::isLoadingCustomFonts):

    We can figure thus out cheaply without caching a bit.

(WebCore::realizeNextFamily):
(WebCore::FontGlyphs::realizeFontDataAt):

    Reorganize a bit to make the logic clearer.
    Get rid of the strange cAllFamiliesScanned constant.

(WebCore::FontGlyphs::glyphDataForVariant):
(WebCore::FontGlyphs::glyphDataForNormalVariant):

    Loop until null, that always works.

* platform/graphics/FontGlyphs.h:
(WebCore::FontGlyphs::loadingCustomFonts): Deleted.
* platform/graphics/ios/FontCacheIOS.mm:
(WebCore::FontCache::similarFontPlatformData):
* platform/graphics/mac/FontCacheMac.mm:
(WebCore::FontCache::similarFontPlatformData):
* platform/graphics/mac/FontMac.mm:
(WebCore::Font::dashesForIntersectionsWithRect):</pre>

<h3>Modified Paths</h3>
<ul>
<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="#trunkSourceWebCoreplatformgraphicsFonth">trunk/Source/WebCore/platform/graphics/Font.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsFontCachecpp">trunk/Source/WebCore/platform/graphics/FontCache.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsFontCacheh">trunk/Source/WebCore/platform/graphics/FontCache.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsFontGlyphscpp">trunk/Source/WebCore/platform/graphics/FontGlyphs.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsFontGlyphsh">trunk/Source/WebCore/platform/graphics/FontGlyphs.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscairoFontCairocpp">trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsiosFontCacheIOSmm">trunk/Source/WebCore/platform/graphics/ios/FontCacheIOS.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsmacFontCacheMacmm">trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsmacFontMacmm">trunk/Source/WebCore/platform/graphics/mac/FontMac.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (178179 => 178180)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-01-09 19:29:40 UTC (rev 178179)
+++ trunk/Source/WebCore/ChangeLog        2015-01-09 19:33:40 UTC (rev 178180)
</span><span class="lines">@@ -1,3 +1,56 @@
</span><ins>+2015-01-09  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        FontCache should only deal with SimpleFontData
+        https://bugs.webkit.org/show_bug.cgi?id=140293
+
+        Reviewed by Andreas Kling.
+
+        FontCache::fontForFamilyAtIndex hands out FontData objects and calls to FontSelector. That sort
+        of code does not belong to the cache layer. Move the functionality up to FontGlyphs.
+
+        * platform/graphics/Font.cpp:
+        (WebCore::Font::operator==):
+        (WebCore::Font::drawText):
+        (WebCore::Font::drawEmphasisMarks):
+        (WebCore::Font::isLoadingCustomFonts):
+        * platform/graphics/Font.h:
+        (WebCore::Font::loadingCustomFonts): Deleted.
+        * platform/graphics/FontCache.cpp:
+        (WebCore::FontCache::similarFontPlatformData):
+
+            Generic null implementation to reduce #ifs.
+
+        (WebCore::FontCache::fontForFamilyAtIndex): Deleted.
+        * platform/graphics/FontCache.h:
+
+            Unfriend FontGlyphs.
+
+        * platform/graphics/FontGlyphs.cpp:
+        (WebCore::FontGlyphs::FontGlyphs):
+        (WebCore::FontGlyphs::isLoadingCustomFonts):
+
+            We can figure thus out cheaply without caching a bit.
+
+        (WebCore::realizeNextFamily):
+        (WebCore::FontGlyphs::realizeFontDataAt):
+
+            Reorganize a bit to make the logic clearer.
+            Get rid of the strange cAllFamiliesScanned constant.
+
+        (WebCore::FontGlyphs::glyphDataForVariant):
+        (WebCore::FontGlyphs::glyphDataForNormalVariant):
+
+            Loop until null, that always works.
+
+        * platform/graphics/FontGlyphs.h:
+        (WebCore::FontGlyphs::loadingCustomFonts): Deleted.
+        * platform/graphics/ios/FontCacheIOS.mm:
+        (WebCore::FontCache::similarFontPlatformData):
+        * platform/graphics/mac/FontCacheMac.mm:
+        (WebCore::FontCache::similarFontPlatformData):
+        * platform/graphics/mac/FontMac.mm:
+        (WebCore::Font::dashesForIntersectionsWithRect):
+
</ins><span class="cx"> 2015-01-09  Csaba Osztrogonác  &lt;ossy@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         REGRESSION(r177925): It broke the !ENABLE(INSPECTOR) build
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFontcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Font.cpp (178179 => 178180)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/Font.cpp        2015-01-09 19:29:40 UTC (rev 178179)
+++ trunk/Source/WebCore/platform/graphics/Font.cpp        2015-01-09 19:33:40 UTC (rev 178180)
</span><span class="lines">@@ -182,9 +182,7 @@
</span><span class="cx"> 
</span><span class="cx"> bool Font::operator==(const Font&amp; other) const
</span><span class="cx"> {
</span><del>-    // Our FontData don't have to be checked, since checking the font description will be fine.
-    // FIXME: This does not work if the font was made with the FontPlatformData constructor.
-    if (loadingCustomFonts() || other.loadingCustomFonts())
</del><ins>+    if (isLoadingCustomFonts() || other.isLoadingCustomFonts())
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     if (m_fontDescription != other.m_fontDescription || m_letterSpacing != other.m_letterSpacing || m_wordSpacing != other.m_wordSpacing)
</span><span class="lines">@@ -337,7 +335,7 @@
</span><span class="cx">     // Don't draw anything while we are using custom fonts that are in the process of loading,
</span><span class="cx">     // except if the 'force' argument is set to true (in which case it will use a fallback
</span><span class="cx">     // font).
</span><del>-    if (loadingCustomFonts() &amp;&amp; customFontNotReadyAction == DoNotPaintIfFontNotReady)
</del><ins>+    if (isLoadingCustomFonts() &amp;&amp; customFontNotReadyAction == DoNotPaintIfFontNotReady)
</ins><span class="cx">         return 0;
</span><span class="cx"> 
</span><span class="cx">     to = (to == -1 ? run.length() : to);
</span><span class="lines">@@ -355,7 +353,7 @@
</span><span class="cx"> 
</span><span class="cx"> void Font::drawEmphasisMarks(GraphicsContext* context, const TextRun&amp; run, const AtomicString&amp; mark, const FloatPoint&amp; point, int from, int to) const
</span><span class="cx"> {
</span><del>-    if (loadingCustomFonts())
</del><ins>+    if (isLoadingCustomFonts())
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     if (to &lt; 0)
</span><span class="lines">@@ -1083,6 +1081,11 @@
</span><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><ins>+
+bool Font::isLoadingCustomFonts() const
+{
+    return m_glyphs &amp;&amp; m_glyphs-&gt;isLoadingCustomFonts();
+}
</ins><span class="cx">     
</span><span class="cx"> GlyphToPathTranslator::GlyphUnderlineType computeUnderlineType(const TextRun&amp; textRun, const GlyphBuffer&amp; glyphBuffer, int index)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFonth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Font.h (178179 => 178180)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/Font.h        2015-01-09 19:29:40 UTC (rev 178179)
+++ trunk/Source/WebCore/platform/graphics/Font.h        2015-01-09 19:33:40 UTC (rev 178180)
</span><span class="lines">@@ -289,10 +289,7 @@
</span><span class="cx">     FontGlyphs* glyphs() const { return m_glyphs.get(); }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    bool loadingCustomFonts() const
-    {
-        return m_glyphs &amp;&amp; m_glyphs-&gt;loadingCustomFonts();
-    }
</del><ins>+    bool isLoadingCustomFonts() const;
</ins><span class="cx"> 
</span><span class="cx">     TypesettingFeatures computeTypesettingFeatures() const
</span><span class="cx">     {
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFontCachecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/FontCache.cpp (178179 => 178180)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/FontCache.cpp        2015-01-09 19:29:40 UTC (rev 178179)
+++ trunk/Source/WebCore/platform/graphics/FontCache.cpp        2015-01-09 19:33:40 UTC (rev 178180)
</span><span class="lines">@@ -490,48 +490,6 @@
</span><span class="cx">     return count;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-RefPtr&lt;FontData&gt; FontCache::fontForFamilyAtIndex(const FontDescription&amp; description, int&amp; familyIndex, FontSelector* fontSelector)
-{
-    ASSERT(familyIndex != cAllFamiliesScanned);
-    RefPtr&lt;FontData&gt; result;
-
-    bool isFirst = !familyIndex;
-    int familyCount = description.familyCount();
-    for (;familyIndex &lt; familyCount &amp;&amp; !result; ++familyIndex) {
-        const AtomicString&amp; family = description.familyAt(familyIndex);
-        if (family.isEmpty())
-            continue;
-        if (fontSelector)
-            result = fontSelector-&gt;getFontData(description, family);
-        if (!result)
-            result = fontForFamily(description, family);
-    }
-    if (familyIndex == familyCount)
-        familyIndex = cAllFamiliesScanned;
-
-#if PLATFORM(COCOA)
-    if (!result) {
-        // We didn't find a font. Try to find a similar font using our own specific knowledge about our platform.
-        // For example on OS X, we know to map any families containing the words Arabic, Pashto, or Urdu to the
-        // Geeza Pro font.
-        result = similarFontPlatformData(description);
-    }
-#endif
-
-    if (!result &amp;&amp; isFirst) {
-        // If it's the primary font that we couldn't find, we try the following. In all other cases, we will
-        // just use per-character system fallback.
-        if (fontSelector) {
-            // Try the user's preferred standard font.
-            if (RefPtr&lt;FontData&gt; data = fontSelector-&gt;getFontData(description, standardFamily))
-                return data.release();
-        }
-        // Still no result.  Hand back our last resort fallback font.
-        result = lastResortFallbackFont(description);
-    }
-    return result.release();
-}
-
</del><span class="cx"> static HashSet&lt;FontSelector*&gt;* gClients;
</span><span class="cx"> 
</span><span class="cx"> void FontCache::addClient(FontSelector* client)
</span><span class="lines">@@ -581,4 +539,11 @@
</span><span class="cx">     purgeInactiveFontData();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if !PLATFORM(COCOA)
+RefPtr&lt;SimpleFontData&gt; FontCache::similarFontPlatformData(const FontDescription&amp;)
+{
+    return nullptr;
+}
+#endif
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFontCacheh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/FontCache.h (178179 => 178180)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/FontCache.h        2015-01-09 19:29:40 UTC (rev 178179)
+++ trunk/Source/WebCore/platform/graphics/FontCache.h        2015-01-09 19:33:40 UTC (rev 178180)
</span><span class="lines">@@ -52,7 +52,6 @@
</span><span class="cx"> 
</span><span class="cx"> class Font;
</span><span class="cx"> class FontPlatformData;
</span><del>-class FontData;
</del><span class="cx"> class FontSelector;
</span><span class="cx"> class OpenTypeVerticalData;
</span><span class="cx"> class SimpleFontData;
</span><span class="lines">@@ -111,8 +110,6 @@
</span><span class="cx"> public:
</span><span class="cx">     friend FontCache&amp; fontCache();
</span><span class="cx"> 
</span><del>-    RefPtr&lt;FontData&gt; fontForFamilyAtIndex(const FontDescription&amp;, int&amp; familyIndex, FontSelector*);
-
</del><span class="cx">     // This method is implemented by the platform.
</span><span class="cx">     RefPtr&lt;SimpleFontData&gt; systemFallbackForCharacters(const FontDescription&amp;, const SimpleFontData* originalFontData, bool isPlatformFont, const UChar* characters, int length);
</span><span class="cx"> 
</span><span class="lines">@@ -133,6 +130,8 @@
</span><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT RefPtr&lt;SimpleFontData&gt; fontForFamily(const FontDescription&amp;, const AtomicString&amp;, bool checkingAlternateName = false);
</span><span class="cx">     WEBCORE_EXPORT Ref&lt;SimpleFontData&gt; lastResortFallbackFont(const FontDescription&amp;);
</span><ins>+    WEBCORE_EXPORT Ref&lt;SimpleFontData&gt; fontForPlatformData(const FontPlatformData&amp;);
+    RefPtr&lt;SimpleFontData&gt; similarFontPlatformData(const FontDescription&amp;);
</ins><span class="cx"> 
</span><span class="cx">     void addClient(FontSelector*);
</span><span class="cx">     void removeClient(FontSelector*);
</span><span class="lines">@@ -183,12 +182,7 @@
</span><span class="cx">     PassRefPtr&lt;SimpleFontData&gt; getSystemFontFallbackForCharacters(const FontDescription&amp;, const SimpleFontData*, const UChar* characters, int length);
</span><span class="cx"> #endif
</span><span class="cx">     std::unique_ptr&lt;FontPlatformData&gt; createFontPlatformData(const FontDescription&amp;, const AtomicString&amp; family);
</span><del>-#if PLATFORM(COCOA)
-    PassRefPtr&lt;SimpleFontData&gt; similarFontPlatformData(const FontDescription&amp;);
-#endif
</del><span class="cx"> 
</span><del>-    WEBCORE_EXPORT Ref&lt;SimpleFontData&gt; fontForPlatformData(const FontPlatformData&amp;);
-
</del><span class="cx">     // Don't purge if this count is &gt; 0;
</span><span class="cx">     int m_purgePreventCount;
</span><span class="cx"> 
</span><span class="lines">@@ -196,7 +190,6 @@
</span><span class="cx">     friend class ComplexTextController;
</span><span class="cx"> #endif
</span><span class="cx">     friend class SimpleFontData;
</span><del>-    friend class FontGlyphs;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> // Get the global fontCache.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFontGlyphscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/FontGlyphs.cpp (178179 => 178180)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/FontGlyphs.cpp        2015-01-09 19:29:40 UTC (rev 178179)
+++ trunk/Source/WebCore/platform/graphics/FontGlyphs.cpp        2015-01-09 19:33:40 UTC (rev 178180)
</span><span class="lines">@@ -41,11 +41,7 @@
</span><span class="cx">     : m_cachedPrimarySimpleFontData(0)
</span><span class="cx">     , m_fontSelector(fontSelector)
</span><span class="cx">     , m_fontSelectorVersion(m_fontSelector ? m_fontSelector-&gt;version() : 0)
</span><del>-    , m_familyIndex(0)
</del><span class="cx">     , m_generation(fontCache().generation())
</span><del>-    , m_pitch(UnknownPitch)
-    , m_loadingCustomFonts(false)
-    , m_isForPlatformFont(false)
</del><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -53,10 +49,7 @@
</span><span class="cx">     : m_cachedPrimarySimpleFontData(0)
</span><span class="cx">     , m_fontSelector(0)
</span><span class="cx">     , m_fontSelectorVersion(0)
</span><del>-    , m_familyIndex(cAllFamiliesScanned)
</del><span class="cx">     , m_generation(fontCache().generation())
</span><del>-    , m_pitch(UnknownPitch)
-    , m_loadingCustomFonts(false)
</del><span class="cx">     , m_isForPlatformFont(true)
</span><span class="cx"> {
</span><span class="cx">     m_realizedFontData.append(fontCache().fontForPlatformData(platformData));
</span><span class="lines">@@ -81,40 +74,72 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-const FontData* FontGlyphs::realizeFontDataAt(const FontDescription&amp; description, unsigned realizedFontIndex)
</del><ins>+bool FontGlyphs::isLoadingCustomFonts() const
</ins><span class="cx"> {
</span><del>-    if (realizedFontIndex &lt; m_realizedFontData.size())
-        return m_realizedFontData[realizedFontIndex].get(); // This fallback font is already in our list.
</del><ins>+    for (auto&amp; font : m_realizedFontData) {
+        if (font-&gt;isLoading())
+            return true;
+    }
+    return false;
+}
</ins><span class="cx"> 
</span><del>-    // Make sure we're not passing in some crazy value here.
-    ASSERT(realizedFontIndex == m_realizedFontData.size());
</del><ins>+static RefPtr&lt;FontData&gt; realizeNextFamily(const FontDescription&amp; description, unsigned&amp; index, FontSelector* fontSelector)
+{
+    ASSERT(index &lt; description.familyCount());
</ins><span class="cx"> 
</span><del>-    if (m_familyIndex &lt;= cAllFamiliesScanned) {
-        if (!m_fontSelector)
-            return 0;
</del><ins>+    while (index &lt; description.familyCount()) {
+        const AtomicString&amp; family = description.familyAt(index++);
+        if (family.isEmpty())
+            continue;
+        if (fontSelector) {
+            if (auto font = fontSelector-&gt;getFontData(description, family))
+                return font;
+        }
+        if (auto font = fontCache().fontForFamily(description, family))
+            return font;
+    }
+    // We didn't find a font. Try to find a similar font using our own specific knowledge about our platform.
+    // For example on OS X, we know to map any families containing the words Arabic, Pashto, or Urdu to the
+    // Geeza Pro font.
+    return fontCache().similarFontPlatformData(description);
+}
</ins><span class="cx"> 
</span><del>-        size_t index = cAllFamiliesScanned - m_familyIndex;
-        if (index == m_fontSelector-&gt;fallbackFontDataCount())
-            return 0;
</del><ins>+const FontData* FontGlyphs::realizeFontDataAt(const FontDescription&amp; description, unsigned index)
+{
+    if (index &lt; m_realizedFontData.size())
+        return &amp;m_realizedFontData[index].get();
</ins><span class="cx"> 
</span><del>-        m_familyIndex--;
-        RefPtr&lt;FontData&gt; fallback = m_fontSelector-&gt;getFallbackFontData(description, index);
-        if (fallback)
-            m_realizedFontData.append(fallback);
-        return fallback.get();
</del><ins>+    ASSERT(index == m_realizedFontData.size());
+    ASSERT(fontCache().generation() == m_generation);
+
+    if (!index) {
+        RefPtr&lt;FontData&gt; result = realizeNextFamily(description, m_lastRealizedFamilyIndex, m_fontSelector.get());
+        if (!result &amp;&amp; m_fontSelector)
+            result = m_fontSelector-&gt;getFontData(description, standardFamily);
+        if (!result)
+            result = fontCache().lastResortFallbackFont(description);
+
+        m_realizedFontData.append(*result);
+        return result.get();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    // Ask the font cache for the font data.
-    // We are obtaining this font for the first time. We keep track of the families we've looked at before
-    // in |m_familyIndex|, so that we never scan the same spot in the list twice. fontForFamilyAtIndex will adjust our
-    // |m_familyIndex| as it scans for the right font to make.
-    ASSERT(fontCache().generation() == m_generation);
-    RefPtr&lt;FontData&gt; result = fontCache().fontForFamilyAtIndex(description, m_familyIndex, m_fontSelector.get());
-    if (result) {
-        m_realizedFontData.append(result);
-        if (result-&gt;isLoading())
-            m_loadingCustomFonts = true;
</del><ins>+    RefPtr&lt;FontData&gt; result;
+    if (m_lastRealizedFamilyIndex &lt; description.familyCount())
+        result = realizeNextFamily(description, m_lastRealizedFamilyIndex, m_fontSelector.get());
+
+    if (!result &amp;&amp; m_fontSelector) {
+        ASSERT(m_lastRealizedFamilyIndex &gt;= description.familyCount());
+
+        unsigned fontSelectorFallbackIndex = m_lastRealizedFamilyIndex - description.familyCount();
+        if (fontSelectorFallbackIndex == m_fontSelector-&gt;fallbackFontDataCount())
+            return nullptr;
+        ++m_lastRealizedFamilyIndex;
+        result = m_fontSelector-&gt;getFallbackFontData(description, fontSelectorFallbackIndex);
</ins><span class="cx">     }
</span><ins>+    if (!result)
+        return nullptr;
+
+    m_realizedFontData.append(*result);
</ins><span class="cx">     return result.get();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -268,13 +293,9 @@
</span><span class="cx">     return fallbackGlyphData;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-GlyphData FontGlyphs::glyphDataForVariant(UChar32 c, const FontDescription&amp; description, FontDataVariant variant, unsigned fallbackLevel)
</del><ins>+GlyphData FontGlyphs::glyphDataForVariant(UChar32 c, const FontDescription&amp; description, FontDataVariant variant, unsigned fallbackIndex)
</ins><span class="cx"> {
</span><del>-    for (; fallbackLevel &lt;= description.familyCount(); ++fallbackLevel) {
-        auto* fontData = realizeFontDataAt(description, fallbackLevel);
-        if (!fontData)
-            break;
-
</del><ins>+    while (auto* fontData = realizeFontDataAt(description, fallbackIndex++)) {
</ins><span class="cx">         auto* simpleFontData = fontData-&gt;simpleFontDataForCharacter(c);
</span><span class="cx">         GlyphData data = simpleFontData ? simpleFontData-&gt;glyphDataForCharacter(c) : GlyphData();
</span><span class="cx">         if (data.fontData) {
</span><span class="lines">@@ -295,10 +316,7 @@
</span><span class="cx"> {
</span><span class="cx">     const unsigned pageNumber = c / GlyphPage::size;
</span><span class="cx"> 
</span><del>-    for (unsigned fallbackLevel = 0; fallbackLevel &lt;= description.familyCount(); ++fallbackLevel) {
-        auto* fontData = realizeFontDataAt(description, fallbackLevel);
-        if (!fontData)
-            break;
</del><ins>+    for (unsigned fallbackIndex = 0; auto* fontData = realizeFontDataAt(description, fallbackIndex); ++fallbackIndex) {
</ins><span class="cx">         auto* simpleFontData = fontData-&gt;simpleFontDataForCharacter(c);
</span><span class="cx">         auto* page = simpleFontData ? simpleFontData-&gt;glyphPage(pageNumber) : nullptr;
</span><span class="cx">         if (!page)
</span><span class="lines">@@ -312,7 +330,7 @@
</span><span class="cx">                 if (!data.fontData-&gt;hasVerticalGlyphs()) {
</span><span class="cx">                     // Use the broken ideograph font data. The broken ideograph font will use the horizontal width of glyphs
</span><span class="cx">                     // to make sure you get a square (even for broken glyphs like symbols used for punctuation).
</span><del>-                    return glyphDataForVariant(c, description, BrokenIdeographVariant, fallbackLevel);
</del><ins>+                    return glyphDataForVariant(c, description, BrokenIdeographVariant, fallbackIndex);
</ins><span class="cx">                 }
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">                 if (data.fontData-&gt;platformData().syntheticOblique())
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFontGlyphsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/FontGlyphs.h (178179 => 178180)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/FontGlyphs.h        2015-01-09 19:29:40 UTC (rev 178179)
+++ trunk/Source/WebCore/platform/graphics/FontGlyphs.h        2015-01-09 19:33:40 UTC (rev 178180)
</span><span class="lines">@@ -40,8 +40,6 @@
</span><span class="cx"> class FontPlatformData;
</span><span class="cx"> class FontSelector;
</span><span class="cx"> 
</span><del>-const int cAllFamiliesScanned = -1;
-
</del><span class="cx"> class FontGlyphs : public RefCounted&lt;FontGlyphs&gt; {
</span><span class="cx">     WTF_MAKE_NONCOPYABLE(FontGlyphs);
</span><span class="cx"> public:
</span><span class="lines">@@ -57,7 +55,7 @@
</span><span class="cx">     bool isFixedPitch(const FontDescription&amp;);
</span><span class="cx">     void determinePitch(const FontDescription&amp;);
</span><span class="cx"> 
</span><del>-    bool loadingCustomFonts() const { return m_loadingCustomFonts; }
</del><ins>+    bool isLoadingCustomFonts() const;
</ins><span class="cx"> 
</span><span class="cx">     FontSelector* fontSelector() { return m_fontSelector.get(); }
</span><span class="cx">     // FIXME: It should be possible to combine fontSelectorVersion and generation.
</span><span class="lines">@@ -76,10 +74,10 @@
</span><span class="cx"> 
</span><span class="cx">     GlyphData glyphDataForSystemFallback(UChar32, const FontDescription&amp;, FontDataVariant);
</span><span class="cx">     GlyphData glyphDataForNormalVariant(UChar32, const FontDescription&amp;);
</span><del>-    GlyphData glyphDataForVariant(UChar32, const FontDescription&amp;, FontDataVariant, unsigned fallbackLevel);
-    
-    Vector&lt;RefPtr&lt;FontData&gt;, 1&gt; m_realizedFontData;
</del><ins>+    GlyphData glyphDataForVariant(UChar32, const FontDescription&amp;, FontDataVariant, unsigned fallbackIndex);
</ins><span class="cx"> 
</span><ins>+    Vector&lt;Ref&lt;FontData&gt;, 1&gt; m_realizedFontData;
+
</ins><span class="cx">     RefPtr&lt;GlyphPage&gt; m_cachedPageZero;
</span><span class="cx">     HashMap&lt;int, RefPtr&lt;GlyphPage&gt;&gt; m_cachedPages;
</span><span class="cx"> 
</span><span class="lines">@@ -89,11 +87,10 @@
</span><span class="cx">     RefPtr&lt;FontSelector&gt; m_fontSelector;
</span><span class="cx">     WidthCache m_widthCache;
</span><span class="cx">     unsigned m_fontSelectorVersion;
</span><del>-    int m_familyIndex;
</del><span class="cx">     unsigned short m_generation;
</span><del>-    unsigned m_pitch : 3; // Pitch
-    unsigned m_loadingCustomFonts : 1;
-    unsigned m_isForPlatformFont : 1;
</del><ins>+    unsigned m_lastRealizedFamilyIndex { 0 };
+    Pitch m_pitch { UnknownPitch };
+    bool m_isForPlatformFont { false };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> inline bool FontGlyphs::isFixedPitch(const FontDescription&amp; description)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscairoFontCairocpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp (178179 => 178180)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp        2015-01-09 19:29:40 UTC (rev 178179)
+++ trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp        2015-01-09 19:33:40 UTC (rev 178180)
</span><span class="lines">@@ -292,7 +292,7 @@
</span><span class="cx"> 
</span><span class="cx"> DashArray Font::dashesForIntersectionsWithRect(const TextRun&amp; run, const FloatPoint&amp; textOrigin, const FloatRect&amp; lineExtents) const
</span><span class="cx"> {
</span><del>-    if (loadingCustomFonts())
</del><ins>+    if (isLoadingCustomFonts())
</ins><span class="cx">         return DashArray();
</span><span class="cx"> 
</span><span class="cx">     GlyphBuffer glyphBuffer;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsiosFontCacheIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/ios/FontCacheIOS.mm (178179 => 178180)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/ios/FontCacheIOS.mm        2015-01-09 19:29:40 UTC (rev 178179)
+++ trunk/Source/WebCore/platform/graphics/ios/FontCacheIOS.mm        2015-01-09 19:33:40 UTC (rev 178180)
</span><span class="lines">@@ -446,7 +446,7 @@
</span><span class="cx">     return lastResortFallbackFont(description);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-PassRefPtr&lt;SimpleFontData&gt; FontCache::similarFontPlatformData(const FontDescription&amp; description)
</del><ins>+RefPtr&lt;SimpleFontData&gt; FontCache::similarFontPlatformData(const FontDescription&amp; description)
</ins><span class="cx"> {
</span><span class="cx">     // Attempt to find an appropriate font using a match based on the presence of keywords in
</span><span class="cx">     // the requested names. For example, we'll match any name that contains &quot;Arabic&quot; to Geeza Pro.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsmacFontCacheMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm (178179 => 178180)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm        2015-01-09 19:29:40 UTC (rev 178179)
+++ trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm        2015-01-09 19:33:40 UTC (rev 178180)
</span><span class="lines">@@ -405,7 +405,7 @@
</span><span class="cx">     return fontForPlatformData(alternateFont);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-PassRefPtr&lt;SimpleFontData&gt; FontCache::similarFontPlatformData(const FontDescription&amp; description)
</del><ins>+RefPtr&lt;SimpleFontData&gt; FontCache::similarFontPlatformData(const FontDescription&amp; description)
</ins><span class="cx"> {
</span><span class="cx">     // Attempt to find an appropriate font using a match based on 
</span><span class="cx">     // the presence of keywords in the the requested names.  For example, we'll
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsmacFontMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/mac/FontMac.mm (178179 => 178180)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/mac/FontMac.mm        2015-01-09 19:29:40 UTC (rev 178179)
+++ trunk/Source/WebCore/platform/graphics/mac/FontMac.mm        2015-01-09 19:33:40 UTC (rev 178180)
</span><span class="lines">@@ -528,7 +528,7 @@
</span><span class="cx"> 
</span><span class="cx"> DashArray Font::dashesForIntersectionsWithRect(const TextRun&amp; run, const FloatPoint&amp; textOrigin, const FloatRect&amp; lineExtents) const
</span><span class="cx"> {
</span><del>-    if (loadingCustomFonts())
</del><ins>+    if (isLoadingCustomFonts())
</ins><span class="cx">         return DashArray();
</span><span class="cx"> 
</span><span class="cx">     GlyphBuffer glyphBuffer;
</span></span></pre>
</div>
</div>

</body>
</html>