Implement horizontal-alignment for line placements.
This commit is contained in:
parent
54c7e64bc9
commit
2320632f87
4 changed files with 36 additions and 4 deletions
|
@ -103,6 +103,7 @@ public:
|
|||
|
||||
pixel_position const& current_position() const { return current_position_; }
|
||||
double angle(double width=0.);
|
||||
double linear_position() const { return position_; }
|
||||
|
||||
|
||||
/** Returns a parallel line in the specified distance. */
|
||||
|
|
|
@ -300,12 +300,21 @@ bool placement_finder::find_line_placements(T & path, bool points)
|
|||
|
||||
double spacing = get_spacing(pp.length(), points ? 0. : layout_.width());
|
||||
|
||||
// first label should be placed at half the spacing
|
||||
pp.forward(spacing/2);
|
||||
horizontal_alignment_e halign = info_->properties.halign;
|
||||
if (halign == H_LEFT)
|
||||
{
|
||||
//Don't move
|
||||
} else if (halign == H_MIDDLE || halign == H_AUTO)
|
||||
{
|
||||
pp.forward(spacing/2);
|
||||
} else if (halign == H_RIGHT)
|
||||
{
|
||||
pp.forward(pp.length());
|
||||
}
|
||||
path_move_dx(pp);
|
||||
do
|
||||
{
|
||||
tolerance_iterator tolerance_offset(info_->properties.label_position_tolerance * scale_factor_, spacing);
|
||||
tolerance_iterator tolerance_offset(info_->properties.label_position_tolerance * scale_factor_, spacing); //TODO: Handle halign
|
||||
while (tolerance_offset.next())
|
||||
{
|
||||
vertex_cache::scoped_state state(pp);
|
||||
|
@ -369,7 +378,7 @@ bool placement_finder::single_line_placement(vertex_cache &pp, text_upright_e or
|
|||
vertex_cache &off_pp = pp.get_offseted(offset, sign*layout_.width());
|
||||
vertex_cache::scoped_state off_state(off_pp); //TODO: Remove this when a clean implementation in vertex_cache::get_offseted was done
|
||||
|
||||
if (!off_pp.move(sign * jalign_offset((*line_itr)->width()))) return false;
|
||||
if (!off_pp.move(sign * jalign_offset((*line_itr)->width())-alignment_offset().x)) return false;
|
||||
|
||||
double last_cluster_angle = 999;
|
||||
signed current_cluster = -1;
|
||||
|
|
21
tests/visual_tests/styles/text-halign.xml
Normal file
21
tests/visual_tests/styles/text-halign.xml
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE Map>
|
||||
<!-- Upright test -->
|
||||
<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">osm</Parameter>
|
||||
<Parameter name="file">../data/lines2.osm</Parameter>
|
||||
</Datasource>
|
||||
</Layer>
|
||||
|
||||
<Style name="My Style">
|
||||
<Rule>
|
||||
<LineSymbolizer stroke-width="12" stroke="red"/>
|
||||
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="line" upright="auto" max-char-angle-delta="0" horizontal-alignment="left" label-position-tolerance="0.0001">"horizontal-alignment=left"</TextSymbolizer>
|
||||
</Rule>
|
||||
</Style>
|
||||
|
||||
</Map>
|
|
@ -80,6 +80,7 @@ text_tests = [
|
|||
{'name': "text-bug1820+0", 'sizes':[(600, 300)], 'bbox':default_text_box},
|
||||
{'name': "text-bug1820+1", 'sizes':[(600, 300)], 'bbox':default_text_box},
|
||||
{'name': "text-expressionformat-color", 'sizes':[(800, 100)], 'bbox':default_text_box},
|
||||
{'name': "text-halign", 'sizes': [(800,800)], 'bbox':default_text_box},
|
||||
# Disabled by default as the required font isn't shipped with mapnik
|
||||
#{'name': "text-malayalam", 'sizes':[(800, 100)], 'bbox':default_text_box},
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue