2 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
3 * Copyright (C) 2009 Apple Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
24 #include "SVGFontFaceUriElement.h"
26 #include "Attribute.h"
27 #include "CSSFontFaceSrcValue.h"
28 #include "CachedFont.h"
29 #include "CachedResourceLoader.h"
30 #include "CachedResourceRequest.h"
32 #include "SVGFontFaceElement.h"
34 #include "XLinkNames.h"
38 using namespace SVGNames;
40 inline SVGFontFaceUriElement::SVGFontFaceUriElement(const QualifiedName& tagName, Document& document)
41 : SVGElement(tagName, document)
43 ASSERT(hasTagName(font_face_uriTag));
46 PassRefPtr<SVGFontFaceUriElement> SVGFontFaceUriElement::create(const QualifiedName& tagName, Document& document)
48 return adoptRef(new SVGFontFaceUriElement(tagName, document));
51 SVGFontFaceUriElement::~SVGFontFaceUriElement()
54 m_cachedFont->removeClient(this);
57 PassRef<CSSFontFaceSrcValue> SVGFontFaceUriElement::srcValue() const
59 auto src = CSSFontFaceSrcValue::create(getAttribute(XLinkNames::hrefAttr));
60 AtomicString value(fastGetAttribute(formatAttr));
61 src.get().setFormat(value.isEmpty() ? "svg" : value); // Default format
65 void SVGFontFaceUriElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
67 if (name == XLinkNames::hrefAttr)
70 SVGElement::parseAttribute(name, value);
73 void SVGFontFaceUriElement::childrenChanged(const ChildChange& change)
75 SVGElement::childrenChanged(change);
77 if (!parentNode() || !parentNode()->hasTagName(font_face_srcTag))
80 ContainerNode* grandparent = parentNode()->parentNode();
81 if (grandparent && grandparent->hasTagName(font_faceTag))
82 downcast<SVGFontFaceElement>(*grandparent).rebuildFontFace();
85 Node::InsertionNotificationRequest SVGFontFaceUriElement::insertedInto(ContainerNode& rootParent)
88 return SVGElement::insertedInto(rootParent);
91 void SVGFontFaceUriElement::loadFont()
94 m_cachedFont->removeClient(this);
96 const AtomicString& href = getAttribute(XLinkNames::hrefAttr);
98 CachedResourceLoader* cachedResourceLoader = document().cachedResourceLoader();
99 CachedResourceRequest request(ResourceRequest(document().completeURL(href)));
100 request.setInitiator(this);
101 m_cachedFont = cachedResourceLoader->requestFont(request);
103 m_cachedFont->addClient(this);
104 m_cachedFont->beginLoadIfNeeded(cachedResourceLoader);
112 #endif // ENABLE(SVG_FONTS)