Implement upright=right_only/left_only.

Closes #1533.
This commit is contained in:
Hermann Kraus 2013-04-01 22:30:19 +02:00
parent e4ad657991
commit 7754f37772
13 changed files with 339 additions and 10 deletions

View file

@ -81,6 +81,9 @@ private:
bool collision(box2d<double> const& box) const;
/** Adds marker to glyph_positions and to collision detector. Returns false if there is a collision. */
bool add_marker(glyph_positions_ptr glyphs, pixel_position const& pos) const;
/** Maps upright==auto, left_only and right_only to left,right to simplify processing.
angle = angle of at start of line (to estimate best option for upright==auto) */
text_upright_e simplify_upright(text_upright_e upright, double angle) const;
box2d<double> get_bbox(glyph_info const& glyph, pixel_position const& pos, rotation const& rot);
Feature const& feature_;
DetectorType &detector_;

View file

@ -126,6 +126,8 @@ enum text_upright
UPRIGHT_AUTO,
UPRIGHT_LEFT,
UPRIGHT_RIGHT,
UPRIGHT_LEFT_ONLY,
UPRIGHT_RIGHT_ONLY,
text_upright_MAX
};

View file

@ -323,9 +323,29 @@ bool placement_finder::find_line_placements(T & path, bool points)
return success;
}
text_upright_e placement_finder::simplify_upright(text_upright_e upright, double angle) const
{
if (upright == UPRIGHT_AUTO)
{
return (fabs(normalize_angle(angle)) > 0.5*M_PI) ? UPRIGHT_LEFT : UPRIGHT_RIGHT;
}
if (upright == UPRIGHT_LEFT_ONLY)
{
return UPRIGHT_LEFT;
}
if (upright == UPRIGHT_RIGHT_ONLY)
{
return UPRIGHT_RIGHT;
}
return upright;
}
bool placement_finder::single_line_placement(vertex_cache &pp, text_upright_e orientation)
{
/********************************************************************************
* IMPORTANT NOTE: See note about coordinate systems in find_point_placement()! *
********************************************************************************/
vertex_cache::scoped_state s(pp);
glyph_positions_ptr glyphs = boost::make_shared<glyph_positions>();
@ -334,12 +354,8 @@ bool placement_finder::single_line_placement(vertex_cache &pp, text_upright_e or
unsigned upside_down_glyph_count = 0;
/* IMPORTANT NOTE: See note about coordinate systems in find_point_placement()! */
text_upright_e real_orientation = orientation;
if (orientation == UPRIGHT_AUTO)
{
real_orientation = (fabs(normalize_angle(pp.angle())) > 0.5*M_PI) ? UPRIGHT_LEFT : UPRIGHT_RIGHT;
}
text_upright_e real_orientation = simplify_upright(orientation, pp.angle());
double sign = (real_orientation == UPRIGHT_LEFT) ? -1 : 1;
double offset = alignment_offset().y + info_->properties.displacement.y * scale_factor_ + sign * layout_.height()/2.;
@ -404,12 +420,20 @@ bool placement_finder::single_line_placement(vertex_cache &pp, text_upright_e or
//See comment above
offset -= sign * (*line_itr)->height()/2;
}
if (orientation == UPRIGHT_AUTO && (upside_down_glyph_count > layout_.get_text().length()/2))
if (upside_down_glyph_count > layout_.get_text().length()/2)
{
if (orientation == UPRIGHT_AUTO)
{
//Try again with oposite orientation
s.restore();
return single_line_placement(pp, real_orientation == UPRIGHT_RIGHT ? UPRIGHT_LEFT : UPRIGHT_RIGHT);
}
//upright==left_only or right_only and more than 50% of characters upside down => no placement
if (orientation == UPRIGHT_LEFT_ONLY || orientation == UPRIGHT_RIGHT_ONLY)
{
return false;
}
}
BOOST_FOREACH(box2d<double> bbox, bboxes)
{
detector_.insert(bbox, layout_.get_text());

View file

@ -89,6 +89,8 @@ static const char * text_upright_strings[] = {
"auto",
"left",
"right",
"left_only",
"right_only",
""
};
IMPLEMENT_ENUM(text_upright_e, text_upright_strings)

View file

@ -0,0 +1,39 @@
<?xml version='1.0' encoding='UTF-8'?>
<osm version='0.6' upload='true' generator='JOSM'>
<node id='-106' action='modify' visible='true' lat='0.2614258628766519' lon='0.28436221472838974'>
<tag k='type' v='point' />
<tag k='wrap' v='no' />
</node>
<node id='-77' action='modify' visible='true' lat='0.22426115456321344' lon='0.7876650822675934' />
<node id='-76' action='modify' visible='true' lat='0.22552097681732494' lon='0.48404558019763577' />
<node id='-67' action='modify' visible='true' lat='0.3218970105980799' lon='0.7870351662881953' />
<node id='-66' action='modify' visible='true' lat='0.32315682259650147' lon='0.48341566421823756' />
<node id='-63' action='modify' visible='true' lat='0.2589062249349994' lon='0.1306627157552161'>
<tag k='type' v='point' />
<tag k='wrap' v='yes' />
</node>
<node id='-59' action='modify' visible='true' lat='0.38992738501365903' lon='0.012688551274111854' />
<node id='-57' action='modify' visible='true' lat='0.38808843986576325' lon='0.9063673051214256' />
<node id='-55' action='modify' visible='true' lat='0.1488697450798257' lon='0.9058750417159153' />
<node id='-54' action='modify' visible='true' lat='0.15070872632895005' lon='0.01219628786860134' />
<way id='-75' action='modify' visible='true'>
<nd ref='-76' />
<nd ref='-77' />
<tag k='type' v='line' />
<tag k='wrap' v='no' />
</way>
<way id='-68' action='modify' visible='true'>
<nd ref='-66' />
<nd ref='-67' />
<tag k='type' v='line' />
<tag k='wrap' v='yes' />
</way>
<way id='-56' action='modify' visible='true'>
<nd ref='-54' />
<nd ref='-55' />
<nd ref='-57' />
<nd ref='-59' />
<nd ref='-54' />
<tag k='type' v='boundary' />
</way>
</osm>

View file

@ -0,0 +1,63 @@
<?xml version='1.0' encoding='UTF-8'?>
<osm version='0.6' upload='true' generator='JOSM'>
<node id='-374' action='modify' visible='true' lat='0.0686724638310369' lon='0.7038862570076257' />
<node id='-373' action='modify' visible='true' lat='0.06993229486822683' lon='0.6673511302025271' />
<node id='-367' action='modify' visible='true' lat='0.06363313935634328' lon='0.2843622147283897' />
<node id='-366' action='modify' visible='true' lat='0.06363313935634328' lon='0.250346751840884' />
<node id='-206' action='modify' visible='true' lat='-0.11453565911646134' lon='0.5480995047469907' />
<node id='-205' action='modify' visible='true' lat='0.18888875585009277' lon='0.5371560278163559' />
<node id='-181' action='modify' visible='true' lat='-0.11957497643332685' lon='0.3855811820622415' />
<node id='-180' action='modify' visible='true' lat='0.18384945467557984' lon='0.3746377051316065' />
<node id='-163' action='modify' visible='true' lat='0.06685200044593859' lon='0.8763046610034405' />
<node id='-162' action='modify' visible='true' lat='0.23679008943647523' lon='0.6246954179627523' />
<node id='-133' action='modify' visible='true' lat='0.24126789205602248' lon='0.30353263048300844' />
<node id='-132' action='modify' visible='true' lat='0.03717753224242952' lon='0.07873666907188823' />
<node id='-77' action='modify' visible='true' lat='0.3099287889371784' lon='0.8179010492787097' />
<node id='-76' action='modify' visible='true' lat='0.3111886023894954' lon='0.514281547208752' />
<node id='-67' action='modify' visible='true' lat='0.3105586956821123' lon='0.3750701157617382' />
<node id='-66' action='modify' visible='true' lat='0.3118185090592599' lon='0.07145061369178042' />
<node id='-59' action='modify' visible='true' lat='0.38970517055516746' lon='0.012910078084524709' />
<node id='-57' action='modify' visible='true' lat='0.3883099615915542' lon='0.9065895247230221' />
<node id='-55' action='modify' visible='true' lat='-0.21121932961473797' lon='0.9056535149055025' />
<node id='-54' action='modify' visible='true' lat='-0.20982409791135584' lon='0.011974068267005027' />
<way id='-372' action='modify' visible='true'>
<nd ref='-374' />
<nd ref='-373' />
</way>
<way id='-368' action='modify' visible='true'>
<nd ref='-366' />
<nd ref='-367' />
</way>
<way id='-204' action='modify' visible='true'>
<nd ref='-206' />
<nd ref='-205' />
</way>
<way id='-179' action='modify' visible='true'>
<nd ref='-180' />
<nd ref='-181' />
</way>
<way id='-161' action='modify' visible='true'>
<nd ref='-162' />
<nd ref='-163' />
</way>
<way id='-131' action='modify' visible='true'>
<nd ref='-132' />
<nd ref='-133' />
</way>
<way id='-75' action='modify' visible='true'>
<nd ref='-77' />
<nd ref='-76' />
</way>
<way id='-68' action='modify' visible='true'>
<nd ref='-66' />
<nd ref='-67' />
</way>
<way id='-56' action='modify' visible='true'>
<nd ref='-54' />
<nd ref='-55' />
<nd ref='-57' />
<nd ref='-59' />
<nd ref='-54' />
<tag k='type' v='boundary' />
</way>
</osm>

View file

@ -0,0 +1,166 @@
{
"keys": [
"",
"-68",
"-75",
"-131",
"-161",
"-204",
"-179",
"-372",
"-368"
],
"data": {},
"grid": [
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ! ! # # ",
" ! !!! !!!! #### ############################## ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" $ ",
" $ % ",
" $ % ",
" $ % ",
" $ % ",
" $ % ",
" % ",
" $ %% ",
" $$ %% ",
" $ & % ",
" $ & % ",
" $ ' & % ",
" $ ' & % ",
" $ ' & % ",
" $ ' & % ",
" $ ' & % ",
" ' & % ",
" $ ' & % ",
" $ ' % ",
" $ ' % ",
" $ ' % ",
" $ ' && %% ",
" $ '' %% ",
" $ ' % ",
" $$ ' % ",
" $ % ",
" $ % ",
" $ % ",
" $ (((( % ",
" $ )))))) ",
" $ ",
" $ & ",
" $ & ",
" $ & ",
" & ",
" & ",
" & ",
" & ",
" & ",
" ' & ",
" ' & ",
" ' & ",
" ' & ",
" ' & ",
" ' & ",
" ' & ",
" ' && ",
" ' ",
" ' ",
" ' ",
" ' ",
" ' ",
" ' ",
" ",
" ",
" ",
" ",
" ",
" ",
" & ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map>
<!-- Minimal testcase for bug #1523. -->
<Map background-color="white" srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs">
<Layer name="layer" srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs">
<StyleName>My Style</StyleName>
<Datasource>
<Parameter name="type">osm</Parameter>
<Parameter name="file">../data/bug1533.osm</Parameter>
</Datasource>
</Layer>
<Style name="My Style">
<Rule>
<Filter>[type] != "boundary" and [mapnik::geometry_type]=linestring</Filter>
<LineSymbolizer stroke-width="1" stroke="red"/>
<MarkersSymbolizer file="shape://arrow" placement="line" transform="scale(.5,.5)"/>
<TextSymbolizer face-name="DejaVu Sans Book" size="10" placement="line" upright="right" dy="10" allow-overlap="true">"right: --&gt;"</TextSymbolizer>
<TextSymbolizer face-name="DejaVu Sans Book" size="10" placement="line" upright="left" dy="-10" allow-overlap="true">"left: &lt;--"</TextSymbolizer>
<TextSymbolizer face-name="DejaVu Sans Book" size="10" placement="line" upright="left_only" allow-overlap="true"
placement-type="list">"left only &lt;--"
<Placement upright="right_only">"right only --&gt;"</Placement>
<Placement upright="right_only">"--&gt;"</Placement>
<Placement upright="left_only">"&lt;--"</Placement>
</TextSymbolizer>
</Rule>
</Style>
</Map>

View file

@ -75,6 +75,7 @@ text_tests = [
{'name': "jalign-auto", 'sizes': [(200, 200)],'bbox':default_text_box},
{'name': "line-offset", 'sizes':[(900, 250)],'bbox': mapnik.Box2d(-5.192, 50.189, -5.174, 50.195)},
{'name': "text-bug1532", 'sizes':[(600, 165)]},
{'name': "text-bug1533", 'sizes':[(600, 600)]},
]
tiff_tests = [