Exemplo n.º 1
0
void FontBuilder::checkForGenericFamilyChange(const FontDescription& oldDescription, FontDescription& newDescription)
{
    if (newDescription.isAbsoluteSize())
        return;

    if (newDescription.isMonospace() == oldDescription.isMonospace())
        return;

    // For now, lump all families but monospace together.
    if (newDescription.genericFamily() != FontDescription::MonospaceFamily
        && oldDescription.genericFamily() != FontDescription::MonospaceFamily)
        return;

    // We know the parent is monospace or the child is monospace, and that font
    // size was unspecified. We want to scale our font size as appropriate.
    // If the font uses a keyword size, then we refetch from the table rather than
    // multiplying by our scale factor.
    float size;
    if (newDescription.keywordSize()) {
        size = fontSizeForKeyword(newDescription.keywordSize(), newDescription.isMonospace());
    } else {
        Settings* settings = m_document->settings();
        float fixedScaleFactor = (settings && settings->defaultFixedFontSize() && settings->defaultFontSize())
            ? static_cast<float>(settings->defaultFixedFontSize()) / settings->defaultFontSize()
            : 1;
        size = oldDescription.isMonospace() ?
            newDescription.specifiedSize() / fixedScaleFactor :
            newDescription.specifiedSize() * fixedScaleFactor;
    }

    newDescription.setSpecifiedSize(size);
}
Exemplo n.º 2
0
void FontBuilder::updateSpecifiedSize(FontDescription& fontDescription, const ComputedStyle& style)
{
    float specifiedSize = fontDescription.specifiedSize();

    if (!specifiedSize && fontDescription.keywordSize())
        specifiedSize = fontSizeForKeyword(fontDescription.keywordSize(), fontDescription.isMonospace());

    fontDescription.setSpecifiedSize(specifiedSize);

    checkForGenericFamilyChange(style.getFontDescription(), fontDescription);
}
Exemplo n.º 3
0
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;
}