Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2007 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  *
      4  * This library is free software; you can redistribute it and/or
      5  * modify it under the terms of the GNU Library General Public
      6  * License as published by the Free Software Foundation; either
      7  * version 2 of the License, or (at your option) any later version.
      8  *
      9  * This library is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  * Library General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Library General Public License
     15  * along with this library; see the file COPYING.LIB.  If not, write to
     16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17  * Boston, MA 02110-1301, USA.
     18  */
     19 
     20 #include "config.h"
     21 
     22 #include "core/rendering/svg/RenderSVGTextPath.h"
     23 
     24 #include "SVGNames.h"
     25 #include "core/rendering/svg/SVGPathData.h"
     26 #include "core/svg/SVGPathElement.h"
     27 #include "core/svg/SVGTextPathElement.h"
     28 
     29 namespace WebCore {
     30 
     31 RenderSVGTextPath::RenderSVGTextPath(Element* element)
     32     : RenderSVGInline(element)
     33 {
     34 }
     35 
     36 Path RenderSVGTextPath::layoutPath() const
     37 {
     38     SVGTextPathElement* textPathElement = static_cast<SVGTextPathElement*>(node());
     39     Element* targetElement = SVGURIReference::targetElementFromIRIString(textPathElement->hrefCurrentValue(), textPathElement->document());
     40     if (!targetElement || !targetElement->hasTagName(SVGNames::pathTag))
     41         return Path();
     42 
     43     SVGPathElement* pathElement = toSVGPathElement(targetElement);
     44 
     45     Path pathData;
     46     updatePathFromGraphicsElement(pathElement, pathData);
     47 
     48     // Spec:  The transform attribute on the referenced 'path' element represents a
     49     // supplemental transformation relative to the current user coordinate system for
     50     // the current 'text' element, including any adjustments to the current user coordinate
     51     // system due to a possible transform attribute on the current 'text' element.
     52     // http://www.w3.org/TR/SVG/text.html#TextPathElement
     53     pathData.transform(pathElement->animatedLocalTransform());
     54     return pathData;
     55 }
     56 
     57 float RenderSVGTextPath::startOffset() const
     58 {
     59     return static_cast<SVGTextPathElement*>(node())->startOffsetCurrentValue().valueAsPercentage();
     60 }
     61 
     62 bool RenderSVGTextPath::exactAlignment() const
     63 {
     64     return static_cast<SVGTextPathElement*>(node())->spacingCurrentValue() == SVGTextPathSpacingExact;
     65 }
     66 
     67 bool RenderSVGTextPath::stretchMethod() const
     68 {
     69     return static_cast<SVGTextPathElement*>(node())->methodCurrentValue() == SVGTextPathMethodStretch;
     70 }
     71 
     72 }
     73