| 1 | /***************************************************************************** |
|---|
| 2 | * |
|---|
| 3 | * This file is part of Mapnik (c++ mapping toolkit) |
|---|
| 4 | * |
|---|
| 5 | * Copyright (C) 2006 Artem Pavlenko |
|---|
| 6 | * Copyright (C) 2006 10East Corp. |
|---|
| 7 | * |
|---|
| 8 | * This library is free software; you can redistribute it and/or |
|---|
| 9 | * modify it under the terms of the GNU Lesser General Public |
|---|
| 10 | * License as published by the Free Software Foundation; either |
|---|
| 11 | * version 2.1 of the License, or (at your option) any later version. |
|---|
| 12 | * |
|---|
| 13 | * This library is distributed in the hope that it will be useful, |
|---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 16 | * Lesser General Public License for more details. |
|---|
| 17 | * |
|---|
| 18 | * You should have received a copy of the GNU Lesser General Public |
|---|
| 19 | * License along with this library; if not, write to the Free Software |
|---|
| 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 21 | * |
|---|
| 22 | *****************************************************************************/ |
|---|
| 23 | |
|---|
| 24 | //$Id$ |
|---|
| 25 | |
|---|
| 26 | #ifndef __PLACEMENT_FINDER__ |
|---|
| 27 | #define __PLACEMENT_FINDER__ |
|---|
| 28 | |
|---|
| 29 | #include <queue> |
|---|
| 30 | |
|---|
| 31 | #include <mapnik/ctrans.hpp> |
|---|
| 32 | #include <mapnik/label_collision_detector.hpp> |
|---|
| 33 | #include <mapnik/text_symbolizer.hpp> |
|---|
| 34 | #include <mapnik/geometry.hpp> |
|---|
| 35 | #include <mapnik/text_path.hpp> |
|---|
| 36 | |
|---|
| 37 | namespace mapnik |
|---|
| 38 | { |
|---|
| 39 | |
|---|
| 40 | struct placement_element |
|---|
| 41 | { |
|---|
| 42 | double starting_x; |
|---|
| 43 | double starting_y; |
|---|
| 44 | |
|---|
| 45 | text_path path; |
|---|
| 46 | }; |
|---|
| 47 | |
|---|
| 48 | struct placement |
|---|
| 49 | { |
|---|
| 50 | typedef coord_transform2<CoordTransform,geometry_type> path_type; |
|---|
| 51 | |
|---|
| 52 | //For shields |
|---|
| 53 | placement(string_info *info_, CoordTransform *ctrans_, const proj_transform *proj_trans_, geometry_ptr geom_, std::pair<double, double> dimensions_); |
|---|
| 54 | |
|---|
| 55 | //For text |
|---|
| 56 | placement(string_info *info_, CoordTransform *ctrans_, const proj_transform *proj_trans_, geometry_ptr geom_, label_placement_e placement_); |
|---|
| 57 | |
|---|
| 58 | ~placement(); |
|---|
| 59 | |
|---|
| 60 | unsigned path_size() const; |
|---|
| 61 | string_info *info; |
|---|
| 62 | |
|---|
| 63 | CoordTransform *ctrans; |
|---|
| 64 | const proj_transform *proj_trans; |
|---|
| 65 | |
|---|
| 66 | geometry_ptr geom; |
|---|
| 67 | label_placement_e label_placement; |
|---|
| 68 | std::pair<double, double> dimensions; |
|---|
| 69 | |
|---|
| 70 | bool has_dimensions; |
|---|
| 71 | |
|---|
| 72 | path_type shape_path; |
|---|
| 73 | std::queue< Envelope<double> > envelopes; |
|---|
| 74 | |
|---|
| 75 | //output |
|---|
| 76 | std::vector<placement_element> placements; |
|---|
| 77 | |
|---|
| 78 | // caching output |
|---|
| 79 | placement_element current_placement; |
|---|
| 80 | |
|---|
| 81 | //helpers |
|---|
| 82 | std::pair<double, double> get_position_at_distance(double target_distance); |
|---|
| 83 | double get_total_distance(); |
|---|
| 84 | void clear_envelopes(); |
|---|
| 85 | |
|---|
| 86 | double total_distance_; //cache for distance |
|---|
| 87 | |
|---|
| 88 | int wrap_width; |
|---|
| 89 | int text_ratio; |
|---|
| 90 | |
|---|
| 91 | int label_spacing; // distance between repeated labels on a single geometry |
|---|
| 92 | }; |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | class placement_finder : boost::noncopyable |
|---|
| 97 | { |
|---|
| 98 | public: |
|---|
| 99 | placement_finder(Envelope<double> e); |
|---|
| 100 | |
|---|
| 101 | bool find_placements(placement *p); |
|---|
| 102 | |
|---|
| 103 | protected: |
|---|
| 104 | bool find_placement_follow(placement *p); |
|---|
| 105 | bool find_placement_horizontal(placement *p); |
|---|
| 106 | |
|---|
| 107 | bool build_path_follow(placement *p, double target_distance); |
|---|
| 108 | bool build_path_horizontal(placement *p, double target_distance); |
|---|
| 109 | |
|---|
| 110 | void update_detector(placement *p); |
|---|
| 111 | |
|---|
| 112 | label_collision_detector3 detector_; |
|---|
| 113 | }; |
|---|
| 114 | |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | #endif |
|---|