FallbackListCompositeKey FontFallbackList::compositeKey(const FontDescription& fontDescription) const { FallbackListCompositeKey key(fontDescription); const FontFamily* currentFamily = &fontDescription.family(); while (currentFamily) { if (currentFamily->family().length()) { FontFaceCreationParams params(adjustFamilyNameToAvoidUnsupportedFonts(currentFamily->family())); RefPtr<FontData> result; if (m_fontSelector) result = m_fontSelector->getFontData(fontDescription, currentFamily->family()); if (!result) { if (FontPlatformData* platformData = FontCache::fontCache()->getFontPlatformData(fontDescription, params)) result = FontCache::fontCache()->fontDataFromFontPlatformData(platformData); } // Include loading state and version when constructing key, that way if called when a font is loading // and then again once it has been loaded or updated different keys are produced. if (result) { FontCacheKey cacheKey = fontDescription.cacheKey(params, FontTraits(0), result->isLoading() || result->isLoadingFallback(), m_fontSelector ? m_fontSelector->version() : 0); key.add(cacheKey); } } currentFamily = currentFamily->next(); } return key; }
static inline void assertDescriptionMatchesMask(FontDescription& source, FontTraitsBitfield bitfield) { FontDescription target; target.setTraits(FontTraits(bitfield)); EXPECT_EQ(source.style(), target.style()); EXPECT_EQ(source.variant(), target.variant()); EXPECT_EQ(source.weight(), target.weight()); EXPECT_EQ(source.stretch(), target.stretch()); }
FontTraits FontDescription::traits() const { return FontTraits(style(), variant(), weight(), stretch()); }
FontTraits FontFace::traits() const { FontStretch stretch = FontStretchNormal; if (m_stretch) { if (!m_stretch->isPrimitiveValue()) return 0; switch (toCSSPrimitiveValue(m_stretch.get())->getValueID()) { case CSSValueUltraCondensed: stretch = FontStretchUltraCondensed; break; case CSSValueExtraCondensed: stretch = FontStretchExtraCondensed; break; case CSSValueCondensed: stretch = FontStretchCondensed; break; case CSSValueSemiCondensed: stretch = FontStretchSemiCondensed; break; case CSSValueSemiExpanded: stretch = FontStretchSemiExpanded; break; case CSSValueExpanded: stretch = FontStretchExpanded; break; case CSSValueExtraExpanded: stretch = FontStretchExtraExpanded; break; case CSSValueUltraExpanded: stretch = FontStretchUltraExpanded; break; default: break; } } FontStyle style = FontStyleNormal; if (m_style) { if (!m_style->isPrimitiveValue()) return 0; switch (toCSSPrimitiveValue(m_style.get())->getValueID()) { case CSSValueNormal: style = FontStyleNormal; break; case CSSValueOblique: style = FontStyleOblique; break; case CSSValueItalic: style = FontStyleItalic; break; default: break; } } FontWeight weight = FontWeight400; if (m_weight) { if (!m_weight->isPrimitiveValue()) return 0; switch (toCSSPrimitiveValue(m_weight.get())->getValueID()) { case CSSValueBold: case CSSValue700: weight = FontWeight700; break; case CSSValueNormal: case CSSValue400: weight = FontWeight400; break; case CSSValue900: weight = FontWeight900; break; case CSSValue800: weight = FontWeight800; break; case CSSValue600: weight = FontWeight600; break; case CSSValue500: weight = FontWeight500; break; case CSSValue300: weight = FontWeight300; break; case CSSValue200: weight = FontWeight200; break; case CSSValue100: weight = FontWeight100; break; // Although 'lighter' and 'bolder' are valid keywords for font-weights, they are invalid // inside font-face rules so they are ignored. Reference: http://www.w3.org/TR/css3-fonts/#descdef-font-weight. case CSSValueLighter: case CSSValueBolder: break; default: ASSERT_NOT_REACHED(); break; } } FontVariant variant = FontVariantNormal; if (RefPtrWillBeRawPtr<CSSValue> fontVariant = m_variant) { // font-variant descriptor can be a value list. if (fontVariant->isPrimitiveValue()) { RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); list->append(fontVariant); fontVariant = list; } else if (!fontVariant->isValueList()) { return 0; } CSSValueList* variantList = toCSSValueList(fontVariant.get()); unsigned numVariants = variantList->length(); if (!numVariants) return 0; for (unsigned i = 0; i < numVariants; ++i) { switch (toCSSPrimitiveValue(variantList->item(i))->getValueID()) { case CSSValueNormal: variant = FontVariantNormal; break; case CSSValueSmallCaps: variant = FontVariantSmallCaps; break; default: break; } } } return FontTraits(style, variant, weight, stretch); }
FontTraits FontFace::traits() const { FontStyle style = FontStyleNormal; if (m_style) { if (!m_style->isPrimitiveValue()) return 0; switch (toCSSPrimitiveValue(m_style.get())->getValueID()) { case CSSValueNormal: style = FontStyleNormal; break; case CSSValueItalic: case CSSValueOblique: style = FontStyleItalic; break; default: break; } } FontWeight weight = FontWeight400; if (m_weight) { if (!m_weight->isPrimitiveValue()) return 0; switch (toCSSPrimitiveValue(m_weight.get())->getValueID()) { case CSSValueBold: case CSSValue700: weight = FontWeight700; break; case CSSValueNormal: case CSSValue400: weight = FontWeight400; break; case CSSValue900: weight = FontWeight900; break; case CSSValue800: weight = FontWeight800; break; case CSSValue600: weight = FontWeight600; break; case CSSValue500: weight = FontWeight500; break; case CSSValue300: weight = FontWeight300; break; case CSSValue200: weight = FontWeight200; break; case CSSValueLighter: case CSSValue100: weight = FontWeight100; break; default: ASSERT_NOT_REACHED(); break; } } FontVariant variant = FontVariantNormal; if (RefPtrWillBeRawPtr<CSSValue> fontVariant = m_variant) { // font-variant descriptor can be a value list. if (fontVariant->isPrimitiveValue()) { RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); list->append(fontVariant); fontVariant = list; } else if (!fontVariant->isValueList()) { return 0; } CSSValueList* variantList = toCSSValueList(fontVariant.get()); unsigned numVariants = variantList->length(); if (!numVariants) return 0; for (unsigned i = 0; i < numVariants; ++i) { switch (toCSSPrimitiveValue(variantList->itemWithoutBoundsCheck(i))->getValueID()) { case CSSValueNormal: variant = FontVariantNormal; break; case CSSValueSmallCaps: variant = FontVariantSmallCaps; break; default: break; } } } return FontTraits(style, variant, weight, FontStretchNormal); }
FontTraits FontFace::traits() const { FontStretch stretch = FontStretchNormal; if (m_stretch) { if (!m_stretch->isPrimitiveValue()) return 0; switch (toCSSPrimitiveValue(m_stretch.get())->getValueID()) { case CSSValueUltraCondensed: stretch = FontStretchUltraCondensed; break; case CSSValueExtraCondensed: stretch = FontStretchExtraCondensed; break; case CSSValueCondensed: stretch = FontStretchCondensed; break; case CSSValueSemiCondensed: stretch = FontStretchSemiCondensed; break; case CSSValueSemiExpanded: stretch = FontStretchSemiExpanded; break; case CSSValueExpanded: stretch = FontStretchExpanded; break; case CSSValueExtraExpanded: stretch = FontStretchExtraExpanded; break; case CSSValueUltraExpanded: stretch = FontStretchUltraExpanded; break; default: break; } } FontStyle style = FontStyleNormal; if (m_style) { if (!m_style->isPrimitiveValue()) return 0; switch (toCSSPrimitiveValue(m_style.get())->getValueID()) { case CSSValueNormal: style = FontStyleNormal; break; case CSSValueOblique: style = FontStyleOblique; break; case CSSValueItalic: style = FontStyleItalic; break; default: break; } } FontWeight weight = FontWeight400; if (m_weight) { if (!m_weight->isPrimitiveValue()) return 0; switch (toCSSPrimitiveValue(m_weight.get())->getValueID()) { case CSSValueBold: case CSSValue700: weight = FontWeight700; break; case CSSValueNormal: case CSSValue400: weight = FontWeight400; break; case CSSValue900: weight = FontWeight900; break; case CSSValue800: weight = FontWeight800; break; case CSSValue600: weight = FontWeight600; break; case CSSValue500: weight = FontWeight500; break; case CSSValue300: weight = FontWeight300; break; case CSSValue200: weight = FontWeight200; break; case CSSValue100: weight = FontWeight100; break; // Although 'lighter' and 'bolder' are valid keywords for font-weights, they are invalid // inside font-face rules so they are ignored. Reference: http://www.w3.org/TR/css3-fonts/#descdef-font-weight. case CSSValueLighter: case CSSValueBolder: break; default: ASSERT_NOT_REACHED(); break; } } return FontTraits(style, weight, stretch); }