void FontBuilder::createFontForDocument(PassRefPtr<FontSelector> fontSelector, RenderStyle* documentStyle) { FontDescription fontDescription = FontDescription(); fontDescription.setScript(localeToScriptCodeForFontSelection(documentStyle->locale())); if (Settings* settings = m_document->settings()) { fontDescription.setUsePrinterFont(m_document->printing()); const AtomicString& standardFont = settings->standardFontFamily(fontDescription.script()); if (!standardFont.isEmpty()) { fontDescription.setGenericFamily(FontDescription::StandardFamily); fontDescription.firstFamily().setFamily(standardFont); fontDescription.firstFamily().appendFamily(0); } fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1); int size = FontSize::fontSizeForKeyword(m_document, CSSValueMedium, false); fontDescription.setSpecifiedSize(size); fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(fontDescription, documentStyle->effectiveZoom(), size)); } else { fontDescription.setUsePrinterFont(m_document->printing()); } FontOrientation fontOrientation; NonCJKGlyphOrientation glyphOrientation; getFontAndGlyphOrientation(documentStyle, fontOrientation, glyphOrientation); fontDescription.setOrientation(fontOrientation); fontDescription.setNonCJKGlyphOrientation(glyphOrientation); documentStyle->setFontDescription(fontDescription); documentStyle->font().update(fontSelector); }
static PassRefPtr<FontData> fontDataForGenericFamily(Document* document, const FontDescription& fontDescription, const AtomicString& familyName) { if (!document || !document->frame()) return 0; const Settings* settings = document->frame()->settings(); if (!settings) return 0; AtomicString genericFamily; UScriptCode script = fontDescription.script(); if (familyName == serifFamily) genericFamily = settings->serifFontFamily(script); else if (familyName == sansSerifFamily) genericFamily = settings->sansSerifFontFamily(script); else if (familyName == cursiveFamily) genericFamily = settings->cursiveFontFamily(script); else if (familyName == fantasyFamily) genericFamily = settings->fantasyFontFamily(script); else if (familyName == monospaceFamily) genericFamily = settings->fixedFontFamily(script); else if (familyName == pictographFamily) genericFamily = settings->pictographFontFamily(script); else if (familyName == standardFamily) genericFamily = settings->standardFontFamily(script); if (!genericFamily.isEmpty()) return fontCache()->getFontResourceData(fontDescription, genericFamily); return 0; }
static AtomicString familyNameFromSettings(const GenericFontFamilySettings& settings, const FontDescription& fontDescription, const AtomicString& genericFamilyName) { UScriptCode script = fontDescription.script(); #if OS(ANDROID) if (fontDescription.genericFamily() == FontDescription::StandardFamily) return FontCache::getGenericFamilyNameForScript(FontFamilyNames::webkit_standard, script); if (genericFamilyName.startsWith("-webkit-")) return FontCache::getGenericFamilyNameForScript(genericFamilyName, script); #else if (fontDescription.genericFamily() == FontDescription::StandardFamily) return settings.standard(script); if (genericFamilyName == FontFamilyNames::webkit_serif) return settings.serif(script); if (genericFamilyName == FontFamilyNames::webkit_sans_serif) return settings.sansSerif(script); if (genericFamilyName == FontFamilyNames::webkit_cursive) return settings.cursive(script); if (genericFamilyName == FontFamilyNames::webkit_fantasy) return settings.fantasy(script); if (genericFamilyName == FontFamilyNames::webkit_monospace) return settings.fixed(script); if (genericFamilyName == FontFamilyNames::webkit_pictograph) return settings.pictograph(script); if (genericFamilyName == FontFamilyNames::webkit_standard) return settings.standard(script); #endif return emptyAtom; }
PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescription& fontDescription, UChar32 c, const SimpleFontData*) { AtomicString familyName = getFamilyNameForCharacter(c, fontDescription.script()); if (familyName.isEmpty()) return getLastResortFallbackFont(fontDescription, DoNotRetain); return fontDataFromFontPlatformData(getFontPlatformData(fontDescription, FontFaceCreationParams(familyName)), DoNotRetain); }
// 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); }
PassRef<RenderStyle> resolveForDocument(const Document& document) { ASSERT(document.hasLivingRenderTree()); RenderView& renderView = *document.renderView(); // HTML5 states that seamless iframes should replace default CSS values // with values inherited from the containing iframe element. However, // some values (such as the case of designMode = "on") still need to // be set by this "document style". auto documentStyle = RenderStyle::create(); bool seamlessWithParent = document.shouldDisplaySeamlesslyWithParent(); if (seamlessWithParent) { RenderStyle* iframeStyle = document.seamlessParentIFrame()->renderStyle(); if (iframeStyle) documentStyle.get().inheritFrom(iframeStyle); } // FIXME: It's not clear which values below we want to override in the seamless case! documentStyle.get().setDisplay(BLOCK); if (!seamlessWithParent) { documentStyle.get().setRTLOrdering(document.visuallyOrdered() ? VisualOrder : LogicalOrder); documentStyle.get().setZoom(!document.printing() ? renderView.frame().pageZoomFactor() : 1); documentStyle.get().setPageScaleTransform(renderView.frame().frameScaleFactor()); documentStyle.get().setLocale(document.contentLanguage()); } // This overrides any -webkit-user-modify inherited from the parent iframe. documentStyle.get().setUserModify(document.inDesignMode() ? READ_WRITE : READ_ONLY); Element* docElement = document.documentElement(); RenderObject* docElementRenderer = docElement ? docElement->renderer() : 0; if (docElementRenderer) { // Use the direction and writing-mode of the body to set the // viewport's direction and writing-mode unless the property is set on the document element. // If there is no body, then use the document element. RenderObject* bodyRenderer = document.body() ? document.body()->renderer() : 0; if (bodyRenderer && !document.writingModeSetOnDocumentElement()) documentStyle.get().setWritingMode(bodyRenderer->style()->writingMode()); else documentStyle.get().setWritingMode(docElementRenderer->style()->writingMode()); if (bodyRenderer && !document.directionSetOnDocumentElement()) documentStyle.get().setDirection(bodyRenderer->style()->direction()); else documentStyle.get().setDirection(docElementRenderer->style()->direction()); } const Pagination& pagination = renderView.frameView().pagination(); if (pagination.mode != Pagination::Unpaginated) { documentStyle.get().setColumnStylesFromPaginationMode(pagination.mode); documentStyle.get().setColumnGap(pagination.gap); if (renderView.hasColumns()) renderView.updateColumnInfoFromStyle(&documentStyle.get()); } // Seamless iframes want to inherit their font from their parent iframe, so early return before setting the font. if (seamlessWithParent) return documentStyle; const Settings& settings = renderView.frame().settings(); FontDescription fontDescription; fontDescription.setScript(localeToScriptCodeForFontSelection(documentStyle.get().locale())); fontDescription.setUsePrinterFont(document.printing() || !settings.screenFontSubstitutionEnabled()); fontDescription.setRenderingMode(settings.fontRenderingMode()); const AtomicString& standardFont = settings.standardFontFamily(fontDescription.script()); if (!standardFont.isEmpty()) { fontDescription.setGenericFamily(FontDescription::StandardFamily); fontDescription.setOneFamily(standardFont); } fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1); int size = fontSizeForKeyword(CSSValueMedium, false, document); fontDescription.setSpecifiedSize(size); bool useSVGZoomRules = document.isSVGDocument(); fontDescription.setComputedSize(computedFontSizeFromSpecifiedSize(size, fontDescription.isAbsoluteSize(), useSVGZoomRules, &documentStyle.get(), document)); FontOrientation fontOrientation; NonCJKGlyphOrientation glyphOrientation; documentStyle.get().getFontAndGlyphOrientation(fontOrientation, glyphOrientation); fontDescription.setOrientation(fontOrientation); fontDescription.setNonCJKGlyphOrientation(glyphOrientation); documentStyle.get().setFontDescription(fontDescription); CSSFontSelector* fontSelector = document.styleResolverIfExists() ? document.styleResolverIfExists()->fontSelector() : 0; documentStyle.get().font().update(fontSelector); return documentStyle; }