[PATCH] cairo_renderer: use transform() instead of set_matrix() for markers

25 views
Skip to first unread message

Thomas Petazzoni

unread,
Mar 26, 2012, 10:49:50 AM3/26/12
to map...@googlegroups.com, d...@maposmatic.org, Thomas Petazzoni
From: Thomas Petazzoni <thomas.p...@free-electrons.com>

Mapnik is current using context.set_matrix() to modify the Cairo
transformation matrix to render markers at the right location and with
the right angle on the map. This is typically used to render one-way
arrows with the MapQuest stylesheet.

Unfortunately, context.set_matrix() completely _overrides_ the
existing Cairo transformation matrix instead of making an _additional_
transformation to it. However, in MapOSMatic
(http://www.maposmatic.org), for our map-rendering needs, we pass to
Mapnik a Cairo surface on which we have already applied a
translation+scaling transformation. The usage of .set_matrix() by
Mapnik completely overrides this transformation, with the result of
having completely misplaced one-way arrows.

By using context.transform(), then the transformation matrix is
applied on _top_ of the current one, which fixes the rendering. Now,
the one-way arrows are at the right locations on our translated+scaled
Cairo surface.

Thanks to Gaël Utard <gael....@kisis.fr> for his help in debugging
this problem.

Signed-off-by: Thomas Petazzoni <thomas.p...@free-electrons.com>
---
src/cairo_renderer.cpp | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/cairo_renderer.cpp b/src/cairo_renderer.cpp
index 589247e..12f6277 100644
--- a/src/cairo_renderer.cpp
+++ b/src/cairo_renderer.cpp
@@ -1269,7 +1269,7 @@ void cairo_renderer_base::start_map_processing(Map const& map)
double x, y, angle;
while (placement.get_point(&x, &y, &angle)) {
Cairo::Matrix matrix = Cairo::rotation_matrix(angle) * Cairo::translation_matrix(x,y) ;
- context.set_matrix(matrix);
+ context.transform(matrix);
context.add_path(arrow_);
}
}
--
1.7.4.1

Dane Springmeyer

unread,
Mar 28, 2012, 11:13:10 PM3/28/12
to map...@googlegroups.com, map...@googlegroups.com, d...@maposmatic.org, Thomas Petazzoni
Looks like a great patch. However it would be great to have some tests to accompany this. There are a number of places transforms are uses so it will be important to test them all.

Anyway, I am traveling this week and mostly offline. I will take a look at applying next week when back. In the meantime it would be great if you could create an issue and attach this patch.

Thanks!

Dane

Reply all
Reply to author
Forward
0 new messages