Reviewed by Eric, Dan & Oliver.
Fixes: http://bugs.webkit.org/show_bug.cgi?id=16980
Support external SVG Fonts, by reusing the custom font handling logic.
This enables us - as first engine - to render HTML pages using SVG Fonts.
Fixes fonts-elem-03-b.svg / fonts-elem-04-b.svg / fonts-elem-07-b.svg
Add new testcase svg-fonts-in-html.html.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@29839 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/loader/CachedFont.cpp b/WebCore/loader/CachedFont.cpp
index b40023d..0d7e0b8 100644
--- a/WebCore/loader/CachedFont.cpp
+++ b/WebCore/loader/CachedFont.cpp
@@ -29,6 +29,7 @@
#include "Cache.h"
#include "CachedResourceClient.h"
#include "CachedResourceClientWalker.h"
+#include "DOMImplementation.h"
#include "FontPlatformData.h"
#if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK)
#include "FontCustomPlatformData.h"
@@ -37,6 +38,14 @@
#include "loader.h"
#include <wtf/Vector.h>
+#if ENABLE(SVG_FONTS)
+#include "HTMLNames.h"
+#include "NodeList.h"
+#include "SVGElement.h"
+#include "SVGFontElement.h"
+#include "SVGGElement.h"
+#endif
+
namespace WebCore {
CachedFont::CachedFont(DocLoader* dl, const String &url)
@@ -93,16 +102,59 @@
return m_fontData;
}
-FontPlatformData CachedFont::platformDataFromCustomData(int size, bool bold, bool italic)
+FontPlatformData CachedFont::platformDataFromCustomData(float size, bool bold, bool italic)
{
+#if ENABLE(SVG_FONTS)
+ if (m_externalSVGDocument)
+ return FontPlatformData(size, bold, italic);
+#endif
#if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK)
ASSERT(m_fontData);
- return m_fontData->fontPlatformData(size, bold, italic);
+ return m_fontData->fontPlatformData(static_cast<int>(size), bold, italic);
#else
return FontPlatformData();
#endif
}
+#if ENABLE(SVG_FONTS)
+bool CachedFont::ensureSVGFontData()
+{
+ if (!m_externalSVGDocument && !m_errorOccurred && !m_loading && m_data) {
+ m_externalSVGDocument = new SVGDocument(DOMImplementation::instance(), 0);
+ m_externalSVGDocument->open();
+
+ TextResourceDecoder decoder("application/xml");
+ m_externalSVGDocument->write(decoder.decode(m_data->data(), m_data->size()));
+
+ m_externalSVGDocument->finishParsing();
+ m_externalSVGDocument->close();
+ }
+
+ return m_externalSVGDocument;
+}
+
+SVGFontElement* CachedFont::getSVGFontById(const String& fontName) const
+{
+ RefPtr<NodeList> list = m_externalSVGDocument->getElementsByTagName(SVGNames::fontTag.localName());
+ if (!list)
+ return 0;
+
+ unsigned fonts = list->length();
+ for (unsigned i = 0; i < fonts; ++i) {
+ Node* node = list->item(i);
+ ASSERT(node);
+
+ if (static_cast<Element*>(node)->getAttribute(HTMLNames::idAttr) != fontName)
+ continue;
+
+ ASSERT(node->hasTagName(SVGNames::fontTag));
+ return static_cast<SVGFontElement*>(node);
+ }
+
+ return 0;
+}
+#endif
+
void CachedFont::allReferencesRemoved()
{
#if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK)