RenderSVGTextPath.cpp [plain text]
#include "config.h"
#if ENABLE(SVG)
#include "RenderSVGTextPath.h"
#include "FloatRect.h"
#include "SVGInlineTextBox.h"
#include "SVGPathElement.h"
#include "SVGRootInlineBox.h"
#include "SVGTextPathElement.h"
#include "SVGTransformList.h"
namespace WebCore {
RenderSVGTextPath::RenderSVGTextPath(Node* n)
: RenderSVGInline(n)
, m_startOffset(0.0f)
, m_exactAlignment(true)
, m_stretchMethod(false)
{
}
Path RenderSVGTextPath::layoutPath() const
{
SVGTextPathElement* textPathElement = static_cast<SVGTextPathElement*>(element());
String pathId = SVGURIReference::getTarget(textPathElement->href());
Element* targetElement = textPathElement->document()->getElementById(pathId);
if (!targetElement || !targetElement->hasTagName(SVGNames::pathTag))
return Path();
SVGPathElement* pathElement = static_cast<SVGPathElement*>(targetElement);
Path pathData = pathElement->toPathData();
pathData.transform(pathElement->animatedLocalTransform());
return pathData;
}
float RenderSVGTextPath::startOffset() const
{
return static_cast<SVGTextPathElement*>(element())->startOffset().valueAsPercentage();
}
bool RenderSVGTextPath::exactAlignment() const
{
return static_cast<SVGTextPathElement*>(element())->spacing() == SVG_TEXTPATH_SPACINGTYPE_EXACT;
}
bool RenderSVGTextPath::stretchMethod() const
{
return static_cast<SVGTextPathElement*>(element())->method() == SVG_TEXTPATH_METHODTYPE_STRETCH;
}
void RenderSVGTextPath::absoluteRects(Vector<IntRect>& rects, int, int)
{
InlineRunBox* firstBox = firstLineBox();
SVGRootInlineBox* rootBox = firstBox ? static_cast<SVGInlineTextBox*>(firstBox)->svgRootInlineBox() : 0;
RenderObject* object = rootBox ? rootBox->object() : 0;
if (!object)
return;
int xRef = object->xPos() + xPos();
int yRef = object->yPos() + yPos();
for (InlineRunBox* curr = firstBox; curr; curr = curr->nextLineBox()) {
FloatRect rect(xRef + curr->xPos(), yRef + curr->yPos(), curr->width(), curr->height());
rects.append(enclosingIntRect(absoluteTransform().mapRect(rect)));
}
}
}
#endif // ENABLE(SVG)