Diff
Modified: trunk/Source/WebCore/CMakeLists.txt (176263 => 176264)
--- trunk/Source/WebCore/CMakeLists.txt 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/CMakeLists.txt 2014-11-18 18:04:17 UTC (rev 176264)
@@ -1842,6 +1842,7 @@
loader/archive/mhtml/MHTMLParser.cpp
loader/cache/CachedCSSStyleSheet.cpp
+ loader/cache/CachedSVGFont.cpp
loader/cache/CachedFont.cpp
loader/cache/CachedImage.cpp
loader/cache/CachedRawResource.cpp
Modified: trunk/Source/WebCore/ChangeLog (176263 => 176264)
--- trunk/Source/WebCore/ChangeLog 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/ChangeLog 2014-11-18 18:04:17 UTC (rev 176264)
@@ -1,3 +1,80 @@
+2014-11-18 Myles C. Maxfield <[email protected]>
+
+ Subclass CachedFont for SVG fonts
+ https://bugs.webkit.org/show_bug.cgi?id=138686
+
+ Reviewed by Simon Fraser.
+
+ 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.
+
2014-11-18 Myles C. Maxfield <[email protected]>
Use underlining metrics from the font file
Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (176263 => 176264)
--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj 2014-11-18 18:04:17 UTC (rev 176264)
@@ -7328,6 +7328,7 @@
<ClCompile Include="..\loader\archive\mhtml\MHTMLParser.cpp" />
<ClCompile Include="..\loader\cache\CachedCSSStyleSheet.cpp" />
<ClCompile Include="..\loader\cache\CachedFont.cpp" />
+ <ClCompile Include="..\loader\cache\CachedSVGFont.cpp" />
<ClCompile Include="..\loader\cache\CachedImage.cpp" />
<ClCompile Include="..\loader\cache\CachedRawResource.cpp" />
<ClCompile Include="..\loader\cache\CachedResource.cpp" />
@@ -19279,6 +19280,7 @@
<ClInclude Include="..\loader\archive\mhtml\MHTMLParser.h" />
<ClInclude Include="..\loader\cache\CachedCSSStyleSheet.h" />
<ClInclude Include="..\loader\cache\CachedFont.h" />
+ <ClInclude Include="..\loader\cache\CachedSVGFont.h" />
<ClInclude Include="..\loader\cache\CachedImage.h" />
<ClInclude Include="..\loader\cache\CachedRawResource.h" />
<ClInclude Include="..\loader\cache\CachedRawResourceClient.h" />
Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters (176263 => 176264)
--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters 2014-11-18 18:04:17 UTC (rev 176264)
@@ -1026,6 +1026,9 @@
<ClCompile Include="..\loader\cache\CachedCSSStyleSheet.cpp">
<Filter>loader\cache</Filter>
</ClCompile>
+ <ClCompile Include="..\loader\cache\CachedSVGFont.cpp">
+ <Filter>loader\cache</Filter>
+ </ClCompile>
<ClCompile Include="..\loader\cache\CachedFont.cpp">
<Filter>loader\cache</Filter>
</ClCompile>
@@ -8052,6 +8055,9 @@
<ClInclude Include="..\loader\cache\CachedCSSStyleSheet.h">
<Filter>loader\cache</Filter>
</ClInclude>
+ <ClInclude Include="..\loader\cache\CachedSVGFont.h">
+ <Filter>loader\cache</Filter>
+ </ClInclude>
<ClInclude Include="..\loader\cache\CachedFont.h">
<Filter>loader\cache</Filter>
</ClInclude>
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (176263 => 176264)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2014-11-18 18:04:17 UTC (rev 176264)
@@ -927,6 +927,8 @@
1AFE119A0CBFFCC4003017FA /* JSSQLResultSetRowList.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AFE11980CBFFCC4003017FA /* JSSQLResultSetRowList.h */; };
1C010700192594DF008A4201 /* InlineTextBoxStyle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C0106FE192594DF008A4201 /* InlineTextBoxStyle.cpp */; };
1C010701192594DF008A4201 /* InlineTextBoxStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C0106FF192594DF008A4201 /* InlineTextBoxStyle.h */; };
+ 1C0939EA1A13E12900B788E5 /* CachedSVGFont.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C0939E81A13E12900B788E5 /* CachedSVGFont.cpp */; };
+ 1C0939EB1A13E12900B788E5 /* CachedSVGFont.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C0939E91A13E12900B788E5 /* CachedSVGFont.h */; };
1C11CCB50AA6093700DADB20 /* DOMNotation.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 85CA96E80A9624E900690CCF /* DOMNotation.h */; };
1C11CCB60AA6093700DADB20 /* DOMComment.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 85089CD10A98C42700A275AA /* DOMComment.h */; };
1C11CCB70AA6093700DADB20 /* DOMNamedNodeMap.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 8518DD760A9CF31B0091B7A6 /* DOMNamedNodeMap.h */; };
@@ -7926,6 +7928,8 @@
1AFE11980CBFFCC4003017FA /* JSSQLResultSetRowList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSSQLResultSetRowList.h; sourceTree = "<group>"; };
1C0106FE192594DF008A4201 /* InlineTextBoxStyle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InlineTextBoxStyle.cpp; sourceTree = "<group>"; };
1C0106FF192594DF008A4201 /* InlineTextBoxStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InlineTextBoxStyle.h; sourceTree = "<group>"; };
+ 1C0939E81A13E12900B788E5 /* CachedSVGFont.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CachedSVGFont.cpp; sourceTree = "<group>"; };
+ 1C0939E91A13E12900B788E5 /* CachedSVGFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedSVGFont.h; sourceTree = "<group>"; };
1C18DA56181AF6A500C4EF22 /* TextPainter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextPainter.cpp; sourceTree = "<group>"; };
1C18DA57181AF6A500C4EF22 /* TextPainter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextPainter.h; sourceTree = "<group>"; };
1C21E57A183ED1FF001C289D /* IOSurfacePool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = IOSurfacePool.cpp; path = ../cg/IOSurfacePool.cpp; sourceTree = "<group>"; };
@@ -19579,6 +19583,8 @@
E467680F1A0177F900B9E26B /* CacheValidation.h */,
BCB16BFE0979C3BD00467741 /* MemoryCache.cpp */,
BCB16BFF0979C3BD00467741 /* MemoryCache.h */,
+ 1C0939E81A13E12900B788E5 /* CachedSVGFont.cpp */,
+ 1C0939E91A13E12900B788E5 /* CachedSVGFont.h */,
);
path = cache;
sourceTree = "<group>";
@@ -26215,6 +26221,7 @@
B22279E90D00BF220071B782 /* SVGFEFuncRElement.h in Headers */,
B22279EC0D00BF220071B782 /* SVGFEGaussianBlurElement.h in Headers */,
B25599850D00D8BA00BB825C /* SVGFEImage.h in Headers */,
+ 1C0939EB1A13E12900B788E5 /* CachedSVGFont.h in Headers */,
B22279EF0D00BF220071B782 /* SVGFEImageElement.h in Headers */,
B22279F20D00BF220071B782 /* SVGFELightElement.h in Headers */,
B22279F40D00BF220071B782 /* SVGFEMergeElement.h in Headers */,
@@ -29426,6 +29433,7 @@
51327D6111A33A2B004F9D65 /* SinkDocument.cpp in Sources */,
49E911CC0EF86D47009D0CAF /* SkewTransformOperation.cpp in Sources */,
4150F9F212B6E0E70008C860 /* SliderThumbElement.cpp in Sources */,
+ 1C0939EA1A13E12900B788E5 /* CachedSVGFont.cpp in Sources */,
4B6FA6F70C39E4A100087011 /* SmartReplaceCF.cpp in Sources */,
E4AFD00B0DAF335400F5F55C /* SMILTime.cpp in Sources */,
E4AFD00D0DAF335500F5F55C /* SMILTimeContainer.cpp in Sources */,
Modified: trunk/Source/WebCore/css/CSSFontFaceSource.cpp (176263 => 176264)
--- trunk/Source/WebCore/css/CSSFontFaceSource.cpp 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/css/CSSFontFaceSource.cpp 2014-11-18 18:04:17 UTC (rev 176264)
@@ -37,6 +37,7 @@
#include "SimpleFontData.h"
#if ENABLE(SVG_FONTS)
+#include "CachedSVGFont.h"
#include "FontCustomPlatformData.h"
#include "SVGFontData.h"
#include "SVGFontElement.h"
@@ -122,42 +123,11 @@
// If we are still loading, then we let the system pick a font.
if (isLoaded()) {
if (m_font) {
-#if ENABLE(SVG_FONTS)
- if (m_hasExternalSVGFont) {
- // For SVG fonts parse the external SVG document, and extract the <font> element.
- if (!m_font->ensureSVGFontData())
- return 0;
+ // Create new FontPlatformData from our CGFontRef, point size and ATSFontRef.
+ if (!m_font->ensureCustomFontData(m_hasExternalSVGFont))
+ return nullptr;
- if (!m_externalSVGFontElement) {
- String fragmentIdentifier;
- size_t start = m_string.find('#');
- if (start != notFound)
- fragmentIdentifier = m_string.string().substring(start + 1);
- m_externalSVGFontElement = m_font->getSVGFontById(fragmentIdentifier);
- }
-
- if (!m_externalSVGFontElement)
- return 0;
-
- if (auto firstFontFace = childrenOfType<SVGFontFaceElement>(*m_externalSVGFontElement).first()) {
- if (!m_svgFontFaceElement) {
- // We're created using a CSS @font-face rule, that means we're not associated with a SVGFontFaceElement.
- // Use the imported <font-face> tag as referencing font-face element for these cases.
- m_svgFontFaceElement = firstFontFace;
- }
-
- fontData = SimpleFontData::create(std::make_unique<SVGFontData>(firstFontFace), fontDescription.computedPixelSize(), syntheticBold, syntheticItalic);
- }
- } else
-#endif
- {
- // Create new FontPlatformData from our CGFontRef, point size and ATSFontRef.
- if (!m_font->ensureCustomFontData())
- return 0;
-
- fontData = SimpleFontData::create(m_font->platformDataFromCustomData(fontDescription.computedPixelSize(), syntheticBold, syntheticItalic,
- fontDescription.orientation(), fontDescription.widthVariant(), fontDescription.renderingMode()), true, false);
- }
+ fontData = m_font->getFontData(fontDescription, m_string, syntheticBold, syntheticItalic, m_hasExternalSVGFont);
} else {
#if ENABLE(SVG_FONTS)
// In-Document SVG Fonts
@@ -179,23 +149,6 @@
return fontData.release();
}
-#if ENABLE(SVG_FONTS)
-SVGFontFaceElement* CSSFontFaceSource::svgFontFaceElement() const
-{
- return m_svgFontFaceElement.get();
-}
-
-void CSSFontFaceSource::setSVGFontFaceElement(PassRefPtr<SVGFontFaceElement> element)
-{
- m_svgFontFaceElement = element;
-}
-
-bool CSSFontFaceSource::isSVGFontFaceSource() const
-{
- return m_svgFontFaceElement || m_hasExternalSVGFont;
-}
-#endif
-
#if ENABLE(FONT_LOAD_EVENTS)
bool CSSFontFaceSource::isDecodeError() const
{
@@ -208,11 +161,7 @@
{
if (!m_font)
return false;
-#if ENABLE(SVG_FONTS)
- if (m_hasExternalSVGFont)
- return m_font->ensureSVGFontData();
-#endif
- return m_font->ensureCustomFontData();
+ return m_font->ensureCustomFontData(m_hasExternalSVGFont);
}
#endif
Modified: trunk/Source/WebCore/css/CSSFontFaceSource.h (176263 => 176264)
--- trunk/Source/WebCore/css/CSSFontFaceSource.h 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/css/CSSFontFaceSource.h 2014-11-18 18:04:17 UTC (rev 176264)
@@ -28,6 +28,11 @@
#include "CachedFontClient.h"
#include "CachedResourceHandle.h"
+#include "SharedBuffer.h"
+#if ENABLE(SVG_FONTS)
+#include "SVGFontElement.h"
+#include "SVGFontFaceElement.h"
+#endif
#include "Timer.h"
#include <wtf/HashMap.h>
#include <wtf/text/AtomicString.h>
@@ -39,10 +44,6 @@
class CSSFontSelector;
class FontDescription;
class SimpleFontData;
-#if ENABLE(SVG_FONTS)
-class SVGFontElement;
-class SVGFontFaceElement;
-#endif
class CSSFontFaceSource final : public CachedFontClient {
public:
@@ -63,10 +64,10 @@
void pruneTable();
#if ENABLE(SVG_FONTS)
- SVGFontFaceElement* svgFontFaceElement() const;
- void setSVGFontFaceElement(PassRefPtr<SVGFontFaceElement>);
- bool isSVGFontFaceSource() const;
- void setHasExternalSVGFont(bool value) { m_hasExternalSVGFont = value; }
+ SVGFontFaceElement* svgFontFaceElement() const { return m_svgFontFaceElement.get(); }
+ void setSVGFontFaceElement(PassRefPtr<SVGFontFaceElement> element) { m_svgFontFaceElement = element; }
+ bool isSVGFontFaceSource() const { return m_svgFontFaceElement || m_hasExternalSVGFont; }
+ void setHasExternalSVGFont() { m_hasExternalSVGFont = true; }
#endif
#if ENABLE(FONT_LOAD_EVENTS)
@@ -84,7 +85,6 @@
#if ENABLE(SVG_FONTS)
RefPtr<SVGFontFaceElement> m_svgFontFaceElement;
- RefPtr<SVGFontElement> m_externalSVGFontElement;
bool m_hasExternalSVGFont;
#endif
};
Modified: trunk/Source/WebCore/css/CSSFontFaceSrcValue.cpp (176263 => 176264)
--- trunk/Source/WebCore/css/CSSFontFaceSrcValue.cpp 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/css/CSSFontFaceSrcValue.cpp 2014-11-18 18:04:17 UTC (rev 176264)
@@ -43,6 +43,11 @@
{
return equalIgnoringCase(m_format, "svg");
}
+
+bool CSSFontFaceSrcValue::isSVGFontTarget() const
+{
+ return isSVGFontFaceSrc() || svgFontFaceElement();
+}
#endif
bool CSSFontFaceSrcValue::isSupportedFormat() const
@@ -93,12 +98,12 @@
return m_cachedFont->loadFailedOrCanceled();
}
-CachedFont* CSSFontFaceSrcValue::cachedFont(Document* document)
+CachedFont* CSSFontFaceSrcValue::cachedFont(Document* document, bool isSVG)
{
if (!m_cachedFont) {
CachedResourceRequest request(ResourceRequest(document->completeURL(m_resource)));
request.setInitiator(cachedResourceRequestInitiators().css);
- m_cachedFont = document->cachedResourceLoader()->requestFont(request);
+ m_cachedFont = document->cachedResourceLoader()->requestFont(request, isSVG);
}
return m_cachedFont.get();
}
Modified: trunk/Source/WebCore/css/CSSFontFaceSrcValue.h (176263 => 176264)
--- trunk/Source/WebCore/css/CSSFontFaceSrcValue.h 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/css/CSSFontFaceSrcValue.h 2014-11-18 18:04:17 UTC (rev 176264)
@@ -58,6 +58,7 @@
#if ENABLE(SVG_FONTS)
bool isSVGFontFaceSrc() const;
+ bool isSVGFontTarget() const;
SVGFontFaceElement* svgFontFaceElement() const { return m_svgFontFaceElement; }
void setSVGFontFaceElement(SVGFontFaceElement* element) { m_svgFontFaceElement = element; }
@@ -69,7 +70,7 @@
bool hasFailedOrCanceledSubresources() const;
- CachedFont* cachedFont(Document*);
+ CachedFont* cachedFont(Document*, bool isSVG);
bool equals(const CSSFontFaceSrcValue&) const;
Modified: trunk/Source/WebCore/css/CSSFontSelector.cpp (176263 => 176264)
--- trunk/Source/WebCore/css/CSSFontSelector.cpp 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/css/CSSFontSelector.cpp 2014-11-18 18:04:17 UTC (rev 176264)
@@ -212,12 +212,12 @@
Settings* settings = m_document ? m_document->frame() ? &m_document->frame()->settings() : 0 : 0;
bool allowDownloading = foundSVGFont || (settings && settings->downloadableBinaryFontsEnabled());
if (allowDownloading && item.isSupportedFormat() && m_document) {
- CachedFont* cachedFont = item.cachedFont(m_document);
+ CachedFont* cachedFont = item.cachedFont(m_document, foundSVGFont);
if (cachedFont) {
source = std::make_unique<CSSFontFaceSource>(item.resource(), cachedFont);
#if ENABLE(SVG_FONTS)
if (foundSVGFont)
- source->setHasExternalSVGFont(true);
+ source->setHasExternalSVGFont();
#endif
}
}
Modified: trunk/Source/WebCore/inspector/InspectorPageAgent.cpp (176263 => 176264)
--- trunk/Source/WebCore/inspector/InspectorPageAgent.cpp 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/inspector/InspectorPageAgent.cpp 2014-11-18 18:04:17 UTC (rev 176264)
@@ -297,6 +297,9 @@
switch (cachedResource.type()) {
case CachedResource::ImageResource:
return InspectorPageAgent::ImageResource;
+#if ENABLE(SVG_FONTS)
+ case CachedResource::SVGFontResource:
+#endif
case CachedResource::FontResource:
return InspectorPageAgent::FontResource;
case CachedResource::CSSStyleSheet:
@@ -454,6 +457,9 @@
switch (cachedResource->type()) {
case CachedResource::ImageResource:
// Skip images that were not auto loaded (images disabled in the user agent).
+#if ENABLE(SVG_FONTS)
+ case CachedResource::SVGFontResource:
+#endif
case CachedResource::FontResource:
// Skip fonts that were referenced in CSS but never used/downloaded.
if (cachedResource->stillNeedsLoad())
Modified: trunk/Source/WebCore/loader/cache/CachedFont.cpp (176263 => 176264)
--- trunk/Source/WebCore/loader/cache/CachedFont.cpp 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/loader/cache/CachedFont.cpp 2014-11-18 18:04:17 UTC (rev 176264)
@@ -31,6 +31,7 @@
#include "CachedResourceClientWalker.h"
#include "CachedResourceLoader.h"
#include "FontCustomPlatformData.h"
+#include "FontDescription.h"
#include "FontPlatformData.h"
#include "MemoryCache.h"
#include "SharedBuffer.h"
@@ -39,6 +40,10 @@
#include "WOFFFileFormat.h"
#include <wtf/Vector.h>
+#if ENABLE(SVG_OTF_CONVERTER)
+#include "SVGToOTFFontConversion.h"
+#endif
+
#if ENABLE(SVG_FONTS)
#include "NodeList.h"
#include "SVGDocument.h"
@@ -50,8 +55,8 @@
namespace WebCore {
-CachedFont::CachedFont(const ResourceRequest& resourceRequest, SessionID sessionID)
- : CachedResource(resourceRequest, FontResource, sessionID)
+CachedFont::CachedFont(const ResourceRequest& resourceRequest, SessionID sessionID, Type type)
+ : CachedResource(resourceRequest, type, sessionID)
, m_loadInitiated(false)
, m_hasCreatedFontDataWrappingResource(false)
{
@@ -91,7 +96,7 @@
}
}
-bool CachedFont::ensureCustomFontData()
+bool CachedFont::ensureCustomFontData(bool)
{
if (!m_fontData && !errorOccurred() && !isLoading() && m_data) {
RefPtr<SharedBuffer> buffer = m_data;
@@ -118,46 +123,18 @@
return m_fontData.get();
}
+PassRefPtr<SimpleFontData> CachedFont::getFontData(const FontDescription& fontDescription, const AtomicString&, bool syntheticBold, bool syntheticItalic, bool)
+{
+ return SimpleFontData::create(platformDataFromCustomData(fontDescription.computedPixelSize(), syntheticBold, syntheticItalic,
+ fontDescription.orientation(), fontDescription.widthVariant(), fontDescription.renderingMode()), true, false);
+}
+
FontPlatformData CachedFont::platformDataFromCustomData(float size, bool bold, bool italic, FontOrientation orientation, FontWidthVariant widthVariant, FontRenderingMode renderingMode)
{
-#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(nullptr, URL());
- RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("application/xml");
- m_externalSVGDocument->setContent(decoder->decodeAndFlush(m_data->data(), m_data->size()));
- if (decoder->sawError())
- m_externalSVGDocument = nullptr;
- }
- return m_externalSVGDocument;
-}
-
-SVGFontElement* CachedFont::getSVGFontById(const String& fontName) const
-{
- auto elements = descendantsOfType<SVGFontElement>(*m_externalSVGDocument);
-
- if (fontName.isEmpty())
- return elements.first();
-
- for (auto& element : elements) {
- if (element.getIdAttribute() == fontName)
- return &element;
- }
- return nullptr;
-}
-
-#endif
-
void CachedFont::allClientsRemoved()
{
m_fontData = nullptr;
Modified: trunk/Source/WebCore/loader/cache/CachedFont.h (176263 => 176264)
--- trunk/Source/WebCore/loader/cache/CachedFont.h 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/loader/cache/CachedFont.h 2014-11-18 18:04:17 UTC (rev 176264)
@@ -31,31 +31,32 @@
#include "FontOrientation.h"
#include "FontRenderingMode.h"
#include "FontWidthVariant.h"
+#include "SimpleFontData.h"
namespace WebCore {
class CachedResourceLoader;
+class FontDescription;
class FontPlatformData;
class SVGDocument;
class SVGFontElement;
struct FontCustomPlatformData;
-class CachedFont final : public CachedResource {
+class CachedFont : public CachedResource {
public:
- CachedFont(const ResourceRequest&, SessionID);
+ CachedFont(const ResourceRequest&, SessionID, Type = FontResource);
virtual ~CachedFont();
void beginLoadIfNeeded(CachedResourceLoader* dl);
virtual bool stillNeedsLoad() const override { return !m_loadInitiated; }
- bool ensureCustomFontData();
- FontPlatformData platformDataFromCustomData(float size, bool bold, bool italic, FontOrientation = Horizontal, FontWidthVariant = RegularWidth, FontRenderingMode = NormalRenderingMode);
+ virtual bool ensureCustomFontData(bool externalSVG);
-#if ENABLE(SVG_FONTS)
- bool ensureSVGFontData();
- SVGFontElement* getSVGFontById(const String&) const;
-#endif
+ virtual PassRefPtr<SimpleFontData> getFontData(const FontDescription&, const AtomicString& remoteURI, bool syntheticBold, bool syntheticItalic, bool externalSVG);
+protected:
+ FontPlatformData platformDataFromCustomData(float size, bool bold, bool italic, FontOrientation = Horizontal, FontWidthVariant = RegularWidth, FontRenderingMode = NormalRenderingMode);
+
private:
virtual void checkNotify() override;
virtual bool mayTryReplaceEncodedData() const override;
@@ -71,10 +72,6 @@
bool m_loadInitiated;
bool m_hasCreatedFontDataWrappingResource;
-#if ENABLE(SVG_FONTS)
- RefPtr<SVGDocument> m_externalSVGDocument;
-#endif
-
friend class MemoryCache;
};
Modified: trunk/Source/WebCore/loader/cache/CachedResource.cpp (176263 => 176264)
--- trunk/Source/WebCore/loader/cache/CachedResource.cpp 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/loader/cache/CachedResource.cpp 2014-11-18 18:04:17 UTC (rev 176264)
@@ -69,6 +69,9 @@
case CachedResource::CSSStyleSheet:
return ResourceLoadPriorityHigh;
case CachedResource::Script:
+#if ENABLE(SVG_FONTS)
+ case CachedResource::SVGFontResource:
+#endif
case CachedResource::FontResource:
case CachedResource::RawResource:
return ResourceLoadPriorityMedium;
Modified: trunk/Source/WebCore/loader/cache/CachedResource.h (176263 => 176264)
--- trunk/Source/WebCore/loader/cache/CachedResource.h 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/loader/cache/CachedResource.h 2014-11-18 18:04:17 UTC (rev 176264)
@@ -66,6 +66,9 @@
CSSStyleSheet,
Script,
FontResource,
+#if ENABLE(SVG_FONTS)
+ SVGFontResource,
+#endif
RawResource,
SVGDocumentResource
#if ENABLE(XSLT)
Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp (176263 => 176264)
--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp 2014-11-18 18:04:17 UTC (rev 176264)
@@ -33,6 +33,7 @@
#include "CachedImage.h"
#include "CachedRawResource.h"
#include "CachedResourceRequest.h"
+#include "CachedSVGFont.h"
#include "CachedScript.h"
#include "CachedXSLStyleSheet.h"
#include "Chrome.h"
@@ -84,6 +85,10 @@
return new CachedScript(request, charset, sessionID);
case CachedResource::SVGDocumentResource:
return new CachedSVGDocument(request, sessionID);
+#if ENABLE(SVG_FONTS)
+ case CachedResource::SVGFontResource:
+ return new CachedSVGFont(request, sessionID);
+#endif
case CachedResource::FontResource:
return new CachedFont(request, sessionID);
case CachedResource::RawResource:
@@ -175,8 +180,10 @@
return downcast<CachedImage>(requestResource(CachedResource::ImageResource, request).get());
}
-CachedResourceHandle<CachedFont> CachedResourceLoader::requestFont(CachedResourceRequest& request)
+CachedResourceHandle<CachedFont> CachedResourceLoader::requestFont(CachedResourceRequest& request, bool isSVG)
{
+ if (isSVG)
+ return downcast<CachedSVGFont>(requestResource(CachedResource::SVGFontResource, request).get());
return downcast<CachedFont>(requestResource(CachedResource::FontResource, request).get());
}
@@ -274,6 +281,9 @@
#endif
case CachedResource::RawResource:
case CachedResource::ImageResource:
+#if ENABLE(SVG_FONTS)
+ case CachedResource::SVGFontResource:
+#endif
case CachedResource::FontResource: {
// These resources can corrupt only the frame's pixels.
if (Frame* f = frame()) {
@@ -314,6 +324,9 @@
case CachedResource::ImageResource:
case CachedResource::CSSStyleSheet:
case CachedResource::Script:
+#if ENABLE(SVG_FONTS)
+ case CachedResource::SVGFontResource:
+#endif
case CachedResource::FontResource:
case CachedResource::RawResource:
#if ENABLE(LINK_PREFETCH)
@@ -361,6 +374,9 @@
if (!shouldBypassMainWorldContentSecurityPolicy && !m_document->contentSecurityPolicy()->allowImageFromSource(url))
return false;
break;
+#if ENABLE(SVG_FONTS)
+ case CachedResource::SVGFontResource:
+#endif
case CachedResource::FontResource: {
if (!shouldBypassMainWorldContentSecurityPolicy && !m_document->contentSecurityPolicy()->allowFontFromSource(url))
return false;
Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.h (176263 => 176264)
--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.h 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.h 2014-11-18 18:04:17 UTC (rev 176264)
@@ -75,7 +75,7 @@
CachedResourceHandle<CachedCSSStyleSheet> requestCSSStyleSheet(CachedResourceRequest&);
CachedResourceHandle<CachedCSSStyleSheet> requestUserCSSStyleSheet(CachedResourceRequest&);
CachedResourceHandle<CachedScript> requestScript(CachedResourceRequest&);
- CachedResourceHandle<CachedFont> requestFont(CachedResourceRequest&);
+ CachedResourceHandle<CachedFont> requestFont(CachedResourceRequest&, bool isSVG);
CachedResourceHandle<CachedRawResource> requestRawResource(CachedResourceRequest&);
CachedResourceHandle<CachedRawResource> requestMainResource(CachedResourceRequest&);
CachedResourceHandle<CachedSVGDocument> requestSVGDocument(CachedResourceRequest&);
Added: trunk/Source/WebCore/loader/cache/CachedSVGFont.cpp (0 => 176264)
--- trunk/Source/WebCore/loader/cache/CachedSVGFont.cpp (rev 0)
+++ trunk/Source/WebCore/loader/cache/CachedSVGFont.cpp 2014-11-18 18:04:17 UTC (rev 176264)
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2009 Torch Mobile, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * 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 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 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
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CachedSVGFont.h"
+
+#if ENABLE(SVG_FONTS)
+
+#include "FontDescription.h"
+#include "FontPlatformData.h"
+#include "SVGDocument.h"
+#include "SVGFontData.h"
+#include "SVGFontElement.h"
+#include "SVGFontFaceElement.h"
+#include "SharedBuffer.h"
+#include "TextResourceDecoder.h"
+#include "TypedElementDescendantIterator.h"
+
+namespace WebCore {
+
+CachedSVGFont::CachedSVGFont(const ResourceRequest& resourceRequest, SessionID sessionID)
+ : CachedFont(resourceRequest, sessionID, SVGFontResource)
+ , m_externalSVGFontElement(nullptr)
+{
+}
+
+PassRefPtr<SimpleFontData> CachedSVGFont::getFontData(const FontDescription& fontDescription, const AtomicString& remoteURI, bool syntheticBold, bool syntheticItalic, bool externalSVG)
+{
+ if (!externalSVG)
+ return CachedFont::getFontData(fontDescription, remoteURI, syntheticBold, syntheticItalic, externalSVG);
+
+ if (SVGFontFaceElement* firstFontFace = this->firstFontFace(remoteURI))
+ return SimpleFontData::create(std::make_unique<SVGFontData>(firstFontFace), fontDescription.computedPixelSize(), syntheticBold, syntheticItalic);
+ return nullptr;
+}
+
+FontPlatformData CachedSVGFont::platformDataFromCustomData(float size, bool bold, bool italic, FontOrientation orientation, FontWidthVariant widthVariant, FontRenderingMode renderingMode)
+{
+ if (m_externalSVGDocument)
+ return FontPlatformData(size, bold, italic);
+ return CachedFont::platformDataFromCustomData(size, bold, italic, orientation, widthVariant, renderingMode);
+}
+
+bool CachedSVGFont::ensureCustomFontData(bool externalSVG)
+{
+ if (!externalSVG)
+ return CachedFont::ensureCustomFontData(externalSVG);
+
+ if (!m_externalSVGDocument && !errorOccurred() && !isLoading() && m_data) {
+ m_externalSVGDocument = SVGDocument::create(nullptr, URL());
+ RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("application/xml");
+ m_externalSVGDocument->setContent(decoder->decodeAndFlush(m_data->data(), m_data->size()));
+ if (decoder->sawError())
+ m_externalSVGDocument = nullptr;
+ }
+ return m_externalSVGDocument;
+}
+
+SVGFontElement* CachedSVGFont::getSVGFontById(const String& fontName) const
+{
+ auto elements = descendantsOfType<SVGFontElement>(*m_externalSVGDocument);
+
+ if (fontName.isEmpty())
+ return elements.first();
+
+ for (auto& element : elements) {
+ if (element.getIdAttribute() == fontName)
+ return &element;
+ }
+ return nullptr;
+}
+
+SVGFontFaceElement* CachedSVGFont::firstFontFace(const AtomicString& remoteURI)
+{
+ if (!m_externalSVGFontElement) {
+ String fragmentIdentifier;
+ size_t start = remoteURI.find('#');
+ if (start != notFound)
+ fragmentIdentifier = remoteURI.string().substring(start + 1);
+ m_externalSVGFontElement = getSVGFontById(fragmentIdentifier);
+ }
+
+ if (!m_externalSVGFontElement)
+ return nullptr;
+
+ if (auto* firstFontFace = childrenOfType<SVGFontFaceElement>(*m_externalSVGFontElement).first())
+ return firstFontFace;
+ return nullptr;
+}
+
+}
+
+#endif
Copied: trunk/Source/WebCore/loader/cache/CachedSVGFont.h (from rev 176263, trunk/Source/WebCore/loader/cache/CachedFont.h) (0 => 176264)
--- trunk/Source/WebCore/loader/cache/CachedSVGFont.h (rev 0)
+++ trunk/Source/WebCore/loader/cache/CachedSVGFont.h 2014-11-18 18:04:17 UTC (rev 176264)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * 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 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 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
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CachedSVGFont_h
+#define CachedSVGFont_h
+
+#if ENABLE(SVG_FONTS)
+
+#include "CachedFont.h"
+
+namespace WebCore {
+
+class SVGFontFaceElement;
+
+class CachedSVGFont final : public CachedFont {
+public:
+ CachedSVGFont(const ResourceRequest&, SessionID);
+
+ virtual bool ensureCustomFontData(bool externalSVG) override;
+
+ virtual PassRefPtr<SimpleFontData> getFontData(const FontDescription&, const AtomicString& remoteURI, bool syntheticBold, bool syntheticItalic, bool externalSVG) override;
+
+private:
+ FontPlatformData platformDataFromCustomData(float size, bool bold, bool italic, FontOrientation = Horizontal, FontWidthVariant = RegularWidth, FontRenderingMode = NormalRenderingMode);
+
+ SVGFontElement* getSVGFontById(const String&) const;
+
+ SVGFontFaceElement* firstFontFace(const AtomicString& remoteURI);
+
+ RefPtr<SVGDocument> m_externalSVGDocument;
+ SVGFontElement* m_externalSVGFontElement;
+};
+
+}
+
+SPECIALIZE_TYPE_TRAITS_CACHED_RESOURCE(CachedSVGFont, CachedResource::SVGFontResource)
+
+#endif
+
+#endif
Modified: trunk/Source/WebCore/loader/cache/MemoryCache.cpp (176263 => 176264)
--- trunk/Source/WebCore/loader/cache/MemoryCache.cpp 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/loader/cache/MemoryCache.cpp 2014-11-18 18:04:17 UTC (rev 176264)
@@ -824,6 +824,9 @@
stats.xslStyleSheets.addResource(resource);
break;
#endif
+#if ENABLE(SVG_FONTS)
+ case CachedResource::SVGFontResource:
+#endif
case CachedResource::FontResource:
stats.fonts.addResource(resource);
break;
Modified: trunk/Source/WebCore/svg/SVGFontFaceUriElement.cpp (176263 => 176264)
--- trunk/Source/WebCore/svg/SVGFontFaceUriElement.cpp 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebCore/svg/SVGFontFaceUriElement.cpp 2014-11-18 18:04:17 UTC (rev 176264)
@@ -88,6 +88,12 @@
return SVGElement::insertedInto(rootParent);
}
+static bool isSVGFontTarget(const SVGFontFaceUriElement& element)
+{
+ Ref<CSSFontFaceSrcValue> srcValue(element.srcValue());
+ return srcValue->isSVGFontTarget();
+}
+
void SVGFontFaceUriElement::loadFont()
{
if (m_cachedFont)
@@ -98,7 +104,7 @@
CachedResourceLoader* cachedResourceLoader = document().cachedResourceLoader();
CachedResourceRequest request(ResourceRequest(document().completeURL(href)));
request.setInitiator(this);
- m_cachedFont = cachedResourceLoader->requestFont(request);
+ m_cachedFont = cachedResourceLoader->requestFont(request, isSVGFontTarget(*this));
if (m_cachedFont) {
m_cachedFont->addClient(this);
m_cachedFont->beginLoadIfNeeded(cachedResourceLoader);
Modified: trunk/Source/WebKit2/ChangeLog (176263 => 176264)
--- trunk/Source/WebKit2/ChangeLog 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebKit2/ChangeLog 2014-11-18 18:04:17 UTC (rev 176264)
@@ -1,3 +1,15 @@
+2014-11-18 Myles C. Maxfield <[email protected]>
+
+ Subclass CachedFont for SVG fonts
+ https://bugs.webkit.org/show_bug.cgi?id=138686
+
+ Reviewed by Simon Fraser.
+
+ Update for enum type.
+
+ * WebProcess/Network/WebResourceLoadScheduler.cpp:
+ (WebKit::maximumBufferingTime):
+
2014-11-18 Carlos Garcia Campos <[email protected]>
[GTK] Add API to create a WebKitWebContext
Modified: trunk/Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.cpp (176263 => 176264)
--- trunk/Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.cpp 2014-11-18 18:04:13 UTC (rev 176263)
+++ trunk/Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.cpp 2014-11-18 18:04:17 UTC (rev 176264)
@@ -92,6 +92,9 @@
switch (resource->type()) {
case CachedResource::CSSStyleSheet:
case CachedResource::Script:
+#if ENABLE(SVG_FONTS)
+ case CachedResource::SVGFontResource:
+#endif
case CachedResource::FontResource:
return std::chrono::milliseconds::max();
case CachedResource::ImageResource: