2 * Copyright (C) 2007, 2008, 2011, 2013 Apple Inc. All rights reserved.
3 * (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
28 #include "CSSFontSelector.h"
30 #include "CachedFont.h"
31 #include "CSSFontFace.h"
32 #include "CSSFontFaceRule.h"
33 #include "CSSFontFaceSource.h"
34 #include "CSSFontFaceSrcValue.h"
35 #include "CSSPrimitiveValue.h"
36 #include "CSSPropertyNames.h"
37 #include "CSSSegmentedFontFace.h"
38 #include "CSSUnicodeRangeValue.h"
39 #include "CSSValueKeywords.h"
40 #include "CSSValueList.h"
41 #include "CachedResourceLoader.h"
43 #include "FontCache.h"
45 #include "FrameLoader.h"
46 #include "SVGFontFaceElement.h"
49 #include "SimpleFontData.h"
50 #include "StyleProperties.h"
51 #include "StyleResolver.h"
52 #include "StyleRule.h"
53 #include "WebKitFontFamilyNames.h"
55 #include <wtf/text/AtomicString.h>
59 static unsigned fontSelectorId;
61 CSSFontSelector::CSSFontSelector(Document* document)
62 : m_document(document)
63 , m_beginLoadingTimer(this, &CSSFontSelector::beginLoadTimerFired)
64 , m_uniqueId(++fontSelectorId)
68 // FIXME: An old comment used to say there was no need to hold a reference to m_document
69 // because "we are guaranteed to be destroyed before the document". But there does not
70 // seem to be any such guarantee.
73 fontCache().addClient(this);
76 CSSFontSelector::~CSSFontSelector()
79 fontCache().removeClient(this);
82 bool CSSFontSelector::isEmpty() const
84 return m_fonts.isEmpty();
87 void CSSFontSelector::addFontFaceRule(const StyleRuleFontFace* fontFaceRule)
89 // Obtain the font-family property and the src property. Both must be defined.
90 const StyleProperties& style = fontFaceRule->properties();
91 RefPtr<CSSValue> fontFamily = style.getPropertyCSSValue(CSSPropertyFontFamily);
92 RefPtr<CSSValue> src = style.getPropertyCSSValue(CSSPropertySrc);
93 RefPtr<CSSValue> unicodeRange = style.getPropertyCSSValue(CSSPropertyUnicodeRange);
94 if (!is<CSSValueList>(fontFamily.get()) || !is<CSSValueList>(src.get()) || (unicodeRange && !is<CSSValueList>(*unicodeRange)))
97 CSSValueList& familyList = downcast<CSSValueList>(*fontFamily);
98 if (!familyList.length())
101 CSSValueList& srcList = downcast<CSSValueList>(*src);
102 if (!srcList.length())
105 CSSValueList* rangeList = downcast<CSSValueList>(unicodeRange.get());
107 unsigned traitsMask = 0;
109 if (RefPtr<CSSValue> fontStyle = style.getPropertyCSSValue(CSSPropertyFontStyle)) {
110 if (!is<CSSPrimitiveValue>(*fontStyle))
113 switch (downcast<CSSPrimitiveValue>(*fontStyle).getValueID()) {
115 traitsMask |= FontStyleNormalMask;
118 case CSSValueOblique:
119 traitsMask |= FontStyleItalicMask;
125 traitsMask |= FontStyleNormalMask;
127 if (RefPtr<CSSValue> fontWeight = style.getPropertyCSSValue(CSSPropertyFontWeight)) {
128 if (!is<CSSPrimitiveValue>(*fontWeight))
131 switch (downcast<CSSPrimitiveValue>(*fontWeight).getValueID()) {
134 traitsMask |= FontWeight700Mask;
138 traitsMask |= FontWeight400Mask;
141 traitsMask |= FontWeight900Mask;
144 traitsMask |= FontWeight800Mask;
147 traitsMask |= FontWeight600Mask;
150 traitsMask |= FontWeight500Mask;
153 traitsMask |= FontWeight300Mask;
156 traitsMask |= FontWeight200Mask;
159 traitsMask |= FontWeight100Mask;
165 traitsMask |= FontWeight400Mask;
167 if (RefPtr<CSSValue> fontVariant = style.getPropertyCSSValue(CSSPropertyFontVariant)) {
168 // font-variant descriptor can be a value list.
169 if (fontVariant->isPrimitiveValue()) {
170 RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
171 list->append(fontVariant.releaseNonNull());
172 fontVariant = list.releaseNonNull();
173 } else if (!is<CSSValueList>(*fontVariant))
176 CSSValueList& variantList = downcast<CSSValueList>(*fontVariant);
177 unsigned numVariants = variantList.length();
181 for (unsigned i = 0; i < numVariants; ++i) {
182 switch (downcast<CSSPrimitiveValue>(variantList.itemWithoutBoundsCheck(i))->getValueID()) {
184 traitsMask |= FontVariantNormalMask;
186 case CSSValueSmallCaps:
187 traitsMask |= FontVariantSmallCapsMask;
194 traitsMask |= FontVariantMask;
196 // Each item in the src property's list is a single CSSFontFaceSource. Put them all into a CSSFontFace.
197 RefPtr<CSSFontFace> fontFace;
199 int srcLength = srcList.length();
201 bool foundSVGFont = false;
203 for (int i = 0; i < srcLength; i++) {
204 // An item in the list either specifies a string (local font name) or a URL (remote font to download).
205 CSSFontFaceSrcValue& item = downcast<CSSFontFaceSrcValue>(*srcList.itemWithoutBoundsCheck(i));
206 std::unique_ptr<CSSFontFaceSource> source;
208 #if ENABLE(SVG_FONTS)
209 foundSVGFont = item.isSVGFontFaceSrc() || item.svgFontFaceElement();
211 if (!item.isLocal()) {
212 Settings* settings = m_document ? m_document->frame() ? &m_document->frame()->settings() : 0 : 0;
213 bool allowDownloading = foundSVGFont || (settings && settings->downloadableBinaryFontsEnabled());
214 if (allowDownloading && item.isSupportedFormat() && m_document) {
215 CachedFont* cachedFont = item.cachedFont(m_document, foundSVGFont);
217 source = std::make_unique<CSSFontFaceSource>(item.resource(), cachedFont);
218 #if ENABLE(SVG_FONTS)
220 source->setHasExternalSVGFont();
225 source = std::make_unique<CSSFontFaceSource>(item.resource());
229 RefPtr<CSSFontFaceRule> rule;
230 #if ENABLE(FONT_LOAD_EVENTS)
231 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=112116 - This CSSFontFaceRule has no parent.
232 if (RuntimeEnabledFeatures::sharedFeatures().fontLoadEventsEnabled())
233 rule = static_pointer_cast<CSSFontFaceRule>(fontFaceRule->createCSSOMWrapper());
235 fontFace = CSSFontFace::create(static_cast<FontTraitsMask>(traitsMask), rule);
239 #if ENABLE(SVG_FONTS)
240 source->setSVGFontFaceElement(item.svgFontFaceElement());
242 fontFace->addSource(WTF::move(source));
248 if (fontFace && !fontFace->isValid())
252 unsigned numRanges = rangeList->length();
253 for (unsigned i = 0; i < numRanges; i++) {
254 CSSUnicodeRangeValue& range = downcast<CSSUnicodeRangeValue>(*rangeList->itemWithoutBoundsCheck(i));
255 fontFace->addRange(range.from(), range.to());
259 // Hash under every single family name.
260 int familyLength = familyList.length();
261 for (int i = 0; i < familyLength; i++) {
262 CSSPrimitiveValue* item = downcast<CSSPrimitiveValue>(familyList.itemWithoutBoundsCheck(i));
264 if (item->isString()) {
265 familyName = item->getStringValue();
266 } else if (item->isValueID()) {
267 // We need to use the raw text for all the generic family types, since @font-face is a way of actually
268 // defining what font to use for those types.
269 switch (item->getValueID()) {
271 familyName = serifFamily;
273 case CSSValueSansSerif:
274 familyName = sansSerifFamily;
276 case CSSValueCursive:
277 familyName = cursiveFamily;
279 case CSSValueFantasy:
280 familyName = fantasyFamily;
282 case CSSValueMonospace:
283 familyName = monospaceFamily;
285 case CSSValueWebkitPictograph:
286 familyName = pictographFamily;
293 if (familyName.isEmpty())
296 std::unique_ptr<Vector<RefPtr<CSSFontFace>>>& familyFontFaces = m_fontFaces.add(familyName, nullptr).iterator->value;
297 if (!familyFontFaces) {
298 familyFontFaces = std::make_unique<Vector<RefPtr<CSSFontFace>>>();
300 ASSERT(!m_locallyInstalledFontFaces.contains(familyName));
302 Vector<unsigned> locallyInstalledFontsTraitsMasks;
303 fontCache().getTraitsInFamily(familyName, locallyInstalledFontsTraitsMasks);
304 if (unsigned numLocallyInstalledFaces = locallyInstalledFontsTraitsMasks.size()) {
305 auto familyLocallyInstalledFaces = std::make_unique<Vector<RefPtr<CSSFontFace>>>();
307 for (unsigned i = 0; i < numLocallyInstalledFaces; ++i) {
308 RefPtr<CSSFontFace> locallyInstalledFontFace = CSSFontFace::create(static_cast<FontTraitsMask>(locallyInstalledFontsTraitsMasks[i]), 0, true);
309 locallyInstalledFontFace->addSource(std::make_unique<CSSFontFaceSource>(familyName));
310 ASSERT(locallyInstalledFontFace->isValid());
311 familyLocallyInstalledFaces->append(locallyInstalledFontFace);
314 m_locallyInstalledFontFaces.set(familyName, WTF::move(familyLocallyInstalledFaces));
318 familyFontFaces->append(fontFace);
324 void CSSFontSelector::registerForInvalidationCallbacks(FontSelectorClient* client)
326 m_clients.add(client);
329 void CSSFontSelector::unregisterForInvalidationCallbacks(FontSelectorClient* client)
331 m_clients.remove(client);
334 void CSSFontSelector::dispatchInvalidationCallbacks()
338 Vector<FontSelectorClient*> clients;
339 copyToVector(m_clients, clients);
340 for (size_t i = 0; i < clients.size(); ++i)
341 clients[i]->fontsNeedUpdate(this);
343 // FIXME: Make Document a FontSelectorClient so that it can simply register for invalidation callbacks.
346 if (StyleResolver* styleResolver = m_document->styleResolverIfExists())
347 styleResolver->invalidateMatchedPropertiesCache();
348 if (m_document->inPageCache() || !m_document->renderView())
350 m_document->scheduleForcedStyleRecalc();
353 void CSSFontSelector::fontLoaded()
355 dispatchInvalidationCallbacks();
358 void CSSFontSelector::fontCacheInvalidated()
360 dispatchInvalidationCallbacks();
363 static PassRefPtr<SimpleFontData> fontDataForGenericFamily(Document* document, const FontDescription& fontDescription, const AtomicString& familyName)
365 if (!document || !document->frame())
368 const Settings& settings = document->frame()->settings();
370 AtomicString genericFamily;
371 UScriptCode script = fontDescription.script();
373 if (familyName == serifFamily)
374 genericFamily = settings.serifFontFamily(script);
375 else if (familyName == sansSerifFamily)
376 genericFamily = settings.sansSerifFontFamily(script);
377 else if (familyName == cursiveFamily)
378 genericFamily = settings.cursiveFontFamily(script);
379 else if (familyName == fantasyFamily)
380 genericFamily = settings.fantasyFontFamily(script);
381 else if (familyName == monospaceFamily)
382 genericFamily = settings.fixedFontFamily(script);
383 else if (familyName == pictographFamily)
384 genericFamily = settings.pictographFontFamily(script);
385 else if (familyName == standardFamily)
386 genericFamily = settings.standardFontFamily(script);
388 if (!genericFamily.isEmpty())
389 return fontCache().getCachedFontData(fontDescription, genericFamily);
394 static FontTraitsMask desiredTraitsMaskForComparison;
396 static inline bool compareFontFaces(CSSFontFace* first, CSSFontFace* second)
398 FontTraitsMask firstTraitsMask = first->traitsMask();
399 FontTraitsMask secondTraitsMask = second->traitsMask();
401 bool firstHasDesiredVariant = firstTraitsMask & desiredTraitsMaskForComparison & FontVariantMask;
402 bool secondHasDesiredVariant = secondTraitsMask & desiredTraitsMaskForComparison & FontVariantMask;
404 if (firstHasDesiredVariant != secondHasDesiredVariant)
405 return firstHasDesiredVariant;
407 // We need to check font-variant css property for CSS2.1 compatibility.
408 if ((desiredTraitsMaskForComparison & FontVariantSmallCapsMask) && !first->isLocalFallback() && !second->isLocalFallback()) {
409 // Prefer a font that has indicated that it can only support small-caps to a font that claims to support
410 // all variants. The specialized font is more likely to be true small-caps and not require synthesis.
411 bool firstRequiresSmallCaps = (firstTraitsMask & FontVariantSmallCapsMask) && !(firstTraitsMask & FontVariantNormalMask);
412 bool secondRequiresSmallCaps = (secondTraitsMask & FontVariantSmallCapsMask) && !(secondTraitsMask & FontVariantNormalMask);
413 if (firstRequiresSmallCaps != secondRequiresSmallCaps)
414 return firstRequiresSmallCaps;
417 bool firstHasDesiredStyle = firstTraitsMask & desiredTraitsMaskForComparison & FontStyleMask;
418 bool secondHasDesiredStyle = secondTraitsMask & desiredTraitsMaskForComparison & FontStyleMask;
420 if (firstHasDesiredStyle != secondHasDesiredStyle)
421 return firstHasDesiredStyle;
423 if ((desiredTraitsMaskForComparison & FontStyleItalicMask) && !first->isLocalFallback() && !second->isLocalFallback()) {
424 // Prefer a font that has indicated that it can only support italics to a font that claims to support
425 // all styles. The specialized font is more likely to be the one the author wants used.
426 bool firstRequiresItalics = (firstTraitsMask & FontStyleItalicMask) && !(firstTraitsMask & FontStyleNormalMask);
427 bool secondRequiresItalics = (secondTraitsMask & FontStyleItalicMask) && !(secondTraitsMask & FontStyleNormalMask);
428 if (firstRequiresItalics != secondRequiresItalics)
429 return firstRequiresItalics;
432 if (secondTraitsMask & desiredTraitsMaskForComparison & FontWeightMask)
434 if (firstTraitsMask & desiredTraitsMaskForComparison & FontWeightMask)
437 // http://www.w3.org/TR/2011/WD-css3-fonts-20111004/#font-matching-algorithm says :
438 // - 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.
439 // - 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.
440 // - If the desired weight is 400, 500 is checked first and then the rule for desired weights less than 400 is used.
441 // - If the desired weight is 500, 400 is checked first and then the rule for desired weights less than 400 is used.
443 static const unsigned fallbackRuleSets = 9;
444 static const unsigned rulesPerSet = 8;
445 static const FontTraitsMask weightFallbackRuleSets[fallbackRuleSets][rulesPerSet] = {
446 { FontWeight200Mask, FontWeight300Mask, FontWeight400Mask, FontWeight500Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
447 { FontWeight100Mask, FontWeight300Mask, FontWeight400Mask, FontWeight500Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
448 { FontWeight200Mask, FontWeight100Mask, FontWeight400Mask, FontWeight500Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
449 { FontWeight500Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
450 { FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask, FontWeight600Mask, FontWeight700Mask, FontWeight800Mask, FontWeight900Mask },
451 { FontWeight700Mask, FontWeight800Mask, FontWeight900Mask, FontWeight500Mask, FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask },
452 { FontWeight800Mask, FontWeight900Mask, FontWeight600Mask, FontWeight500Mask, FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask },
453 { FontWeight900Mask, FontWeight700Mask, FontWeight600Mask, FontWeight500Mask, FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask },
454 { FontWeight800Mask, FontWeight700Mask, FontWeight600Mask, FontWeight500Mask, FontWeight400Mask, FontWeight300Mask, FontWeight200Mask, FontWeight100Mask }
457 unsigned ruleSetIndex = 0;
458 unsigned w = FontWeight100Bit;
459 while (!(desiredTraitsMaskForComparison & (1 << w))) {
464 ASSERT_WITH_SECURITY_IMPLICATION(ruleSetIndex < fallbackRuleSets);
465 const FontTraitsMask* weightFallbackRule = weightFallbackRuleSets[ruleSetIndex];
466 for (unsigned i = 0; i < rulesPerSet; ++i) {
467 if (secondTraitsMask & weightFallbackRule[i])
469 if (firstTraitsMask & weightFallbackRule[i])
476 PassRefPtr<FontData> CSSFontSelector::getFontData(const FontDescription& fontDescription, const AtomicString& familyName)
478 if (m_fontFaces.isEmpty()) {
479 if (familyName.startsWith("-webkit-"))
480 return fontDataForGenericFamily(m_document, fontDescription, familyName);
481 if (fontDescription.genericFamily() == FontDescription::StandardFamily && !fontDescription.isSpecifiedFont())
482 return fontDataForGenericFamily(m_document, fontDescription, standardFamily);
486 CSSSegmentedFontFace* face = getFontFace(fontDescription, familyName);
487 // If no face was found, then return 0 and let the OS come up with its best match for the name.
489 // If we were handed a generic family, but there was no match, go ahead and return the correct font based off our
491 if (fontDescription.genericFamily() == FontDescription::StandardFamily && !fontDescription.isSpecifiedFont())
492 return fontDataForGenericFamily(m_document, fontDescription, standardFamily);
493 return fontDataForGenericFamily(m_document, fontDescription, familyName);
496 // We have a face. Ask it for a font data. If it cannot produce one, it will fail, and the OS will take over.
497 return face->getFontData(fontDescription);
500 CSSSegmentedFontFace* CSSFontSelector::getFontFace(const FontDescription& fontDescription, const AtomicString& family)
502 Vector<RefPtr<CSSFontFace>>* familyFontFaces = m_fontFaces.get(family);
503 if (!familyFontFaces || familyFontFaces->isEmpty())
506 std::unique_ptr<HashMap<unsigned, RefPtr<CSSSegmentedFontFace>>>& segmentedFontFaceCache = m_fonts.add(family, nullptr).iterator->value;
507 if (!segmentedFontFaceCache)
508 segmentedFontFaceCache = std::make_unique<HashMap<unsigned, RefPtr<CSSSegmentedFontFace>>>();
510 FontTraitsMask traitsMask = fontDescription.traitsMask();
512 RefPtr<CSSSegmentedFontFace>& face = segmentedFontFaceCache->add(traitsMask, nullptr).iterator->value;
514 face = CSSSegmentedFontFace::create(this);
516 // Collect all matching faces and sort them in order of preference.
517 Vector<CSSFontFace*, 32> candidateFontFaces;
518 for (int i = familyFontFaces->size() - 1; i >= 0; --i) {
519 CSSFontFace* candidate = familyFontFaces->at(i).get();
520 unsigned candidateTraitsMask = candidate->traitsMask();
521 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & FontStyleNormalMask))
523 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMask & FontVariantNormalMask))
525 #if ENABLE(SVG_FONTS)
526 // For SVG Fonts that specify that they only support the "normal" variant, we will assume they are incapable
527 // of small-caps synthesis and just ignore the font face as a candidate.
528 if (candidate->hasSVGFontFaceSource() && (traitsMask & FontVariantSmallCapsMask) && !(candidateTraitsMask & FontVariantSmallCapsMask))
531 candidateFontFaces.append(candidate);
534 if (Vector<RefPtr<CSSFontFace>>* familyLocallyInstalledFontFaces = m_locallyInstalledFontFaces.get(family)) {
535 unsigned numLocallyInstalledFontFaces = familyLocallyInstalledFontFaces->size();
536 for (unsigned i = 0; i < numLocallyInstalledFontFaces; ++i) {
537 CSSFontFace* candidate = familyLocallyInstalledFontFaces->at(i).get();
538 unsigned candidateTraitsMask = candidate->traitsMask();
539 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & FontStyleNormalMask))
541 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMask & FontVariantNormalMask))
543 candidateFontFaces.append(candidate);
547 desiredTraitsMaskForComparison = traitsMask;
548 std::stable_sort(candidateFontFaces.begin(), candidateFontFaces.end(), compareFontFaces);
549 unsigned numCandidates = candidateFontFaces.size();
550 for (unsigned i = 0; i < numCandidates; ++i)
551 face->appendFontFace(candidateFontFaces[i]);
556 void CSSFontSelector::clearDocument()
559 ASSERT(!m_beginLoadingTimer.isActive());
560 ASSERT(m_fontsToBeginLoading.isEmpty());
564 m_beginLoadingTimer.stop();
566 CachedResourceLoader* cachedResourceLoader = m_document->cachedResourceLoader();
567 for (size_t i = 0; i < m_fontsToBeginLoading.size(); ++i) {
568 // Balances incrementRequestCount() in beginLoadingFontSoon().
569 cachedResourceLoader->decrementRequestCount(m_fontsToBeginLoading[i].get());
572 m_fontsToBeginLoading.clear();
577 void CSSFontSelector::beginLoadingFontSoon(CachedFont* font)
582 m_fontsToBeginLoading.append(font);
583 // Increment the request count now, in order to prevent didFinishLoad from being dispatched
584 // after this font has been requested but before it began loading. Balanced by
585 // decrementRequestCount() in beginLoadTimerFired() and in clearDocument().
586 m_document->cachedResourceLoader()->incrementRequestCount(font);
587 m_beginLoadingTimer.startOneShot(0);
590 void CSSFontSelector::beginLoadTimerFired(Timer&)
592 Vector<CachedResourceHandle<CachedFont>> fontsToBeginLoading;
593 fontsToBeginLoading.swap(m_fontsToBeginLoading);
595 // CSSFontSelector could get deleted via beginLoadIfNeeded() or loadDone() unless protected.
596 Ref<CSSFontSelector> protect(*this);
598 CachedResourceLoader* cachedResourceLoader = m_document->cachedResourceLoader();
599 for (size_t i = 0; i < fontsToBeginLoading.size(); ++i) {
600 fontsToBeginLoading[i]->beginLoadIfNeeded(cachedResourceLoader);
601 // Balances incrementRequestCount() in beginLoadingFontSoon().
602 cachedResourceLoader->decrementRequestCount(fontsToBeginLoading[i].get());
604 // Ensure that if the request count reaches zero, the frame loader will know about it.
605 cachedResourceLoader->loadDone(0);
606 // New font loads may be triggered by layout after the document load is complete but before we have dispatched
607 // didFinishLoading for the frame. Make sure the delegate is always dispatched by checking explicitly.
608 if (m_document && m_document->frame())
609 m_document->frame()->loader().checkLoadComplete();
612 bool CSSFontSelector::resolvesFamilyFor(const FontDescription& description) const
614 for (unsigned i = 0; i < description.familyCount(); ++i) {
615 const AtomicString& familyName = description.familyAt(i);
616 if (description.genericFamily() == FontDescription::StandardFamily && !description.isSpecifiedFont())
618 if (familyName.isEmpty())
620 if (m_fontFaces.contains(familyName))
622 DEPRECATED_DEFINE_STATIC_LOCAL(String, webkitPrefix, ("-webkit-"));
623 if (familyName.startsWith(webkitPrefix))
630 size_t CSSFontSelector::fallbackFontDataCount()
635 if (Settings* settings = m_document->settings())
636 return settings->fontFallbackPrefersPictographs() ? 1 : 0;
641 PassRefPtr<FontData> CSSFontSelector::getFallbackFontData(const FontDescription& fontDescription, size_t index)
643 ASSERT_UNUSED(index, !index);
648 Settings* settings = m_document->settings();
649 if (!settings || !settings->fontFallbackPrefersPictographs())
652 return fontCache().getCachedFontData(fontDescription, settings->pictographFontFamily());