void WayRenderer::stroke(cairo_t* cr, AssetCache& cache)
{
	if (s->width <= 0.0)
		return;

	addWayPath(cr);

	cairo_save(cr);

	setLineCap(cr,  s->linecap);
	setLineJoin(cr, s->linejoin);
	cairo_set_source_rgba(cr, COLOR2RGBA(s->color));
	const string& image = s->image.str();
	cairo_pattern_t* pattern = NULL;
	if (!image.empty()) {
		pattern = cairo_pattern_create_for_surface(cache.getImage(image));
		cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
		cairo_set_source(cr, pattern);
	}

	if (s->dashes.size() > 0)
		cairo_set_dash(cr, s->dashes.data(), s->dashes.size(), 0.0);
	cairo_set_line_width(cr, s->width);

	cairo_stroke(cr);

	if (pattern != NULL)
		cairo_pattern_destroy(pattern);

	cairo_restore(cr);
}
Exemple #2
0
void NodeRenderer::icon(const Cairo::RefPtr<Cairo::Context>& cr, AssetCache& cache)
{
	// path to icon not set
	if (s->icon_image.str().size() == 0 || s->icon_width == 0.0 || s->icon_height == 0.0)
		return;

	cr->save();

	Cairo::RefPtr<Cairo::ImageSurface> image = cache.getImage(s->icon_image.str());
	double width = s->icon_width < 0 ? image->get_width() : s->icon_width;
	double height = s->icon_height < 0 ? image->get_height() : s->icon_height;
	double x0 = floor(location.x - width/2.0);
	double y0 = floor(location.y - height/2.0);
	cr->translate(x0, y0);
	cr->scale(width / image->get_width(),
			  height / image->get_height());
	cr->set_source(image, 0, 0);

	if (s->icon_opacity < 1.0)
		cr->paint_with_alpha(s->icon_opacity);
	else
		cr->paint();

	cr->restore();
}
void WayRenderer::fill(cairo_t* cr, AssetCache& cache)
{
	if (!way->isClosed())
		return;

	addWayPath(cr);

	cairo_save(cr);

	const string& bg = s->fill_image.str();
	if (!bg.empty()) {
		cairo_pattern_t* pattern = cairo_pattern_create_for_surface(cache.getImage(bg));
		cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
		cairo_set_source(cr, pattern);
		cairo_fill(cr);
		cairo_pattern_destroy(pattern);
	} else {
		cairo_set_source_rgba(cr, COLOR2RGBA(s->fill_color));
		cairo_fill(cr);
	}

	cairo_restore(cr);
}