[cairo] How do I...?

Tim Teulings rael at edge.ping.de
Mon Apr 5 04:17:24 PDT 2010


I use cairo as part of my libosmsocut project (http://libosmscout.sf.net) to 
draw maps based on OpenStreetMap data (after using it as possibly backend 
for drawing widgets as part of libIllumination). 

Cairo is very useful for this on over all I'm very happy (thanks for that 
great work!)! 

I'm now starting to implement more sophisticated draw features and have some 
questions how to realize this using cairo and how much I can handle using 
cairo features itself and how much of this I have to do in my code (by doing 
some preprocessing for example). I'm searching for solutions that are 
optimized for visual quality but even more for drawing speed (especially on 
slow devices). 

Currently ways are drawn by just stroking paths using move_to and line_to 
and setting color, pen thickness as appropiate. Coordinates are a result of 
the (mercator) transformed coordinates I get from OSM nodes (as part of a 

This should be OK, I assume ;-)? 

For outlines I simply draw a line twice with different line thickness. 
Should be still OK, but is there possibly a faster/simpler solution (=> path 

Now I want to further decorate the drawn way. 

* First I want to have periodical markers on the way like for example arrows 
that show the driving direction (oneway) or images that signal bumpers. The 
markers should be centered on the line. How do I do this? 

* Now, in the case that a way has multiple lanes (motorway for example), I 
also want to draw lane seperation markers (at least on higher zoom level 
:-)). For the case that the the way exists of two lanes this is simple 
because I just can draw another line with different color and width over the 
existing path. But what do I do in case where a motorway has three lanes? If 
I still just draw another line over the existing way I now have to calculate 
new polygon point coordinates that do the necessary "away from line center" 
transformation or is there a way where cairo can do this for me, too? 


More information about the cairo mailing list