Ignore:
Timestamp:
Nov 18, 2014, 12:04:38 PM (11 years ago)
Author:
[email protected]
Message:

Subclass CachedFont for SVG fonts
https://bugs.webkit.org/show_bug.cgi?id=138686

Reviewed by Simon Fraser.

Re-landing due to flakey bots.

Source/WebCore:

CachedFont had many #if ENABLE(SVG_FONTS) scattered throughout it.
Splitting out this SVG-specific code into a subclass of CachedFont
cleans up the design.

No new tests because there is no behavior change.

  • CMakeLists.txt:
  • WebCore.vcxproj/WebCore.vcxproj:
  • WebCore.vcxproj/WebCore.vcxproj.filters:
  • WebCore.xcodeproj/project.pbxproj:
  • css/CSSFontFaceSource.cpp:

(WebCore::CSSFontFaceSource::getFontData): There are two sections
in this function; one for SVG fonts and one for regular fonts.
I've moved these two sections into CachedFont and SVGCachedFont,
thereby simplifying this function.
(WebCore::CSSFontFaceSource::ensureFontData): Ditto.
(WebCore::CSSFontFaceSource::svgFontFaceElement): Moved to header.
(WebCore::CSSFontFaceSource::setSVGFontFaceElement): Ditto.
(WebCore::CSSFontFaceSource::isSVGFontFaceSource): Ditto.

  • css/CSSFontFaceSource.h: Put functions that are simple enough to

be inlined here.

  • css/CSSFontFaceSrcValue.cpp:

(WebCore::CSSFontFaceSrcValue::isSVGFontTarget): Convenience
function.
(WebCore::CSSFontFaceSrcValue::cachedFont): Pass through a boolean
from CSSFontSelector to CachedResourceHandle regarding if we should
be using SVGCachedFont instead of CachedFont.

  • css/CSSFontFaceSrcValue.h: New convenience function.
  • css/CSSFontSelector.cpp:

(WebCore::CSSFontSelector::addFontFaceRule): Pass through a boolean

  • inspector/InspectorPageAgent.cpp:

(WebCore::InspectorPageAgent::cachedResourceType): Update for new
CachedResource type
(WebCore::cachedResourcesForFrame): Ditto.

  • loader/cache/CachedFont.cpp:

(WebCore::CachedFont::CachedFont):
(WebCore::CachedFont::ensureCustomFontData): Taken from
CSSFontFaceSource::getFontData()
(WebCore::CachedFont::getFontData): Ditto.
(WebCore::CachedFont::platformDataFromCustomData): Ditto.
(WebCore::CachedFont::ensureSVGFontData): Moved to SVGCachedFont.
(WebCore::CachedFont::getSVGFontById): Ditto.

  • loader/cache/CachedFont.h:
  • loader/cache/CachedResource.cpp:

(WebCore::defaultPriorityForResourceType): Update for new enum
type.

  • loader/cache/CachedResource.h:
  • loader/cache/CachedResourceLoader.cpp:

(WebCore::createResource): Takes new boolean.
(WebCore::CachedResourceLoader::requestFont): Ditto.
(WebCore::CachedResourceLoader::checkInsecureContent): Update for
new enum type
(WebCore::CachedResourceLoader::canRequest): Ditto.

  • loader/cache/CachedResourceLoader.h:
  • loader/cache/CachedSVGFont.cpp: Added.

(WebCore::CachedSVGFont::CachedSVGFont): Moved from
CSSFontFaceSource::getFontData() and CachedFont
(WebCore::CachedSVGFont::getFontData): Ditto.
(WebCore::CachedSVGFont::platformDataFromCustomData): Ditto.
(WebCore::CachedSVGFont::ensureCustomFontData): Ditto.
(WebCore::CachedSVGFont::getSVGFontById): Ditto.
(WebCore::CachedSVGFont::firstFontFace): Ditto.

  • loader/cache/CachedSVGFont.h: Subclass CachedFont.
  • loader/cache/MemoryCache.cpp:

(WebCore::MemoryCache::getStatistics): Update for new enum.

  • svg/SVGFontFaceUriElement.cpp:

(WebCore::isSVGFontTarget): Convenience function.
(WebCore::SVGFontFaceUriElement::loadFont): Update for new
boolean.

Source/WebKit2:

Update for enum type.

  • WebProcess/Network/WebResourceLoadScheduler.cpp:

(WebKit::maximumBufferingTime):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/CSSFontFaceSource.cpp

    r176267 r176276  
    3838
    3939#if ENABLE(SVG_FONTS)
     40#include "CachedSVGFont.h"
    4041#include "FontCustomPlatformData.h"
    4142#include "SVGFontData.h"
     
    123124    if (isLoaded()) {
    124125        if (m_font) {
    125 #if ENABLE(SVG_FONTS)
    126             if (m_hasExternalSVGFont) {
    127                 // For SVG fonts parse the external SVG document, and extract the <font> element.
    128                 if (!m_font->ensureSVGFontData())
    129                     return 0;
     126            // Create new FontPlatformData from our CGFontRef, point size and ATSFontRef.
     127            if (!m_font->ensureCustomFontData(m_hasExternalSVGFont))
     128                return nullptr;
    130129
    131                 if (!m_externalSVGFontElement) {
    132                     String fragmentIdentifier;
    133                     size_t start = m_string.find('#');
    134                     if (start != notFound)
    135                         fragmentIdentifier = m_string.string().substring(start + 1);
    136                     m_externalSVGFontElement = m_font->getSVGFontById(fragmentIdentifier);
    137                 }
    138 
    139                 if (!m_externalSVGFontElement)
    140                     return 0;
    141 
    142                 if (auto firstFontFace = childrenOfType<SVGFontFaceElement>(*m_externalSVGFontElement).first()) {
    143                     if (!m_svgFontFaceElement) {
    144                         // We're created using a CSS @font-face rule, that means we're not associated with a SVGFontFaceElement.
    145                         // Use the imported <font-face> tag as referencing font-face element for these cases.
    146                         m_svgFontFaceElement = firstFontFace;
    147                     }
    148 
    149                     fontData = SimpleFontData::create(std::make_unique<SVGFontData>(firstFontFace), fontDescription.computedPixelSize(), syntheticBold, syntheticItalic);
    150                 }
    151             } else
    152 #endif
    153             {
    154                 // Create new FontPlatformData from our CGFontRef, point size and ATSFontRef.
    155                 if (!m_font->ensureCustomFontData())
    156                     return 0;
    157 
    158                 fontData = SimpleFontData::create(m_font->platformDataFromCustomData(fontDescription.computedPixelSize(), syntheticBold, syntheticItalic,
    159                     fontDescription.orientation(), fontDescription.widthVariant(), fontDescription.renderingMode()), true, false);
    160             }
     130            fontData = m_font->getFontData(fontDescription, m_string, syntheticBold, syntheticItalic, m_hasExternalSVGFont);
    161131        } else {
    162132#if ENABLE(SVG_FONTS)
     
    180150}
    181151
    182 #if ENABLE(SVG_FONTS)
    183 SVGFontFaceElement* CSSFontFaceSource::svgFontFaceElement() const
    184 {
    185     return m_svgFontFaceElement.get();
    186 }
    187 
    188 void CSSFontFaceSource::setSVGFontFaceElement(PassRefPtr<SVGFontFaceElement> element)
    189 {
    190     m_svgFontFaceElement = element;
    191 }
    192 
    193 bool CSSFontFaceSource::isSVGFontFaceSource() const
    194 {
    195     return m_svgFontFaceElement || m_hasExternalSVGFont;
    196 }
    197 #endif
    198 
    199152#if ENABLE(FONT_LOAD_EVENTS)
    200153bool CSSFontFaceSource::isDecodeError() const
     
    209162    if (!m_font)
    210163        return false;
    211 #if ENABLE(SVG_FONTS)
    212     if (m_hasExternalSVGFont)
    213         return m_font->ensureSVGFontData();
    214 #endif
    215     return m_font->ensureCustomFontData();
     164    return m_font->ensureCustomFontData(m_hasExternalSVGFont);
    216165}
    217166#endif
Note: See TracChangeset for help on using the changeset viewer.