bool FontFace::setFamilyValue(const CSSValue& familyValue) { AtomicString family; if (familyValue.isFontFamilyValue()) { family = AtomicString(toCSSFontFamilyValue(familyValue).value()); } else if (toCSSPrimitiveValue(familyValue).isValueID()) { // We need to use the raw text for all the generic family types, since @font-face is a way of actually // defining what font to use for those types. switch (toCSSPrimitiveValue(familyValue).getValueID()) { case CSSValueSerif: family = FontFamilyNames::webkit_serif; break; case CSSValueSansSerif: family = FontFamilyNames::webkit_sans_serif; break; case CSSValueCursive: family = FontFamilyNames::webkit_cursive; break; case CSSValueFantasy: family = FontFamilyNames::webkit_fantasy; break; case CSSValueMonospace: family = FontFamilyNames::webkit_monospace; break; case CSSValueWebkitPictograph: family = FontFamilyNames::webkit_pictograph; break; default: return false; } } m_family = family; return true; }
FontFace* FontFace::create(Document* document, const StyleRuleFontFace* fontFaceRule) { const StylePropertySet& properties = fontFaceRule->properties(); // Obtain the font-family property and the src property. Both must be defined. CSSValue* family = properties.getPropertyCSSValue(CSSPropertyFontFamily); if (!family || (!family->isFontFamilyValue() && !family->isPrimitiveValue())) return nullptr; CSSValue* src = properties.getPropertyCSSValue(CSSPropertySrc); if (!src || !src->isValueList()) return nullptr; FontFace* fontFace = new FontFace(document); if (fontFace->setFamilyValue(*family) && fontFace->setPropertyFromStyle(properties, CSSPropertyFontStyle) && fontFace->setPropertyFromStyle(properties, CSSPropertyFontWeight) && fontFace->setPropertyFromStyle(properties, CSSPropertyFontStretch) && fontFace->setPropertyFromStyle(properties, CSSPropertyUnicodeRange) && fontFace->setPropertyFromStyle(properties, CSSPropertyFontVariant) && fontFace->setPropertyFromStyle(properties, CSSPropertyFontFeatureSettings) && fontFace->setPropertyFromStyle(properties, CSSPropertyFontDisplay) && !fontFace->family().isEmpty() && fontFace->traits().bitfield()) { fontFace->initCSSFontFace(document, src); return fontFace; } return nullptr; }