Skip to content
This repository
Browse code

Merge pull request #1291 from mapnik/non-buffered-avoid-edged-check

Non buffered placement dimensions for consistent avoid edged checking (#1283 and #1287)
  • Loading branch information...
commit 6915d3fea525b33e56647af09b978565946c759b 2 parents 44769de + 9dd69d0
Dane Springmeyer springmeyer authored
12 bindings/python/mapnik_python.cpp
@@ -150,12 +150,13 @@ void render_layer2(const mapnik::Map& map,
150 150
151 151 void render3(const mapnik::Map& map,
152 152 PycairoSurface* surface,
  153 + double scale_factor = 1.0,
153 154 unsigned offset_x = 0,
154 155 unsigned offset_y = 0)
155 156 {
156 157 python_unblock_auto_block b;
157 158 Cairo::RefPtr<Cairo::Surface> s(new Cairo::Surface(surface->surface));
158   - mapnik::cairo_renderer<Cairo::Surface> ren(map,s,offset_x, offset_y);
  159 + mapnik::cairo_renderer<Cairo::Surface> ren(map,s,scale_factor,offset_x,offset_y);
159 160 ren.apply();
160 161 }
161 162
@@ -169,12 +170,13 @@ void render4(const mapnik::Map& map, PycairoSurface* surface)
169 170
170 171 void render5(const mapnik::Map& map,
171 172 PycairoContext* context,
  173 + double scale_factor = 1.0,
172 174 unsigned offset_x = 0,
173 175 unsigned offset_y = 0)
174 176 {
175 177 python_unblock_auto_block b;
176 178 Cairo::RefPtr<Cairo::Context> c(new Cairo::Context(context->ctx));
177   - mapnik::cairo_renderer<Cairo::Context> ren(map,c,offset_x, offset_y);
  179 + mapnik::cairo_renderer<Cairo::Context> ren(map,c,scale_factor,offset_x, offset_y);
178 180 ren.apply();
179 181 }
180 182
@@ -207,7 +209,7 @@ void render_to_file1(const mapnik::Map& map,
207 209 if (format == "pdf" || format == "svg" || format =="ps" || format == "ARGB32" || format == "RGB24")
208 210 {
209 211 #if defined(HAVE_CAIRO)
210   - mapnik::save_to_cairo_file(map,filename,format);
  212 + mapnik::save_to_cairo_file(map,filename,format,1.0);
211 213 #else
212 214 throw mapnik::ImageWriterException("Cairo backend not available, cannot write to format: " + format);
213 215 #endif
@@ -226,7 +228,7 @@ void render_to_file2(const mapnik::Map& map,const std::string& filename)
226 228 if (format == "pdf" || format == "svg" || format =="ps")
227 229 {
228 230 #if defined(HAVE_CAIRO)
229   - mapnik::save_to_cairo_file(map,filename,format);
  231 + mapnik::save_to_cairo_file(map,filename,format,1.0);
230 232 #else
231 233 throw mapnik::ImageWriterException("Cairo backend not available, cannot write to format: " + format);
232 234 #endif
@@ -248,7 +250,7 @@ void render_to_file3(const mapnik::Map& map,
248 250 if (format == "pdf" || format == "svg" || format =="ps" || format == "ARGB32" || format == "RGB24")
249 251 {
250 252 #if defined(HAVE_CAIRO)
251   - mapnik::save_to_cairo_file(map,filename,format);
  253 + mapnik::save_to_cairo_file(map,filename,format,scale_factor);
252 254 #else
253 255 throw mapnik::ImageWriterException("Cairo backend not available, cannot write to format: " + format);
254 256 #endif
2  demo/viewer/mapwidget.cpp
@@ -570,7 +570,7 @@ void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
570 570 Cairo::RefPtr<Cairo::ImageSurface> image_surface =
571 571 Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, map.width(),map.height());
572 572
573   - mapnik::cairo_renderer<Cairo::Surface> png_render(map, image_surface);
  573 + mapnik::cairo_renderer<Cairo::Surface> png_render(map, image_surface, scaling_factor);
574 574 png_render.apply();
575 575
576 576 image_32 buf(image_surface);
7 include/mapnik/cairo_renderer.hpp
@@ -72,7 +72,7 @@ class cairo_face_manager : private boost::noncopyable
72 72 class MAPNIK_DECL cairo_renderer_base : private boost::noncopyable
73 73 {
74 74 protected:
75   - cairo_renderer_base(Map const& m, Cairo::RefPtr<Cairo::Context> const& context, unsigned offset_x=0, unsigned offset_y=0);
  75 + cairo_renderer_base(Map const& m, Cairo::RefPtr<Cairo::Context> const& context, double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0);
76 76 public:
77 77 ~cairo_renderer_base();
78 78 void start_map_processing(Map const& map);
@@ -127,6 +127,9 @@ class MAPNIK_DECL cairo_renderer_base : private boost::noncopyable
127 127
128 128 Map const& m_;
129 129 Cairo::RefPtr<Cairo::Context> context_;
  130 + unsigned width_;
  131 + unsigned height_;
  132 + double scale_factor_;
130 133 CoordTransform t_;
131 134 boost::shared_ptr<freetype_engine> font_engine_;
132 135 face_manager<freetype_engine> font_manager_;
@@ -141,7 +144,7 @@ class MAPNIK_DECL cairo_renderer : public feature_style_processor<cairo_renderer
141 144 {
142 145 public:
143 146 typedef cairo_renderer_base processor_impl_type;
144   - cairo_renderer(Map const& m, Cairo::RefPtr<T> const& surface, unsigned offset_x=0, unsigned offset_y=0);
  147 + cairo_renderer(Map const& m, Cairo::RefPtr<T> const& surface, double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0);
145 148 void end_map_processing(Map const& map);
146 149 };
147 150 }
3  include/mapnik/image_util.hpp
@@ -60,7 +60,8 @@ class ImageWriterException : public std::exception
60 60 #if defined(HAVE_CAIRO)
61 61 MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map,
62 62 std::string const& filename,
63   - std::string const& type);
  63 + std::string const& type,
  64 + double scale_factor);
64 65 #endif
65 66
66 67 template <typename T>
5 src/agg/process_shield_symbolizer.cpp
@@ -42,9 +42,10 @@ void agg_renderer<T>::process(shield_symbolizer const& sym,
42 42 shield_symbolizer_helper<face_manager<freetype_engine>,
43 43 label_collision_detector4> helper(
44 44 sym, feature, prj_trans,
45   - detector_->extent().width(), detector_->extent().height(),
  45 + width_, height_,
46 46 scale_factor_,
47   - t_, font_manager_, *detector_, query_extent_);
  47 + t_, font_manager_, *detector_,
  48 + query_extent_);
48 49
49 50 text_renderer<T> ren(*current_buffer_,
50 51 font_manager_,
5 src/agg/process_text_symbolizer.cpp
@@ -35,9 +35,10 @@ void agg_renderer<T>::process(text_symbolizer const& sym,
35 35 text_symbolizer_helper<face_manager<freetype_engine>,
36 36 label_collision_detector4> helper(
37 37 sym, feature, prj_trans,
38   - detector_->extent().width(), detector_->extent().height(),
  38 + width_,height_,
39 39 scale_factor_,
40   - t_, font_manager_, *detector_, query_extent_);
  40 + t_, font_manager_, *detector_,
  41 + query_extent_);
41 42
42 43 text_renderer<T> ren(*current_buffer_,
43 44 font_manager_,
35 src/cairo_renderer.cpp
@@ -737,9 +737,16 @@ class cairo_context : private boost::noncopyable
737 737 Cairo::RefPtr<Cairo::Context> context_;
738 738 };
739 739
740   -cairo_renderer_base::cairo_renderer_base(Map const& m, Cairo::RefPtr<Cairo::Context> const& context, unsigned offset_x, unsigned offset_y)
  740 +cairo_renderer_base::cairo_renderer_base(Map const& m,
  741 + Cairo::RefPtr<Cairo::Context> const& context,
  742 + double scale_factor,
  743 + unsigned offset_x,
  744 + unsigned offset_y)
741 745 : m_(m),
742 746 context_(context),
  747 + width_(m.width()),
  748 + height_(m.height()),
  749 + scale_factor_(scale_factor),
743 750 t_(m.width(),m.height(),m.get_current_extent(),offset_x,offset_y),
744 751 font_engine_(boost::make_shared<freetype_engine>()),
745 752 font_manager_(*font_engine_),
@@ -750,16 +757,16 @@ cairo_renderer_base::cairo_renderer_base(Map const& m, Cairo::RefPtr<Cairo::Cont
750 757 }
751 758
752 759 template <>
753   -cairo_renderer<Cairo::Context>::cairo_renderer(Map const& m, Cairo::RefPtr<Cairo::Context> const& context, unsigned offset_x, unsigned offset_y)
  760 +cairo_renderer<Cairo::Context>::cairo_renderer(Map const& m, Cairo::RefPtr<Cairo::Context> const& context, double scale_factor, unsigned offset_x, unsigned offset_y)
754 761 : feature_style_processor<cairo_renderer>(m),
755   - cairo_renderer_base(m,context,offset_x,offset_y)
  762 + cairo_renderer_base(m,context,scale_factor,offset_x,offset_y)
756 763 {
757 764 }
758 765
759 766 template <>
760   -cairo_renderer<Cairo::Surface>::cairo_renderer(Map const& m, Cairo::RefPtr<Cairo::Surface> const& surface, unsigned offset_x, unsigned offset_y)
  767 +cairo_renderer<Cairo::Surface>::cairo_renderer(Map const& m, Cairo::RefPtr<Cairo::Surface> const& surface, double scale_factor, unsigned offset_x, unsigned offset_y)
761 768 : feature_style_processor<cairo_renderer>(m),
762   - cairo_renderer_base(m,Cairo::Context::create(surface),offset_x,offset_y)
  769 + cairo_renderer_base(m,Cairo::Context::create(surface),scale_factor,offset_x,offset_y)
763 770 {
764 771 }
765 772
@@ -1185,11 +1192,11 @@ void cairo_renderer_base::process(shield_symbolizer const& sym,
1185 1192 proj_transform const& prj_trans)
1186 1193 {
1187 1194 shield_symbolizer_helper<face_manager<freetype_engine>,
1188   - label_collision_detector4> helper(
1189   - sym, feature, prj_trans,
1190   - detector_.extent().width(), detector_.extent().height(),
1191   - 1.0 /*scale_factor*/,
1192   - t_, font_manager_, detector_, query_extent_);
  1195 + label_collision_detector4> helper(
  1196 + sym, feature, prj_trans,
  1197 + width_, height_,
  1198 + 1.0 /*scale_factor*/,
  1199 + t_, font_manager_, detector_, query_extent_);
1193 1200 cairo_context context(context_);
1194 1201 context.set_operator(sym.comp_op());
1195 1202
@@ -1462,8 +1469,12 @@ void cairo_renderer_base::process(text_symbolizer const& sym,
1462 1469 mapnik::feature_impl & feature,
1463 1470 proj_transform const& prj_trans)
1464 1471 {
1465   - text_symbolizer_helper<face_manager<freetype_engine>, label_collision_detector4> helper(sym, feature, prj_trans, detector_.extent().width(), detector_.extent().height(), 1.0 /*scale_factor*/, t_, font_manager_, detector_, query_extent_);
1466   -
  1472 + text_symbolizer_helper<face_manager<freetype_engine>,
  1473 + label_collision_detector4> helper(
  1474 + sym, feature, prj_trans,
  1475 + width_, height_,
  1476 + 1.0 /*scale_factor*/,
  1477 + t_, font_manager_, detector_, query_extent_);
1467 1478 cairo_context context(context_);
1468 1479 context.set_operator(sym.comp_op());
1469 1480
4 src/grid/process_shield_symbolizer.cpp
@@ -47,8 +47,8 @@ void grid_renderer<T>::process(shield_symbolizer const& sym,
47 47 sym, feature, prj_trans,
48 48 width_, height_,
49 49 scale_factor_,
50   - t_, font_manager_, detector_, query_extent);
51   -
  50 + t_, font_manager_, detector_,
  51 + query_extent);
52 52 bool placement_found = false;
53 53
54 54 text_renderer<T> ren(pixmap_,
2  src/grid/process_text_symbolizer.cpp
@@ -35,7 +35,7 @@ void grid_renderer<T>::process(text_symbolizer const& sym,
35 35 text_symbolizer_helper<face_manager<freetype_engine>,
36 36 label_collision_detector4> helper(
37 37 sym, feature, prj_trans,
38   - detector_.extent().width(), detector_.extent().height(),
  38 + width_, height_,
39 39 scale_factor_ * (1.0/pixmap_.get_resolution()),
40 40 t_, font_manager_, detector_,
41 41 query_extent);
9 src/image_util.cpp
@@ -352,18 +352,19 @@ void save_to_file(T const& image, std::string const& filename, rgba_palette cons
352 352
353 353 #if defined(HAVE_CAIRO)
354 354 // TODO - move to separate cairo_io.hpp
355   -void save_to_cairo_file(mapnik::Map const& map, std::string const& filename)
  355 +void save_to_cairo_file(mapnik::Map const& map, std::string const& filename, double scale_factor)
356 356 {
357 357 boost::optional<std::string> type = type_from_filename(filename);
358 358 if (type)
359 359 {
360   - save_to_cairo_file(map,filename,*type);
  360 + save_to_cairo_file(map,filename,*type,scale_factor);
361 361 }
362 362 }
363 363
364 364 void save_to_cairo_file(mapnik::Map const& map,
365 365 std::string const& filename,
366   - std::string const& type)
  366 + std::string const& type,
  367 + double scale_factor)
367 368 {
368 369 std::ofstream file (filename.c_str(), std::ios::out|std::ios::trunc|std::ios::binary);
369 370 if (file)
@@ -417,7 +418,7 @@ void save_to_cairo_file(mapnik::Map const& map,
417 418 */
418 419
419 420
420   - mapnik::cairo_renderer<Cairo::Context> ren(map, context);
  421 + mapnik::cairo_renderer<Cairo::Context> ren(map, context, scale_factor);
421 422 ren.apply();
422 423
423 424 if (type == "ARGB32" || type == "RGB24")

0 comments on commit 6915d3f

Please sign in to comment.
Something went wrong with that request. Please try again.