diff --git a/include/mbgl/util/url.hpp b/include/mbgl/util/url.hpp index 14d9dd316..a7e5291ec 100644 --- a/include/mbgl/util/url.hpp +++ b/include/mbgl/util/url.hpp @@ -7,6 +7,7 @@ namespace mbgl { namespace util { std::string percentEncode(const std::string&); +std::string percentDecode(const std::string&); } } diff --git a/src/renderer/painter_symbol.cpp b/src/renderer/painter_symbol.cpp index 66961b318..c2d62bec7 100644 --- a/src/renderer/painter_symbol.cpp +++ b/src/renderer/painter_symbol.cpp @@ -56,45 +56,38 @@ void Painter::renderSymbol(SymbolBucket &bucket, std::shared_ptr lay const timestamp currentTime = util::now(); std::deque &history = frameHistory.history; + if (history.size() >= 2) { + // Remove frames until only one is outside the duration, or until there are only three + while (history.size() > 3 && history[1].t + duration < currentTime) { + history.pop_front(); + } - // Remove frames until only one is outside the duration, or until there are only three - while (history.size() > 3 && history[1].t + duration < currentTime) { - history.pop_front(); + if (history[1].t + duration < currentTime) { + history[0].z = history[1].z; + } + + // Find the range of zoom levels we want to fade between + float startingZ = history.front().z; + const FrameSnapshot lastFrame = history.back(); + float endingZ = lastFrame.z; + float lowZ = std::fmin(startingZ, endingZ); + float highZ = std::fmax(startingZ, endingZ); + + // Calculate the speed of zooming, and how far it would zoom in terms of zoom levels in one + // duration + float zoomDiff = endingZ - history[1].z, timeDiff = lastFrame.t - history[1].t; + float fadedist = zoomDiff / (timeDiff / duration); + + // At end of a zoom when the zoom stops changing continue pretending to zoom at that speed + // bump is how much farther it would have been if it had continued zooming at the same rate + float bump = (currentTime - lastFrame.t) / duration * fadedist; + + textShader->setFadeDist(fadedist * 10); + textShader->setMinFadeZoom(std::floor(lowZ * 10)); + textShader->setMaxFadeZoom(std::floor(highZ * 10)); + textShader->setFadeZoom((map.getState().getNormalizedZoom() + bump) * 10); } - if (history[1].t + duration < currentTime) { - history[0].z = history[1].z; - } - - assert("there should never be less than three frames in the history" && - (history.size() >= 3)); - - // Find the range of zoom levels we want to fade between - float startingZ = history.front().z; - const FrameSnapshot lastFrame = history.back(); - float endingZ = lastFrame.z; - float lowZ = std::fmin(startingZ, endingZ); - float highZ = std::fmax(startingZ, endingZ); - - // Calculate the speed of zooming, and how far it would zoom in terms of zoom levels in one - // duration - float zoomDiff = endingZ - history[1].z, timeDiff = lastFrame.t - history[1].t; - float fadedist = zoomDiff / (timeDiff / duration); - -#if defined(DEBUG) -// if (std::isnan(fadedist)) -// fprintf(stderr, "fadedist should never be NaN\n"); -#endif - - // At end of a zoom when the zoom stops changing continue pretending to zoom at that speed - // bump is how much farther it would have been if it had continued zooming at the same rate - float bump = (currentTime - lastFrame.t) / duration * fadedist; - - textShader->setFadeDist(fadedist * 10); - textShader->setMinFadeZoom(std::floor(lowZ * 10)); - textShader->setMaxFadeZoom(std::floor(highZ * 10)); - textShader->setFadeZoom((map.getState().getNormalizedZoom() + bump) * 10); - // This defines the gamma around the SDF cutoff value. const float sdfGamma = 1.0f / 10.0f; diff --git a/src/text/placement.cpp b/src/text/placement.cpp index 26cc9f70f..0c95e3a80 100644 --- a/src/text/placement.cpp +++ b/src/text/placement.cpp @@ -80,7 +80,7 @@ void getSegmentGlyphs(std::back_insert_iterator glyphs, Anchor & // skip duplicate nodes while (newAnchor == end) { segment += direction; - if ((int)line.size() <= segment) { + if ((int)line.size() <= segment || segment < 0) { anchor.scale = scale; return; } diff --git a/src/util/url.cpp b/src/util/url.cpp index b1a721d86..e9b967210 100644 --- a/src/util/url.cpp +++ b/src/util/url.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include namespace mbgl { namespace util { @@ -25,5 +27,25 @@ std::string percentEncode(const std::string& input) { return encoded.str(); } +std::string percentDecode(const std::string& input) { + std::string decoded; + + auto it = input.begin(); + const auto end = input.end(); + char hex[3] = "00"; + + while (it != end) { + auto cur = std::find(it, end, '%'); + decoded.append(it, cur); + it = cur; + if (cur != end) { + it += input.copy(hex, 2, cur - input.begin() + 1) + 1; + decoded += static_cast(std::strtoul(hex, nullptr, 16)); + } + } + + return decoded; +} + } } diff --git a/test/fixtures/fixture_request.cpp b/test/fixtures/fixture_request.cpp index 1a7ed2ccc..7e351ecfa 100644 --- a/test/fixtures/fixture_request.cpp +++ b/test/fixtures/fixture_request.cpp @@ -1,12 +1,15 @@ #include #include #include +#include #include const std::string base_directory = []{ std::string fn = __FILE__; fn.erase(fn.find_last_of("/")); - return fn; + fn.erase(fn.find_last_of("/")); + fn.erase(fn.find_last_of("/")); + return fn + "/node_modules/mapbox-gl-test-suite/"; }(); @@ -23,14 +26,11 @@ platform::request_http(const std::string &url, l = uv_default_loop(); } - std::string clean_url = base_directory + "/" + url; - auto pos = clean_url.find("://"); - if (pos != std::string::npos) { - clean_url.replace(pos, 3, "/"); + std::string clean_url = util::percentDecode(url); + if (clean_url.find("local://") == 0) { + clean_url = base_directory + clean_url.substr(8); } - std::replace(clean_url.begin(), clean_url.end(), '+', ' '); - std::shared_ptr req = std::make_shared(url, callback, loop); int err; diff --git a/test/headless.cpp b/test/headless.cpp index a2f58e98d..2453f1bb3 100644 --- a/test/headless.cpp +++ b/test/headless.cpp @@ -18,17 +18,12 @@ const std::string base_directory = []{ std::string fn = __FILE__; fn.erase(fn.find_last_of("/")); - return fn + "/../node_modules/mapbox-gl-test-suite/"; + fn.erase(fn.find_last_of("/")); + return fn + "/node_modules/mapbox-gl-test-suite/"; }(); class HeadlessTest : public ::testing::TestWithParam {}; -void ResolveLocalURL(rapidjson::Value& value, rapidjson::Document& doc) { - std::string str { value.GetString(), value.GetStringLength() }; - str.replace(0, 8, base_directory); // local:// - value.SetString(str.c_str(), str.length(), doc.GetAllocator()); -} - TEST_P(HeadlessTest, render) { using namespace mbgl; @@ -43,12 +38,6 @@ TEST_P(HeadlessTest, render) { ASSERT_EQ(false, styleDoc.HasParseError()); ASSERT_EQ(true, styleDoc.IsObject()); - if (styleDoc.HasMember("sprite")) { - ResolveLocalURL(styleDoc["sprite"], styleDoc); - } - - ResolveLocalURL(styleDoc["sources"]["mapbox"]["tiles"][rapidjson::SizeType(0)], styleDoc); - rapidjson::StringBuffer buffer; rapidjson::Writer writer(buffer); styleDoc.Accept(writer); @@ -91,7 +80,7 @@ TEST_P(HeadlessTest, render) { } } - map.setStyleJSON(style); + map.setStyleJSON(style, base_directory); map.setAppliedClasses(classes); view.resize(width, height);