+2015-01-17 Myles C. Maxfield <mmaxfield@apple.com>
+
+ [SVG -> OTF Converter] Crashes when SVG font is invalid
+ https://bugs.webkit.org/show_bug.cgi?id=140378
+
+ Reviewed by Antti Koivisto.
+
+ Because CachedSVGFonts are cached, they have to be able to be used
+ in subsequent documents regardless how the first document left it.
+
+ Tests: fast/css/font-face-svg-decoding-error.html
+ svg/custom/svg-fonts-in-html.html
+ svg/text/text-overflow-ellipsis-svgfont-kerning-ligatures.html
+
+ * loader/cache/CachedFont.cpp:
+ (WebCore::CachedFont::ensureCustomFontData):
+ * loader/cache/CachedFont.h:
+ * loader/cache/CachedSVGFont.cpp:
+ (WebCore::CachedSVGFont::getFontData):
+ (WebCore::CachedSVGFont::ensureCustomFontData):
+ (WebCore::CachedSVGFont::maybeInitializeExternalSVGFontElement):
+ * loader/cache/CachedSVGFont.h:
+
2015-01-17 Chris Dumez <cdumez@apple.com>
Converting time, angle and frequency units in CSS calc() function
PassRefPtr<SimpleFontData> CachedSVGFont::getFontData(const FontDescription& fontDescription, const AtomicString& remoteURI, bool syntheticBold, bool syntheticItalic, bool externalSVG)
{
-#if !ENABLE(SVG_OTF_CONVERTER)
+#if ENABLE(SVG_OTF_CONVERTER)
+ if (!externalSVG || firstFontFace(remoteURI))
+ return CachedFont::getFontData(fontDescription, remoteURI, syntheticBold, syntheticItalic, externalSVG);
+#else
if (!externalSVG)
-#endif
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);
+#endif
return nullptr;
}
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 !ENABLE(SVG_OTF_CONVERTER)
if (decoder->sawError())
m_externalSVGDocument = nullptr;
-#if ENABLE(SVG_OTF_CONVERTER)
- firstFontFace(remoteURI); // Sets m_externalSVGFontElement
- if (m_externalSVGFontElement) {
- Vector<char> convertedFont = convertSVGToOTFFont(*m_externalSVGFontElement);
- return CachedFont::ensureCustomFontData(SharedBuffer::adoptVector(convertedFont));
- }
+#else
+ if (decoder->sawError())
+ m_externalSVGDocument = nullptr;
+ else
+ maybeInitializeExternalSVGFontElement(remoteURI);
+ if (!m_externalSVGFontElement)
+ return false;
+ Vector<char> convertedFont = convertSVGToOTFFont(*m_externalSVGFontElement);
+ m_convertedFont = SharedBuffer::adoptVector(convertedFont);
#endif
}
+
+#if !ENABLE(SVG_OTF_CONVERTER)
return m_externalSVGDocument;
+#else
+ return m_externalSVGDocument && CachedFont::ensureCustomFontData(m_convertedFont.get());
+#endif
}
SVGFontElement* CachedSVGFont::getSVGFontById(const String& fontName) const
{
+ ASSERT(m_externalSVGDocument);
auto elements = descendantsOfType<SVGFontElement>(*m_externalSVGDocument);
if (fontName.isEmpty())
return nullptr;
}
-SVGFontFaceElement* CachedSVGFont::firstFontFace(const AtomicString& remoteURI)
+SVGFontElement* CachedSVGFont::maybeInitializeExternalSVGFontElement(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 m_externalSVGFontElement;
+ String fragmentIdentifier;
+ size_t start = remoteURI.find('#');
+ if (start != notFound)
+ fragmentIdentifier = remoteURI.string().substring(start + 1);
+ m_externalSVGFontElement = getSVGFontById(fragmentIdentifier);
+ return m_externalSVGFontElement;
+}
- if (!m_externalSVGFontElement)
+SVGFontFaceElement* CachedSVGFont::firstFontFace(const AtomicString& remoteURI)
+{
+ if (!maybeInitializeExternalSVGFontElement(remoteURI))
return nullptr;
if (auto* firstFontFace = childrenOfType<SVGFontFaceElement>(*m_externalSVGFontElement).first())