Cleanup in font loading code
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Jan 2016 21:36:41 +0000 (21:36 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Jan 2016 21:36:41 +0000 (21:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=153023

Reviewed by Zalan Bujtas.

See detailed notes below.

No new tests because there is no behavior change.

* css/CSSFontFace.cpp:
(WebCore::CSSFontFace::isLoaded): Deleted. Never called.
* css/CSSFontFace.h: Ditto.
* css/CSSFontFaceSource.cpp:
(WebCore::CSSFontFaceSource::font): No need to use a helper
isLoaded() function.
(WebCore::CSSFontFaceSource::isLoaded): Deleted. Unnecessary.
* css/CSSFontFaceSource.h:
* css/CSSFontFaceSrcValue.cpp:
(WebCore::CSSFontFaceSrcValue::cachedFont): Un-indent code.
* css/CSSFontSelector.cpp:
(WebCore::registerLocalFontFacesForFamily): constructFamilyFontFaces()
always returns an empty Vector. Therefore, the function of this function
is to perform the ancillary processing related to the case where the Faces
don't already exist. Renames the function and removes the empty vector
return.
(WebCore::CSSFontSelector::addFontFaceRule): Update for
registerLocalFontFacesForFamily().
(WebCore::FontFaceComparator::FontFaceComparator): Instead of using a static,
construct a wrapper class around the comparator.
(WebCore::FontFaceComparator::operator()): Ditto.
(WebCore::CSSFontSelector::getFontFace): Un-indent code and update to use
FontFaceComparator.
(WebCore::CSSFontSelector::fallbackFontAt): Migrate off PassRefPtr.
(WebCore::constructFamilyFontFaces): Deleted.
(WebCore::compareFontFaces): Deleted.
(WebCore::CSSFontSelector::resolvesFamilyFor): Deleted. Never called.
* css/CSSFontSelector.h:
* css/CSSSegmentedFontFace.cpp:
(WebCore::CSSSegmentedFontFace::isValid): Deleted.
(WebCore::CSSSegmentedFontFace::fontRanges): Cache negative validity results.
* css/CSSSegmentedFontFace.h:
* platform/graphics/FontCascade.h:
(WebCore::FontCascade::fontSelector): Use nullptr.
* platform/graphics/FontSelector.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@194923 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/css/CSSFontFace.cpp
Source/WebCore/css/CSSFontFace.h
Source/WebCore/css/CSSFontFaceSource.cpp
Source/WebCore/css/CSSFontFaceSource.h
Source/WebCore/css/CSSFontFaceSrcValue.cpp
Source/WebCore/css/CSSFontSelector.cpp
Source/WebCore/css/CSSFontSelector.h
Source/WebCore/css/CSSSegmentedFontFace.cpp
Source/WebCore/css/CSSSegmentedFontFace.h
Source/WebCore/platform/graphics/FontCascade.h
Source/WebCore/platform/graphics/FontSelector.h

index a317094..cb2f39e 100644 (file)
@@ -1,3 +1,50 @@
+2016-01-12  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Cleanup in font loading code
+        https://bugs.webkit.org/show_bug.cgi?id=153023
+
+        Reviewed by Zalan Bujtas.
+
+        See detailed notes below.
+
+        No new tests because there is no behavior change.
+
+        * css/CSSFontFace.cpp:
+        (WebCore::CSSFontFace::isLoaded): Deleted. Never called.
+        * css/CSSFontFace.h: Ditto.
+        * css/CSSFontFaceSource.cpp:
+        (WebCore::CSSFontFaceSource::font): No need to use a helper
+        isLoaded() function.
+        (WebCore::CSSFontFaceSource::isLoaded): Deleted. Unnecessary.
+        * css/CSSFontFaceSource.h:
+        * css/CSSFontFaceSrcValue.cpp:
+        (WebCore::CSSFontFaceSrcValue::cachedFont): Un-indent code.
+        * css/CSSFontSelector.cpp:
+        (WebCore::registerLocalFontFacesForFamily): constructFamilyFontFaces()
+        always returns an empty Vector. Therefore, the function of this function
+        is to perform the ancillary processing related to the case where the Faces
+        don't already exist. Renames the function and removes the empty vector
+        return.
+        (WebCore::CSSFontSelector::addFontFaceRule): Update for
+        registerLocalFontFacesForFamily().
+        (WebCore::FontFaceComparator::FontFaceComparator): Instead of using a static,
+        construct a wrapper class around the comparator.
+        (WebCore::FontFaceComparator::operator()): Ditto.
+        (WebCore::CSSFontSelector::getFontFace): Un-indent code and update to use
+        FontFaceComparator.
+        (WebCore::CSSFontSelector::fallbackFontAt): Migrate off PassRefPtr.
+        (WebCore::constructFamilyFontFaces): Deleted.
+        (WebCore::compareFontFaces): Deleted.
+        (WebCore::CSSFontSelector::resolvesFamilyFor): Deleted. Never called.
+        * css/CSSFontSelector.h:
+        * css/CSSSegmentedFontFace.cpp:
+        (WebCore::CSSSegmentedFontFace::isValid): Deleted.
+        (WebCore::CSSSegmentedFontFace::fontRanges): Cache negative validity results.
+        * css/CSSSegmentedFontFace.h:
+        * platform/graphics/FontCascade.h:
+        (WebCore::FontCascade::fontSelector): Use nullptr.
+        * platform/graphics/FontSelector.h:
+
 2016-01-12  Ryosuke Niwa  <rniwa@webkit.org>
 
         Add a build flag for custom element
index 67856ec..7dc41e5 100644 (file)
 
 namespace WebCore {
 
-bool CSSFontFace::isLoaded() const
-{
-    size_t size = m_sources.size();
-    for (size_t i = 0; i < size; i++) {
-        if (!m_sources[i]->isLoaded())
-            return false;
-    }
-    return true;
-}
-
 bool CSSFontFace::isValid() const
 {
     size_t size = m_sources.size();
index 1d7259f..994fc69 100644 (file)
@@ -75,7 +75,6 @@ public:
     void addedToSegmentedFontFace(CSSSegmentedFontFace*);
     void removedFromSegmentedFontFace(CSSSegmentedFontFace*);
 
-    bool isLoaded() const;
     bool isValid() const;
 
     bool isLocalFallback() const { return m_isLocalFallback; }
index dfcfada..03455f3 100644 (file)
@@ -80,13 +80,6 @@ void CSSFontFaceSource::pruneTable()
     m_fontTable.clear();
 }
 
-bool CSSFontFaceSource::isLoaded() const
-{
-    if (m_font)
-        return m_font->isLoaded();
-    return true;
-}
-
 bool CSSFontFaceSource::isValid() const
 {
     if (m_font)
@@ -124,7 +117,7 @@ RefPtr<Font> CSSFontFaceSource::font(const FontDescription& fontDescription, boo
     if (font)
         return font.release();
 
-    if (isLoaded()) {
+    if (!m_font || m_font->isLoaded()) {
         if (m_font) {
             bool hasExternalSVGFont = false;
 #if ENABLE(SVG_FONTS)
index 2db61ee..b3862e9 100644 (file)
@@ -53,7 +53,6 @@ public:
     CSSFontFaceSource(const String&, CachedFont* = nullptr);
     virtual ~CSSFontFaceSource();
 
-    bool isLoaded() const;
     bool isValid() const;
 
     const AtomicString& string() const { return m_string; }
index a2d0afa..eb0ef12 100644 (file)
@@ -100,14 +100,15 @@ bool CSSFontFaceSrcValue::traverseSubresources(const std::function<bool (const C
 
 CachedFont* CSSFontFaceSrcValue::cachedFont(Document* document, bool isSVG, bool isInitiatingElementInUserAgentShadowTree)
 {
-    if (!m_cachedFont) {
-        ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions();
-        options.setContentSecurityPolicyImposition(isInitiatingElementInUserAgentShadowTree ? ContentSecurityPolicyImposition::SkipPolicyCheck : ContentSecurityPolicyImposition::DoPolicyCheck);
+    if (m_cachedFont)
+        return m_cachedFont.get();
 
-        CachedResourceRequest request(ResourceRequest(document->completeURL(m_resource)), options);
-        request.setInitiator(cachedResourceRequestInitiators().css);
-        m_cachedFont = document->cachedResourceLoader().requestFont(request, isSVG);
-    }
+    ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions();
+    options.setContentSecurityPolicyImposition(isInitiatingElementInUserAgentShadowTree ? ContentSecurityPolicyImposition::SkipPolicyCheck : ContentSecurityPolicyImposition::DoPolicyCheck);
+
+    CachedResourceRequest request(ResourceRequest(document->completeURL(m_resource)), options);
+    request.setInitiator(cachedResourceRequestInitiators().css);
+    m_cachedFont = document->cachedResourceLoader().requestFont(request, isSVG);
     return m_cachedFont.get();
 }
 
index b992801..b89c218 100644 (file)
@@ -231,24 +231,22 @@ static String familyNameFromPrimitive(const CSSPrimitiveValue& value)
     }
 }
 
-static Vector<Ref<CSSFontFace>> constructFamilyFontFaces(const String& familyName, HashMap<String, Vector<Ref<CSSFontFace>>, CaseFoldingHash>& locallyInstalledFontFaces)
+static void registerLocalFontFacesForFamily(const String& familyName, HashMap<String, Vector<Ref<CSSFontFace>>, CaseFoldingHash>& locallyInstalledFontFaces)
 {
-    auto result = Vector<Ref<CSSFontFace>>();
-
     ASSERT(!locallyInstalledFontFaces.contains(familyName));
 
     Vector<FontTraitsMask> traitsMasks = FontCache::singleton().getTraitsInFamily(familyName);
-    if (!traitsMasks.isEmpty()) {
-        Vector<Ref<CSSFontFace>> faces = { };
-        for (auto mask : traitsMasks) {
-            Ref<CSSFontFace> face = CSSFontFace::create(mask, nullptr, true);
-            face->addSource(std::make_unique<CSSFontFaceSource>(familyName));
-            ASSERT(face->isValid());
-            faces.append(WTFMove(face));
-        }
-        locallyInstalledFontFaces.add(familyName, WTFMove(faces));
+    if (traitsMasks.isEmpty())
+        return;
+
+    Vector<Ref<CSSFontFace>> faces = { };
+    for (auto mask : traitsMasks) {
+        Ref<CSSFontFace> face = CSSFontFace::create(mask, nullptr, true);
+        face->addSource(std::make_unique<CSSFontFaceSource>(familyName));
+        ASSERT(face->isValid());
+        faces.append(WTFMove(face));
     }
-    return result;
+    locallyInstalledFontFaces.add(familyName, WTFMove(faces));
 }
 
 void CSSFontSelector::addFontFaceRule(const StyleRuleFontFace& fontFaceRule, bool isInitiatingElementInUserAgentShadowTree)
@@ -326,8 +324,10 @@ void CSSFontSelector::addFontFaceRule(const StyleRuleFontFace& fontFaceRule, boo
 
         auto addResult = m_fontFaces.add(familyName, Vector<Ref<CSSFontFace>>());
         auto& familyFontFaces = addResult.iterator->value;
-        if (addResult.isNewEntry)
-            familyFontFaces = constructFamilyFontFaces(familyName, m_locallyInstalledFontFaces);
+        if (addResult.isNewEntry) {
+            registerLocalFontFacesForFamily(familyName, m_locallyInstalledFontFaces);
+            familyFontFaces = { };
+        }
 
         familyFontFaces.append(fontFace.copyRef());
         
@@ -391,71 +391,80 @@ static const AtomicString& resolveGenericFamily(Document* document, const FontDe
     return familyName;
 }
 
-static FontTraitsMask desiredTraitsMaskForComparison;
-
-static inline bool compareFontFaces(const CSSFontFace& first, const CSSFontFace& second)
-{
-    FontTraitsMask firstTraitsMask = first.traitsMask();
-    FontTraitsMask secondTraitsMask = second.traitsMask();
-
-    bool firstHasDesiredStyle = firstTraitsMask & desiredTraitsMaskForComparison & FontStyleMask;
-    bool secondHasDesiredStyle = secondTraitsMask & desiredTraitsMaskForComparison & FontStyleMask;
-
-    if (firstHasDesiredStyle != secondHasDesiredStyle)
-        return firstHasDesiredStyle;
-
-    if ((desiredTraitsMaskForComparison & FontStyleItalicMask) && !first.isLocalFallback() && !second.isLocalFallback()) {
-        // Prefer a font that has indicated that it can only support italics to a font that claims to support
-        // all styles.  The specialized font is more likely to be the one the author wants used.
-        bool firstRequiresItalics = (firstTraitsMask & FontStyleItalicMask) && !(firstTraitsMask & FontStyleNormalMask);
-        bool secondRequiresItalics = (secondTraitsMask & FontStyleItalicMask) && !(secondTraitsMask & FontStyleNormalMask);
-        if (firstRequiresItalics != secondRequiresItalics)
-            return firstRequiresItalics;
+class FontFaceComparator {
+public:
+    FontFaceComparator(FontTraitsMask desiredTraitsMaskForComparison)
+        : m_desiredTraitsMaskForComparison(desiredTraitsMaskForComparison)
+    {
     }
 
-    if (secondTraitsMask & desiredTraitsMaskForComparison & FontWeightMask)
-        return false;
-    if (firstTraitsMask & desiredTraitsMaskForComparison & FontWeightMask)
-        return true;
-
-    // http://www.w3.org/TR/2011/WD-css3-fonts-20111004/#font-matching-algorithm says :
-    //   - If the desired weight is less than 400, weights below the desired weight are checked in descending order followed by weights above the desired weight in ascending order until a match is found.
-    //   - If the desired weight is greater than 500, weights above the desired weight are checked in ascending order followed by weights below the desired weight in descending order until a match is found.
-    //   - If the desired weight is 400, 500 is checked first and then the rule for desired weights less than 400 is used.
-    //   - If the desired weight is 500, 400 is checked first and then the rule for desired weights less than 400 is used.
-
-    static const unsigned fallbackRuleSets = 9;
-    static const unsigned rulesPerSet = 8;
-    static const FontTraitsMask weightFallbackRuleSets[fallbackRuleSets][rulesPerSet] = {
-        { FontWeight200Mask, FontWeight300Mask, FontWeight400Mask, FontWeight500Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
-        { FontWeight100Mask, FontWeight300Mask, FontWeight400Mask, FontWeight500Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
-        { FontWeight200Mask, FontWeight100Mask, FontWeight400Mask, FontWeight500Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
-        { FontWeight500Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
-        { FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
-        { FontWeight700Mask, FontWeight800Mask, FontWeight900Mask, FontWeight500Mask, FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask },
-        { FontWeight800Mask, FontWeight900Mask, FontWeight600Mask, FontWeight500Mask, FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask },
-        { FontWeight900Mask, FontWeight700Mask, FontWeight600Mask, FontWeight500Mask, FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask },
-        { FontWeight800Mask, FontWeight700Mask, FontWeight600Mask, FontWeight500Mask, FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask }
-    };
-
-    unsigned ruleSetIndex = 0;
-    unsigned w = FontWeight100Bit;
-    while (!(desiredTraitsMaskForComparison & (1 << w))) {
-        w++;
-        ruleSetIndex++;
-    }
+    bool operator()(const CSSFontFace& first, const CSSFontFace& second)
+    {
+        FontTraitsMask firstTraitsMask = first.traitsMask();
+        FontTraitsMask secondTraitsMask = second.traitsMask();
+
+        bool firstHasDesiredStyle = firstTraitsMask & m_desiredTraitsMaskForComparison & FontStyleMask;
+        bool secondHasDesiredStyle = secondTraitsMask & m_desiredTraitsMaskForComparison & FontStyleMask;
 
-    ASSERT_WITH_SECURITY_IMPLICATION(ruleSetIndex < fallbackRuleSets);
-    const FontTraitsMask* weightFallbackRule = weightFallbackRuleSets[ruleSetIndex];
-    for (unsigned i = 0; i < rulesPerSet; ++i) {
-        if (secondTraitsMask & weightFallbackRule[i])
+        if (firstHasDesiredStyle != secondHasDesiredStyle)
+            return firstHasDesiredStyle;
+
+        if ((m_desiredTraitsMaskForComparison & FontStyleItalicMask) && !first.isLocalFallback() && !second.isLocalFallback()) {
+            // Prefer a font that has indicated that it can only support italics to a font that claims to support
+            // all styles. The specialized font is more likely to be the one the author wants used.
+            bool firstRequiresItalics = (firstTraitsMask & FontStyleItalicMask) && !(firstTraitsMask & FontStyleNormalMask);
+            bool secondRequiresItalics = (secondTraitsMask & FontStyleItalicMask) && !(secondTraitsMask & FontStyleNormalMask);
+            if (firstRequiresItalics != secondRequiresItalics)
+                return firstRequiresItalics;
+        }
+
+        if (secondTraitsMask & m_desiredTraitsMaskForComparison & FontWeightMask)
             return false;
-        if (firstTraitsMask & weightFallbackRule[i])
+        if (firstTraitsMask & m_desiredTraitsMaskForComparison & FontWeightMask)
             return true;
+
+        // http://www.w3.org/TR/2011/WD-css3-fonts-20111004/#font-matching-algorithm says :
+        //   - If the desired weight is less than 400, weights below the desired weight are checked in descending order followed by weights above the desired weight in ascending order until a match is found.
+        //   - If the desired weight is greater than 500, weights above the desired weight are checked in ascending order followed by weights below the desired weight in descending order until a match is found.
+        //   - If the desired weight is 400, 500 is checked first and then the rule for desired weights less than 400 is used.
+        //   - If the desired weight is 500, 400 is checked first and then the rule for desired weights less than 400 is used.
+
+        static const unsigned fallbackRuleSets = 9;
+        static const unsigned rulesPerSet = 8;
+        static const FontTraitsMask weightFallbackRuleSets[fallbackRuleSets][rulesPerSet] = {
+            { FontWeight200Mask, FontWeight300Mask, FontWeight400Mask, FontWeight500Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
+            { FontWeight100Mask, FontWeight300Mask, FontWeight400Mask, FontWeight500Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
+            { FontWeight200Mask, FontWeight100Mask, FontWeight400Mask, FontWeight500Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
+            { FontWeight500Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
+            { FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
+            { FontWeight700Mask, FontWeight800Mask, FontWeight900Mask, FontWeight500Mask, FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask },
+            { FontWeight800Mask, FontWeight900Mask, FontWeight600Mask, FontWeight500Mask, FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask },
+            { FontWeight900Mask, FontWeight700Mask, FontWeight600Mask, FontWeight500Mask, FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask },
+            { FontWeight800Mask, FontWeight700Mask, FontWeight600Mask, FontWeight500Mask, FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask }
+        };
+
+        unsigned ruleSetIndex = 0;
+        unsigned w = FontWeight100Bit;
+        while (!(m_desiredTraitsMaskForComparison & (1 << w))) {
+            w++;
+            ruleSetIndex++;
+        }
+
+        ASSERT_WITH_SECURITY_IMPLICATION(ruleSetIndex < fallbackRuleSets);
+        const FontTraitsMask* weightFallbackRule = weightFallbackRuleSets[ruleSetIndex];
+        for (unsigned i = 0; i < rulesPerSet; ++i) {
+            if (secondTraitsMask & weightFallbackRule[i])
+                return false;
+            if (firstTraitsMask & weightFallbackRule[i])
+                return true;
+        }
+
+        return false;
     }
 
-    return false;
-}
+private:
+    FontTraitsMask m_desiredTraitsMaskForComparison;
+};
 
 FontRanges CSSFontSelector::fontRangesForFamily(const FontDescription& fontDescription, const AtomicString& familyName)
 {
@@ -485,33 +494,34 @@ CSSSegmentedFontFace* CSSFontSelector::getFontFace(const FontDescription& fontDe
     FontTraitsMask traitsMask = fontDescription.traitsMask();
 
     RefPtr<CSSSegmentedFontFace>& face = segmentedFontFaceCache.add(traitsMask, nullptr).iterator->value;
-    if (!face) {
-        face = CSSSegmentedFontFace::create(this);
+    if (face)
+        return face.get();
+
+    face = CSSSegmentedFontFace::create(this);
 
-        Vector<std::reference_wrapper<CSSFontFace>, 32> candidateFontFaces;
-        for (int i = familyFontFaces.size() - 1; i >= 0; --i) {
-            CSSFontFace& candidate = familyFontFaces[i];
-            unsigned candidateTraitsMask = candidate.traitsMask();
+    Vector<std::reference_wrapper<CSSFontFace>, 32> candidateFontFaces;
+    for (int i = familyFontFaces.size() - 1; i >= 0; --i) {
+        CSSFontFace& candidate = familyFontFaces[i];
+        unsigned candidateTraitsMask = candidate.traitsMask();
+        if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & FontStyleNormalMask))
+            continue;
+        candidateFontFaces.append(candidate);
+    }
+
+    auto localIterator = m_locallyInstalledFontFaces.find(family);
+    if (localIterator != m_locallyInstalledFontFaces.end()) {
+        for (auto& candidate : localIterator->value) {
+            unsigned candidateTraitsMask = candidate->traitsMask();
             if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & FontStyleNormalMask))
                 continue;
             candidateFontFaces.append(candidate);
         }
+    }
 
-        auto iterator = m_locallyInstalledFontFaces.find(family);
-        if (iterator != m_locallyInstalledFontFaces.end()) {
-            for (auto& candidate : iterator->value) {
-                unsigned candidateTraitsMask = candidate->traitsMask();
-                if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & FontStyleNormalMask))
-                    continue;
-                candidateFontFaces.append(candidate);
-            }
-        }
+    std::stable_sort(candidateFontFaces.begin(), candidateFontFaces.end(), FontFaceComparator(traitsMask));
+    for (auto& candidate : candidateFontFaces)
+        face->appendFontFace(candidate.get());
 
-        desiredTraitsMaskForComparison = traitsMask;
-        std::stable_sort(candidateFontFaces.begin(), candidateFontFaces.end(), compareFontFaces);
-        for (auto& candidate : candidateFontFaces)
-            face->appendFontFace(candidate.get());
-    }
     return face.get();
 }
 
@@ -570,21 +580,6 @@ void CSSFontSelector::beginLoadTimerFired()
         m_document->frame()->loader().checkLoadComplete();
 }
 
-bool CSSFontSelector::resolvesFamilyFor(const FontCascadeDescription& description) const
-{
-    for (unsigned i = 0; i < description.familyCount(); ++i) {
-        const AtomicString& familyName = description.familyAt(i);
-        if (familyName.isEmpty())
-            continue;
-        if (m_fontFaces.contains(familyName))
-            return true;
-        static NeverDestroyed<String> webkitPrefix("-webkit-");
-        if (familyName.startsWith(webkitPrefix.get()))
-            return true;
-    }
-    return false;
-}
-
 size_t CSSFontSelector::fallbackFontCount()
 {
     if (!m_document)
@@ -596,7 +591,7 @@ size_t CSSFontSelector::fallbackFontCount()
     return 0;
 }
 
-PassRefPtr<Font> CSSFontSelector::fallbackFontAt(const FontDescription& fontDescription, size_t index)
+RefPtr<Font> CSSFontSelector::fallbackFontAt(const FontDescription& fontDescription, size_t index)
 {
     ASSERT_UNUSED(index, !index);
 
index 6f130f7..26dead1 100644 (file)
@@ -59,11 +59,9 @@ public:
 
     virtual FontRanges fontRangesForFamily(const FontDescription&, const AtomicString&) override;
     virtual size_t fallbackFontCount() override;
-    virtual PassRefPtr<Font> fallbackFontAt(const FontDescription&, size_t) override;
+    virtual RefPtr<Font> fallbackFontAt(const FontDescription&, size_t) override;
     CSSSegmentedFontFace* getFontFace(const FontDescription&, const AtomicString& family);
 
-    virtual bool resolvesFamilyFor(const FontCascadeDescription&) const override;
-
     void clearDocument();
 
     void addFontFaceRule(const StyleRuleFontFace&, bool isInitiatingElementInUserAgentShadowTree);
index f18805d..f0eb933 100644 (file)
@@ -54,16 +54,6 @@ void CSSSegmentedFontFace::pruneTable()
     m_descriptionToRangesMap.clear();
 }
 
-bool CSSSegmentedFontFace::isValid() const
-{
-    // Valid if at least one font face is valid.
-    for (auto& face : m_fontFaces) {
-        if (face->isValid())
-            return true;
-    }
-    return false;
-}
-
 void CSSSegmentedFontFace::fontLoaded(CSSFontFace*)
 {
     pruneTable();
@@ -108,9 +98,6 @@ static void appendFontWithInvalidUnicodeRangeIfLoading(FontRanges& ranges, Ref<F
 
 FontRanges CSSSegmentedFontFace::fontRanges(const FontDescription& fontDescription)
 {
-    if (!isValid())
-        return FontRanges();
-
     FontTraitsMask desiredTraitsMask = fontDescription.traitsMask();
 
     auto addResult = m_descriptionToRangesMap.add(FontDescriptionKey(fontDescription), FontRanges());
index 5ffebb1..8d977b3 100644 (file)
@@ -68,7 +68,6 @@ private:
     CSSSegmentedFontFace(CSSFontSelector*);
 
     void pruneTable();
-    bool isValid() const;
 #if ENABLE(FONT_LOAD_EVENTS)
     bool isLoading() const;
 #endif
index 21090b3..70a1279 100644 (file)
@@ -367,7 +367,7 @@ inline bool FontCascade::isFixedPitch() const
 
 inline FontSelector* FontCascade::fontSelector() const
 {
-    return m_fonts ? m_fonts->fontSelector() : 0;
+    return m_fonts ? m_fonts->fontSelector() : nullptr;
 }
 
 inline float FontCascade::tabWidth(const Font& font, unsigned tabSize, float position) const
index d20b58c..74ff96a 100644 (file)
@@ -42,10 +42,9 @@ public:
     virtual ~FontSelector() { }
 
     virtual FontRanges fontRangesForFamily(const FontDescription&, const AtomicString&) = 0;
-    virtual PassRefPtr<Font> fallbackFontAt(const FontDescription&, size_t) = 0;
+    virtual RefPtr<Font> fallbackFontAt(const FontDescription&, size_t) = 0;
 
     virtual size_t fallbackFontCount() = 0;
-    virtual bool resolvesFamilyFor(const FontCascadeDescription&) const = 0;
 
     virtual void fontCacheInvalidated() { }