Changeset 693
- Timestamp:
- 04/12/08 11:22:27 (9 months ago)
- Location:
- trunk
- Files:
-
- 5 modified
-
bindings/python/mapnik_feature.cpp (modified) (1 diff)
-
include/mapnik/feature.hpp (modified) (1 diff)
-
include/mapnik/value.hpp (modified) (15 diffs)
-
src/agg_renderer.cpp (modified) (2 diffs)
-
src/cairo_renderer.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bindings/python/mapnik_feature.cpp
r650 r693 47 47 { 48 48 return ::PyUnicode_FromWideChar((wchar_t*)s.getBuffer(),implicit_cast<ssize_t>(s.length())); 49 } 50 51 PyObject * operator() (mapnik::value_null const& s) const 52 { 53 return NULL; 49 54 } 50 55 }; -
trunk/include/mapnik/feature.hpp
r692 r693 121 121 } 122 122 123 bool exists(const std::string &k) const124 {125 return props_.find(k) != props_.end();126 }127 128 123 std::string to_string() const 129 124 { -
trunk/include/mapnik/value.hpp
r660 r693 40 40 namespace mapnik { 41 41 42 typedef boost::variant<bool,int,double,UnicodeString> value_base; 42 struct value_null 43 { 44 }; 45 46 typedef boost::variant<value_null,bool,int,double,UnicodeString> value_base; 43 47 44 48 namespace impl { … … 47 51 { 48 52 template <typename T, typename U> 49 bool operator() (const T &, const U & ) const53 bool operator() (const T &, const U &) const 50 54 { 51 55 return false; … … 73 77 return lhs == rhs; 74 78 } 79 80 bool operator() (value_null, value_null) const 81 { 82 return false; 83 } 75 84 }; 76 85 86 struct not_equals 87 : public boost::static_visitor<bool> 88 { 89 template <typename T, typename U> 90 bool operator() (const T &, const U &) const 91 { 92 return true; 93 } 94 95 template <typename T> 96 bool operator() (T lhs, T rhs) const 97 { 98 return lhs != rhs; 99 } 100 101 bool operator() (int lhs, double rhs) const 102 { 103 return lhs != rhs; 104 } 105 106 bool operator() (double lhs, int rhs) const 107 { 108 return lhs != rhs; 109 } 110 111 bool operator() (UnicodeString const& lhs, 112 UnicodeString const& rhs) const 113 { 114 return lhs != rhs; 115 } 116 117 bool operator() (value_null, value_null) const 118 { 119 return false; 120 } 121 122 template <typename T> 123 bool operator() (value_null, const T &) const 124 { 125 return false; 126 } 127 128 template <typename T> 129 bool operator() (const T &, value_null) const 130 { 131 return false; 132 } 133 }; 134 77 135 struct greater_than 78 136 : public boost::static_visitor<bool> 79 137 { 80 138 template <typename T, typename U> 81 bool operator()( const T &, const U &) const82 { 83 return false; 84 } 85 86 template <typename T> 87 bool operator()( T lhs, T rhs) const139 bool operator()(const T &, const U &) const 140 { 141 return false; 142 } 143 144 template <typename T> 145 bool operator()(T lhs, T rhs) const 88 146 { 89 147 return lhs > rhs; … … 103 161 { 104 162 return lhs > rhs; 163 } 164 165 bool operator() (value_null, value_null) const 166 { 167 return false; 105 168 } 106 169 }; … … 110 173 { 111 174 template <typename T, typename U> 112 bool operator()( const T &, const U &) const175 bool operator()(const T &, const U &) const 113 176 { 114 177 return false; … … 131 194 } 132 195 133 bool operator() (UnicodeString const& lhs, UnicodeString const& rhs ) const196 bool operator() (UnicodeString const& lhs, UnicodeString const& rhs) const 134 197 { 135 198 return lhs >= rhs; 199 } 200 201 bool operator() (value_null, value_null) const 202 { 203 return false; 136 204 } 137 205 }; … … 141 209 { 142 210 template <typename T, typename U> 143 bool operator()( const T &, const U &) const144 { 145 return false; 146 } 147 148 template <typename T> 149 bool operator()( T lhs,Trhs) const211 bool operator()(const T &, const U &) const 212 { 213 return false; 214 } 215 216 template <typename T> 217 bool operator()(T lhs, T rhs) const 150 218 { 151 219 return lhs < rhs; … … 162 230 } 163 231 164 bool operator()( UnicodeString const& lhs,165 UnicodeString const& rhs ) const232 bool operator()(UnicodeString const& lhs, 233 UnicodeString const& rhs ) const 166 234 { 167 235 return lhs < rhs; 236 } 237 238 bool operator() (value_null, value_null) const 239 { 240 return false; 168 241 } 169 242 }; … … 173 246 { 174 247 template <typename T, typename U> 175 bool operator()( const T &, const U &) const176 { 177 return false; 178 } 179 180 template <typename T> 181 bool operator()(T lhs, T rhs ) const248 bool operator()(const T &, const U &) const 249 { 250 return false; 251 } 252 253 template <typename T> 254 bool operator()(T lhs, T rhs) const 182 255 { 183 256 return lhs <= rhs; … … 195 268 196 269 template <typename T> 197 bool operator()( UnicodeString const& lhs,198 UnicodeString const& rhs ) const270 bool operator()(UnicodeString const& lhs, 271 UnicodeString const& rhs ) const 199 272 { 200 273 return lhs <= rhs; 274 } 275 276 bool operator() (value_null, value_null) const 277 { 278 return false; 201 279 } 202 280 }; … … 387 465 return ss.str(); 388 466 } 389 }; 467 468 std::string operator() (value_null const& val) const 469 { 470 return ""; 471 } 472 }; 390 473 391 474 struct to_unicode : public boost::static_visitor<UnicodeString> … … 411 494 out << std::setprecision(16) << val; 412 495 return UnicodeString(out.str().c_str()); 496 } 497 498 UnicodeString operator() (value_null const& val) const 499 { 500 return UnicodeString(""); 413 501 } 414 502 }; … … 456 544 return ss.str(); 457 545 } 546 547 std::string operator() (value_null const& val) const 548 { 549 return "null"; 550 } 458 551 }; 459 552 } 460 553 461 554 class value 462 555 { … … 469 562 public: 470 563 value () 471 : base_( 0) {}564 : base_(value_null()) {} 472 565 473 566 template <typename T> value(T _val_) … … 481 574 bool operator!=(value const& other) const 482 575 { 483 return !(boost::apply_visitor(impl::equals(),base_,other.base_));576 return boost::apply_visitor(impl::not_equals(),base_,other.base_); 484 577 } 485 578 -
trunk/src/agg_renderer.cpp
r692 r693 457 457 { 458 458 typedef coord_transform2<CoordTransform,geometry2d> path_type; 459 if (feature.exists(sym.get_name())) 460 { 461 UnicodeString text = feature[sym.get_name()].to_unicode(); 462 boost::shared_ptr<ImageData32> const& data = sym.get_image(); 463 if (text.length() > 0 && data) 464 { 465 face_ptr face = font_manager_.get_face(sym.get_face_name()); 466 if (face) 459 UnicodeString text = feature[sym.get_name()].to_unicode(); 460 boost::shared_ptr<ImageData32> const& data = sym.get_image(); 461 if (text.length() > 0 && data) 462 { 463 face_ptr face = font_manager_.get_face(sym.get_face_name()); 464 if (face) 465 { 466 text_renderer<mapnik::Image32> ren(pixmap_,face); 467 ren.set_pixel_size(sym.get_text_size()); 468 ren.set_fill(sym.get_fill()); 469 470 string_info info(text); 471 face->get_string_info(info); 472 473 placement_finder<label_collision_detector4> finder(detector_); 474 475 unsigned num_geom = feature.num_geometries(); 476 for (unsigned i=0;i<num_geom;++i) 467 477 { 468 text_renderer<mapnik::Image32> ren(pixmap_,face); 469 ren.set_pixel_size(sym.get_text_size()); 470 ren.set_fill(sym.get_fill()); 471 472 string_info info(text); 473 face->get_string_info(info); 474 475 placement_finder<label_collision_detector4> finder(detector_); 476 477 unsigned num_geom = feature.num_geometries(); 478 for (unsigned i=0;i<num_geom;++i) 479 { 480 geometry2d const& geom = feature.get_geometry(i); 481 if (geom.num_points() > 0) // don't bother with empty geometries 482 { 483 path_type path(t_,geom,prj_trans); 484 placement text_placement(info, sym); 485 text_placement.avoid_edges = sym.get_avoid_edges(); 486 finder.find_point_placements<path_type>(text_placement,path); 478 geometry2d const& geom = feature.get_geometry(i); 479 if (geom.num_points() > 0) // don't bother with empty geometries 480 { 481 path_type path(t_,geom,prj_trans); 482 placement text_placement(info, sym); 483 text_placement.avoid_edges = sym.get_avoid_edges(); 484 finder.find_point_placements<path_type>(text_placement,path); 487 485 488 for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ ii)489 {490 int w = data->width();491 int h = data->height();486 for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ ii) 487 { 488 int w = data->width(); 489 int h = data->height(); 492 490 493 double x = text_placement.placements[ii].starting_x;494 double y = text_placement.placements[ii].starting_y;491 double x = text_placement.placements[ii].starting_x; 492 double y = text_placement.placements[ii].starting_y; 495 493 496 int px=int(x - (w/2));497 int py=int(y - (h/2));494 int px=int(x - (w/2)); 495 int py=int(y - (h/2)); 498 496 499 pixmap_.set_rectangle_alpha(px,py,*data);497 pixmap_.set_rectangle_alpha(px,py,*data); 500 498 501 Envelope<double> dim = ren.prepare_glyphs(&text_placement.placements[ii]);499 Envelope<double> dim = ren.prepare_glyphs(&text_placement.placements[ii]); 502 500 503 ren.render(x,y); 504 } 501 ren.render(x,y); 505 502 } 506 503 } … … 669 666 { 670 667 typedef coord_transform2<CoordTransform,geometry2d> path_type; 671 672 if (feature.exists(sym.get_name())) 673 { 674 UnicodeString text = feature[sym.get_name()].to_unicode(); 675 if ( text.length() > 0 ) 676 { 677 Color const& fill = sym.get_fill(); 678 face_ptr face = font_manager_.get_face(sym.get_face_name()); 679 if (face) 668 669 UnicodeString text = feature[sym.get_name()].to_unicode(); 670 if ( text.length() > 0 ) 671 { 672 Color const& fill = sym.get_fill(); 673 face_ptr face = font_manager_.get_face(sym.get_face_name()); 674 if (face) 675 { 676 text_renderer<mapnik::Image32> ren(pixmap_,face); 677 ren.set_pixel_size(sym.get_text_size()); 678 ren.set_fill(fill); 679 ren.set_halo_fill(sym.get_halo_fill()); 680 ren.set_halo_radius(sym.get_halo_radius()); 681 682 placement_finder<label_collision_detector4> finder(detector_); 683 684 string_info info(text); 685 face->get_string_info(info); 686 unsigned num_geom = feature.num_geometries(); 687 for (unsigned i=0;i<num_geom;++i) 680 688 { 681 text_renderer<mapnik::Image32> ren(pixmap_,face); 682 ren.set_pixel_size(sym.get_text_size()); 683 ren.set_fill(fill); 684 ren.set_halo_fill(sym.get_halo_fill()); 685 ren.set_halo_radius(sym.get_halo_radius()); 686 687 placement_finder<label_collision_detector4> finder(detector_); 688 689 string_info info(text); 690 face->get_string_info(info); 691 unsigned num_geom = feature.num_geometries(); 692 for (unsigned i=0;i<num_geom;++i) 689 geometry2d const& geom = feature.get_geometry(i); 690 if (geom.num_points() > 0) // don't bother with empty geometries 693 691 { 694 geometry2d const& geom = feature.get_geometry(i); 695 if (geom.num_points() > 0) // don't bother with empty geometries 692 path_type path(t_,geom,prj_trans); 693 placement text_placement(info,sym); 694 if (sym.get_label_placement() == POINT_PLACEMENT) 696 695 { 697 path_type path(t_,geom,prj_trans); 698 placement text_placement(info,sym); 699 if (sym.get_label_placement() == POINT_PLACEMENT) 700 { 701 double label_x, label_y, z=0.0; 702 geom.label_position(&label_x, &label_y); 703 prj_trans.backward(label_x,label_y, z); 704 t_.forward(&label_x,&label_y); 705 finder.find_point_placement(text_placement,label_x,label_y); 706 } 707 else //LINE_PLACEMENT 708 { 709 finder.find_line_placements<path_type>(text_placement,path); 710 } 696 double label_x, label_y, z=0.0; 697 geom.label_position(&label_x, &label_y); 698 prj_trans.backward(label_x,label_y, z); 699 t_.forward(&label_x,&label_y); 700 finder.find_point_placement(text_placement,label_x,label_y); 701 } 702 else //LINE_PLACEMENT 703 { 704 finder.find_line_placements<path_type>(text_placement,path); 705 } 711 706 712 for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ii) 713 { 714 double x = text_placement.placements[ii].starting_x; 715 double y = text_placement.placements[ii].starting_y; 716 Envelope<double> dim = ren.prepare_glyphs(&text_placement.placements[ii]); 717 ren.render(x,y); 718 } 707 for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ii) 708 { 709 double x = text_placement.placements[ii].starting_x; 710 double y = text_placement.placements[ii].starting_y; 711 Envelope<double> dim = ren.prepare_glyphs(&text_placement.placements[ii]); 712 ren.render(x,y); 719 713 } 720 714 } 721 } 722 else723 {724 throw config_error("Unable to find specified font face '" + sym.get_face_name() + "'");725 }715 } 716 } 717 else 718 { 719 throw config_error("Unable to find specified font face '" + sym.get_face_name() + "'"); 726 720 } 727 721 } -
trunk/src/cairo_renderer.cpp
r692 r693 751 751 typedef coord_transform2<CoordTransform,geometry2d> path_type; 752 752 753 if (feature.exists(sym.get_name())) 754 { 755 UnicodeString text = feature[sym.get_name()].to_unicode(); 756 boost::shared_ptr<ImageData32> const& data = sym.get_image(); 757 758 if (text.length() > 0 && data) 759 { 760 cairo_face_ptr face = face_manager_.get_face(sym.get_face_name()); 761 762 if (face) 763 { 764 cairo_context context(context_); 765 766 context.set_font_face(face); 767 768 string_info info(text); 769 770 face->get_string_info(sym.get_text_size(), info); 771 772 placement_finder<label_collision_detector4> finder(detector_); 773 774 for (unsigned i = 0; i < feature.num_geometries(); ++i) 775 { 776 geometry2d const& geom = feature.get_geometry(i); 777 778 if (geom.num_points() > 0) // don't bother with empty geometries 753 UnicodeString text = feature[sym.get_name()].to_unicode(); 754 boost::shared_ptr<ImageData32> const& data = sym.get_image(); 755 756 if (text.length() > 0 && data) 757 { 758 cairo_face_ptr face = face_manager_.get_face(sym.get_face_name()); 759 760 if (face) 761 { 762 cairo_context context(context_); 763 764 context.set_font_face(face); 765 766 string_info info(text); 767 768 face->get_string_info(sym.get_text_size(), info); 769 770 placement_finder<label_collision_detector4> finder(detector_); 771 772 for (unsigned i = 0; i < feature.num_geometries(); ++i) 773 { 774 geometry2d const& geom = feature.get_geometry(i); 775 776 if (geom.num_points() > 0) // don't bother with empty geometries 777 { 778 path_type path(t_, geom, prj_trans); 779 placement text_placement(info, sym); 780 781 text_placement.avoid_edges = sym.get_avoid_edges(); 782 finder.find_point_placements<path_type>(text_placement, path); 783 784 for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ ii) 779 785 { 780 path_type path(t_, geom, prj_trans); 781 placement text_placement(info, sym); 782 783 text_placement.avoid_edges = sym.get_avoid_edges(); 784 finder.find_point_placements<path_type>(text_placement, path); 785 786 for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ ii) 787 { 788 double shield_x = text_placement.placements[ii].starting_x - data->width() / 2; 789 double shield_y = text_placement.placements[ii].starting_y - data->height() / 2; 790 791 context.add_image(shield_x, shield_y, *data); 792 context.add_text(sym, text_placement.placements[ii], face); 793 } 786 double shield_x = text_placement.placements[ii].starting_x - data->width() / 2; 787 double shield_y = text_placement.placements[ii].starting_y - data->height() / 2; 788 789 context.add_image(shield_x, shield_y, *data); 790 context.add_text(sym, text_placement.placements[ii], face); 794 791 } 795 792 } … … 928 925 typedef coord_transform2<CoordTransform,geometry2d> path_type; 929 926 930 if (feature.exists(sym.get_name())) 931 { 932 UnicodeString text = feature[sym.get_name()].to_unicode(); 933 934 if (text.length() > 0) 935 { 936 cairo_face_ptr face = face_manager_.get_face(sym.get_face_name()); 937 938 if (face) 939 { 940 cairo_context context(context_); 941 942 context.set_font_face(face); 943 944 string_info info(text); 945 946 face->get_string_info(sym.get_text_size(), info); 947 948 placement_finder<label_collision_detector4> finder(detector_); 949 950 for (unsigned i = 0; i < feature.num_geometries(); ++i) 951 { 952 geometry2d const& geom = feature.get_geometry(i); 953 954 if (geom.num_points() > 0) // don't bother with empty geometries 927 UnicodeString text = feature[sym.get_name()].to_unicode(); 928 929 if (text.length() > 0) 930 { 931 cairo_face_ptr face = face_manager_.get_face(sym.get_face_name()); 932 933 if (face) 934 { 935 cairo_context context(context_); 936 937 context.set_font_face(face); 938 939 string_info info(text); 940 941 face->get_string_info(sym.get_text_size(), info); 942 943 placement_finder<label_collision_detector4> finder(detector_); 944 945 &n
