Implement justify-alignment=auto.

Closes #1125.
This commit is contained in:
Hermann Kraus 2012-03-19 17:12:53 +01:00
parent 0a5765fab8
commit 9b62a19cf4
9 changed files with 71 additions and 12 deletions

View file

@ -329,6 +329,7 @@ void export_text_placement()
.value("LEFT",J_LEFT)
.value("MIDDLE",J_MIDDLE)
.value("RIGHT",J_RIGHT)
.value("AUTO", J_AUTO)
;
enumeration_<text_transform_e>("text_transform")

View file

@ -137,6 +137,7 @@ private:
double first_line_space_;
vertical_alignment_e valign_;
horizontal_alignment_e halign_;
justify_alignment_e jalign_;
std::vector<unsigned> line_breaks_;
std::vector<std::pair<double, double> > line_sizes_;
std::queue< box2d<double> > envelopes_;

View file

@ -110,6 +110,7 @@ enum justify_alignment
J_LEFT = 0,
J_MIDDLE,
J_RIGHT,
J_AUTO,
justify_alignment_MAX
};

View file

@ -305,24 +305,48 @@ template <typename DetectorT>
void placement_finder<DetectorT>::init_alignment()
{
valign_ = p.valign;
if (valign_ == V_AUTO) {
if (valign_ == V_AUTO)
{
if (p.displacement.second > 0.0)
{
valign_ = V_BOTTOM;
else if (p.displacement.second < 0.0)
} else if (p.displacement.second < 0.0)
{
valign_ = V_TOP;
else
} else
{
valign_ = V_MIDDLE;
}
}
halign_ = p.halign;
if (halign_ == H_AUTO) {
if (halign_ == H_AUTO)
{
if (p.displacement.first > 0.0)
{
halign_ = H_RIGHT;
else if (p.displacement.first < 0.0)
} else if (p.displacement.first < 0.0)
{
halign_ = H_LEFT;
else
} else
{
halign_ = H_MIDDLE;
}
}
jalign_ = p.jalign;
if (jalign_ == J_AUTO)
{
if (p.displacement.first > 0.0)
{
jalign_ = J_LEFT;
} else if (p.displacement.first < 0.0)
{
jalign_ = J_RIGHT;
} else {
jalign_ = J_MIDDLE;
}
}
}
@ -389,9 +413,9 @@ void placement_finder<DetectorT>::find_point_placement(double label_x,
if (info_.get_rtl()) y = -y;
// adjust for desired justification
if (p.jalign == J_LEFT)
if (jalign_ == J_LEFT)
x = -(string_width_ / 2.0);
else if (p.jalign == J_RIGHT)
else if (jalign_ == J_RIGHT)
x = (string_width_ / 2.0) - line_width;
else /* J_MIDDLE */
x = -(line_width / 2.0);
@ -420,9 +444,9 @@ void placement_finder<DetectorT>::find_point_placement(double label_x,
}
// reset to begining of line position
if (p.jalign == J_LEFT)
if (jalign_ == J_LEFT)
x = -(string_width_ / 2.0);
else if (p.jalign == J_RIGHT)
else if (jalign_ == J_RIGHT)
x = (string_width_ / 2.0) - line_width;
else
x = -(line_width / 2.0);

View file

@ -40,7 +40,7 @@ text_symbolizer_properties::text_symbolizer_properties() :
displacement(0,0),
label_placement(POINT_PLACEMENT),
halign(H_AUTO),
jalign(J_MIDDLE),
jalign(J_AUTO),
valign(V_AUTO),
label_spacing(0),
label_position_tolerance(0),

View file

@ -69,6 +69,7 @@ static const char * justify_alignment_strings[] = {
"left",
"center",
"right",
"auto",
""
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View file

@ -0,0 +1,30 @@
<?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>[nr] = '5'</Filter>
<PointSymbolizer/>
<TextSymbolizer face-name="DejaVu Sans Book" size="10" placement="point" dx="-30" dy="-30" justify-alignment="auto">'Text line 1&#10;line 2'</TextSymbolizer>
<TextSymbolizer face-name="DejaVu Sans Book" size="10" placement="point" dx="0" dy="-30" justify-alignment="auto">'Text line 1&#10;line 2'</TextSymbolizer>
<TextSymbolizer face-name="DejaVu Sans Book" size="10" placement="point" dx="30" dy="-30" justify-alignment="auto">'Text line 1&#10;line 2'</TextSymbolizer>
<TextSymbolizer face-name="DejaVu Sans Book" size="10" placement="point" dx="30" dy="0" justify-alignment="auto">'Text line 1&#10;line 2'</TextSymbolizer>
<TextSymbolizer face-name="DejaVu Sans Book" size="10" placement="point" dx="-30" dy="0" justify-alignment="auto">'Text line 1&#10;line 2'</TextSymbolizer>
<TextSymbolizer face-name="DejaVu Sans Book" size="10" placement="point" dx="-30" dy="30" justify-alignment="auto">'Text line 1&#10;line 2'</TextSymbolizer>
<TextSymbolizer face-name="DejaVu Sans Book" size="10" placement="point" dx="0" dy="30" justify-alignment="auto">'Text line 1&#10;line 2'</TextSymbolizer>
<TextSymbolizer face-name="DejaVu Sans Book" size="10" placement="point" dx="30" dy="30" justify-alignment="auto">'Text line 1&#10;line 2'</TextSymbolizer>
</Rule>
</Style>
</Map>

View file

@ -28,7 +28,8 @@ files = [
("formating-4", 500),
("shieldsymbolizer-1", 490, 495, 497, 498, 499, 500, 501, 502, 505, 510),
("expressionformat", 500),
("rtl-point", (200, 200))
("rtl-point", (200, 200)),
("jalign-auto", (200, 200))
]
def render(filename, width, height=100):