Commit 1a66e77b authored by eric@webkit.org's avatar eric@webkit.org

Reviewed by Sam Weinig.

        Use static functions (and a couple templates)
        to further reduce the amount of copy/paste code in SVGRenderTreeAsText

        No test changes, only code cleanup.

        * rendering/SVGRenderTreeAsText.cpp:
        (WebCore::writeNameValuePair):
        (WebCore::writeNameAndQuotedValue):
        (WebCore::writeIfNotEmpty):
        (WebCore::writeIfNotDefault):
        (WebCore::writeStyle):
        (WebCore::writePositionAndStyle):
        (WebCore::operator<<):

git-svn-id: svn://svn.chromium.org/blink/trunk@42807 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 8b23243f
2009-04-23 Eric Seidel <eric@webkit.org>
Reviewed by Sam Weinig.
Use static functions (and a couple templates)
to further reduce the amount of copy/paste code in SVGRenderTreeAsText
No test changes, only code cleanup.
* rendering/SVGRenderTreeAsText.cpp:
(WebCore::writeNameValuePair):
(WebCore::writeNameAndQuotedValue):
(WebCore::writeIfNotEmpty):
(WebCore::writeIfNotDefault):
(WebCore::writeStyle):
(WebCore::writePositionAndStyle):
(WebCore::operator<<):
2009-04-23 Eric Seidel <eric@webkit.org> 2009-04-23 Eric Seidel <eric@webkit.org>
Reviewed by Simon Fraser. Reviewed by Simon Fraser.
...@@ -79,6 +79,31 @@ TextStream& operator<<(TextStream& ts, TextStreamSeparator& sep) ...@@ -79,6 +79,31 @@ TextStream& operator<<(TextStream& ts, TextStreamSeparator& sep)
return ts; return ts;
} }
template<typename ValueType>
static void writeNameValuePair(TextStream& ts, const char* name, ValueType value)
{
ts << " [" << name << "=" << value << "]";
}
template<typename ValueType>
static void writeNameAndQuotedValue(TextStream& ts, const char* name, ValueType value)
{
ts << " [" << name << "=\"" << value << "\"]";
}
static void writeIfNotEmpty(TextStream& ts, const char* name, const String& value)
{
if (!value.isEmpty())
writeNameValuePair(ts, name, value);
}
template<typename ValueType>
static void writeIfNotDefault(TextStream& ts, const char* name, ValueType value, ValueType defaultValue)
{
if (value != defaultValue)
writeNameValuePair(ts, name, value);
}
TextStream& operator<<(TextStream& ts, const IntPoint& p) TextStream& operator<<(TextStream& ts, const IntPoint& p)
{ {
return ts << "(" << p.x() << "," << p.y() << ")"; return ts << "(" << p.x() << "," << p.y() << ")";
...@@ -233,13 +258,9 @@ static void writeStyle(TextStream& ts, const RenderObject& object) ...@@ -233,13 +258,9 @@ static void writeStyle(TextStream& ts, const RenderObject& object)
const SVGRenderStyle* svgStyle = style->svgStyle(); const SVGRenderStyle* svgStyle = style->svgStyle();
if (!object.localTransform().isIdentity()) if (!object.localTransform().isIdentity())
ts << " [transform=" << object.localTransform() << "]"; writeNameValuePair(ts, "transform", object.localTransform());
if (svgStyle->imageRendering() != SVGRenderStyle::initialImageRendering()) { writeIfNotDefault(ts, "image rendering", svgStyle->imageRendering(), SVGRenderStyle::initialImageRendering());
unsigned imageRenderingAsInteger = svgStyle->imageRendering(); writeIfNotDefault(ts, "opacity", style->opacity(), RenderStyle::initialOpacity());
ts << " [image rendering=" << imageRenderingAsInteger << "]";
}
if (style->opacity() != RenderStyle::initialOpacity())
ts << " [opacity=" << style->opacity() << "]";
if (object.isRenderPath()) { if (object.isRenderPath()) {
const RenderPath& path = static_cast<const RenderPath&>(object); const RenderPath& path = static_cast<const RenderPath&>(object);
SVGPaintServer* strokePaintServer = SVGPaintServer::strokePaintServer(style, &path); SVGPaintServer* strokePaintServer = SVGPaintServer::strokePaintServer(style, &path);
...@@ -253,20 +274,15 @@ static void writeStyle(TextStream& ts, const RenderObject& object) ...@@ -253,20 +274,15 @@ static void writeStyle(TextStream& ts, const RenderObject& object)
const DashArray& dashArray = dashArrayFromRenderingStyle(style); const DashArray& dashArray = dashArrayFromRenderingStyle(style);
double strokeWidth = SVGRenderStyle::cssPrimitiveToLength(&path, svgStyle->strokeWidth(), 1.0f); double strokeWidth = SVGRenderStyle::cssPrimitiveToLength(&path, svgStyle->strokeWidth(), 1.0f);
if (svgStyle->strokeOpacity() != 1.0f) writeIfNotDefault(ts, "opacity", svgStyle->strokeOpacity(), 1.0f);
ts << s << "[opacity=" << svgStyle->strokeOpacity() << "]"; writeIfNotDefault(ts, "stroke width", strokeWidth, 1.0);
if (strokeWidth != 1.0f) writeIfNotDefault(ts, "miter limit", svgStyle->strokeMiterLimit(), 4.0f);
ts << s << "[stroke width=" << strokeWidth << "]"; writeIfNotDefault(ts, "line cap", svgStyle->capStyle(), ButtCap);
if (svgStyle->strokeMiterLimit() != 4) writeIfNotDefault(ts, "line join", svgStyle->joinStyle(), MiterJoin);
ts << s << "[miter limit=" << svgStyle->strokeMiterLimit() << "]"; writeIfNotDefault(ts, "dash offset", dashOffset, 0.0);
if (svgStyle->capStyle() != 0)
ts << s << "[line cap=" << svgStyle->capStyle() << "]";
if (svgStyle->joinStyle() != 0)
ts << s << "[line join=" << svgStyle->joinStyle() << "]";
if (dashOffset != 0.0f)
ts << s << "[dash offset=" << dashOffset << "]";
if (!dashArray.isEmpty()) if (!dashArray.isEmpty())
ts << s << "[dash array=" << dashArray << "]"; writeNameValuePair(ts, "dash array", dashArray);
ts << "}]"; ts << "}]";
} }
SVGPaintServer* fillPaintServer = SVGPaintServer::fillPaintServer(style, &path); SVGPaintServer* fillPaintServer = SVGPaintServer::fillPaintServer(style, &path);
...@@ -276,52 +292,42 @@ static void writeStyle(TextStream& ts, const RenderObject& object) ...@@ -276,52 +292,42 @@ static void writeStyle(TextStream& ts, const RenderObject& object)
if (fillPaintServer) if (fillPaintServer)
ts << s << *fillPaintServer; ts << s << *fillPaintServer;
if (style->svgStyle()->fillOpacity() != 1.0f) writeIfNotDefault(ts, "opacity", svgStyle->fillOpacity(), 1.0f);
ts << s << "[opacity=" << style->svgStyle()->fillOpacity() << "]"; writeIfNotDefault(ts, "fill rule", svgStyle->fillRule(), RULE_NONZERO);
if (style->svgStyle()->fillRule() != RULE_NONZERO)
ts << s << "[fill rule=" << style->svgStyle()->fillRule() << "]";
ts << "}]"; ts << "}]";
} }
} }
if (!svgStyle->clipPath().isEmpty()) if (!svgStyle->clipPath().isEmpty())
ts << " [clip path=\"" << svgStyle->clipPath() << "\"]"; writeNameAndQuotedValue(ts, "clip path", svgStyle->clipPath());
if (!svgStyle->startMarker().isEmpty()) writeIfNotEmpty(ts, "start marker", svgStyle->startMarker());
ts << " [start marker=" << svgStyle->startMarker() << "]"; writeIfNotEmpty(ts, "middle marker", svgStyle->midMarker());
if (!svgStyle->midMarker().isEmpty()) writeIfNotEmpty(ts, "end marker", svgStyle->endMarker());
ts << " [middle marker=" << svgStyle->midMarker() << "]"; writeIfNotEmpty(ts, "filter", svgStyle->filter());
if (!svgStyle->endMarker().isEmpty())
ts << " [end marker=" << svgStyle->endMarker() << "]";
if (!svgStyle->filter().isEmpty())
ts << " [filter=" << svgStyle->filter() << "]";
} }
static TextStream& operator<<(TextStream& ts, const RenderPath& path) static TextStream& writePositionAndStyle(TextStream& ts, const RenderObject& object)
{ {
ts << " " << path.absoluteTransform().mapRect(path.repaintRectInLocalCoordinates()); ts << " " << object.absoluteTransform().mapRect(object.repaintRectInLocalCoordinates());
writeStyle(ts, object);
writeStyle(ts, path); return ts;
}
ts << " [data=\"" << path.path().debugString() << "\"]";
static TextStream& operator<<(TextStream& ts, const RenderPath& path)
{
writePositionAndStyle(ts, path);
writeNameAndQuotedValue(ts, "data", path.path().debugString());
return ts; return ts;
} }
static TextStream& operator<<(TextStream& ts, const RenderSVGContainer& container) static TextStream& operator<<(TextStream& ts, const RenderSVGContainer& container)
{ {
ts << " " << container.absoluteTransform().mapRect(container.repaintRectInLocalCoordinates()); return writePositionAndStyle(ts, container);
writeStyle(ts, container);
return ts;
} }
static TextStream& operator<<(TextStream& ts, const RenderSVGRoot& root) static TextStream& operator<<(TextStream& ts, const RenderSVGRoot& root)
{ {
ts << " " << root.absoluteTransform().mapRect(root.repaintRectInLocalCoordinates()); return writePositionAndStyle(ts, root);
writeStyle(ts, root);
return ts;
} }
static TextStream& operator<<(TextStream& ts, const RenderSVGText& text) static TextStream& operator<<(TextStream& ts, const RenderSVGText& text)
...@@ -335,7 +341,7 @@ static TextStream& operator<<(TextStream& ts, const RenderSVGText& text) ...@@ -335,7 +341,7 @@ static TextStream& operator<<(TextStream& ts, const RenderSVGText& text)
ts << " at (" << text.x() << "," << text.y() << ") size " << box->width() << "x" << box->height() << " contains " << chunks.size() << " chunk(s)"; ts << " at (" << text.x() << "," << text.y() << ") size " << box->width() << "x" << box->height() << " contains " << chunks.size() << " chunk(s)";
if (text.parent() && (text.parent()->style()->color() != text.style()->color())) if (text.parent() && (text.parent()->style()->color() != text.style()->color()))
ts << " [color=" << text.style()->color().name() << "]"; writeNameValuePair(ts, "color", text.style()->color().name());
return ts; return ts;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment