23 #include <boost/unordered_map.hpp> 24 #include <boost/math/constants/constants.hpp> 45 cairo_append_path(cr,
path);
52 path = cairo_copy_path(cr);
54 double x0, y0, x1, y1;
55 cairo_path_extents(cr, &x0, &y0, &x1, &y1);
63 cairo_path_data_t *
data, last_move_to, current;
65 double bestDiff = -std::numeric_limits<double>::infinity();
69 for (
int i = 0; i < path->num_data; i += path->data[i].header.length) {
70 data = &path->data[i];
71 switch (data->header.type) {
72 case CAIRO_PATH_MOVE_TO:
73 last_move_to = data[1];
77 case CAIRO_PATH_CLOSE_PATH:
78 data = (&last_move_to) - 1;
79 case CAIRO_PATH_LINE_TO:
80 dx = current.point.x - data[1].point.x;
81 dy = current.point.y - data[1].point.y;
83 length = sqrt(dx*dx + dy*dy);
84 diff = length - width;
85 if (diff > 0 && diff > bestDiff) {
89 angle = -boost::math::constants::pi<double>()/2.0;
90 best.
x = current.point.x - dx * 0.5;
91 best.
y = current.point.y - dy * 0.5;
98 case CAIRO_PATH_CURVE_TO:
104 return (bestDiff > 0);
110 cairo_path_data_t *
data, last_move_to, current;
113 for (
int i = 0; i < path->num_data; i += path->data[i].header.length) {
114 data = &path->data[i];
115 switch (data->header.type) {
116 case CAIRO_PATH_MOVE_TO:
117 last_move_to = data[1];
121 case CAIRO_PATH_CLOSE_PATH:
122 data = (&last_move_to) - 1;
123 case CAIRO_PATH_LINE_TO:
124 dx = current.point.x - data[1].point.x;
125 dy = current.point.y - data[1].point.y;
126 dis += sqrt(dx*dx + dy*dy);
129 positions.push_back(
FloatPoint(current.point.x - 0.5*dx,
130 current.point.y - 0.5*dy));
137 case CAIRO_PATH_CURVE_TO:
150 ,
way(data->getWay(wid))
157 cairo_path_destroy(
path);
171 cairo_pattern_t* pattern = cairo_pattern_create_for_surface(cache.
getImage(bg));
172 cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
173 cairo_set_source(cr, pattern);
175 cairo_pattern_destroy(pattern);
219 cairo_pattern_t* pattern = NULL;
220 if (!image.empty()) {
221 pattern = cairo_pattern_create_for_surface(cache.
getImage(image));
222 cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
223 cairo_set_source(cr, pattern);
228 cairo_set_line_width(cr,
s->
width);
233 cairo_pattern_destroy(pattern);
239 std::list<shared_ptr<Label> >& labels,
AssetCache& cache)
252 cairo_select_font_face(cr,
258 cairo_text_extents_t textSize;
259 cairo_text_extents(cr,
s->
text.
c_str(), &textSize);
273 cairo_translate(cr, best.
x, best.
y);
274 cairo_rotate(cr, angle);
277 cairo_move_to(cr, -textSize.width/2.0 - textSize.x_bearing,
278 -textSize.height/2.0 - textSize.y_bearing);
284 cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
287 cairo_stroke_preserve(cr);
298 std::list<shared_ptr<Shield> >& shields,
312 cairo_select_font_face(cr,
318 cairo_text_extents_t textSize;
321 std::list<FloatPoint> positions;
MaybeCachedString shield_text
basic_rect< double > FloatRect
void setLineCap(cairo_t *cr, Style::LineCap cap)
bool getTextPosition(cairo_path_t *transformedPath, int width, FloatPoint &best, double &angle)
Find the best fitting segment on a cairo path and return angle.
void stroke(cairo_t *cr, AssetCache &cache)
const cairo_matrix_t * transform
void fill(cairo_t *cr, AssetCache &cache)
const string & str() const
Returns the internal string.
MaybeCachedString fill_image
const shared_ptr< Geodata > & data
MaybeCachedString font_family
void label(cairo_t *cr, std::list< shared_ptr< Label > > &labels, AssetCache &cache)
void shield(cairo_t *cr, std::list< shared_ptr< Shield > > &shields, AssetCache &cache)
A Style stores the MapCSS properties for a single Node or Way, or a Relation of type multipolygon...
FloatRect bounds
is set by addWayPath for ways or in transformLocation for nodes
std::vector< double > casing_dashes
void paintLine(cairo_t *cr, const std::vector< NodeId > &nodeIDs, bool reverse=false, bool connect=false) const
This file is part of alaCarte.
basic_vector2< double > FloatPoint
WayRenderer(const shared_ptr< Geodata > &data, WayId wid, const Style *s, const cairo_matrix_t *transform)
void setLineJoin(cairo_t *cr, Style::LineJoin join)
TextPosition text_position
void addLabel(std::list< shared_ptr< Label > > &labels, const FloatPoint &p, const cairo_text_extents_t *textSize) const
used by node and way renderer to place a shield.
cairo_surface_t * getImage(string path)
const char * c_str() const
Returns the internal c string.
void addShield(std::list< shared_ptr< Shield > > &shields, const FloatPoint &p, const cairo_text_extents_t *textSize) const
used by node and way renderer to place a shield.
std::vector< double > dashes
#define RENDERER_SHIELD_DISTANCE
This file is part of alaCarte.
void addWayPath(cairo_t *cr)
This file is part of alaCarte.
void getShieldPosition(cairo_path_t *transformedPath, std::list< FloatPoint > &positions)
Find the best fitting segment on a cairo path for a shield.
const std::vector< NodeId > & getNodeIDs() const
basic_vector2< T > getCenter() const