RefPtr<Font> CachedSVGFont::createFont(const FontDescription& fontDescription, const AtomicString& remoteURI, bool syntheticBold, bool syntheticItalic, bool externalSVG) { #if ENABLE(SVG_OTF_CONVERTER) if (!externalSVG || firstFontFace(remoteURI)) return CachedFont::createFont(fontDescription, remoteURI, syntheticBold, syntheticItalic, externalSVG); #else if (!externalSVG) return CachedFont::createFont(fontDescription, remoteURI, syntheticBold, syntheticItalic, externalSVG); if (SVGFontFaceElement* firstFontFace = this->firstFontFace(remoteURI)) return Font::create(std::make_unique<SVGFontData>(firstFontFace), fontDescription.computedPixelSize(), syntheticBold, syntheticItalic); #endif return nullptr; }
FontPlatformData::FontPlatformData(FcPattern* pattern, const FontDescription& fontDescription) : m_pattern(pattern) , m_fallbacks(0) , m_size(fontDescription.computedPixelSize()) , m_syntheticBold(false) , m_syntheticOblique(false) , m_fixedWidth(false) , m_scaledFont(0) { RefPtr<cairo_font_face_t> fontFace = adoptRef(cairo_ft_font_face_create_for_pattern(m_pattern.get())); initializeWithFontFace(fontFace.get()); int spacing; if (FcPatternGetInteger(pattern, FC_SPACING, 0, &spacing) == FcResultMatch && spacing == FC_MONO) m_fixedWidth = true; if (fontDescription.weight() >= FontWeightBold) { // The FC_EMBOLDEN property instructs us to fake the boldness of the font. FcBool fontConfigEmbolden; if (FcPatternGetBool(pattern, FC_EMBOLDEN, 0, &fontConfigEmbolden) == FcResultMatch) m_syntheticBold = fontConfigEmbolden; } }
HRESULT STDMETHODCALLTYPE DOMElement::font(WebFontDescription* webFontDescription) { if (!webFontDescription) { ASSERT_NOT_REACHED(); return E_POINTER; } ASSERT(m_element); WebCore::RenderObject* renderer = m_element->renderer(); if (!renderer) return E_FAIL; FontDescription fontDescription = renderer->style()->font().fontDescription(); AtomicString family = fontDescription.firstFamily(); webFontDescription->family = family.characters(); webFontDescription->familyLength = family.length(); webFontDescription->size = fontDescription.computedSize(); webFontDescription->bold = fontDescription.weight() >= WebCore::FontWeight600; webFontDescription->italic = fontDescription.italic(); return S_OK; }
PassRefPtr<SimpleFontData> FontCache::fallbackOnStandardFontStyle( const FontDescription& fontDescription, UChar32 character) { FontDescription substituteDescription(fontDescription); substituteDescription.setStyle(FontStyleNormal); substituteDescription.setWeight(FontWeightNormal); FontFaceCreationParams creationParams( substituteDescription.family().family()); FontPlatformData* substitutePlatformData = getFontPlatformData(substituteDescription, creationParams); if (substitutePlatformData && substitutePlatformData->fontContainsCharacter(character)) { FontPlatformData platformData = FontPlatformData(*substitutePlatformData); platformData.setSyntheticBold(fontDescription.weight() >= FontWeight600); platformData.setSyntheticItalic( fontDescription.style() == FontStyleItalic || fontDescription.style() == FontStyleOblique); return fontDataFromFontPlatformData(&platformData, DoNotRetain); } return nullptr; }
PassRefPtr<FontData> CSSFontSelector::getFontData(const FontDescription& fontDescription, const AtomicString& familyName) { if (m_fontFaces.isEmpty()) { if (familyName.startsWith("-webkit-")) return fontDataForGenericFamily(m_document, fontDescription, familyName); if (fontDescription.genericFamily() == FontDescription::StandardFamily && !fontDescription.isSpecifiedFont()) return fontDataForGenericFamily(m_document, fontDescription, "-webkit-standard"); return 0; } CSSSegmentedFontFace* face = getFontFace(fontDescription, familyName); // If no face was found, then return 0 and let the OS come up with its best match for the name. if (!face) { // If we were handed a generic family, but there was no match, go ahead and return the correct font based off our // settings. if (fontDescription.genericFamily() == FontDescription::StandardFamily && !fontDescription.isSpecifiedFont()) return fontDataForGenericFamily(m_document, fontDescription, "-webkit-standard"); return fontDataForGenericFamily(m_document, fontDescription, familyName); } // We have a face. Ask it for a font data. If it cannot produce one, it will fail, and the OS will take over. return face->getFontData(fontDescription); }
FontPlatformData::FontPlatformData(const FontDescription& description, const AtomicString& familyName, int wordSpacing, int letterSpacing) : m_data(adoptRef(new FontPlatformDataPrivate())) { QFont font; int requestedSize = description.computedPixelSize(); font.setFamily(familyName); if (requestedSize) font.setPixelSize(requestedSize); font.setItalic(description.italic()); font.setWeight(toQFontWeight(description.weight())); font.setWordSpacing(wordSpacing); font.setLetterSpacing(QFont::AbsoluteSpacing, letterSpacing); if (description.fontSmoothing() == NoSmoothing || (description.fontSmoothing() == AutoSmoothing && !Font::shouldUseSmoothing())) font.setStyleStrategy(QFont::NoAntialias); m_data->bold = font.bold(); // WebKit allows font size zero but QFont does not. We will return // m_data->size if a font size of zero is requested and pixelSize() // otherwise. m_data->size = (!requestedSize) ? requestedSize : font.pixelSize(); m_data->rawFont = QRawFont::fromFont(font, QFontDatabase::Any); }
void TextAutoSizingValue::reset() { HashSet<RefPtr<Node> >::iterator end = m_autoSizedNodes.end(); for (HashSet<RefPtr<Node> >::iterator i = m_autoSizedNodes.begin(); i != end; ++i) { const RefPtr<Node>& autoSizingNode = *i; RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer()); if (!text) continue; // Reset the font size back to the original specified size FontDescription fontDescription = text->style().fontDescription(); float originalSize = fontDescription.specifiedSize(); if (fontDescription.computedSize() != originalSize) { fontDescription.setComputedSize(originalSize); RefPtr<RenderStyle> style = cloneRenderStyleWithState(text->style()); style->setFontDescription(fontDescription); style->font().update(autoSizingNode->document().ensureStyleResolver().fontSelector()); text->parent()->setStyle(style.releaseNonNull()); } // Reset the line height of the parent. RenderElement* parentRenderer = text->parent(); if (!parentRenderer) continue; if (parentRenderer->isAnonymousBlock()) parentRenderer = parentRenderer->parent(); const RenderStyle& parentStyle = parentRenderer->style(); Length originalLineHeight = parentStyle.specifiedLineHeight(); if (originalLineHeight != parentStyle.lineHeight()) { RefPtr<RenderStyle> newParentStyle = cloneRenderStyleWithState(parentStyle); newParentStyle->setLineHeight(originalLineHeight); newParentStyle->setFontDescription(fontDescription); newParentStyle->font().update(autoSizingNode->document().ensureStyleResolver().fontSelector()); parentRenderer->setStyle(newParentStyle.releaseNonNull()); } } }
static void fillFontDescription(FontDescription& fontDescription, LOGFONT& logFont, float fontSize) { fontDescription.setIsAbsoluteSize(true); fontDescription.setGenericFamily(FontDescription::NoFamily); fontDescription.firstFamily().setFamily(String(logFont.lfFaceName)); fontDescription.setSpecifiedSize(fontSize); fontDescription.setWeight(logFont.lfWeight >= 700 ? FontWeightBold : FontWeightNormal); // FIXME: Use real weight. fontDescription.setItalic(logFont.lfItalic); }
FontPlatformData::FontPlatformData(const FontDescription& description, const AtomicString& familyName, int wordSpacing, int letterSpacing) : m_data(adoptRef(new FontPlatformDataPrivate())) { QFont& font = m_data->font; int requestedSize = description.computedPixelSize(); font.setFamily(familyName); font.setPixelSize(requestedSize); font.setItalic(description.italic()); font.setWeight(toQFontWeight(description.weight())); font.setWordSpacing(wordSpacing); font.setLetterSpacing(QFont::AbsoluteSpacing, letterSpacing); const bool smallCaps = description.smallCaps(); font.setCapitalization(smallCaps ? QFont::SmallCaps : QFont::MixedCase); font.setStyleStrategy(QFont::ForceIntegerMetrics); m_data->bold = font.bold(); // WebKit allows font size zero but QFont does not. We will return // m_data->size if a font size of zero is requested and pixelSize() // otherwise. m_data->size = (!requestedSize) ? requestedSize : font.pixelSize(); #if HAVE(QRAWFONT) m_data->rawFont = QRawFont::fromFont(font, QFontDatabase::Any); #endif }
bool FontFaceSet::resolveFontStyle(const String& fontString, Font& font) { if (fontString.isEmpty()) return false; // Interpret fontString in the same way as the 'font' attribute of // CanvasRenderingContext2D. MutableStylePropertySet* parsedStyle = MutableStylePropertySet::create(HTMLStandardMode); CSSParser::parseValue(parsedStyle, CSSPropertyFont, fontString, true, 0); if (parsedStyle->isEmpty()) return false; String fontValue = parsedStyle->getPropertyValue(CSSPropertyFont); if (fontValue == "inherit" || fontValue == "initial") return false; RefPtr<ComputedStyle> style = ComputedStyle::create(); FontFamily fontFamily; fontFamily.setFamily(defaultFontFamily); FontDescription defaultFontDescription; defaultFontDescription.setFamily(fontFamily); defaultFontDescription.setSpecifiedSize(defaultFontSize); defaultFontDescription.setComputedSize(defaultFontSize); style->setFontDescription(defaultFontDescription); style->font().update(style->font().getFontSelector()); document()->ensureStyleResolver().computeFont(style.get(), *parsedStyle); font = style->font(); font.update(document()->styleEngine().fontSelector()); return true; }
//------------------------------------------------------------------------------ bool Font::Load(const FontDescription& d) { if (d.IsBold() == true) this->font.setWeight(QFont::Bold); else this->font.setWeight(QFont::Normal); if (d.IsItalic() == true) this->font.setStyle(QFont::StyleItalic); else this->font.setStyle(QFont::StyleNormal); if (d.IsMonospace() == true) this->font.setFamily("Courier"); else this->font.setFamily("Sans"); this->font.setPointSize(d.GetHeight()); QFontMetrics m(this->font); this->height = m.height(); this->ascent_height = m.ascent(); this->capital_height = this->height; this->initialized = true; return true; }
void FontPlatformData::initializeWithFontFace(cairo_font_face_t* fontFace, const FontDescription& fontDescription) { cairo_font_options_t* options = getDefaultFontOptions(); cairo_matrix_t ctm; cairo_matrix_init_identity(&ctm); // Scaling a font with width zero size leads to a failed cairo_scaled_font_t instantiations. // Instead we scale we scale the font to a very tiny size and just abort rendering later on. float realSize = m_size ? m_size : 1; cairo_matrix_t fontMatrix; if (!m_pattern) cairo_matrix_init_scale(&fontMatrix, realSize, realSize); else { setCairoFontOptionsFromFontConfigPattern(options, m_pattern.get()); // FontConfig may return a list of transformation matrices with the pattern, for instance, // for fonts that are oblique. We use that to initialize the cairo font matrix. FcMatrix fontConfigMatrix, *tempFontConfigMatrix; FcMatrixInit(&fontConfigMatrix); // These matrices may be stacked in the pattern, so it's our job to get them all and multiply them. for (int i = 0; FcPatternGetMatrix(m_pattern.get(), FC_MATRIX, i, &tempFontConfigMatrix) == FcResultMatch; i++) FcMatrixMultiply(&fontConfigMatrix, &fontConfigMatrix, tempFontConfigMatrix); cairo_matrix_init(&fontMatrix, fontConfigMatrix.xx, -fontConfigMatrix.yx, -fontConfigMatrix.xy, fontConfigMatrix.yy, 0, 0); // We requested an italic font, but Fontconfig gave us one that was neither oblique nor italic. int actualFontSlant; if (fontDescription.italic() && FcPatternGetInteger(m_pattern.get(), FC_SLANT, 0, &actualFontSlant) == FcResultMatch) m_syntheticOblique = actualFontSlant == FC_SLANT_ROMAN; // The matrix from FontConfig does not include the scale. cairo_matrix_scale(&fontMatrix, realSize, realSize); } if (syntheticOblique()) { static const float syntheticObliqueSkew = -tanf(14 * acosf(0) / 90); cairo_matrix_t skew = {1, 0, syntheticObliqueSkew, 1, 0, 0}; cairo_matrix_multiply(&fontMatrix, &skew, &fontMatrix); } m_scaledFont = cairo_scaled_font_create(fontFace, &fontMatrix, &ctm, options); cairo_font_options_destroy(options); }
TEST(FontDescriptionTest, TestHashCollision) { FontWeight weights[] = { FontWeight100, FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600, FontWeight700, FontWeight800, FontWeight900, }; FontStretch stretches[] { FontStretchUltraCondensed, FontStretchExtraCondensed, FontStretchCondensed, FontStretchSemiCondensed, FontStretchNormal, FontStretchSemiExpanded, FontStretchExpanded, FontStretchExtraExpanded, FontStretchUltraExpanded }; FontStyle styles[] = { FontStyleNormal, FontStyleOblique, FontStyleItalic }; FontVariant variants[] = { FontVariantNormal, FontVariantSmallCaps }; FontDescription source; WTF::Vector<unsigned> hashes; for (size_t i = 0; i < WTF_ARRAY_LENGTH(weights); i++) { source.setWeight(weights[i]); for (size_t j = 0; j < WTF_ARRAY_LENGTH(stretches); j++) { source.setStretch(stretches[j]); for (size_t k = 0; k < WTF_ARRAY_LENGTH(styles); k++) { source.setStyle(styles[k]); for (size_t m = 0; m < WTF_ARRAY_LENGTH(variants); m++) { source.setVariant(variants[m]); unsigned hash = source.styleHashWithoutFamilyList(); ASSERT_FALSE(hashes.contains(hash)); hashes.append(hash); } } } } }
RefPtr<Font> FontCache::systemFallbackForCharacters(const FontDescription& desc, const Font* originalFontData, bool isPlatformFont, const UChar* characters, unsigned int length) { ASSERT(characters && (length==1||length==2)); UChar32 c = 0; if (length==1) { c = characters[0]; } else { c = U16_GET_SUPPLEMENTARY(characters[0], characters[1]); } FontPlatformData alt(desc, desc.familyAt(0)); if (alt.font() && alt.font()->font()) { alt.font()->setSpecificUnicodeChar(c); return fontForPlatformData(alt); } else { return lastResortFallbackFont(desc); } }
FontPlatformData FontCustomPlatformData::fontPlatformData(const FontDescription& fontDescription, bool bold, bool italic) { int size = fontDescription.computedPixelSize(); FontOrientation orientation = fontDescription.orientation(); FontWidthVariant widthVariant = fontDescription.widthVariant(); #if CORETEXT_WEB_FONTS RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(m_fontDescriptor.get(), size, nullptr)); if (font && fontDescription.featureSettings() && fontDescription.featureSettings()->size()) font = applyFontFeatureSettings(font.get(), *fontDescription.featureSettings()); return FontPlatformData(font.get(), size, bold, italic, orientation, widthVariant); #else return FontPlatformData(m_cgFont.get(), size, bold, italic, orientation, widthVariant); #endif }
void FontBuilder::createFontForDocument(PassRefPtrWillBeRawPtr<FontSelector> fontSelector, RenderStyle* documentStyle) { FontDescription fontDescription = FontDescription(); fontDescription.setScript(localeToScriptCodeForFontSelection(documentStyle->locale())); setFontFamilyToStandard(fontDescription, m_document); fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1); int size = FontSize::fontSizeForKeyword(m_document, CSSValueMedium, false); fontDescription.setSpecifiedSize(size); fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(fontDescription, documentStyle->effectiveZoom(), size)); FontOrientation fontOrientation; NonCJKGlyphOrientation glyphOrientation; getFontAndGlyphOrientation(documentStyle, fontOrientation, glyphOrientation); fontDescription.setOrientation(fontOrientation); fontDescription.setNonCJKGlyphOrientation(glyphOrientation); documentStyle->setFontDescription(fontDescription); documentStyle->font().update(fontSelector); }
static inline void addToHarfBuzzBufferInternal(hb_buffer_t* buffer, const FontDescription& fontDescription, const UChar* normalizedBuffer, unsigned normalizedBufferLength, unsigned startIndex, unsigned numCharacters) { // TODO: Revisit whether we can always fill the hb_buffer_t with the // full run text, but only specify startIndex and numCharacters for the part // to be shaped. Then simplify/change the complicated index computations in // extractShapeResults(). if (fontDescription.variant() == FontVariantSmallCaps) { String upperText = String(normalizedBuffer, normalizedBufferLength) .upper(); // TextRun is 16 bit, therefore upperText is 16 bit, even after we call // makeUpper(). ASSERT(!upperText.is8Bit()); hb_buffer_add_utf16(buffer, toUint16(upperText.characters16()), normalizedBufferLength, startIndex, numCharacters); } else { hb_buffer_add_utf16(buffer, toUint16(normalizedBuffer), normalizedBufferLength, startIndex, numCharacters); } }
static Font makeFont(const WebFontDescription& description) { AtomicString::init(); String fontFamilyString(description.family, description.familyLength); FontDescription f; f.setOneFamily(fontFamilyString); f.setSpecifiedSize(description.size); f.setComputedSize(description.size); f.setItalic(description.italic); f.setWeight(description.bold ? FontWeightBold : FontWeightNormal); f.setIsAbsoluteSize(true); FontSmoothingType smoothingType; if (SUCCEEDED(WebPreferences::sharedStandardPreferences()->fontSmoothing(&smoothingType))) f.setRenderingMode(smoothingType == FontSmoothingTypeWindows ? AlternateRenderingMode : NormalRenderingMode); Font font(f, 0, 0); font.update(0); return font; }
PassRefPtr<FontData> FontFallbackList::getFontData(const FontDescription& fontDescription, int& familyIndex) const { RefPtr<FontData> result; int startIndex = familyIndex; const FontFamily* startFamily = &fontDescription.family(); for (int i = 0; startFamily && i < startIndex; i++) startFamily = startFamily->next(); const FontFamily* currFamily = startFamily; while (currFamily && !result) { familyIndex++; if (currFamily->family().length()) { if (m_fontSelector) result = m_fontSelector->getFontData(fontDescription, currFamily->family()); if (!result) result = FontCache::fontCache()->getFontData(fontDescription, currFamily->family()); } currFamily = currFamily->next(); } if (!currFamily) familyIndex = cAllFamiliesScanned; if (result || startIndex) return result.release(); // If it's the primary font that we couldn't find, we try the following. In all other cases, we will // just use per-character system fallback. if (m_fontSelector) { // Try the user's preferred standard font. if (RefPtr<FontData> data = m_fontSelector->getFontData(fontDescription, FontFamilyNames::webkit_standard)) return data.release(); } // Still no result. Hand back our last resort fallback font. return FontCache::fontCache()->getLastResortFallbackFont(fontDescription); }
// static AtomicString FontCache::getGenericFamilyNameForScript(const AtomicString& familyName, const FontDescription& fontDescription) { // This is a hack to use the preferred font for CJK scripts. // FIXME: Use new Skia API once Android system supports per-family and per-script fallback fonts. UChar32 examplerChar; switch (fontDescription.script()) { case USCRIPT_SIMPLIFIED_HAN: case USCRIPT_TRADITIONAL_HAN: case USCRIPT_KATAKANA_OR_HIRAGANA: examplerChar = 0x4E00; // A common character in Japanese and Chinese. break; case USCRIPT_HANGUL: examplerChar = 0xAC00; break; default: // For other scripts, use the default generic family mapping logic. return familyName; } RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault()); return getFamilyNameForCharacter(fm.get(), examplerChar, fontDescription, FontFallbackPriority::Text); }
void RenderThemeSafari::setFontFromControlSize(CSSStyleSelector* selector, RenderStyle* style, NSControlSize controlSize) const { FontDescription fontDescription; fontDescription.setIsAbsoluteSize(true); fontDescription.setGenericFamily(FontDescription::SerifFamily); float fontSize = systemFontSizeForControlSize(controlSize); fontDescription.firstFamily().setFamily("Lucida Grande"); fontDescription.setComputedSize(fontSize); fontDescription.setSpecifiedSize(fontSize); // Reset line height style->setLineHeight(RenderStyle::initialLineHeight()); if (style->setFontDescription(fontDescription)) style->font().update(selector->fontSelector()); }
static Font dragLabelFont(int size, bool bold, FontRenderingMode renderingMode) { NONCLIENTMETRICS metrics; metrics.cbSize = sizeof(metrics); SystemParametersInfo(SPI_GETNONCLIENTMETRICS, metrics.cbSize, &metrics, 0); FontDescription desc; desc.setWeight(bold ? FontWeightBold : FontWeightNormal); FontFamily family; family.setFamily(metrics.lfSmCaptionFont.lfFaceName); desc.setFamily(family); desc.setSpecifiedSize((float)size); desc.setComputedSize((float)size); desc.setRenderingMode(renderingMode); Font result = Font(desc, 0, 0); result.update(0); return result; }
TEST(DragImageTest, TrimWhitespace) { KURL url(ParsedURLString, "http://www.example.com/"); String testLabel = " Example Example Example \n "; String expectedLabel = "Example Example Example"; float deviceScaleFactor = 1.0f; FontDescription fontDescription; fontDescription.firstFamily().setFamily("Arial"); fontDescription.setSpecifiedSize(16); fontDescription.setIsAbsoluteSize(true); fontDescription.setGenericFamily(FontDescription::NoFamily); fontDescription.setWeight(FontWeightNormal); fontDescription.setStyle(FontStyleNormal); std::unique_ptr<DragImage> testImage = DragImage::create(url, testLabel, fontDescription, deviceScaleFactor); std::unique_ptr<DragImage> expectedImage = DragImage::create(url, expectedLabel, fontDescription, deviceScaleFactor); EXPECT_EQ(testImage->size().width(), expectedImage->size().width()); }
GlyphData FontCascadeFonts::glyphDataForSystemFallback(UChar32 c, const FontDescription& description, FontVariant variant) { // System fallback is character-dependent. auto& primaryRanges = realizeFallbackRangesAt(description, 0); auto* originalFont = primaryRanges.fontForCharacter(c); if (!originalFont) originalFont = &primaryRanges.fontForFirstRange(); RefPtr<Font> systemFallbackFont = originalFont->systemFallbackFontForCharacter(c, description, m_isForPlatformFont); if (!systemFallbackFont) return GlyphData(); if (systemFallbackFont->platformData().orientation() == Vertical && !systemFallbackFont->hasVerticalGlyphs() && FontCascade::isCJKIdeographOrSymbol(c)) variant = BrokenIdeographVariant; GlyphData fallbackGlyphData; if (variant == NormalVariant) fallbackGlyphData = systemFallbackFont->glyphDataForCharacter(c); else fallbackGlyphData = systemFallbackFont->variantFont(description, variant)->glyphDataForCharacter(c); if (fallbackGlyphData.font && fallbackGlyphData.font->platformData().orientation() == Vertical && !fallbackGlyphData.font->isTextOrientationFallback()) { if (variant == NormalVariant && !FontCascade::isCJKIdeographOrSymbol(c)) fallbackGlyphData = glyphDataForNonCJKCharacterWithGlyphOrientation(c, description.nonCJKGlyphOrientation(), fallbackGlyphData); #if PLATFORM(COCOA) || USE(CAIRO) if (fallbackGlyphData.font->platformData().syntheticOblique() && FontCascade::isCJKIdeographOrSymbol(c)) fallbackGlyphData = glyphDataForCJKCharacterWithoutSyntheticItalic(c, fallbackGlyphData); #endif } // Keep the system fallback fonts we use alive. if (fallbackGlyphData.glyph) m_systemFallbackFontSet.add(systemFallbackFont.release()); return fallbackGlyphData; }
PassRefPtr<SimpleFontData> FontCache::getLastResortFallbackFont(const FontDescription& description, ShouldRetain) { DEFINE_STATIC_LOCAL(const AtomicString, sansStr, ("Sans")); DEFINE_STATIC_LOCAL(const AtomicString, serifStr, ("Serif")); DEFINE_STATIC_LOCAL(const AtomicString, monospaceStr, ("Monospace")); FontPlatformData* fontPlatformData = 0; switch (description.genericFamily()) { case FontDescription::SerifFamily: fontPlatformData = getCachedFontPlatformData(description, serifStr); break; case FontDescription::MonospaceFamily: fontPlatformData = getCachedFontPlatformData(description, monospaceStr); break; case FontDescription::SansSerifFamily: default: fontPlatformData = getCachedFontPlatformData(description, sansStr); break; } if (!fontPlatformData) { DEFINE_STATIC_LOCAL(const AtomicString, arialStr, ("Arial")); fontPlatformData = getCachedFontPlatformData(description, arialStr); }
static String getFamilyNameStringFromFontDescriptionAndFamily(const FontDescription& fontDescription, const AtomicString& family) { // If we're creating a fallback font (e.g. "-webkit-monospace"), convert the name into // the fallback name (like "monospace") that fontconfig understands. if (family.length() && !family.startsWith("-webkit-")) return family.string(); switch (fontDescription.genericFamily()) { case FontDescription::StandardFamily: case FontDescription::SerifFamily: return "serif"; case FontDescription::SansSerifFamily: return "sans-serif"; case FontDescription::MonospaceFamily: return "monospace"; case FontDescription::CursiveFamily: return "cursive"; case FontDescription::FantasyFamily: return "fantasy"; case FontDescription::NoFamily: default: return ""; } }
PassRefPtr<SimpleFontData> CSSFontFaceSource::getFontData( const FontDescription& fontDescription) { // If the font hasn't loaded or an error occurred, then we've got nothing. if (!isValid()) return nullptr; if (isLocal()) { // We're local. Just return a SimpleFontData from the normal cache. return createFontData(fontDescription); } // See if we have a mapping in our FontData cache. // TODO(drott): Check whether losing traits information here is problematic. // crbug.com/516677 FontCacheKey key = fontDescription.cacheKey(FontFaceCreationParams()); RefPtr<SimpleFontData>& fontData = m_fontDataTable.add(key, nullptr).storedValue->value; if (!fontData) fontData = createFontData(fontDescription); // No release, because fontData is a reference to a RefPtr that is held in the // m_fontDataTable. return fontData; }
void createFontForDocument(RenderStyle* style) { FontDescription fontDescription = FontDescription(); fontDescription.setScript(localeToScriptCodeForFontSelection(style->locale())); // Using 14px default to match Material Design English Body1: // http://www.google.com/design/spec/style/typography.html#typography-typeface const float defaultFontSize = 14.0; fontDescription.setSpecifiedSize(defaultFontSize); fontDescription.setComputedSize(defaultFontSize); FontOrientation fontOrientation = Horizontal; NonCJKGlyphOrientation glyphOrientation = NonCJKGlyphOrientationVerticalRight; fontDescription.setOrientation(fontOrientation); fontDescription.setNonCJKGlyphOrientation(glyphOrientation); style->setFontDescription(fontDescription); style->font().update(UIDartState::Current()->font_selector()); }
virtual void applyValue(CSSStyleSelector* selector, CSSValue* value) const { if (!value->isPrimitiveValue()) return; CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); FontDescription fontDescription = selector->fontDescription(); switch (primitiveValue->getIdent()) { case CSSValueInvalid: ASSERT_NOT_REACHED(); break; case CSSValueBolder: fontDescription.setWeight(fontDescription.bolderWeight()); break; case CSSValueLighter: fontDescription.setWeight(fontDescription.lighterWeight()); break; default: fontDescription.setWeight(*primitiveValue); } selector->setFontDescription(fontDescription); }
void RenderThemeChromiumSkia::systemFont(int propId, FontDescription& fontDescription) const { float fontSize = defaultFontSize; switch (propId) { case CSSValueWebkitMiniControl: case CSSValueWebkitSmallControl: case CSSValueWebkitControl: // Why 2 points smaller? Because that's what Gecko does. Note that we // are assuming a 96dpi screen, which is the default that we use on // Windows. static const float pointsPerInch = 72.0f; static const float pixelsPerInch = 96.0f; fontSize -= (2.0f / pointsPerInch) * pixelsPerInch; break; } fontDescription.firstFamily().setFamily(defaultGUIFont()); fontDescription.setSpecifiedSize(fontSize); fontDescription.setIsAbsoluteSize(true); fontDescription.setGenericFamily(FontDescription::NoFamily); fontDescription.setWeight(FontWeightNormal); fontDescription.setItalic(false); }