#include "config.h"
#if SVG_SUPPORT
#include "SVGHelper.h"
#include "Document.h"
#include "FrameView.h"
#include "RenderView.h"
#include "SVGAnimatedLength.h"
#include "SVGAnimatedRect.h"
#include "SVGSVGElement.h"
#include "SVGStringList.h"
#include "ksvg.h"
#include <math.h>
using namespace std;
namespace WebCore {
float SVGHelper::PercentageOfViewport(float value, const SVGElement* viewportElement, LengthMode mode)
{
float width = 0, height = 0;
if (!viewportElement)
return 0.0;
if (viewportElement->isSVG()) {
const SVGSVGElement* svg = static_cast<const SVGSVGElement*>(viewportElement);
if (svg->hasAttribute(SVGNames::viewBoxAttr)) {
width = svg->viewBox()->baseVal()->width();
height = svg->viewBox()->baseVal()->height();
} else if (svg->width()->baseVal()->unitType() == SVGLength::SVG_LENGTHTYPE_PERCENTAGE ||
svg->height()->baseVal()->unitType() == SVGLength::SVG_LENGTHTYPE_PERCENTAGE) {
Document *doc = svg->document();
if (doc->documentElement() == svg) {
RenderView* view = static_cast<RenderView *>(doc->renderer());
if (view) {
width = view->frameView()->visibleWidth(); height = view->frameView()->visibleHeight(); }
}
} else {
width = svg->width()->baseVal()->value();
height = svg->height()->baseVal()->value();
}
}
if (mode == LM_WIDTH)
return value * width;
else if (mode == LM_HEIGHT)
return value * height;
else if (mode == LM_OTHER)
return value * sqrt(pow(double(width), 2) + pow(double(height), 2)) / sqrt(2.0);
return 0.0;
}
void SVGHelper::ParseSeperatedList(SVGStringList *list, const DeprecatedString &data, const DeprecatedChar &delimiter)
{
list->clear();
DeprecatedStringList substrings = DeprecatedStringList::split(delimiter, data);
DeprecatedStringList::ConstIterator it = substrings.begin();
DeprecatedStringList::ConstIterator end = substrings.end();
for (; it != end; ++it) {
StringImpl* string = new StringImpl(*it);
string->ref();
list->appendItem(string);
}
}
}
#endif // SVG_SUPPORT