From c52b2ba7a889a8f6881114ad33397fa60e57c70c Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 3 Jul 2014 13:59:41 -0700 Subject: [PATCH 1/6] Support for text-transform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is 1-1 locale-unaware text transform using std::ctype. If we want a transform that cares for things like ß -> SS, we need to switch to boost::locale. --- include/llmr/style/style_bucket.hpp | 1 + include/llmr/style/types.hpp | 13 +++++++++++++ src/map/tile_parser.cpp | 14 ++++++++++++-- src/style/style_parser.cpp | 1 + 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/llmr/style/style_bucket.hpp b/include/llmr/style/style_bucket.hpp index 1e3cb2db0..b963caba8 100644 --- a/include/llmr/style/style_bucket.hpp +++ b/include/llmr/style/style_bucket.hpp @@ -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; diff --git a/include/llmr/style/types.hpp b/include/llmr/style/types.hpp index 95365947f..fd862c00d 100644 --- a/include/llmr/style/types.hpp +++ b/include/llmr/style/types.hpp @@ -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; diff --git a/src/map/tile_parser.cpp b/src/map/tile_parser.cpp index 02f1a50f5..c420f8111 100644 --- a/src/map/tile_parser.cpp +++ b/src/map/tile_parser.cpp @@ -19,6 +19,8 @@ #include #include +#include + #ifdef __linux__ #include namespace regex_impl = boost; @@ -208,8 +210,16 @@ std::unique_ptr 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::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) { diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp index 645f3aa0f..e33db355e 100644 --- a/src/style/style_parser.cpp +++ b/src/style/style_parser.cpp @@ -890,6 +890,7 @@ void StyleParser::parseRender(JSVal value, std::shared_ptr &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")) { From 3554a3736a17780ab07179bb5b9c1cfa2cd6936f Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Thu, 3 Jul 2014 14:59:06 -0700 Subject: [PATCH 2/6] re-add setAppliedClasses() to style --- include/llmr/map/map.hpp | 1 + include/llmr/style/style.hpp | 1 + src/map/map.cpp | 4 ++++ src/style/style.cpp | 5 +++++ 4 files changed, 11 insertions(+) diff --git a/include/llmr/map/map.hpp b/include/llmr/map/map.hpp index 75090f941..32aabec15 100644 --- a/include/llmr/map/map.hpp +++ b/include/llmr/map/map.hpp @@ -54,6 +54,7 @@ public: // Styling void toggleClass(const std::string &name); const std::vector &getAppliedClasses() const; + void setAppliedClasses(std::vector &class_names); void setDefaultTransitionDuration(uint64_t duration_milliseconds = 0); void setStyleJSON(std::string newStyleJSON); std::string getStyleJSON() const; diff --git a/include/llmr/style/style.hpp b/include/llmr/style/style.hpp index dcdfa36bc..2fb08257b 100644 --- a/include/llmr/style/style.hpp +++ b/include/llmr/style/style.hpp @@ -38,6 +38,7 @@ public: const std::set> getActiveSources() const; const std::vector &getAppliedClasses() const; + void setAppliedClasses(std::vector &class_names); void toggleClass(const std::string &name); // Updates the styling information to reflect the current array diff --git a/src/map/map.cpp b/src/map/map.cpp index 50c172caa..410bd4e61 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -389,6 +389,10 @@ const std::vector &Map::getAppliedClasses() const { return style->getAppliedClasses(); } +void Map::setAppliedClasses(std::vector &class_names) { + style->setAppliedClasses(class_names); +} + void Map::setDefaultTransitionDuration(uint64_t duration_milliseconds) { style->setDefaultTransitionDuration(duration_milliseconds); } diff --git a/src/style/style.cpp b/src/style/style.cpp index b11cd9226..77d69299e 100644 --- a/src/style/style.cpp +++ b/src/style/style.cpp @@ -63,6 +63,11 @@ const std::vector &Style::getAppliedClasses() const { return appliedClasses; } +void Style::setAppliedClasses(std::vector &class_names) { + appliedClasses.swap(class_names); + updateClasses(); +} + void Style::toggleClass(const std::string &name) { if (name.length()) { auto it = std::find(appliedClasses.begin(), appliedClasses.end(), name); From 5714fddadec692914f79f34f11e9b2b427ac6e9e Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Thu, 3 Jul 2014 17:19:49 -0700 Subject: [PATCH 3/6] bump Cocoa for latest v3 catch-up --- ios/mapbox-gl-cocoa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/mapbox-gl-cocoa b/ios/mapbox-gl-cocoa index 359b6b6b0..f9dec39f7 160000 --- a/ios/mapbox-gl-cocoa +++ b/ios/mapbox-gl-cocoa @@ -1 +1 @@ -Subproject commit 359b6b6b03703be2e80e9597ec13d96512dc78a0 +Subproject commit f9dec39f77186edf132348ca58697c511a3827b4 From 97d8e73f2facf9a2f00bbcfc242a1999dbe2a689 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Thu, 3 Jul 2014 18:58:09 -0700 Subject: [PATCH 4/6] add map change notification options --- include/llmr/platform/platform.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/llmr/platform/platform.hpp b/include/llmr/platform/platform.hpp index 220acd397..8db0d34b9 100644 --- a/include/llmr/platform/platform.hpp +++ b/include/llmr/platform/platform.hpp @@ -24,6 +24,19 @@ struct Response { std::function callback; }; +enum MapChange : uint8_t { + MapChangeRegionWillChange = 0, + MapChangeRegionWillChangeAnimated = 1, + MapChangeRegionDidChange = 2, + MapChangeRegionDidChangeAnimated = 3, + MapChangeWillStartLoadingMap = 4, + MapChangeDidFinishLoadingMap = 5, + MapChangeDidFailLoadingMap = 6, + MapChangeWillStartRenderingMap = 7, + MapChangeDidFinishRenderingMap = 8, + MapChangeDidFinishRenderingMapFullyRendered = 9 +}; + // Makes an HTTP request of a URL, preferrably on a background thread, and calls a function with the // results in the original thread (which runs the libuv loop). // If the loop pointer is NULL, the callback function will be called on an arbitrary thread. From e5d9a20c7c3282a7b058ef40c2ade3429f04f99d Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Thu, 3 Jul 2014 19:02:46 -0700 Subject: [PATCH 5/6] native-side map change notifications --- include/llmr/platform/platform.hpp | 4 ++-- ios/mapbox-gl-cocoa | 2 +- src/map/transform.cpp | 18 ++++++++++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/include/llmr/platform/platform.hpp b/include/llmr/platform/platform.hpp index 8db0d34b9..138843fee 100644 --- a/include/llmr/platform/platform.hpp +++ b/include/llmr/platform/platform.hpp @@ -48,8 +48,8 @@ std::shared_ptr request_http(const std::string &url, // Cancels an HTTP request. void cancel_request_http(const std::shared_ptr &req); -// Notifies a watcher of map x/y/scale/rotation changes. -void notify_map_change(); +// Notifies a watcher of map changes. +void notify_map_change(MapChange key); // Shows an alpha image with the specified dimensions in a named window. void show_debug_image(std::string name, const char *data, size_t width, size_t height); diff --git a/ios/mapbox-gl-cocoa b/ios/mapbox-gl-cocoa index f9dec39f7..0d472e64d 160000 --- a/ios/mapbox-gl-cocoa +++ b/ios/mapbox-gl-cocoa @@ -1 +1 @@ -Subproject commit f9dec39f77186edf132348ca58697c511a3827b4 +Subproject commit 0d472e64d643af90a96a7eb7988e372947336fc6 diff --git a/src/map/transform.cpp b/src/map/transform.cpp index c7bbbfdf7..72449956d 100644 --- a/src/map/transform.cpp +++ b/src/map/transform.cpp @@ -28,6 +28,8 @@ bool Transform::resize(const uint16_t w, const uint16_t h, const float ratio, if (final.width != w || final.height != h || final.pixelRatio != ratio || final.framebuffer[0] != fb_w || final.framebuffer[1] != fb_h) { + platform::notify_map_change(platform::MapChangeRegionWillChange); + current.width = final.width = w; current.height = final.height = h; current.pixelRatio = final.pixelRatio = ratio; @@ -35,7 +37,9 @@ bool Transform::resize(const uint16_t w, const uint16_t h, const float ratio, current.framebuffer[1] = final.framebuffer[1] = fb_h; if (!canRotate() && current.angle) _setAngle(0); constrain(current.scale, current.y); - platform::notify_map_change(); + + platform::notify_map_change(platform::MapChangeRegionDidChange); + return true; } else { return false; @@ -76,7 +80,9 @@ void Transform::_moveBy(const double dx, const double dy, const timestamp durati std::make_shared>(current.y, final.y, current.y, start, duration)); } - platform::notify_map_change(); + platform::notify_map_change(duration ? + platform::MapChangeRegionDidChangeAnimated : + platform::MapChangeRegionDidChange); } void Transform::setLonLat(const double lon, const double lat, const timestamp duration) { @@ -294,7 +300,9 @@ void Transform::_setScaleXY(const double new_scale, const double xn, const doubl Bc = s / 360; Cc = s / (2 * M_PI); - platform::notify_map_change(); + platform::notify_map_change(duration ? + platform::MapChangeRegionDidChangeAnimated : + platform::MapChangeRegionDidChange); } #pragma mark - Constraints @@ -388,7 +396,9 @@ void Transform::_setAngle(double new_angle, const timestamp duration) { current.angle, final.angle, current.angle, start, duration)); } - platform::notify_map_change(); + platform::notify_map_change(duration ? + platform::MapChangeRegionDidChangeAnimated : + platform::MapChangeRegionDidChange); } double Transform::getAngle() const { From 9e9623d2ecbbbdd7411fe591892e2877870ce3b0 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Thu, 3 Jul 2014 19:08:26 -0700 Subject: [PATCH 6/6] fix up OS X/headless notify_map_change() for new API --- common/glfw_view.cpp | 2 +- test/headless.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/glfw_view.cpp b/common/glfw_view.cpp index bcfa5f1bc..d4f896914 100644 --- a/common/glfw_view.cpp +++ b/common/glfw_view.cpp @@ -281,7 +281,7 @@ void show_color_debug_image(std::string name, const char *data, size_t logical_w } #endif -void notify_map_change() { +void notify_map_change(MapChange change) { // no-op } diff --git a/test/headless.cpp b/test/headless.cpp index 8c1dc3a26..34a3f1db7 100644 --- a/test/headless.cpp +++ b/test/headless.cpp @@ -15,7 +15,7 @@ namespace llmr { namespace platform { -void notify_map_change() { +void notify_map_change(MapChange change) { // no-op }