From 23755a527a5e0f24a7591fcc41dece7ce5f080b7 Mon Sep 17 00:00:00 2001 From: Raul Marin Date: Thu, 3 May 2018 17:03:25 +0200 Subject: [PATCH 1/8] Use pkg-config to find FreeType2 if available --- SConstruct | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/SConstruct b/SConstruct index 39225faec..35a9afa1d 100644 --- a/SConstruct +++ b/SConstruct @@ -1401,6 +1401,7 @@ if not preconfigured: ['harfbuzz', 'harfbuzz/hb.h',True,'C++'] ] + CHECK_PKG_CONFIG = conf.CheckPKGConfig('0.15.0') if env.get('FREETYPE_LIBS') or env.get('FREETYPE_INCLUDES'): REQUIRED_LIBSHEADERS.insert(0,['freetype','ft2build.h',True,'C']) if env.get('FREETYPE_INCLUDES'): @@ -1409,6 +1410,21 @@ if not preconfigured: if env.get('FREETYPE_LIBS'): lib_path = env['FREETYPE_LIBS'] env.AppendUnique(LIBPATH = fix_path(lib_path)) + elif CHECK_PKG_CONFIG and conf.CheckPKG('freetype2'): + # Freetype 2.9+ doesn't use freetype-config and uses pkg-config instead + cmd = 'pkg-config freetype2 --libs --cflags' + if env['RUNTIME_LINK'] == 'static': + cmd += ' --static' + + temp_env = Environment(ENV=os.environ) + try: + temp_env.ParseConfig(cmd) + for lib in temp_env['LIBS']: + env.AppendUnique(LIBPATH = fix_path(lib)) + for inc in temp_env['CPPPATH']: + env.AppendUnique(CPPPATH = fix_path(inc)) + except OSError as e: + pass elif conf.parse_config('FREETYPE_CONFIG'): # check if freetype links to bz2 if env['RUNTIME_LINK'] == 'static': @@ -1642,9 +1658,6 @@ if not preconfigured: color_print(1,'%s not detected on your system' % env['QUERIED_ICU_DATA'] ) env['MISSING_DEPS'].append('ICU_DATA') - - CHECK_PKG_CONFIG = conf.CheckPKGConfig('0.15.0') - if len(env['REQUESTED_PLUGINS']): if env['HOST']: for plugin in env['REQUESTED_PLUGINS']: From 497055d80d03bb3332f201ddc87865771fed5661 Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Wed, 28 Feb 2018 10:35:19 +0100 Subject: [PATCH 2/8] postgis: Thread safe ConnectionManager --- plugins/input/postgis/connection_manager.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/input/postgis/connection_manager.hpp b/plugins/input/postgis/connection_manager.hpp index 942a1abf2..899fc9fc2 100644 --- a/plugins/input/postgis/connection_manager.hpp +++ b/plugins/input/postgis/connection_manager.hpp @@ -115,6 +115,9 @@ public: bool registerPool(ConnectionCreator const& creator,unsigned initialSize,unsigned maxSize) { +#ifdef MAPNIK_THREADSAFE + std::lock_guard lock(mutex_); +#endif ContType::const_iterator itr = pools_.find(creator.id()); if (itr != pools_.end()) @@ -134,6 +137,9 @@ public: std::shared_ptr getPool(std::string const& key) { +#ifdef MAPNIK_THREADSAFE + std::lock_guard lock(mutex_); +#endif ContType::const_iterator itr=pools_.find(key); if (itr!=pools_.end()) { From ab05de48df8764479df5a17ddbe9ad65c29417b0 Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Thu, 3 May 2018 10:21:10 +0200 Subject: [PATCH 3/8] postgis: Exclude password from ConnectionCreator::id() - Password is not necessary for connection identification - When password is not required by the database, user can accidentally use multiple different passwords without noticing. This leads to allocating more connection pools and increase of connection consumption. --- plugins/input/postgis/connection_manager.hpp | 2 +- test/unit/datasource/postgis.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/plugins/input/postgis/connection_manager.hpp b/plugins/input/postgis/connection_manager.hpp index 942a1abf2..0096f794b 100644 --- a/plugins/input/postgis/connection_manager.hpp +++ b/plugins/input/postgis/connection_manager.hpp @@ -67,7 +67,7 @@ public: inline std::string id() const { - return connection_string(); + return connection_string_safe(); } inline std::string connection_string() const diff --git a/test/unit/datasource/postgis.cpp b/test/unit/datasource/postgis.cpp index 5d43bbacc..f5a5add36 100644 --- a/test/unit/datasource/postgis.cpp +++ b/test/unit/datasource/postgis.cpp @@ -28,6 +28,7 @@ #include #include #include +#include "../../../plugins/input/postgis/connection_manager.hpp" /* Compile and run just this test: @@ -406,3 +407,20 @@ TEST_CASE("postgis") { } } + + +TEST_CASE("ConnectionCreator") { + +SECTION("ConnectionCreator::id() should not expose password") +{ + ConnectionCreator creator(boost::optional("host"), + boost::optional("12345"), + boost::optional("dbname"), + boost::optional("user"), + boost::optional("pass"), + boost::optional("111")); + + CHECK(creator.id() == "host=host port=12345 dbname=dbname user=user connect_timeout=111"); +} + +} From 89b5cb4f22b604d20a31464d7d7e6b2cfbf25aec Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Tue, 8 May 2018 15:39:13 +0000 Subject: [PATCH 4/8] Remove useless ellipsoid.hpp --- include/mapnik/ellipsoid.hpp | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 include/mapnik/ellipsoid.hpp diff --git a/include/mapnik/ellipsoid.hpp b/include/mapnik/ellipsoid.hpp deleted file mode 100644 index 9f937b7d7..000000000 --- a/include/mapnik/ellipsoid.hpp +++ /dev/null @@ -1,34 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2017 Artem Pavlenko - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ - -#ifndef MAPNIK_ELLIPSOID_HPP -#define MAPNIK_ELLIPSOID_HPP - -namespace mapnik { -struct ellipsoid -{ - double a; // semi mayor axis - double b; // semi minor axis -}; -} - -#endif // MAPNIK_ELLIPSOID_HPP From 3deb55cc5f1ccca5ab5ddb99df639a5e10852d14 Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Tue, 8 May 2018 16:44:41 +0000 Subject: [PATCH 5/8] Use existing constant --- src/scale_denominator.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/scale_denominator.cpp b/src/scale_denominator.cpp index 07decaa4d..1ea7f7dae 100644 --- a/src/scale_denominator.cpp +++ b/src/scale_denominator.cpp @@ -23,13 +23,14 @@ // mapnik #include #include +#include // stl #include namespace mapnik { -static const double meters_per_degree = 6378137 * 2 * M_PI / 360; +static const double meters_per_degree = EARTH_CIRCUMFERENCE / 360; double scale_denominator(double map_scale, bool geographic) { From 846e961b05df7fd8c34ad8024e8c4a2d3c7af05b Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Tue, 8 May 2018 16:50:19 +0000 Subject: [PATCH 6/8] Replace magic number with described constant --- src/scale_denominator.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/scale_denominator.cpp b/src/scale_denominator.cpp index 1ea7f7dae..993bdd709 100644 --- a/src/scale_denominator.cpp +++ b/src/scale_denominator.cpp @@ -34,7 +34,11 @@ static const double meters_per_degree = EARTH_CIRCUMFERENCE / 360; double scale_denominator(double map_scale, bool geographic) { - double denom = map_scale / 0.00028; + // Pixel size in meters. + // Corresponding approximate resolution is 90.71 DPI. + constexpr double pixel_size = 0.00028; + + double denom = map_scale / pixel_size; if (geographic) denom *= meters_per_degree; return denom; } From 0195047d7a7019ebb0c5fcb1b2b87220133564fe Mon Sep 17 00:00:00 2001 From: Raul Marin Date: Fri, 11 May 2018 11:58:41 +0200 Subject: [PATCH 7/8] Marker symbolizer: Fix bug with lines with 0 length (division by zero) --- include/mapnik/geom_util.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/mapnik/geom_util.hpp b/include/mapnik/geom_util.hpp index 49aa06a6a..bdae5b156 100755 --- a/include/mapnik/geom_util.hpp +++ b/include/mapnik/geom_util.hpp @@ -314,6 +314,12 @@ bool middle_point(PathType & path, double & x, double & y, boost::optional::epsilon()) + { + x = x0; + y = y0; + return true; + } double dist = 0.0; while (SEG_END != (command = path.vertex(&x1, &y1))) { From 0becc1c5e9b3222abcc3a79e93a3efa4218733b9 Mon Sep 17 00:00:00 2001 From: Raul Marin Date: Fri, 11 May 2018 15:39:20 +0200 Subject: [PATCH 8/8] Markers point placement: Add some basic tests --- .../symbolizer/markers_point_placement.cpp | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 test/unit/symbolizer/markers_point_placement.cpp diff --git a/test/unit/symbolizer/markers_point_placement.cpp b/test/unit/symbolizer/markers_point_placement.cpp new file mode 100644 index 000000000..d4f7a029d --- /dev/null +++ b/test/unit/symbolizer/markers_point_placement.cpp @@ -0,0 +1,122 @@ + +#include "catch.hpp" + +#include +#include +#include + +using namespace mapnik; + +TEST_CASE("marker placement point") { + +SECTION("empty geometry") { + + mapnik::geometry::line_string g; + using va_type = mapnik::geometry::line_string_vertex_adapter; + va_type va(g); + + using detector_type = mapnik::label_collision_detector4; + detector_type detector(mapnik::box2d(0, 0, 100, 100)); + + using placement_type = mapnik::markers_point_placement; + + mapnik::markers_placement_params params { + mapnik::box2d(0, 0, 10, 10), + agg::trans_affine(), + 0, 0, false, false, DIRECTION_AUTO, 1.0 }; + + placement_type placement(va, detector, params); + + double x, y, angle; + CHECK( !placement.get_point(x, y, angle, true) ); +} + +SECTION("point") { + + mapnik::geometry::point g(2.0, 3.0); + using va_type = mapnik::geometry::point_vertex_adapter; + va_type va(g); + + using detector_type = mapnik::label_collision_detector4; + detector_type detector(mapnik::box2d(0, 0, 100, 100)); + + using placement_type = mapnik::markers_point_placement; + + mapnik::markers_placement_params params { + mapnik::box2d(0, 0, 10, 10), + agg::trans_affine(), + 0, 0, false, false, DIRECTION_AUTO, 1.0 }; + + placement_type placement(va, detector, params); + + double x, y, angle; + + CHECK( placement.get_point(x, y, angle, true) ); + CHECK( x == Approx(2.0) ); + CHECK( y == Approx(3.0) ); + CHECK( angle == Approx(0.0) ); + + CHECK( !placement.get_point(x, y, angle, true) ); +} + +SECTION("line string") { + + mapnik::geometry::line_string g; + g.emplace_back(1.0, 1.0); + g.emplace_back(2.0, 2.0); + using va_type = mapnik::geometry::line_string_vertex_adapter; + va_type va(g); + + using detector_type = mapnik::label_collision_detector4; + detector_type detector(mapnik::box2d(0, 0, 100, 100)); + + using placement_type = mapnik::markers_point_placement; + + mapnik::markers_placement_params params { + mapnik::box2d(0, 0, 10, 10), + agg::trans_affine(), + 0, 0, false, false, DIRECTION_AUTO, 1.0 }; + + placement_type placement(va, detector, params); + + double x, y, angle; + + CHECK( placement.get_point(x, y, angle, true) ); + CHECK( x == Approx(1.5) ); + CHECK( y == Approx(1.5) ); + CHECK( angle == Approx(0) ); + + CHECK( !placement.get_point(x, y, angle, true) ); +} + +SECTION("line string zero length") { + + mapnik::geometry::line_string g; + g.emplace_back(1.0, 1.0); + g.emplace_back(1.0, 1.0); + using va_type = mapnik::geometry::line_string_vertex_adapter; + va_type va(g); + + using detector_type = mapnik::label_collision_detector4; + detector_type detector(mapnik::box2d(0, 0, 100, 100)); + + using placement_type = mapnik::markers_point_placement; + + mapnik::markers_placement_params params { + mapnik::box2d(0, 0, 10, 10), + agg::trans_affine(), + 0, 0, false, false, DIRECTION_AUTO, 1.0 }; + + placement_type placement(va, detector, params); + + double x, y, angle; + + CHECK( placement.get_point(x, y, angle, true) ); + CHECK( x == Approx(1.0) ); + CHECK( y == Approx(1.0) ); + CHECK( angle == Approx(0) ); + + CHECK( !placement.get_point(x, y, angle, true) ); +} + +} \ No newline at end of file