May 28, 2011
My Summer of Code project this year is about improving Mapnik's text rendering. There are two problems with the way text is currently rendered. I'll describe these problems and show how I intend to solve them.
When rendering crowded areas there is often no space to place a label at the point it should go to and the label therefore is dropped.
In the example above many symbols are missing a label because there was no space, but they could have been shown when moved a bit. I already worked on this problem this winter and now you can tell Mapnik 2 to try different locations and font sizes. But the algorithm is quite limited at the moment and many important properties can't be changed. So the first part of my work is to add these missing features. The most important change will be that one is able to change the text. So if rendering "Example Street" fails, it could try "Example St.".
The other big problem is that Mapnik doesn't have any means to change formatting in a TextSymbolizer. When you try to label a mountain peak with name and elevation like this
you need two symbolizers, one for the name and one for the elevation and calculate a appropriate offset for the second one. But if the name is a bit longer and mapnik splits it into multiple lines this calculation is wrong, the texts overlap and mapnik drops one.
My project is to add formating capabilities to TextSymbolizers. When I'm done one will only need one symbolizer for this job and the positions will adjust automatically.