[svg] Minor parser tweaks
- remove the custom-func SkSVGAttributeParser::parse version and always dispatch via SkSVGAttributeParser::parse<T>(T*) - this should avoid adding any other parse helper declarations in the future - relocate the turbulence parse helpers to SkSVGAttributeParser (while keeping the definition in SkSVGFETurbulence.cpp) - update ParseResult initialization to use move semantics Change-Id: I8ed9811671a6fbc5971f9d1f14e7b9c07da7dec0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/332540 Commit-Queue: Florin Malita <fmalita@chromium.org> Commit-Queue: Florin Malita <fmalita@google.com> Reviewed-by: Tyler Denniston <tdenniston@google.com>
This commit is contained in:
parent
e5e8e66e9b
commit
401321d98e
@ -43,10 +43,6 @@ public:
|
||||
bool parseFontWeight(SkSVGFontWeight*);
|
||||
bool parseTextAnchor(SkSVGTextAnchor*);
|
||||
|
||||
bool parseEOSToken();
|
||||
bool parseCommaWspToken();
|
||||
bool parseExpectedStringToken(const char*);
|
||||
|
||||
// TODO: Migrate all parse*() functions to this style (and delete the old version)
|
||||
// so they can be used by parse<T>():
|
||||
bool parse(SkSVGNumberType* v) { return parseNumber(v); }
|
||||
@ -57,27 +53,17 @@ public:
|
||||
template <typename T>
|
||||
static ParseResult<T> parse(const char* expectedName,
|
||||
const char* name,
|
||||
const char* value,
|
||||
bool (*parseFnc)(const char*, T*)) {
|
||||
if (strcmp(name, expectedName) != 0) {
|
||||
return ParseResult<T>();
|
||||
const char* value) {
|
||||
ParseResult<T> result;
|
||||
|
||||
if (!strcmp(name, expectedName)) {
|
||||
T parsedValue;
|
||||
if (SkSVGAttributeParser(value).parse(&parsedValue)) {
|
||||
result.set(std::move(parsedValue));
|
||||
}
|
||||
}
|
||||
|
||||
T parsedValue;
|
||||
if (parseFnc(value, &parsedValue)) {
|
||||
return ParseResult<T>(&parsedValue);
|
||||
}
|
||||
|
||||
return ParseResult<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static ParseResult<T> parse(const char* expectedName, const char* name, const char* value) {
|
||||
const auto parseFnc = +[](const char* str, T* v) {
|
||||
SkSVGAttributeParser parser(str);
|
||||
return parser.parse(v);
|
||||
};
|
||||
return parse(expectedName, name, value, parseFnc);
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -85,11 +71,17 @@ private:
|
||||
void* operator new(size_t) = delete;
|
||||
void* operator new(size_t, void*) = delete;
|
||||
|
||||
template <typename T>
|
||||
bool parse(T*);
|
||||
|
||||
template <typename F>
|
||||
bool advanceWhile(F func);
|
||||
|
||||
bool parseWSToken();
|
||||
bool parseEOSToken();
|
||||
bool parseSepToken();
|
||||
bool parseCommaWspToken();
|
||||
bool parseExpectedStringToken(const char*);
|
||||
bool parseScalarToken(SkScalar*);
|
||||
bool parseInt32Token(int32_t*);
|
||||
bool parseHexToken(uint32_t*);
|
||||
|
@ -34,9 +34,6 @@ protected:
|
||||
private:
|
||||
SkSVGFeTurbulence() : INHERITED(SkSVGTag::kFeTurbulence) {}
|
||||
|
||||
static bool parse(const char*, SkSVGFeTurbulenceBaseFrequency*);
|
||||
static bool parse(const char*, SkSVGFeTurbulenceType*);
|
||||
|
||||
using INHERITED = SkSVGFe;
|
||||
};
|
||||
|
||||
|
@ -19,43 +19,43 @@ bool SkSVGFeTurbulence::parseAndSetAttribute(const char* name, const char* value
|
||||
SkSVGAttributeParser::parse<SkSVGIntegerType>("numOctaves", name, value)) ||
|
||||
this->setSeed(SkSVGAttributeParser::parse<SkSVGNumberType>("seed", name, value)) ||
|
||||
this->setBaseFrequency(SkSVGAttributeParser::parse<SkSVGFeTurbulenceBaseFrequency>(
|
||||
"baseFrequency", name, value, SkSVGFeTurbulence::parse)) ||
|
||||
"baseFrequency", name, value)) ||
|
||||
this->setTurbulenceType(SkSVGAttributeParser::parse<SkSVGFeTurbulenceType>(
|
||||
"type", name, value, SkSVGFeTurbulence::parse));
|
||||
"type", name, value));
|
||||
}
|
||||
|
||||
bool SkSVGFeTurbulence::parse(const char* v, SkSVGFeTurbulenceBaseFrequency* freq) {
|
||||
SkSVGAttributeParser parser(v);
|
||||
|
||||
template <>
|
||||
bool SkSVGAttributeParser::parse<SkSVGFeTurbulenceBaseFrequency>(
|
||||
SkSVGFeTurbulenceBaseFrequency* freq) {
|
||||
SkSVGNumberType freqX;
|
||||
if (!parser.parseNumber(&freqX)) {
|
||||
if (!this->parseNumber(&freqX)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SkSVGNumberType freqY;
|
||||
parser.parseCommaWspToken();
|
||||
if (parser.parseNumber(&freqY)) {
|
||||
this->parseCommaWspToken();
|
||||
if (this->parseNumber(&freqY)) {
|
||||
*freq = SkSVGFeTurbulenceBaseFrequency(freqX, freqY);
|
||||
} else {
|
||||
*freq = SkSVGFeTurbulenceBaseFrequency(freqX, freqX);
|
||||
}
|
||||
|
||||
return parser.parseEOSToken();
|
||||
return this->parseEOSToken();
|
||||
}
|
||||
|
||||
bool SkSVGFeTurbulence::parse(const char* v, SkSVGFeTurbulenceType* type) {
|
||||
SkSVGAttributeParser parser(v);
|
||||
template <>
|
||||
bool SkSVGAttributeParser::parse<SkSVGFeTurbulenceType>(SkSVGFeTurbulenceType* type) {
|
||||
bool parsedValue = false;
|
||||
|
||||
if (parser.parseExpectedStringToken("fractalNoise")) {
|
||||
if (this->parseExpectedStringToken("fractalNoise")) {
|
||||
*type = SkSVGFeTurbulenceType(SkSVGFeTurbulenceType::kFractalNoise);
|
||||
parsedValue = true;
|
||||
} else if (parser.parseExpectedStringToken("turbulence")) {
|
||||
} else if (this->parseExpectedStringToken("turbulence")) {
|
||||
*type = SkSVGFeTurbulenceType(SkSVGFeTurbulenceType::kTurbulence);
|
||||
parsedValue = true;
|
||||
}
|
||||
|
||||
return parsedValue && parser.parseEOSToken();
|
||||
return parsedValue && this->parseEOSToken();
|
||||
}
|
||||
|
||||
sk_sp<SkImageFilter> SkSVGFeTurbulence::onMakeImageFilter(const SkSVGRenderContext& ctx,
|
||||
|
Loading…
Reference in New Issue
Block a user