Commit 0ca81d5b authored by fs's avatar fs Committed by Commit bot

SVGPathUtilities tidying

Rename buildSVGPathByteStreamFromString to buildByteStreamFromString to
be more consistent with other functions (buildStringFromByteStream and
buildPathFromByteStream). Also drop the PathParsingMode argument, since
it's always UnalteredParsing (and it's unlikely we'll need to build
normalized byte streams ATM.)

Make buildStringFromByteStream return the resulting String instead of
using an out-parameter. Tidies up call-sites and makes for slightly
smaller code.

BUG=467592

Review URL: https://codereview.chromium.org/1469323002

Cr-Commit-Position: refs/heads/master@{#361338}
parent 4ec0dffe
...@@ -366,9 +366,8 @@ static TextStream& operator<<(TextStream& ts, const LayoutSVGShape& shape) ...@@ -366,9 +366,8 @@ static TextStream& operator<<(TextStream& ts, const LayoutSVGShape& shape)
} else if (isSVGPolyElement(*svgElement)) { } else if (isSVGPolyElement(*svgElement)) {
writeNameAndQuotedValue(ts, "points", toSVGPolyElement(*svgElement).points()->currentValue()->valueAsString()); writeNameAndQuotedValue(ts, "points", toSVGPolyElement(*svgElement).points()->currentValue()->valueAsString());
} else if (isSVGPathElement(*svgElement)) { } else if (isSVGPathElement(*svgElement)) {
String pathString;
// FIXME: We should switch to UnalteredParsing here - this will affect the path dumping output of dozens of tests. // FIXME: We should switch to UnalteredParsing here - this will affect the path dumping output of dozens of tests.
buildStringFromByteStream(toSVGPathElement(*svgElement).pathByteStream(), pathString, NormalizedParsing); String pathString = buildStringFromByteStream(toSVGPathElement(*svgElement).pathByteStream(), NormalizedParsing);
writeNameAndQuotedValue(ts, "data", pathString); writeNameAndQuotedValue(ts, "data", pathString);
} else { } else {
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
......
...@@ -122,14 +122,12 @@ const SVGPathByteStream& SVGPath::byteStream() const ...@@ -122,14 +122,12 @@ const SVGPathByteStream& SVGPath::byteStream() const
String SVGPath::valueAsString() const String SVGPath::valueAsString() const
{ {
String string; return buildStringFromByteStream(byteStream(), UnalteredParsing);
buildStringFromByteStream(byteStream(), string, UnalteredParsing);
return string;
} }
void SVGPath::setValueAsString(const String& string, ExceptionState& exceptionState) void SVGPath::setValueAsString(const String& string, ExceptionState& exceptionState)
{ {
if (!buildSVGPathByteStreamFromString(string, ensureByteStream(), UnalteredParsing)) if (!buildByteStreamFromString(string, ensureByteStream()))
exceptionState.throwDOMException(SyntaxError, "Problem parsing path \"" + string + "\""); exceptionState.throwDOMException(SyntaxError, "Problem parsing path \"" + string + "\"");
byteStreamChanged(); byteStreamChanged();
} }
......
...@@ -53,20 +53,19 @@ bool buildPathFromByteStream(const SVGPathByteStream& stream, Path& result) ...@@ -53,20 +53,19 @@ bool buildPathFromByteStream(const SVGPathByteStream& stream, Path& result)
return parser.parsePathDataFromSource(NormalizedParsing); return parser.parsePathDataFromSource(NormalizedParsing);
} }
bool buildStringFromByteStream(const SVGPathByteStream& stream, String& result, PathParsingMode parsingMode) String buildStringFromByteStream(const SVGPathByteStream& stream, PathParsingMode parsingMode)
{ {
if (stream.isEmpty()) if (stream.isEmpty())
return true; return String();
SVGPathStringBuilder builder; SVGPathStringBuilder builder;
SVGPathByteStreamSource source(stream); SVGPathByteStreamSource source(stream);
SVGPathParser parser(&source, &builder); SVGPathParser parser(&source, &builder);
bool ok = parser.parsePathDataFromSource(parsingMode); parser.parsePathDataFromSource(parsingMode);
result = builder.result(); return builder.result();
return ok;
} }
bool buildSVGPathByteStreamFromString(const String& d, SVGPathByteStream& result, PathParsingMode parsingMode) bool buildByteStreamFromString(const String& d, SVGPathByteStream& result)
{ {
result.clear(); result.clear();
if (d.isEmpty()) if (d.isEmpty())
...@@ -78,7 +77,7 @@ bool buildSVGPathByteStreamFromString(const String& d, SVGPathByteStream& result ...@@ -78,7 +77,7 @@ bool buildSVGPathByteStreamFromString(const String& d, SVGPathByteStream& result
SVGPathByteStreamBuilder builder(result); SVGPathByteStreamBuilder builder(result);
SVGPathStringSource source(d); SVGPathStringSource source(d);
SVGPathParser parser(&source, &builder); SVGPathParser parser(&source, &builder);
bool ok = parser.parsePathDataFromSource(parsingMode); bool ok = parser.parsePathDataFromSource(UnalteredParsing);
result.shrinkToFit(); result.shrinkToFit();
return ok; return ok;
} }
......
...@@ -35,10 +35,10 @@ bool CORE_EXPORT buildPathFromString(const String&, Path&); ...@@ -35,10 +35,10 @@ bool CORE_EXPORT buildPathFromString(const String&, Path&);
bool buildPathFromByteStream(const SVGPathByteStream&, Path&); bool buildPathFromByteStream(const SVGPathByteStream&, Path&);
// String -> SVGPathByteStream // String -> SVGPathByteStream
bool buildSVGPathByteStreamFromString(const String&, SVGPathByteStream&, PathParsingMode); bool buildByteStreamFromString(const String&, SVGPathByteStream&);
// SVGPathByteStream -> String // SVGPathByteStream -> String
bool buildStringFromByteStream(const SVGPathByteStream&, String&, PathParsingMode); String buildStringFromByteStream(const SVGPathByteStream&, PathParsingMode);
unsigned getSVGPathSegAtLengthFromSVGPathByteStream(const SVGPathByteStream&, float length); unsigned getSVGPathSegAtLengthFromSVGPathByteStream(const SVGPathByteStream&, float length);
float getTotalLengthOfSVGPathByteStream(const SVGPathByteStream&); float getTotalLengthOfSVGPathByteStream(const SVGPathByteStream&);
......
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