Mapnik 3.1.0 Release Jan 08, 2021 | Artem Pavlenko
Mapnik 3.0.24 Release Jan 05, 2021 | Artem Pavlenko
Mapnik 3.0.23 Release Jan 18, 2020 | Artem Pavlenko
Mapnik 3.0.22 Release Jan 22, 2019 | Artem Pavlenko
Mapnik 3.0.21 Release Oct 08, 2018 | Artem Pavlenko
Mapnik 3.0.20 Release Apr 12, 2018 | Artem Pavlenko
Mapnik 3.0.19 Release Mar 06, 2018 | Artem Pavlenko
Mapnik 3.0.18 Release Jan 26, 2018 | Artem Pavlenko
Mapnik 3.0.16 Release Nov 16, 2017 | Artem Pavlenko
Mapnik 3.0.12 Release Sep 08, 2016 | Artem Pavlenko
Mapnik 3.0.10 Release Feb 29, 2016 | Artem Pavlenko
Node Mapnik 3.5.0 Release Feb 29, 2016 | Sam Matthews

latest news

Text formating

Sep 02, 2011

BY:   Herman Kraus

Now that Google Summer of Code is over I'd like to show you some of theresults:

I already posted information about the newtext placement system. No big changes happened here, just a fewbugfixes. I also added some testsand reference images.

Improving text formating was the second half of my project.

Currently when you want to label a peak like this

Name
Elevation
you define these two symbolizers:The image will look like this:
Sample image
This usually works, but it has some limitations. For example let's see what happens when the name gets a little longer:
Sample image
Mapnik breaks the long name and the elevation disappears, because the offset is not correct.

Now let's have a look at how it is done with the new placement system:You only define one TextSymbolizer but with a different syntax:(Note: 
 is the XML encoding of a newline character)
Sample imageSample image
As you can see Mapnik automatically takes care of correct line spacing, no need to calculate offsets manually.

Backwards incompatible changes

To make this work some backwards incompatibilities had to be introduced.

  • Line spacing is no longer defined by the largest character in a certain text, but by the line spacing value defined in the font file. This should result in a nice line spacing by default, but if you have defined additional line spacing in your style you have to remove it or at least reduce it to get the same effect as before.
  • The text rendered by a TextSymbolizer is no longer given in the name attribute, but as a text node.
    <TextSymbolizer name="[abc]" />
    becomes
    <TextSymbolizer>[abc]</TextSymbolizer>

Parameters you can change

You can change the following text attributes with the Format instruction:

  • face-name
  • size
  • character-spacing
  • line-spacing
  • opacity
  • wrap-character
  • text-transform
  • fill
  • halo-fill
  • halo-radius

But you are not limited to using a fixed format. You can implement your own class in C++ to do the formating. It's very simple:In the same way you can do custom text formating:

Next steps

The code is ready, now it's required to test it on larger styles to find any remaining bugs. Python bindings also have to be updated to fully support the new features. When this is done the code will be released as Mapnik 2.1 as it's to late in the release cycle to include it in Mapnik 2.0.

Copyright © 2018 Artem Pavlenko | Downloads | License | Media