| 1 | /* |
| 2 | * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 | * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> |
| 4 | * |
| 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. |
| 9 | * |
| 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. |
| 14 | * |
| 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. |
| 19 | */ |
| 20 | |
| 21 | #include "config.h" |
| 22 | #include "SVGTextElement.h" |
| 23 | |
| 24 | #include "RenderSVGResource.h" |
| 25 | #include "RenderSVGText.h" |
| 26 | #include "SVGNames.h" |
| 27 | #include "SVGRenderStyle.h" |
| 28 | #include "SVGTSpanElement.h" |
| 29 | #include <wtf/IsoMallocInlines.h> |
| 30 | |
| 31 | namespace WebCore { |
| 32 | |
| 33 | WTF_MAKE_ISO_ALLOCATED_IMPL(SVGTextElement); |
| 34 | |
| 35 | inline SVGTextElement::SVGTextElement(const QualifiedName& tagName, Document& document) |
| 36 | : SVGTextPositioningElement(tagName, document) |
| 37 | { |
| 38 | ASSERT(hasTagName(SVGNames::textTag)); |
| 39 | } |
| 40 | |
| 41 | Ref<SVGTextElement> SVGTextElement::create(const QualifiedName& tagName, Document& document) |
| 42 | { |
| 43 | return adoptRef(*new SVGTextElement(tagName, document)); |
| 44 | } |
| 45 | |
| 46 | // We override SVGGraphics::animatedLocalTransform() so that the transform-origin |
| 47 | // is not taken into account. |
| 48 | AffineTransform SVGTextElement::animatedLocalTransform() const |
| 49 | { |
| 50 | AffineTransform matrix; |
| 51 | auto* style = renderer() ? &renderer()->style() : nullptr; |
| 52 | |
| 53 | // if CSS property was set, use that, otherwise fallback to attribute (if set) |
| 54 | if (style && style->hasTransform()) { |
| 55 | TransformationMatrix t; |
| 56 | // For now, the transform-origin is not taken into account |
| 57 | // Also, any percentage values will not be taken into account |
| 58 | style->applyTransform(t, FloatRect(0, 0, 0, 0), RenderStyle::ExcludeTransformOrigin); |
| 59 | // Flatten any 3D transform |
| 60 | matrix = t.toAffineTransform(); |
| 61 | } else |
| 62 | matrix = transform().concatenate(); |
| 63 | |
| 64 | const AffineTransform* transform = const_cast<SVGTextElement*>(this)->supplementalTransform(); |
| 65 | if (transform) |
| 66 | return *transform * matrix; |
| 67 | return matrix; |
| 68 | } |
| 69 | |
| 70 | RenderPtr<RenderElement> SVGTextElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&) |
| 71 | { |
| 72 | return createRenderer<RenderSVGText>(*this, WTFMove(style)); |
| 73 | } |
| 74 | |
| 75 | bool SVGTextElement::childShouldCreateRenderer(const Node& child) const |
| 76 | { |
| 77 | if (child.isTextNode() |
| 78 | || child.hasTagName(SVGNames::aTag) |
| 79 | #if ENABLE(SVG_FONTS) |
| 80 | || child.hasTagName(SVGNames::altGlyphTag) |
| 81 | #endif |
| 82 | || child.hasTagName(SVGNames::textPathTag) |
| 83 | || child.hasTagName(SVGNames::trefTag) |
| 84 | || child.hasTagName(SVGNames::tspanTag)) |
| 85 | return true; |
| 86 | |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | } |
| 91 | |