bool FontFaceSet::check(const String& fontString, const String& text, ExceptionState& exceptionState) { if (!inActiveDocumentContext()) return false; Font font; if (!resolveFontStyle(fontString, font)) { exceptionState.ThrowDOMException(SyntaxError, "Could not resolve '" + fontString + "' as a font."); return false; } CSSFontSelector* fontSelector = document()->styleEngine()->fontSelector(); FontFaceCache* fontFaceCache = fontSelector->fontFaceCache(); bool hasLoadedFaces = false; for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next()) { CSSSegmentedFontFace* face = fontFaceCache->get(font.fontDescription(), f->family()); if (face) { if (!face->checkFont(nullToSpace(text))) return false; hasLoadedFaces = true; } } if (hasLoadedFaces) return true; for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next()) { if (fontSelector->isPlatformFontAvailable(font.fontDescription(), f->family())) return true; } return false; }
void FontFaceSet::clearForBinding(ScriptState*, ExceptionState&) { if (!inActiveDocumentContext() || m_nonCSSConnectedFaces.isEmpty()) return; CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); FontFaceCache* fontFaceCache = fontSelector->fontFaceCache(); for (const auto& fontFace : m_nonCSSConnectedFaces) { fontFaceCache->removeFontFace(fontFace.get(), false); if (fontFace->loadStatus() == FontFace::Loading) removeFromLoadingFonts(fontFace); } m_nonCSSConnectedFaces.clear(); fontSelector->fontFaceInvalidated(); }
void FontFaceSet::clear() { if (!inActiveDocumentContext() || m_nonCSSConnectedFaces.isEmpty()) return; CSSFontSelector* fontSelector = document()->styleEngine()->fontSelector(); FontFaceCache* fontFaceCache = fontSelector->fontFaceCache(); for (ListHashSet<RefPtr<FontFace> >::iterator it = m_nonCSSConnectedFaces.begin(); it != m_nonCSSConnectedFaces.end(); ++it) { fontFaceCache->removeFontFace(it->get(), false); if ((*it)->loadStatus() == FontFace::Loading) removeFromLoadingFonts(*it); } m_nonCSSConnectedFaces.clear(); fontSelector->fontFaceInvalidated(); }
void ScopedStyleResolver::addFontFaceRules(const RuleSet& ruleSet) { // FIXME(BUG 72461): We don't add @font-face rules of scoped style sheets for the moment. if (!treeScope().rootNode().isDocumentNode()) return; Document& document = treeScope().document(); CSSFontSelector* cssFontSelector = document.styleEngine().fontSelector(); const WillBeHeapVector<RawPtrWillBeMember<StyleRuleFontFace>> fontFaceRules = ruleSet.fontFaceRules(); for (auto& fontFaceRule : fontFaceRules) { if (RefPtrWillBeRawPtr<FontFace> fontFace = FontFace::create(&document, fontFaceRule)) cssFontSelector->fontFaceCache()->add(cssFontSelector, fontFaceRule, fontFace); } if (fontFaceRules.size()) document.styleResolver()->invalidateMatchedPropertiesCache(); }
bool FontFaceSet::deleteForBinding(ScriptState*, FontFace* fontFace, ExceptionState&) { ASSERT(fontFace); if (!inActiveDocumentContext()) return false; WillBeHeapListHashSet<RefPtrWillBeMember<FontFace>>::iterator it = m_nonCSSConnectedFaces.find(fontFace); if (it != m_nonCSSConnectedFaces.end()) { m_nonCSSConnectedFaces.remove(it); CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); fontSelector->fontFaceCache()->removeFontFace(fontFace, false); if (fontFace->loadStatus() == FontFace::Loading) removeFromLoadingFonts(fontFace); fontSelector->fontFaceInvalidated(); return true; } return false; }
PassRefPtrWillBeRawPtr<FontFaceSet> FontFaceSet::addForBinding(ScriptState*, FontFace* fontFace, ExceptionState&) { ASSERT(fontFace); if (!inActiveDocumentContext()) return this; if (m_nonCSSConnectedFaces.contains(fontFace)) return this; if (isCSSConnectedFontFace(fontFace)) return this; CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); m_nonCSSConnectedFaces.add(fontFace); fontSelector->fontFaceCache()->addFontFace(fontSelector, fontFace, false); if (fontFace->loadStatus() == FontFace::Loading) addToLoadingFonts(fontFace); fontSelector->fontFaceInvalidated(); return this; }
void FontFaceSet::add(FontFace* fontFace, ExceptionState& exceptionState) { if (!inActiveDocumentContext()) return; if (!fontFace) { exceptionState.ThrowTypeError("The argument is not a FontFace."); return; } if (m_nonCSSConnectedFaces.contains(fontFace)) return; if (isCSSConnectedFontFace(fontFace)) { exceptionState.ThrowDOMException(InvalidModificationError, "Cannot add a CSS-connected FontFace."); return; } CSSFontSelector* fontSelector = document()->styleEngine()->fontSelector(); m_nonCSSConnectedFaces.add(fontFace); fontSelector->fontFaceCache()->addFontFace(fontSelector, fontFace, false); if (fontFace->loadStatus() == FontFace::Loading) addToLoadingFonts(fontFace); fontSelector->fontFaceInvalidated(); }
bool FontFaceSet::remove(FontFace* fontFace, ExceptionState& exceptionState) { if (!inActiveDocumentContext()) return false; if (!fontFace) { exceptionState.ThrowTypeError("The argument is not a FontFace."); return false; } ListHashSet<RefPtr<FontFace> >::iterator it = m_nonCSSConnectedFaces.find(fontFace); if (it != m_nonCSSConnectedFaces.end()) { m_nonCSSConnectedFaces.remove(it); CSSFontSelector* fontSelector = document()->styleEngine()->fontSelector(); fontSelector->fontFaceCache()->removeFontFace(fontFace, false); if (fontFace->loadStatus() == FontFace::Loading) removeFromLoadingFonts(fontFace); fontSelector->fontFaceInvalidated(); return true; } if (isCSSConnectedFontFace(fontFace)) exceptionState.ThrowDOMException(InvalidModificationError, "Cannot delete a CSS-connected FontFace."); return false; }