Configuration Options for TextSymbolizer

nameThis is the query field you want to use for the label text, e.g. "street_name"
face_nameFont name (see UsingCustomFonts)
fontset_name ?
sizeFont size
text_ratio?
wrap_characterUse this character instead of a space to wrap long names (since r1254)
wrap_widthLength before wrapping long names
text_convertAllows conversion of text to lower or upper case before display. Values are "none" (default), "toupper", and "tolower". (since r1254)
line_spacingVertical spacing between lines of multiline labels (in pixels) (since r1254)
character_spacingHorizontal spacing between characters (in pixels). Currently works for point placement only, not line placement. (since r1254)
spacingSpace between repeated labels
label_position_toleranceAllow labels to be moved from their point in line placement. Integer value representing distance along a line in line placement mode, defaults to 1/2 min_distance.
force_odd_labelsForce an odd amount of labels to be generated. Defaults to false.
max_char_angle_deltaMaximum angle (in degrees) between two consecutive characters in a label allowed (to stop placing labels around sharp corners) see r365 for more info
fillColor of the text fill, e.g. #FFFFFF
halo_fillColor of the text halo
halo_radiusRadius of the halo in whole pixels (fractional pixels are not accepted)
dx, dyDisplace label by fixed amount on either axis. Also see note at vertical_alignment
avoid_edgesBoolean to avoid labeling near intersection edges
min_distanceMinimum distance between repeated labels such as street names or shield symbols (works across features, added in r490)
allow_overlapAllow labels to overlap other labels - Note: you can also clear the label collision cache at the LAYER level to promote more overlap. See 'clear_label_cache' at wiki:XMLConfigReference#Layer
placement"line" to label along lines instead of by point
vertical_alignmentPosition of label relative to point position ("top" (label on top of point), "middle", "bottom") default is "middle" for dy=0, "bottom" for dy>0, "top" for dy<0 (since r1527, "middle" before that)

Examples

Some examples of Mapnik's ability to place text along lines:

http://trac.mapnik.org/raw-attachment/ticket/62/output_old.png

XML

 <TextSymbolizer name="FIELD_NAME" face_name="DejaVu Sans Book" size="10" fill="black" halo_fill= "white" halo_radius="1" placement="line" allow_overlap="false"/>

See XMLGettingStarted for more XML example uses of TextSymbolizer.

Python

t = TextSymbolizer('FIELD_NAME', 'DejaVu Sans Book', 10, Color('black'))
t.halo_fill = Color('white')
t.halo_radius = 1
t.label_placement = label_placement.LINE_PLACEMENT # POINT_PLACEMENT is default
dir(t) # for the rest of the attributes

C++

#include <mapnik/map.hpp>
#include <mapnik/font_engine_freetype.hpp>

using namespace mapnik;
try {
   freetype_engine::register_font("/path/to/font.ttf");
   /* some code */
   rule_type rule;
   text_symbolizer ts("FIELD_NAME", "DejaVu Sans Book", 10, color(0, 0, 0));
   ts.set_halo_fill(color(255, 255, 200));
   ts.set_halo_radius(1);
   rule.append(ts);
}

The first parameter is the field name of a database field, or from a shape file, or an osm file. In case of a shape file or osm file, the field name is case sensitive. You must load the needed fonts first, otherwise you'll get a run time error. But you can load as many true type fonts as you like. Mapnik is coming with a couple of fonts in "mapnik/fonts". I recomend to load all of this fonts, regardless if you need them or not.