Font stacks as arrays
This commit is contained in:
committed by
John Firebaugh
parent
58d6b84b2b
commit
6df50dba45
@@ -473,24 +473,30 @@ StyleParser::Status StyleParser::parseOptionalProperty(const char *property_name
|
||||
}
|
||||
}
|
||||
|
||||
std::string normalizeFontStack(const std::string &name) {
|
||||
namespace algo = boost::algorithm;
|
||||
std::vector<std::string> parts;
|
||||
algo::split(parts, name, algo::is_any_of(","), algo::token_compress_on);
|
||||
std::for_each(parts.begin(), parts.end(), [](std::string& str) { algo::trim(str); });
|
||||
return algo::join(parts, ", ");
|
||||
}
|
||||
|
||||
template<> StyleParser::Result<std::string> StyleParser::parseProperty(JSVal value, const char *property_name) {
|
||||
if (!value.IsString()) {
|
||||
if (std::string { "text-font" } == property_name) {
|
||||
if (!value.IsArray()) {
|
||||
Log::Warning(Event::ParseStyle, "value of '%s' must be an array of strings", property_name);
|
||||
return Result<std::string> { StyleParserFailure, std::string() };
|
||||
} else {
|
||||
std::string result = "";
|
||||
for (rapidjson::SizeType i = 0; i < value.Size(); ++i) {
|
||||
JSVal stop = value[i];
|
||||
if (stop.IsString()) {
|
||||
result += stop.GetString();
|
||||
if (i < value.Size()-1) {
|
||||
result += ",";
|
||||
}
|
||||
} else {
|
||||
Log::Warning(Event::ParseStyle, "text-font members must be strings");
|
||||
return Result<std::string> { StyleParserFailure, {} };
|
||||
}
|
||||
}
|
||||
return Result<std::string> { StyleParserSuccess, result };
|
||||
}
|
||||
} else if (!value.IsString()) {
|
||||
Log::Warning(Event::ParseStyle, "value of '%s' must be a string", property_name);
|
||||
return Result<std::string> { StyleParserFailure, std::string() };
|
||||
}
|
||||
|
||||
if (std::string { "text-font" } == property_name) {
|
||||
return Result<std::string> {
|
||||
StyleParserSuccess, normalizeFontStack({ value.GetString(), value.GetStringLength() })
|
||||
};
|
||||
} else {
|
||||
return Result<std::string> { StyleParserSuccess, { value.GetString(), value.GetStringLength() } };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user