Merge pull request #348 from mapbox/text-transform
Support for text-transform
This commit is contained in:
@@ -40,6 +40,7 @@ class StyleBucketText {
|
||||
public:
|
||||
std::string field;
|
||||
TextPathType path = TextPathType::Default;
|
||||
TextTransformType transform = TextTransformType::Default;
|
||||
std::string font;
|
||||
float max_size = 16.0f;
|
||||
float max_width = 15.0f * 24;
|
||||
|
||||
@@ -52,6 +52,13 @@ enum class TextPathType : uint8_t {
|
||||
Default = Horizontal
|
||||
};
|
||||
|
||||
enum class TextTransformType : uint8_t {
|
||||
None,
|
||||
Uppercase,
|
||||
Lowercase,
|
||||
Default = None
|
||||
};
|
||||
|
||||
enum class TranslateAnchorType : uint8_t {
|
||||
Map,
|
||||
Viewport,
|
||||
@@ -98,6 +105,12 @@ inline TextPathType parseTextPathType(const std::string &path) {
|
||||
return TextPathType::Default;
|
||||
}
|
||||
|
||||
inline TextTransformType parseTextTransformType(const std::string& transform) {
|
||||
if (transform == "uppercase") return TextTransformType::Uppercase;
|
||||
if (transform == "lowercase") return TextTransformType::Lowercase;
|
||||
return TextTransformType::Default;
|
||||
};
|
||||
|
||||
inline TranslateAnchorType parseTranslateAnchorType(const std::string &anchor) {
|
||||
if (anchor == "map") return TranslateAnchorType::Map;
|
||||
if (anchor == "viewport") return TranslateAnchorType::Viewport;
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include <llmr/util/std.hpp>
|
||||
#include <llmr/util/utf.hpp>
|
||||
|
||||
#include <locale>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <boost/regex.hpp>
|
||||
namespace regex_impl = boost;
|
||||
@@ -208,8 +210,16 @@ std::unique_ptr<Bucket> TileParser::createTextBucket(const VectorTileLayer& laye
|
||||
return nullptr;
|
||||
VectorTileFeature feature{feature_pbf, layer};
|
||||
|
||||
const std::u32string string = ucs4conv.convert(
|
||||
util::replaceTokens(properties.field, feature.properties));
|
||||
std::string u8string = util::replaceTokens(properties.field, feature.properties);
|
||||
|
||||
auto& convert = std::use_facet<std::ctype<char>>(std::locale());
|
||||
if (properties.transform == TextTransformType::Uppercase) {
|
||||
convert.toupper(&u8string[0], &u8string[0] + u8string.size());
|
||||
} else if (properties.transform == TextTransformType::Lowercase) {
|
||||
convert.tolower(&u8string[0], &u8string[0] + u8string.size());
|
||||
}
|
||||
|
||||
std::u32string string = ucs4conv.convert(u8string);
|
||||
|
||||
// Loop through all characters of this text and collect unique codepoints.
|
||||
for (char32_t chr : string) {
|
||||
|
||||
@@ -890,6 +890,7 @@ void StyleParser::parseRender(JSVal value, std::shared_ptr<StyleLayer> &layer) {
|
||||
|
||||
parseRenderProperty(value, render.field, "text-field");
|
||||
parseRenderProperty(value, render.path, "text-path", parseTextPathType);
|
||||
parseRenderProperty(value, render.transform, "text-transform", parseTextTransformType);
|
||||
parseRenderProperty(value, render.font, "text-font");
|
||||
parseRenderProperty(value, render.max_size, "text-max-size");
|
||||
if (parseRenderProperty(value, render.max_width, "text-max-width")) {
|
||||
|
||||
Reference in New Issue
Block a user