|
|
|
|
@@ -209,6 +209,24 @@ Color parseColor(JSVal value) {
|
|
|
|
|
css_color.a}};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::tuple<bool,std::vector<float>> parseFloatArray(JSVal value) {
|
|
|
|
|
if (!value.IsArray()) {
|
|
|
|
|
Log::Warning(Event::ParseStyle, "dasharray value must be an array of numbers");
|
|
|
|
|
return std::tuple<bool, std::vector<float>> { false, std::vector<float>() };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<float> vec;
|
|
|
|
|
for (rapidjson::SizeType i = 0; i < value.Size(); ++i) {
|
|
|
|
|
JSVal part = value[i];
|
|
|
|
|
if (!part.IsNumber()) {
|
|
|
|
|
Log::Warning(Event::ParseStyle, "dasharray value must be an array of numbers");
|
|
|
|
|
return std::tuple<bool, std::vector<float>> { false, std::vector<float>() };
|
|
|
|
|
}
|
|
|
|
|
vec.push_back(part.GetDouble());
|
|
|
|
|
}
|
|
|
|
|
return std::tuple<bool, std::vector<float>> { true, vec };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
bool StyleParser::parseFunctionArgument(JSVal value) {
|
|
|
|
|
JSVal rvalue = replaceConstant(value);
|
|
|
|
|
@@ -239,6 +257,12 @@ Color StyleParser::parseFunctionArgument(JSVal value) {
|
|
|
|
|
return parseColor(rvalue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
std::vector<float> StyleParser::parseFunctionArgument(JSVal value) {
|
|
|
|
|
JSVal rvalue = replaceConstant(value);
|
|
|
|
|
return std::get<1>(parseFloatArray(rvalue));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T> inline float defaultBaseValue() { return 1.75; }
|
|
|
|
|
template <> inline float defaultBaseValue<Color>() { return 1.0; }
|
|
|
|
|
|
|
|
|
|
@@ -332,24 +356,6 @@ template<> std::tuple<bool, std::string> StyleParser::parseProperty(JSVal value,
|
|
|
|
|
return std::tuple<bool, std::string> { true, { value.GetString(), value.GetStringLength() } };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<> std::tuple<bool, std::vector<float>> StyleParser::parseProperty(JSVal value, const char *property_name) {
|
|
|
|
|
if (!value.IsArray()) {
|
|
|
|
|
Log::Warning(Event::ParseStyle, "value of '%s' must be an array", property_name);
|
|
|
|
|
return std::tuple<bool, std::vector<float>> { false, std::vector<float>() };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<float> vec;
|
|
|
|
|
for (rapidjson::SizeType i = 0; i < value.Size(); ++i) {
|
|
|
|
|
JSVal part = value[i];
|
|
|
|
|
if (!part.IsNumber()) {
|
|
|
|
|
Log::Warning(Event::ParseStyle, "value of '%s' must be an array of numbers", property_name);
|
|
|
|
|
return std::tuple<bool, std::vector<float>> { false, std::vector<float>() };
|
|
|
|
|
}
|
|
|
|
|
vec.push_back(part.GetDouble());
|
|
|
|
|
}
|
|
|
|
|
return std::tuple<bool, std::vector<float>> { true, vec };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<> std::tuple<bool, TranslateAnchorType> StyleParser::parseProperty(JSVal value, const char *property_name) {
|
|
|
|
|
if (!value.IsString()) {
|
|
|
|
|
Log::Warning(Event::ParseStyle, "value of '%s' must be a string", property_name);
|
|
|
|
|
@@ -423,6 +429,18 @@ template<> std::tuple<bool, Function<Color>> StyleParser::parseProperty(JSVal va
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<> std::tuple<bool, Function<std::vector<float>>> StyleParser::parseProperty(JSVal value, const char *property_name) {
|
|
|
|
|
if (value.IsObject()) {
|
|
|
|
|
return parseFunction<std::vector<float>>(value);
|
|
|
|
|
} else if (value.IsArray()) {
|
|
|
|
|
std::tuple<bool, std::vector<float>> parsed = parseFloatArray(value);
|
|
|
|
|
return std::tuple<bool, Function<std::vector<float>>> { std::get<0>(parsed), ConstantFunction<std::vector<float>>(std::get<1>(parsed)) };
|
|
|
|
|
} else {
|
|
|
|
|
Log::Warning(Event::ParseStyle, "value of '%s' must be an array of numbers, or a number array function", property_name);
|
|
|
|
|
return std::tuple<bool, Function<std::vector<float>>> { false, ConstantFunction<std::vector<float>>(std::vector<float>()) };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
bool StyleParser::parseOptionalProperty(const char *property_name, const std::vector<PropertyKey> &keys, ClassProperties &klass, JSVal value) {
|
|
|
|
|
if (value.HasMember(property_name)) {
|
|
|
|
|
@@ -585,7 +603,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) {
|
|
|
|
|
parseOptionalProperty<PropertyTransition>("line-gap-width-transition", Key::LineGapWidth, klass, value);
|
|
|
|
|
parseOptionalProperty<Function<float>>("line-blur", Key::LineBlur, klass, value);
|
|
|
|
|
parseOptionalProperty<PropertyTransition>("line-blur-transition", Key::LineBlur, klass, value);
|
|
|
|
|
parseOptionalProperty<std::vector<float>>("line-dasharray", Key::LineDashArray, klass, value);
|
|
|
|
|
parseOptionalProperty<Function<std::vector<float>>>("line-dasharray", Key::LineDashArray, klass, value);
|
|
|
|
|
parseOptionalProperty<std::string>("line-image", Key::LineImage, klass, value);
|
|
|
|
|
|
|
|
|
|
parseOptionalProperty<Function<float>>("icon-opacity", Key::IconOpacity, klass, value);
|
|
|
|
|
|