2c8c2c6d3641a1825ddeafaf8fdac51edd5133fd
[WebKit-https.git] / Source / WebCore / css / CSSFontSelector.cpp
1 /*
2  * Copyright (C) 2007, 2008, 2011, 2013 Apple Inc. All rights reserved.
3  *           (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #include "config.h"
28 #include "CSSFontSelector.h"
29
30 #include "CachedFont.h"
31 #include "CSSFontFace.h"
32 #include "CSSFontFaceRule.h"
33 #include "CSSFontFaceSource.h"
34 #include "CSSFontFaceSrcValue.h"
35 #include "CSSFontFamily.h"
36 #include "CSSFontFeatureValue.h"
37 #include "CSSPrimitiveValue.h"
38 #include "CSSPrimitiveValueMappings.h"
39 #include "CSSPropertyNames.h"
40 #include "CSSSegmentedFontFace.h"
41 #include "CSSUnicodeRangeValue.h"
42 #include "CSSValueKeywords.h"
43 #include "CSSValueList.h"
44 #include "CSSValuePool.h"
45 #include "CachedResourceLoader.h"
46 #include "Document.h"
47 #include "Font.h"
48 #include "FontCache.h"
49 #include "FontVariantBuilder.h"
50 #include "Frame.h"
51 #include "FrameLoader.h"
52 #include "SVGFontFaceElement.h"
53 #include "SVGNames.h"
54 #include "Settings.h"
55 #include "StyleProperties.h"
56 #include "StyleResolver.h"
57 #include "StyleRule.h"
58 #include "WebKitFontFamilyNames.h"
59 #include <wtf/Ref.h>
60 #include <wtf/text/AtomicString.h>
61
62 namespace WebCore {
63
64 static unsigned fontSelectorId;
65
66 CSSFontSelector::CSSFontSelector(Document& document)
67     : m_document(&document)
68     , m_beginLoadingTimer(*this, &CSSFontSelector::beginLoadTimerFired)
69     , m_uniqueId(++fontSelectorId)
70     , m_version(0)
71 {
72     // FIXME: An old comment used to say there was no need to hold a reference to m_document
73     // because "we are guaranteed to be destroyed before the document". But there does not
74     // seem to be any such guarantee.
75
76     ASSERT(m_document);
77     FontCache::singleton().addClient(*this);
78 }
79
80 CSSFontSelector::~CSSFontSelector()
81 {
82     clearDocument();
83     FontCache::singleton().removeClient(*this);
84 }
85
86 bool CSSFontSelector::isEmpty() const
87 {
88     return m_fonts.isEmpty();
89 }
90
91 void CSSFontSelector::appendSources(CSSFontFace& fontFace, CSSValueList& srcList, Document* document, bool isInitiatingElementInUserAgentShadowTree)
92 {
93     for (auto& src : srcList) {
94         // An item in the list either specifies a string (local font name) or a URL (remote font to download).
95         CSSFontFaceSrcValue& item = downcast<CSSFontFaceSrcValue>(src.get());
96         std::unique_ptr<CSSFontFaceSource> source;
97         SVGFontFaceElement* fontFaceElement = nullptr;
98         bool foundSVGFont = false;
99
100 #if ENABLE(SVG_FONTS)
101         foundSVGFont = item.isSVGFontFaceSrc() || item.svgFontFaceElement();
102         fontFaceElement = item.svgFontFaceElement();
103 #endif
104         if (!item.isLocal()) {
105             Settings* settings = document ? document->settings() : nullptr;
106             bool allowDownloading = foundSVGFont || (settings && settings->downloadableBinaryFontsEnabled());
107             if (allowDownloading && item.isSupportedFormat() && document) {
108                 if (CachedFont* cachedFont = item.cachedFont(document, foundSVGFont, isInitiatingElementInUserAgentShadowTree))
109                     source = std::make_unique<CSSFontFaceSource>(fontFace, item.resource(), cachedFont);
110             }
111         } else
112             source = std::make_unique<CSSFontFaceSource>(fontFace, item.resource(), nullptr, fontFaceElement);
113
114         if (source)
115             fontFace.adoptSource(WTFMove(source));
116     }
117     fontFace.sourcesPopulated();
118 }
119
120 String CSSFontSelector::familyNameFromPrimitive(const CSSPrimitiveValue& value)
121 {
122     if (value.isFontFamily())
123         return value.fontFamily().familyName;
124     if (!value.isValueID())
125         return { };
126
127     // We need to use the raw text for all the generic family types, since @font-face is a way of actually
128     // defining what font to use for those types.
129     switch (value.getValueID()) {
130     case CSSValueSerif:
131         return serifFamily;
132     case CSSValueSansSerif:
133         return sansSerifFamily;
134     case CSSValueCursive:
135         return cursiveFamily;
136     case CSSValueFantasy:
137         return fantasyFamily;
138     case CSSValueMonospace:
139         return monospaceFamily;
140     case CSSValueWebkitPictograph:
141         return pictographFamily;
142     default:
143         return { };
144     }
145 }
146
147 void CSSFontSelector::registerLocalFontFacesForFamily(const String& familyName)
148 {
149     ASSERT(!m_locallyInstalledFontFaces.contains(familyName));
150
151     Vector<FontTraitsMask> traitsMasks = FontCache::singleton().getTraitsInFamily(familyName);
152     if (traitsMasks.isEmpty())
153         return;
154
155     Vector<Ref<CSSFontFace>> faces = { };
156     for (auto mask : traitsMasks) {
157         Ref<CSSFontFace> face = CSSFontFace::create(*this, nullptr, true);
158         
159         RefPtr<CSSValueList> familyList = CSSValueList::createCommaSeparated();
160         familyList->append(CSSValuePool::singleton().createFontFamilyValue(familyName));
161         face->setFamilies(*familyList);
162         face->setTraitsMask(mask);
163         face->adoptSource(std::make_unique<CSSFontFaceSource>(face.get(), familyName));
164         ASSERT(!face->allSourcesFailed());
165         faces.append(WTFMove(face));
166     }
167     m_locallyInstalledFontFaces.add(familyName, WTFMove(faces));
168 }
169
170 void CSSFontSelector::addFontFaceRule(const StyleRuleFontFace& fontFaceRule, bool isInitiatingElementInUserAgentShadowTree)
171 {
172     const StyleProperties& style = fontFaceRule.properties();
173     RefPtr<CSSValue> fontFamily = style.getPropertyCSSValue(CSSPropertyFontFamily);
174     RefPtr<CSSValue> fontStyle = style.getPropertyCSSValue(CSSPropertyFontStyle);
175     RefPtr<CSSValue> fontWeight = style.getPropertyCSSValue(CSSPropertyFontWeight);
176     RefPtr<CSSValue> src = style.getPropertyCSSValue(CSSPropertySrc);
177     RefPtr<CSSValue> unicodeRange = style.getPropertyCSSValue(CSSPropertyUnicodeRange);
178     RefPtr<CSSValue> featureSettings = style.getPropertyCSSValue(CSSPropertyFontFeatureSettings);
179     RefPtr<CSSValue> variantLigatures = style.getPropertyCSSValue(CSSPropertyFontVariantLigatures);
180     RefPtr<CSSValue> variantPosition = style.getPropertyCSSValue(CSSPropertyFontVariantPosition);
181     RefPtr<CSSValue> variantCaps = style.getPropertyCSSValue(CSSPropertyFontVariantCaps);
182     RefPtr<CSSValue> variantNumeric = style.getPropertyCSSValue(CSSPropertyFontVariantNumeric);
183     RefPtr<CSSValue> variantAlternates = style.getPropertyCSSValue(CSSPropertyFontVariantAlternates);
184     RefPtr<CSSValue> variantEastAsian = style.getPropertyCSSValue(CSSPropertyFontVariantEastAsian);
185     if (!is<CSSValueList>(fontFamily.get()) || !is<CSSValueList>(src.get()) || (unicodeRange && !is<CSSValueList>(*unicodeRange)))
186         return;
187
188     CSSValueList& familyList = downcast<CSSValueList>(*fontFamily);
189     if (!familyList.length())
190         return;
191
192     if (!fontStyle)
193         fontStyle = CSSValuePool::singleton().createIdentifierValue(CSSValueNormal).ptr();
194
195     if (!fontWeight)
196         fontWeight = CSSValuePool::singleton().createIdentifierValue(CSSValueNormal);
197
198     CSSValueList* rangeList = downcast<CSSValueList>(unicodeRange.get());
199
200     CSSValueList& srcList = downcast<CSSValueList>(*src);
201     if (!srcList.length())
202         return;
203
204     Ref<CSSFontFace> fontFace = CSSFontFace::create(*this);
205
206     if (!fontFace->setFamilies(*fontFamily))
207         return;
208     if (!fontFace->setStyle(*fontStyle))
209         return;
210     if (!fontFace->setWeight(*fontWeight))
211         return;
212     if (rangeList && !fontFace->setUnicodeRange(*rangeList))
213         return;
214     if (variantLigatures && !fontFace->setVariantLigatures(*variantLigatures))
215         return;
216     if (variantPosition && !fontFace->setVariantPosition(*variantPosition))
217         return;
218     if (variantCaps && !fontFace->setVariantCaps(*variantCaps))
219         return;
220     if (variantNumeric && !fontFace->setVariantNumeric(*variantNumeric))
221         return;
222     if (variantAlternates && !fontFace->setVariantAlternates(*variantAlternates))
223         return;
224     if (variantEastAsian && !fontFace->setVariantEastAsian(*variantEastAsian))
225         return;
226     if (featureSettings && !fontFace->setFeatureSettings(*featureSettings))
227         return;
228
229     appendSources(fontFace, srcList, m_document, isInitiatingElementInUserAgentShadowTree);
230     if (fontFace->allSourcesFailed())
231         return;
232
233     for (auto& item : familyList) {
234         String familyName = familyNameFromPrimitive(downcast<CSSPrimitiveValue>(item.get()));
235         if (familyName.isEmpty())
236             continue;
237
238         auto addResult = m_fontFaces.add(familyName, Vector<Ref<CSSFontFace>>());
239         auto& familyFontFaces = addResult.iterator->value;
240         if (addResult.isNewEntry) {
241             registerLocalFontFacesForFamily(familyName);
242             familyFontFaces = { };
243         }
244
245         familyFontFaces.append(fontFace.copyRef());
246         
247         ++m_version;
248     }
249 }
250
251 void CSSFontSelector::registerForInvalidationCallbacks(FontSelectorClient& client)
252 {
253     m_clients.add(&client);
254 }
255
256 void CSSFontSelector::unregisterForInvalidationCallbacks(FontSelectorClient& client)
257 {
258     m_clients.remove(&client);
259 }
260
261 void CSSFontSelector::dispatchInvalidationCallbacks()
262 {
263     ++m_version;
264
265     Vector<FontSelectorClient*> clients;
266     copyToVector(m_clients, clients);
267     for (size_t i = 0; i < clients.size(); ++i)
268         clients[i]->fontsNeedUpdate(*this);
269 }
270
271 void CSSFontSelector::fontLoaded()
272 {
273     dispatchInvalidationCallbacks();
274 }
275
276 void CSSFontSelector::fontCacheInvalidated()
277 {
278     dispatchInvalidationCallbacks();
279 }
280
281 static const AtomicString& resolveGenericFamily(Document* document, const FontDescription& fontDescription, const AtomicString& familyName)
282 {
283     if (!document || !document->frame())
284         return familyName;
285
286     const Settings& settings = document->frame()->settings();
287
288     UScriptCode script = fontDescription.script();
289     if (familyName == serifFamily)
290         return settings.serifFontFamily(script);
291     if (familyName == sansSerifFamily)
292         return settings.sansSerifFontFamily(script);
293     if (familyName == cursiveFamily)
294         return settings.cursiveFontFamily(script);
295     if (familyName == fantasyFamily)
296         return settings.fantasyFontFamily(script);
297     if (familyName == monospaceFamily)
298         return settings.fixedFontFamily(script);
299     if (familyName == pictographFamily)
300         return settings.pictographFontFamily(script);
301     if (familyName == standardFamily)
302         return settings.standardFontFamily(script);
303
304     return familyName;
305 }
306
307 class FontFaceComparator {
308 public:
309     FontFaceComparator(FontTraitsMask desiredTraitsMaskForComparison)
310         : m_desiredTraitsMaskForComparison(desiredTraitsMaskForComparison)
311     {
312         ASSERT_WITH_SECURITY_IMPLICATION(m_desiredTraitsMaskForComparison & FontWeightMask);
313     }
314
315     bool operator()(const CSSFontFace& first, const CSSFontFace& second)
316     {
317         FontTraitsMask firstTraitsMask = first.traitsMask();
318         FontTraitsMask secondTraitsMask = second.traitsMask();
319
320         bool firstHasDesiredStyle = firstTraitsMask & m_desiredTraitsMaskForComparison & FontStyleMask;
321         bool secondHasDesiredStyle = secondTraitsMask & m_desiredTraitsMaskForComparison & FontStyleMask;
322
323         if (firstHasDesiredStyle != secondHasDesiredStyle)
324             return firstHasDesiredStyle;
325
326         if ((m_desiredTraitsMaskForComparison & FontStyleItalicMask) && !first.isLocalFallback() && !second.isLocalFallback()) {
327             // Prefer a font that has indicated that it can only support italics to a font that claims to support
328             // all styles. The specialized font is more likely to be the one the author wants used.
329             bool firstRequiresItalics = (firstTraitsMask & FontStyleItalicMask) && !(firstTraitsMask & FontStyleNormalMask);
330             bool secondRequiresItalics = (secondTraitsMask & FontStyleItalicMask) && !(secondTraitsMask & FontStyleNormalMask);
331             if (firstRequiresItalics != secondRequiresItalics)
332                 return firstRequiresItalics;
333         }
334
335         if (secondTraitsMask & m_desiredTraitsMaskForComparison & FontWeightMask)
336             return false;
337         if (firstTraitsMask & m_desiredTraitsMaskForComparison & FontWeightMask)
338             return true;
339
340         // http://www.w3.org/TR/2011/WD-css3-fonts-20111004/#font-matching-algorithm says :
341         //   - 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.
342         //   - 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.
343         //   - If the desired weight is 400, 500 is checked first and then the rule for desired weights less than 400 is used.
344         //   - If the desired weight is 500, 400 is checked first and then the rule for desired weights less than 400 is used.
345
346         static const unsigned fallbackRuleSets = 9;
347         static const unsigned rulesPerSet = 8;
348         static const FontTraitsMask weightFallbackRuleSets[fallbackRuleSets][rulesPerSet] = {
349             { FontWeight200Mask, FontWeight300Mask, FontWeight400Mask, FontWeight500Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
350             { FontWeight100Mask, FontWeight300Mask, FontWeight400Mask, FontWeight500Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
351             { FontWeight200Mask, FontWeight100Mask, FontWeight400Mask, FontWeight500Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
352             { FontWeight500Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
353             { FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
354             { FontWeight700Mask, FontWeight800Mask, FontWeight900Mask, FontWeight500Mask, FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask },
355             { FontWeight800Mask, FontWeight900Mask, FontWeight600Mask, FontWeight500Mask, FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask },
356             { FontWeight900Mask, FontWeight700Mask, FontWeight600Mask, FontWeight500Mask, FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask },
357             { FontWeight800Mask, FontWeight700Mask, FontWeight600Mask, FontWeight500Mask, FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask }
358         };
359
360         unsigned ruleSetIndex = 0;
361         for (; !(m_desiredTraitsMaskForComparison & (1 << (FontWeight100Bit + ruleSetIndex))); ruleSetIndex++) { }
362
363         const FontTraitsMask* weightFallbackRule = weightFallbackRuleSets[ruleSetIndex];
364         for (unsigned i = 0; i < rulesPerSet; ++i) {
365             if (secondTraitsMask & weightFallbackRule[i])
366                 return false;
367             if (firstTraitsMask & weightFallbackRule[i])
368                 return true;
369         }
370
371         return false;
372     }
373
374 private:
375     FontTraitsMask m_desiredTraitsMaskForComparison;
376 };
377
378 FontRanges CSSFontSelector::fontRangesForFamily(const FontDescription& fontDescription, const AtomicString& familyName)
379 {
380     // FIXME: The spec (and Firefox) says user specified generic families (sans-serif etc.) should be resolved before the @font-face lookup too.
381     bool resolveGenericFamilyFirst = familyName == standardFamily;
382
383     AtomicString familyForLookup = resolveGenericFamilyFirst ? resolveGenericFamily(m_document, fontDescription, familyName) : familyName;
384     CSSSegmentedFontFace* face = getFontFace(fontDescription, familyForLookup);
385     if (!face) {
386         if (!resolveGenericFamilyFirst)
387             familyForLookup = resolveGenericFamily(m_document, fontDescription, familyName);
388         return FontRanges(FontCache::singleton().fontForFamily(fontDescription, familyForLookup));
389     }
390
391     return face->fontRanges(fontDescription);
392 }
393
394 CSSSegmentedFontFace* CSSFontSelector::getFontFace(const FontDescription& fontDescription, const AtomicString& family)
395 {
396     auto iterator = m_fontFaces.find(family);
397     if (iterator == m_fontFaces.end())
398         return nullptr;
399     auto& familyFontFaces = iterator->value;
400
401     auto& segmentedFontFaceCache = m_fonts.add(family, HashMap<unsigned, std::unique_ptr<CSSSegmentedFontFace>>()).iterator->value;
402
403     FontTraitsMask traitsMask = fontDescription.traitsMask();
404
405     auto& face = segmentedFontFaceCache.add(traitsMask, nullptr).iterator->value;
406     if (face)
407         return face.get();
408
409     face = std::make_unique<CSSSegmentedFontFace>(*this);
410
411     Vector<std::reference_wrapper<CSSFontFace>, 32> candidateFontFaces;
412     for (int i = familyFontFaces.size() - 1; i >= 0; --i) {
413         CSSFontFace& candidate = familyFontFaces[i];
414         unsigned candidateTraitsMask = candidate.traitsMask();
415         if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & FontStyleNormalMask))
416             continue;
417         candidateFontFaces.append(candidate);
418     }
419
420     auto localIterator = m_locallyInstalledFontFaces.find(family);
421     if (localIterator != m_locallyInstalledFontFaces.end()) {
422         for (auto& candidate : localIterator->value) {
423             unsigned candidateTraitsMask = candidate->traitsMask();
424             if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & FontStyleNormalMask))
425                 continue;
426             candidateFontFaces.append(candidate);
427         }
428     }
429
430     std::stable_sort(candidateFontFaces.begin(), candidateFontFaces.end(), FontFaceComparator(traitsMask));
431     for (auto& candidate : candidateFontFaces)
432         face->appendFontFace(candidate.get());
433
434     return face.get();
435 }
436
437 void CSSFontSelector::clearDocument()
438 {
439     if (!m_document) {
440         ASSERT(!m_beginLoadingTimer.isActive());
441         ASSERT(m_fontsToBeginLoading.isEmpty());
442         return;
443     }
444
445     m_beginLoadingTimer.stop();
446
447     CachedResourceLoader& cachedResourceLoader = m_document->cachedResourceLoader();
448     for (auto& fontHandle : m_fontsToBeginLoading) {
449         // Balances incrementRequestCount() in beginLoadingFontSoon().
450         cachedResourceLoader.decrementRequestCount(fontHandle.get());
451     }
452     m_fontsToBeginLoading.clear();
453
454     m_document = nullptr;
455
456     // FIXME: This object should outlive the Document.
457     m_fontFaces.clear();
458     m_locallyInstalledFontFaces.clear();
459     m_fonts.clear();
460     m_clients.clear();
461 }
462
463 void CSSFontSelector::beginLoadingFontSoon(CachedFont* font)
464 {
465     if (!m_document)
466         return;
467
468     m_fontsToBeginLoading.append(font);
469     // Increment the request count now, in order to prevent didFinishLoad from being dispatched
470     // after this font has been requested but before it began loading. Balanced by
471     // decrementRequestCount() in beginLoadTimerFired() and in clearDocument().
472     m_document->cachedResourceLoader().incrementRequestCount(font);
473     m_beginLoadingTimer.startOneShot(0);
474 }
475
476 void CSSFontSelector::beginLoadTimerFired()
477 {
478     Vector<CachedResourceHandle<CachedFont>> fontsToBeginLoading;
479     fontsToBeginLoading.swap(m_fontsToBeginLoading);
480
481     // CSSFontSelector could get deleted via beginLoadIfNeeded() or loadDone() unless protected.
482     Ref<CSSFontSelector> protect(*this);
483
484     CachedResourceLoader& cachedResourceLoader = m_document->cachedResourceLoader();
485     for (auto& fontHandle : fontsToBeginLoading) {
486         fontHandle->beginLoadIfNeeded(cachedResourceLoader);
487         // Balances incrementRequestCount() in beginLoadingFontSoon().
488         cachedResourceLoader.decrementRequestCount(fontHandle.get());
489     }
490     // Ensure that if the request count reaches zero, the frame loader will know about it.
491     cachedResourceLoader.loadDone(nullptr);
492     // New font loads may be triggered by layout after the document load is complete but before we have dispatched
493     // didFinishLoading for the frame. Make sure the delegate is always dispatched by checking explicitly.
494     if (m_document && m_document->frame())
495         m_document->frame()->loader().checkLoadComplete();
496 }
497
498
499 size_t CSSFontSelector::fallbackFontCount()
500 {
501     if (!m_document)
502         return 0;
503
504     if (Settings* settings = m_document->settings())
505         return settings->fontFallbackPrefersPictographs() ? 1 : 0;
506
507     return 0;
508 }
509
510 RefPtr<Font> CSSFontSelector::fallbackFontAt(const FontDescription& fontDescription, size_t index)
511 {
512     ASSERT_UNUSED(index, !index);
513
514     if (!m_document)
515         return nullptr;
516
517     Settings* settings = m_document->settings();
518     if (!settings || !settings->fontFallbackPrefersPictographs())
519         return nullptr;
520
521     return FontCache::singleton().fontForFamily(fontDescription, settings->pictographFontFamily());
522 }
523
524 }