Fix the problem reported in #1003 (NE, NW, SE not working for text-placement=simple).

Add test cases for this problem.

Conflicts:

	src/text_placements.cpp
	tests/data/placement/clean.sh
	tests/data/placement/test.py
This commit is contained in:
Hermann Kraus 2012-01-08 15:01:54 +01:00
parent 1fa26fa067
commit cbcb545b65
19 changed files with 208 additions and 0 deletions

View file

@ -107,14 +107,17 @@ bool text_placement_info_simple::next_position_only()
displacement = boost::make_tuple(
abs(parent_->displacement_.get<0>()),
-abs(parent_->displacement_.get<1>()));
break;
case SOUTHEAST:
displacement = boost::make_tuple(
abs(parent_->displacement_.get<0>()),
abs(parent_->displacement_.get<1>()));
break;
case NORTHWEST:
displacement = boost::make_tuple(
-abs(parent_->displacement_.get<0>()),
-abs(parent_->displacement_.get<1>()));
break;
case SOUTHWEST:
displacement = boost::make_tuple(
-abs(parent_->displacement_.get<0>()),

5
tests/data/placement/clean.sh Executable file
View file

@ -0,0 +1,5 @@
rm -f list-[0-9][0-9]0-agg.png
rm -f simple-[0-9][0-9]0-agg.png
rm -f simple-{E,N,NE,NW,N,SE,SW,S,W}-500-agg.png
rm -f list-out.xml simple-out.xml

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map>
<Map background-color="white" srs="+proj=latlong +datum=WGS84">
<Layer name="layer" srs="+proj=latlong +datum=WGS84">
<StyleName>My Style</StyleName>
<Datasource>
<Parameter name="type">shape</Parameter>
<Parameter name="file">points.shp</Parameter>
</Datasource>
</Layer>
<Style name="My Style">
<Rule>
<Filter>[name] = 'Test five'</Filter>
<PointSymbolizer/>
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" dx="10" dy="10" placement-type="simple" placements="E">[name]</TextSymbolizer>
</Rule>
</Style>
</Map>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map>
<Map background-color="white" srs="+proj=latlong +datum=WGS84">
<Layer name="layer" srs="+proj=latlong +datum=WGS84">
<StyleName>My Style</StyleName>
<Datasource>
<Parameter name="type">shape</Parameter>
<Parameter name="file">points.shp</Parameter>
</Datasource>
</Layer>
<Style name="My Style">
<Rule>
<Filter>[name] = 'Test five'</Filter>
<PointSymbolizer/>
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" dx="10" dy="10" placement-type="simple" placements="N">[name]</TextSymbolizer>
</Rule>
</Style>
</Map>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map>
<Map background-color="white" srs="+proj=latlong +datum=WGS84">
<Layer name="layer" srs="+proj=latlong +datum=WGS84">
<StyleName>My Style</StyleName>
<Datasource>
<Parameter name="type">shape</Parameter>
<Parameter name="file">points.shp</Parameter>
</Datasource>
</Layer>
<Style name="My Style">
<Rule>
<Filter>[name] = 'Test five'</Filter>
<PointSymbolizer/>
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" dx="-10" dy="-10" placement-type="simple" placements="NE">[name]</TextSymbolizer>
</Rule>
</Style>
</Map>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map>
<Map background-color="white" srs="+proj=latlong +datum=WGS84">
<Layer name="layer" srs="+proj=latlong +datum=WGS84">
<StyleName>My Style</StyleName>
<Datasource>
<Parameter name="type">shape</Parameter>
<Parameter name="file">points.shp</Parameter>
</Datasource>
</Layer>
<Style name="My Style">
<Rule>
<Filter>[name] = 'Test five'</Filter>
<PointSymbolizer/>
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" dx="10" dy="10" placement-type="simple" placements="NW">[name]</TextSymbolizer>
</Rule>
</Style>
</Map>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map>
<Map background-color="white" srs="+proj=latlong +datum=WGS84">
<Layer name="layer" srs="+proj=latlong +datum=WGS84">
<StyleName>My Style</StyleName>
<Datasource>
<Parameter name="type">shape</Parameter>
<Parameter name="file">points.shp</Parameter>
</Datasource>
</Layer>
<Style name="My Style">
<Rule>
<Filter>[name] = 'Test five'</Filter>
<PointSymbolizer/>
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" dx="10" dy="10" placement-type="simple" placements="S">[name]</TextSymbolizer>
</Rule>
</Style>
</Map>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map>
<Map background-color="white" srs="+proj=latlong +datum=WGS84">
<Layer name="layer" srs="+proj=latlong +datum=WGS84">
<StyleName>My Style</StyleName>
<Datasource>
<Parameter name="type">shape</Parameter>
<Parameter name="file">points.shp</Parameter>
</Datasource>
</Layer>
<Style name="My Style">
<Rule>
<Filter>[name] = 'Test five'</Filter>
<PointSymbolizer/>
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" dx="10" dy="10" placement-type="simple" placements="SE">[name]</TextSymbolizer>
</Rule>
</Style>
</Map>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map>
<Map background-color="white" srs="+proj=latlong +datum=WGS84">
<Layer name="layer" srs="+proj=latlong +datum=WGS84">
<StyleName>My Style</StyleName>
<Datasource>
<Parameter name="type">shape</Parameter>
<Parameter name="file">points.shp</Parameter>
</Datasource>
</Layer>
<Style name="My Style">
<Rule>
<Filter>[name] = 'Test five'</Filter>
<PointSymbolizer/>
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" dx="10" dy="10" placement-type="simple" placements="SW">[name]</TextSymbolizer>
</Rule>
</Style>
</Map>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map>
<Map background-color="white" srs="+proj=latlong +datum=WGS84">
<Layer name="layer" srs="+proj=latlong +datum=WGS84">
<StyleName>My Style</StyleName>
<Datasource>
<Parameter name="type">shape</Parameter>
<Parameter name="file">points.shp</Parameter>
</Datasource>
</Layer>
<Style name="My Style">
<Rule>
<Filter>[name] = 'Test five'</Filter>
<PointSymbolizer/>
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" dx="10" dy="10" placement-type="simple" placements="W">[name]</TextSymbolizer>
</Rule>
</Style>
</Map>

32
tests/data/placement/test.py Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import mapnik
import cairo
import sys
import os.path
dirname = os.path.dirname(sys.argv[0])
widths = [ 800, 600, 400, 300, 250, 200, 150, 100]
filenames = ["list", "simple"]
filenames_one_width = ["simple-E", "simple-NE", "simple-NW", "simple-N",
"simple-SE", "simple-SW", "simple-S", "simple-W"]
def render(filename, width):
print "Rendering style \"%s\" with width %d" % (filename, width)
m = mapnik.Map(width, 100)
mapnik.load_map(m, os.path.join(dirname, "%s.xml" % filename), False)
bbox = mapnik.Box2d(-0.05, -0.01, 0.95, 0.01)
m.zoom_to_box(bbox)
mapnik.render_to_file(m, '%s-%d-agg.png' % (filename, width))
return m
for filename in filenames:
for width in widths:
m = render(filename, width)
mapnik.save_map(m, "%s-out.xml" % filename)
for filename in filenames_one_width:
render(filename, 500)