diff options
Diffstat (limited to 'Source/WebCore/loader/cache/CachedFont.cpp')
-rw-r--r-- | Source/WebCore/loader/cache/CachedFont.cpp | 155 |
1 files changed, 61 insertions, 94 deletions
diff --git a/Source/WebCore/loader/cache/CachedFont.cpp b/Source/WebCore/loader/cache/CachedFont.cpp index fbf658cc0..91929778b 100644 --- a/Source/WebCore/loader/cache/CachedFont.cpp +++ b/Source/WebCore/loader/cache/CachedFont.cpp @@ -11,10 +11,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR @@ -31,27 +31,22 @@ #include "CachedResourceClientWalker.h" #include "CachedResourceLoader.h" #include "FontCustomPlatformData.h" +#include "FontDescription.h" #include "FontPlatformData.h" -#include "MemoryCache.h" -#include "ResourceBuffer.h" #include "SharedBuffer.h" #include "TextResourceDecoder.h" +#include "TypedElementDescendantIterator.h" #include "WOFFFileFormat.h" #include <wtf/Vector.h> -#if ENABLE(SVG_FONTS) -#include "NodeList.h" -#include "SVGDocument.h" -#include "SVGElement.h" -#include "SVGFontElement.h" -#include "SVGGElement.h" -#include "SVGNames.h" +#if USE(DIRECT2D) +#include <dwrite.h> #endif namespace WebCore { -CachedFont::CachedFont(const ResourceRequest& resourceRequest) - : CachedResource(resourceRequest, FontResource) +CachedFont::CachedFont(CachedResourceRequest&& request, SessionID sessionID, Type type) + : CachedResource(WTFMove(request), type, sessionID) , m_loadInitiated(false) , m_hasCreatedFontDataWrappingResource(false) { @@ -61,21 +56,20 @@ CachedFont::~CachedFont() { } -void CachedFont::load(CachedResourceLoader*, const ResourceLoaderOptions& options) +void CachedFont::load(CachedResourceLoader&) { // Don't load the file yet. Wait for an access before triggering the load. setLoading(true); - m_options = options; } -void CachedFont::didAddClient(CachedResourceClient* c) +void CachedFont::didAddClient(CachedResourceClient& client) { - ASSERT(c->resourceClientType() == CachedFontClient::expectedType()); + ASSERT(client.resourceClientType() == CachedFontClient::expectedType()); if (!isLoading()) - static_cast<CachedFontClient*>(c)->fontLoaded(this); + static_cast<CachedFontClient&>(client).fontLoaded(*this); } -void CachedFont::finishLoading(ResourceBuffer* data) +void CachedFont::finishLoading(SharedBuffer* data) { m_data = data; setEncodedSize(m_data.get() ? m_data->size() : 0); @@ -83,103 +77,76 @@ void CachedFont::finishLoading(ResourceBuffer* data) checkNotify(); } -void CachedFont::beginLoadIfNeeded(CachedResourceLoader* dl) +void CachedFont::beginLoadIfNeeded(CachedResourceLoader& loader) { if (!m_loadInitiated) { m_loadInitiated = true; - CachedResource::load(dl, m_options); + CachedResource::load(loader); } } -bool CachedFont::ensureCustomFontData() +bool CachedFont::ensureCustomFontData(const AtomicString&) { - if (!m_fontData && !errorOccurred() && !isLoading() && m_data) { - SharedBuffer* buffer = m_data.get()->sharedBuffer(); - ASSERT(buffer); - - RefPtr<SharedBuffer> sfntBuffer; - - bool fontIsWOFF = isWOFF(buffer); - if (fontIsWOFF) { - Vector<char> sfnt; - if (convertWOFFToSfnt(buffer, sfnt)) { - sfntBuffer = SharedBuffer::adoptVector(sfnt); - buffer = sfntBuffer.get(); - } else - buffer = nullptr; - } - - m_fontData = buffer ? createFontCustomPlatformData(*buffer) : nullptr; - if (m_fontData) - m_hasCreatedFontDataWrappingResource = !fontIsWOFF; - else - setStatus(DecodeError); - } - return m_fontData.get(); + return ensureCustomFontData(m_data.get()); } -FontPlatformData CachedFont::platformDataFromCustomData(float size, bool bold, bool italic, FontOrientation orientation, FontWidthVariant widthVariant, FontRenderingMode renderingMode) +bool CachedFont::ensureCustomFontData(SharedBuffer* data) { -#if ENABLE(SVG_FONTS) - if (m_externalSVGDocument) - return FontPlatformData(size, bold, italic); -#endif - ASSERT(m_fontData); - return m_fontData->fontPlatformData(static_cast<int>(size), bold, italic, orientation, widthVariant, renderingMode); -} - -#if ENABLE(SVG_FONTS) -bool CachedFont::ensureSVGFontData() -{ - if (!m_externalSVGDocument && !errorOccurred() && !isLoading() && m_data) { - m_externalSVGDocument = SVGDocument::create(0, URL()); - - RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("application/xml"); - String svgSource = decoder->decode(m_data->data(), m_data->size()); - svgSource.append(decoder->flush()); - - m_externalSVGDocument->setContent(svgSource); - - if (decoder->sawError()) - m_externalSVGDocument = 0; + if (!m_fontCustomPlatformData && !errorOccurred() && !isLoading() && data) { + bool wrapping; + m_fontCustomPlatformData = createCustomFontData(*data, wrapping); + m_hasCreatedFontDataWrappingResource = m_fontCustomPlatformData && wrapping; + if (!m_fontCustomPlatformData) + setStatus(DecodeError); } - return m_externalSVGDocument; + return m_fontCustomPlatformData.get(); } -SVGFontElement* CachedFont::getSVGFontById(const String& fontName) const +std::unique_ptr<FontCustomPlatformData> CachedFont::createCustomFontData(SharedBuffer& bytes, bool& wrapping) { - RefPtr<NodeList> list = m_externalSVGDocument->getElementsByTagNameNS(SVGNames::fontTag.namespaceURI(), SVGNames::fontTag.localName()); - if (!list) - return 0; - - unsigned listLength = list->length(); - if (!listLength) - return 0; - -#ifndef NDEBUG - for (unsigned i = 0; i < listLength; ++i) { - ASSERT(list->item(i)); - ASSERT(isSVGFontElement(list->item(i))); + wrapping = true; + +#if !PLATFORM(COCOA) + if (isWOFF(bytes)) { + wrapping = false; + Vector<char> convertedFont; + if (!convertWOFFToSfnt(bytes, convertedFont)) + return nullptr; + + auto buffer = SharedBuffer::adoptVector(convertedFont); + return createFontCustomPlatformData(buffer); } #endif - if (fontName.isEmpty()) - return toSVGFontElement(list->item(0)); + return createFontCustomPlatformData(bytes); +} - for (unsigned i = 0; i < listLength; ++i) { - SVGFontElement* element = toSVGFontElement(list->item(i)); - if (element->getIdAttribute() == fontName) - return element; - } +RefPtr<Font> CachedFont::createFont(const FontDescription& fontDescription, const AtomicString&, bool syntheticBold, bool syntheticItalic, const FontFeatureSettings& fontFaceFeatures, const FontVariantSettings& fontFaceVariantSettings) +{ + return Font::create(platformDataFromCustomData(fontDescription, syntheticBold, syntheticItalic, fontFaceFeatures, fontFaceVariantSettings), true); +} - return 0; +FontPlatformData CachedFont::platformDataFromCustomData(const FontDescription& fontDescription, bool bold, bool italic, const FontFeatureSettings& fontFaceFeatures, const FontVariantSettings& fontFaceVariantSettings) +{ + ASSERT(m_fontCustomPlatformData); + return platformDataFromCustomData(*m_fontCustomPlatformData, fontDescription, bold, italic, fontFaceFeatures, fontFaceVariantSettings); } + +FontPlatformData CachedFont::platformDataFromCustomData(FontCustomPlatformData& fontCustomPlatformData, const FontDescription& fontDescription, bool bold, bool italic, const FontFeatureSettings& fontFaceFeatures, const FontVariantSettings& fontFaceVariantSettings) +{ +#if PLATFORM(COCOA) + return fontCustomPlatformData.fontPlatformData(fontDescription, bold, italic, fontFaceFeatures, fontFaceVariantSettings); +#else + UNUSED_PARAM(fontFaceFeatures); + UNUSED_PARAM(fontFaceVariantSettings); + return fontCustomPlatformData.fontPlatformData(fontDescription, bold, italic); #endif +} void CachedFont::allClientsRemoved() { - m_fontData = nullptr; + m_fontCustomPlatformData = nullptr; } void CachedFont::checkNotify() @@ -187,9 +154,9 @@ void CachedFont::checkNotify() if (isLoading()) return; - CachedResourceClientWalker<CachedFontClient> w(m_clients); - while (CachedFontClient* c = w.next()) - c->fontLoaded(this); + CachedResourceClientWalker<CachedFontClient> walker(m_clients); + while (CachedFontClient* client = walker.next()) + client->fontLoaded(*this); } bool CachedFont::mayTryReplaceEncodedData() const |