diff --git a/CHANGELOG.md b/CHANGELOG.md index 17e888ea7..7eebcb77a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ For a complete change history, see the git log. ## Future +- Added support for `background-image` in cairo_renderer (#1724) + - Added Layer `buffer-size` that can be used to override Map `buffer-size` to avoid over-fetching of data that does not need to be buffered as much as other layers. Map level `buffer-size` will be default if layers do not set the option. Renamed a diff --git a/include/mapnik/cairo_renderer.hpp b/include/mapnik/cairo_renderer.hpp index 7ab2bb920..3e958b1c1 100644 --- a/include/mapnik/cairo_renderer.hpp +++ b/include/mapnik/cairo_renderer.hpp @@ -127,6 +127,7 @@ protected: cairo_face_manager face_manager_; boost::shared_ptr detector_; box2d query_extent_; + void setup(Map const& m); }; template diff --git a/src/cairo_renderer.cpp b/src/cairo_renderer.cpp index 6f9c31e9b..7d610623f 100644 --- a/src/cairo_renderer.cpp +++ b/src/cairo_renderer.cpp @@ -137,7 +137,7 @@ cairo_renderer_base::cairo_renderer_base(Map const& m, box2d(-m.buffer_size(), -m.buffer_size(), m.width() + m.buffer_size(), m.height() + m.buffer_size()))) { - MAPNIK_LOG_DEBUG(cairo_renderer) << "cairo_renderer_base: Scale=" << m.scale(); + setup(m); } cairo_renderer_base::cairo_renderer_base(Map const& m, @@ -182,6 +182,46 @@ cairo_renderer::cairo_renderer(Map const& m, cairo_surface_pt cairo_renderer_base::~cairo_renderer_base() {} +void cairo_renderer_base::setup(Map const& map) +{ + boost::optional bg = m_.background(); + if (bg) + { + cairo_save_restore guard(context_); + context_.set_color(*bg); + context_.paint(); + } + boost::optional const& image_filename = map.background_image(); + if (image_filename) + { + // NOTE: marker_cache returns premultiplied image, if needed + boost::optional bg_marker = mapnik::marker_cache::instance().find(*image_filename,true); + if (bg_marker && (*bg_marker)->is_bitmap()) + { + mapnik::image_ptr bg_image = *(*bg_marker)->get_bitmap_data(); + int w = bg_image->width(); + int h = bg_image->height(); + if ( w > 0 && h > 0) + { + // repeat background-image both vertically and horizontally + unsigned x_steps = unsigned(std::ceil(width_/double(w))); + unsigned y_steps = unsigned(std::ceil(height_/double(h))); + for (unsigned x=0;x + + + + + ellipse + + csv + +x,y +2.5,2.5 + + + + + + + + + + frame + + csv + +x,y +0,0 +5,0 +0,5 +5,5 + + + + + \ No newline at end of file diff --git a/tests/visual_tests/test.py b/tests/visual_tests/test.py index 2c4dbee18..48b2212e6 100755 --- a/tests/visual_tests/test.py +++ b/tests/visual_tests/test.py @@ -44,6 +44,7 @@ files = [ {'name': "marker-on-line-spacing-eq-width", 'sizes':[(600,400)]}, {'name': "marker-on-line-spacing-eq-width-overlap", 'sizes':[(600,400)]}, {'name': "marker_line_placement_on_points"}, + {'name': "marker-with-background-image", 'sizes':[(600,400),(400,600),(257,256)]}, {'name': "whole-centroid", 'sizes':[(600,400)], 'bbox': mapnik.Box2d(736908, 4390316, 2060771, 5942346)}, {'name': "simple-E", 'bbox':mapnik.Box2d(-0.05, -0.01, 0.95, 0.01)},