diff options
author | Tom MacWright <tom@macwright.org> | 2015-03-12 16:44:33 -0400 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2015-08-20 11:58:57 -0700 |
commit | 6df50dba45fd262d9d868802d1c49663efa656a6 (patch) | |
tree | ae256baaadf67d322cad863888d61b7b68d5b41a /src | |
parent | 58d6b84b2b9d0180792a36601d86e0cd5997f789 (diff) | |
download | qtlocation-mapboxgl-6df50dba45fd262d9d868802d1c49663efa656a6.tar.gz |
Font stacks as arrays
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/style/style_parser.cpp | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index fb834c02bf..933587862e 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -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() } }; } |