示例#1
0
void FontFace::initCSSFontFace(Document* document, PassRefPtrWillBeRawPtr<CSSValue> src)
{
    m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get());
    if (m_error)
        return;

    // Each item in the src property's list is a single CSSFontFaceSource. Put them all into a CSSFontFace.
    ASSERT(src);
    ASSERT(src->isValueList());
    CSSValueList* srcList = toCSSValueList(src.get());
    int srcLength = srcList->length();

    for (int i = 0; i < srcLength; i++) {
        // An item in the list either specifies a string (local font name) or a URL (remote font to download).
        CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->item(i));
        OwnPtrWillBeRawPtr<CSSFontFaceSource> source = nullptr;

        if (!item->isLocal()) {
            const Settings* settings = document ? document->settings() : nullptr;
            bool allowDownloading = settings && settings->downloadableBinaryFontsEnabled();
            if (allowDownloading && item->isSupportedFormat() && document) {
                FontResource* fetched = item->fetch(document);
                if (fetched) {
                    FontLoader* fontLoader = document->styleEngine().fontSelector()->fontLoader();
                    source = adoptPtrWillBeNoop(new RemoteFontFaceSource(fetched, fontLoader));
                }
            }
        } else {
            source = adoptPtrWillBeNoop(new LocalFontFaceSource(item->resource()));
        }

        if (source)
            m_cssFontFace->addSource(source.release());
    }
}
示例#2
0
void FontFace::initCSSFontFace(Document* document, PassRefPtrWillBeRawPtr<CSSValue> src)
{
    m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get());
    if (m_error)
        return;

    // Each item in the src property's list is a single CSSFontFaceSource. Put them all into a CSSFontFace.
    ASSERT(src);
    ASSERT(src->isValueList());
    CSSValueList* srcList = toCSSValueList(src.get());
    int srcLength = srcList->length();

    bool foundSVGFont = false;

    for (int i = 0; i < srcLength; i++) {
        // An item in the list either specifies a string (local font name) or a URL (remote font to download).
        CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->item(i));
        OwnPtrWillBeRawPtr<CSSFontFaceSource> source = nullptr;

#if ENABLE(SVG_FONTS)
        foundSVGFont = item->isSVGFontFaceSrc() || item->svgFontFaceElement();
#endif
        if (!item->isLocal()) {
            Settings* settings = document ? document->frame() ? document->frame()->settings() : 0 : 0;
            bool allowDownloading = foundSVGFont || (settings && settings->downloadableBinaryFontsEnabled());
            if (allowDownloading && item->isSupportedFormat() && document) {
                FontResource* fetched = item->fetch(document);
                if (fetched) {
                    FontLoader* fontLoader = document->styleEngine()->fontSelector()->fontLoader();

#if ENABLE(SVG_FONTS)
                    if (foundSVGFont) {
                        source = adoptPtrWillBeNoop(new SVGRemoteFontFaceSource(item->resource(), fetched, fontLoader));
                    } else
#endif
                    {
                        source = adoptPtrWillBeNoop(new RemoteFontFaceSource(fetched, fontLoader));
                    }
                }
            }
        } else {
#if ENABLE(SVG_FONTS)
            if (item->svgFontFaceElement()) {
                RefPtrWillBeRawPtr<SVGFontFaceElement> fontfaceElement = item->svgFontFaceElement();
                // SVGFontFaceSource assumes that it is the case where <font-face> element resides in the same document.
                // We put a RELEASE_ASSERT here as it will cause UAF if the assumption is false.
                RELEASE_ASSERT(fontfaceElement->inDocument());
                RELEASE_ASSERT(fontfaceElement->document() == document);
                source = adoptPtrWillBeNoop(new SVGFontFaceSource(fontfaceElement.get()));
            } else
#endif
            {
                source = adoptPtrWillBeNoop(new LocalFontFaceSource(item->resource()));
            }
        }

        if (source)
            m_cssFontFace->addSource(source.release());
    }
}
示例#3
0
void FontFace::initCSSFontFace(const unsigned char* data, unsigned size)
{
    m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get());
    if (m_error)
        return;

    RefPtr<SharedBuffer> buffer = SharedBuffer::create(data, size);
    OwnPtrWillBeRawPtr<BinaryDataFontFaceSource> source = adoptPtrWillBeNoop(new BinaryDataFontFaceSource(buffer.get(), m_otsParseMessage));
    if (source->isValid())
        setLoadStatus(Loaded);
    else
        setError(DOMException::create(SyntaxError, "Invalid font data in ArrayBuffer."));
    m_cssFontFace->addSource(source.release());
}
示例#4
0
文件: FontFace.cpp 项目: Mihiri/blink
void FontFace::initCSSFontFace(const unsigned char* data, unsigned size)
{
    m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get());

    RefPtr<SharedBuffer> buffer = SharedBuffer::create(data, size);
    OwnPtr<BinaryDataFontFaceSource> source = adoptPtr(new BinaryDataFontFaceSource(buffer.get()));
    if (source->isValid()) {
        m_status = Loaded;
    } else {
        m_status = Error;
        m_error = DOMError::create(SyntaxError, "Invalid font data in ArrayBuffer.");
    }
    m_cssFontFace->addSource(source.release());
}
示例#5
0
文件: FontFace.cpp 项目: Mihiri/blink
void FontFace::initCSSFontFace(Document* document, PassRefPtrWillBeRawPtr<CSSValue> src)
{
    m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get());

    // Each item in the src property's list is a single CSSFontFaceSource. Put them all into a CSSFontFace.
    CSSValueList* srcList = toCSSValueList(src.get());
    int srcLength = srcList->length();

    bool foundSVGFont = false;

    for (int i = 0; i < srcLength; i++) {
        // An item in the list either specifies a string (local font name) or a URL (remote font to download).
        CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->itemWithoutBoundsCheck(i));
        OwnPtr<CSSFontFaceSource> source;

#if ENABLE(SVG_FONTS)
        foundSVGFont = item->isSVGFontFaceSrc() || item->svgFontFaceElement();
#endif
        if (!item->isLocal()) {
            Settings* settings = document ? document->frame() ? document->frame()->settings() : 0 : 0;
            bool allowDownloading = foundSVGFont || (settings && settings->downloadableBinaryFontsEnabled());
            if (allowDownloading && item->isSupportedFormat() && document) {
                FontResource* fetched = item->fetch(document);
                if (fetched) {
#if ENABLE(SVG_FONTS)
                    if (foundSVGFont) {
                        source = adoptPtr(new SVGRemoteFontFaceSource(item->resource(), fetched));
                    } else
#endif
                    {
                        source = adoptPtr(new RemoteFontFaceSource(fetched));
                    }
                }
            }
        } else {
#if ENABLE(SVG_FONTS)
            if (item->svgFontFaceElement()) {
                source = adoptPtr(new SVGFontFaceSource(item->svgFontFaceElement()));
            } else
#endif
            {
                source = adoptPtr(new LocalFontFaceSource(item->resource()));
            }
        }

        if (source)
            m_cssFontFace->addSource(source.release());
    }
}
示例#6
0
void FontFace::initCSSFontFace(Document* document, CSSValue* src)
{
    m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get());
    if (m_error)
        return;

    // Each item in the src property's list is a single CSSFontFaceSource. Put them all into a CSSFontFace.
    ASSERT(src);
    ASSERT(src->isValueList());
    CSSValueList* srcList = toCSSValueList(src);
    int srcLength = srcList->length();

    for (int i = 0; i < srcLength; i++) {
        // An item in the list either specifies a string (local font name) or a URL (remote font to download).
        CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->item(i));
        CSSFontFaceSource* source = nullptr;

        if (!item->isLocal()) {
            const Settings* settings = document ? document->settings() : nullptr;
            bool allowDownloading = settings && settings->downloadableBinaryFontsEnabled();
            if (allowDownloading && item->isSupportedFormat() && document) {
                FontResource* fetched = item->fetch(document);
                if (fetched) {
                    CSSFontSelector* fontSelector = document->styleEngine().fontSelector();
                    source = new RemoteFontFaceSource(fetched, fontSelector, CSSValueToFontDisplay(m_display.get()));
                }
            }
        } else {
            source = new LocalFontFaceSource(item->resource());
        }

        if (source)
            m_cssFontFace->addSource(source);
    }

    if (m_display) {
        DEFINE_STATIC_LOCAL(EnumerationHistogram, fontDisplayHistogram, ("WebFont.FontDisplayValue", FontDisplayEnumMax));
        fontDisplayHistogram.count(CSSValueToFontDisplay(m_display.get()));
    }
}