Updated TextSymbolizer (markdown)

tmcw 2011-12-09 12:45:11 -08:00
parent 4cec2974b6
commit 39cca49437

@ -1,7 +1,3 @@
<!-- Name: TextSymbolizer -->
<!-- Version: 39 -->
<!-- Last-Modified: 2011/09/15 16:28:11 -->
<!-- Author: herm -->
## Configuration Options for TextSymbolizer ## Configuration Options for TextSymbolizer
| *parameter* | *value* | *description* | *unit* | *default* | | *parameter* | *value* | *description* | *unit* | *default* |
@ -44,45 +40,51 @@ In Mapnik2 all underscores "_" are replaced by dashes "-" (e.g. avoid-edges inst
## Examples ## Examples
Some examples of Mapnik's ability to place text along lines: Some examples of Mapnik's ability to place text along lines:
[[BR]]
[[Image(http://trac.mapnik.org/raw-attachment/ticket/62/output_old.png)]] ![thumb](http://trac.mapnik.org/raw-attachment/ticket/62/output_old.png)
### XML ### XML
#!xml ```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"/> #!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 [wiki:XMLGettingStarted] for more XML example uses of TextSymbolizer. See [wiki:XMLGettingStarted] for more XML example uses of TextSymbolizer.
### Python ### Python
#!python ```python
t = TextSymbolizer('FIELD_NAME', 'DejaVu Sans Book', 10, Color('black')) #!python
t.halo_fill = Color('white') t = TextSymbolizer('FIELD_NAME', 'DejaVu Sans Book', 10, Color('black'))
t.halo_radius = 1 t.halo_fill = Color('white')
t.label_placement = label_placement.LINE_PLACEMENT # POINT_PLACEMENT is default t.halo_radius = 1
dir(t) # for the rest of the attributes t.label_placement = label_placement.LINE_PLACEMENT # POINT_PLACEMENT is default
dir(t) # for the rest of the attributes
```
### C++ ### C++
#!cpp ```cpp
#include <mapnik/map.hpp> #!cpp
#include <mapnik/font_engine_freetype.hpp> #include <mapnik/map.hpp>
#include <mapnik/font_engine_freetype.hpp>
using namespace mapnik; using namespace mapnik;
try { try {
freetype_engine::register_font("/path/to/font.ttf"); freetype_engine::register_font("/path/to/font.ttf");
/* some code */ /* some code */
rule_type rule; rule_type rule;
text_symbolizer ts("FIELD_NAME", "DejaVu Sans Book", 10, color(0, 0, 0)); text_symbolizer ts("FIELD_NAME", "DejaVu Sans Book", 10, color(0, 0, 0));
ts.set_halo_fill(color(255, 255, 200)); ts.set_halo_fill(color(255, 255, 200));
ts.set_halo_radius(1); ts.set_halo_radius(1);
rule.append(ts); 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. 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 recommend to load all of this fonts, regardless if you need them or not. 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 recommend to load all of this fonts, regardless if you need them or not.
@ -109,22 +111,30 @@ Note: Whitespace is ignored, e.g. "N,S,15,10" and "N, S,15,10" and "N, S, 15, 10
An XML example might look like: An XML example might look like:
#!xml ```xml
<TextSymbolizer #!xml
name="[label]" <TextSymbolizer
allow-overlap="false" name="[label]"
face-name="DejaVu Sans Book" allow-overlap="false"
placement-type="simple" face-name="DejaVu Sans Book"
placements="N,S,15,10,8" placement-type="simple"
/> placements="N,S,15,10,8"
/>
```
## New syntax ## New syntax
Starting with r3354 Mapnik2 supports a new syntax: Starting with r3354 Mapnik2 supports a new syntax:
#!xml ```
<TextSymbolizer name="[label]" /> #!xml
<TextSymbolizer name="[label]" />
```
becomes becomes
#!xml ```xml
<TextSymbolizer>[label]</TextSymbolizer> #!xml
<TextSymbolizer>[label]</TextSymbolizer>
```
This change was made to be forward compatible with changes to text formatting being introduced in later versions. This change was made to be forward compatible with changes to text formatting being introduced in later versions.