enable aliased lines using stroke-gamma for line_symbolizer - closes #689
This commit is contained in:
parent
c6646176f4
commit
fd2d9d7ff3
8 changed files with 72 additions and 12 deletions
|
@ -64,17 +64,21 @@ struct stroke_pickle_suite : boost::python::pickle_suite
|
||||||
getstate(const stroke& s)
|
getstate(const stroke& s)
|
||||||
{
|
{
|
||||||
boost::python::list dashes = get_dashes_list(s);
|
boost::python::list dashes = get_dashes_list(s);
|
||||||
return boost::python::make_tuple(s.get_opacity(),dashes,s.get_line_cap(),s.get_line_join());
|
return boost::python::make_tuple(s.get_opacity(),
|
||||||
|
dashes,
|
||||||
|
s.get_line_cap(),
|
||||||
|
s.get_line_join(),
|
||||||
|
s.get_gamma());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
setstate (stroke& s, boost::python::tuple state)
|
setstate (stroke& s, boost::python::tuple state)
|
||||||
{
|
{
|
||||||
using namespace boost::python;
|
using namespace boost::python;
|
||||||
if (len(state) != 4)
|
if (len(state) != 5)
|
||||||
{
|
{
|
||||||
PyErr_SetObject(PyExc_ValueError,
|
PyErr_SetObject(PyExc_ValueError,
|
||||||
("expected 4-item tuple in call to __setstate__; got %s"
|
("expected 5-item tuple in call to __setstate__; got %s"
|
||||||
% state).ptr()
|
% state).ptr()
|
||||||
);
|
);
|
||||||
throw_error_already_set();
|
throw_error_already_set();
|
||||||
|
@ -93,8 +97,8 @@ struct stroke_pickle_suite : boost::python::pickle_suite
|
||||||
}
|
}
|
||||||
|
|
||||||
s.set_line_cap(extract<line_cap_e>(state[2]));
|
s.set_line_cap(extract<line_cap_e>(state[2]));
|
||||||
|
|
||||||
s.set_line_join(extract<line_join_e>(state[3]));
|
s.set_line_join(extract<line_join_e>(state[3]));
|
||||||
|
s.set_gamma(extract<double>(state[4]));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +146,11 @@ void export_stroke ()
|
||||||
&stroke::set_opacity,
|
&stroke::set_opacity,
|
||||||
"Gets or sets the opacity of this stroke.\n"
|
"Gets or sets the opacity of this stroke.\n"
|
||||||
"The value is a float between 0 and 1.\n")
|
"The value is a float between 0 and 1.\n")
|
||||||
|
.add_property("gamma",
|
||||||
|
&stroke::get_gamma,
|
||||||
|
&stroke::set_gamma,
|
||||||
|
"Gets or sets the gamma of this stroke.\n"
|
||||||
|
"The value is a float between 0 and 1.\n")
|
||||||
.add_property("line_cap",
|
.add_property("line_cap",
|
||||||
&stroke::get_line_cap,
|
&stroke::get_line_cap,
|
||||||
&stroke::set_line_cap,
|
&stroke::set_line_cap,
|
||||||
|
|
|
@ -69,6 +69,7 @@ class MAPNIK_DECL stroke
|
||||||
line_join_e line_join_;
|
line_join_e line_join_;
|
||||||
dash_array dash_;
|
dash_array dash_;
|
||||||
double dash_offset_;
|
double dash_offset_;
|
||||||
|
double gamma_;
|
||||||
public:
|
public:
|
||||||
explicit stroke();
|
explicit stroke();
|
||||||
stroke(color const& c, double width=1.0);
|
stroke(color const& c, double width=1.0);
|
||||||
|
@ -76,13 +77,12 @@ public:
|
||||||
stroke& operator=(const stroke& rhs);
|
stroke& operator=(const stroke& rhs);
|
||||||
|
|
||||||
void set_color(const color& c);
|
void set_color(const color& c);
|
||||||
|
|
||||||
color const& get_color() const;
|
color const& get_color() const;
|
||||||
|
|
||||||
double get_width() const;
|
double get_width() const;
|
||||||
void set_width(double w);
|
void set_width(double w);
|
||||||
void set_opacity(double opacity);
|
|
||||||
|
|
||||||
|
void set_opacity(double opacity);
|
||||||
double get_opacity() const;
|
double get_opacity() const;
|
||||||
|
|
||||||
void set_line_cap(line_cap_e line_cap);
|
void set_line_cap(line_cap_e line_cap);
|
||||||
|
@ -90,9 +90,13 @@ public:
|
||||||
|
|
||||||
void set_line_join(line_join_e line_join);
|
void set_line_join(line_join_e line_join);
|
||||||
line_join_e get_line_join() const;
|
line_join_e get_line_join() const;
|
||||||
|
|
||||||
|
void set_gamma(double gamma);
|
||||||
|
double get_gamma() const;
|
||||||
|
|
||||||
void add_dash(double dash,double gap);
|
void add_dash(double dash,double gap);
|
||||||
bool has_dash() const;
|
bool has_dash() const;
|
||||||
|
|
||||||
void set_dash_offset(double offset);
|
void set_dash_offset(double offset);
|
||||||
double dash_offset() const;
|
double dash_offset() const;
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
|
||||||
unsigned a=col.alpha();
|
unsigned a=col.alpha();
|
||||||
renderer ren(renb);
|
renderer ren(renb);
|
||||||
ras_ptr->reset();
|
ras_ptr->reset();
|
||||||
ras_ptr->gamma(agg::gamma_linear());
|
ras_ptr->gamma(agg::gamma_linear(0.0, stroke_.get_gamma()));
|
||||||
|
|
||||||
agg::scanline_p8 sl;
|
agg::scanline_p8 sl;
|
||||||
metawriter_with_properties writer = sym.get_metawriter();
|
metawriter_with_properties writer = sym.get_metawriter();
|
||||||
|
|
|
@ -1557,6 +1557,9 @@ void map_parser::parse_stroke(stroke & strk, ptree const & sym)
|
||||||
// stroke-linecap
|
// stroke-linecap
|
||||||
optional<line_cap_e> line_cap = get_opt_attr<line_cap_e>(sym, "stroke-linecap");
|
optional<line_cap_e> line_cap = get_opt_attr<line_cap_e>(sym, "stroke-linecap");
|
||||||
if (line_cap) strk.set_line_cap(*line_cap);
|
if (line_cap) strk.set_line_cap(*line_cap);
|
||||||
|
// stroke-gamma
|
||||||
|
optional<double> gamma = get_opt_attr<double>(sym, "stroke-gamma");
|
||||||
|
if (gamma) strk.set_gamma(*gamma);
|
||||||
// stroke-dashaffset
|
// stroke-dashaffset
|
||||||
optional<double> offset = get_opt_attr<double>(sym, "stroke-dashoffet");
|
optional<double> offset = get_opt_attr<double>(sym, "stroke-dashoffet");
|
||||||
if (offset) strk.set_dash_offset(*offset);
|
if (offset) strk.set_dash_offset(*offset);
|
||||||
|
|
|
@ -544,6 +544,14 @@ private:
|
||||||
{
|
{
|
||||||
set_attr( node, "stroke-linecap", strk.get_line_cap() );
|
set_attr( node, "stroke-linecap", strk.get_line_cap() );
|
||||||
}
|
}
|
||||||
|
if ( strk.get_gamma() != dfl.get_gamma() || explicit_defaults_ )
|
||||||
|
{
|
||||||
|
set_attr( node, "stroke-gamma", strk.get_gamma());
|
||||||
|
}
|
||||||
|
if ( strk.dash_offset() != dfl.dash_offset() || explicit_defaults_ )
|
||||||
|
{
|
||||||
|
set_attr( node, "stroke-dashoffset", strk.dash_offset());
|
||||||
|
}
|
||||||
if ( ! strk.get_dash_array().empty() )
|
if ( ! strk.get_dash_array().empty() )
|
||||||
{
|
{
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
|
@ -554,10 +562,6 @@ private:
|
||||||
}
|
}
|
||||||
set_attr( node, "stroke-dasharray", os.str() );
|
set_attr( node, "stroke-dasharray", os.str() );
|
||||||
}
|
}
|
||||||
if ( strk.dash_offset() != dfl.dash_offset() || explicit_defaults_ )
|
|
||||||
{
|
|
||||||
set_attr( node, "stroke-dashoffset", strk.dash_offset());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void add_metawriter_attributes(ptree &node, symbolizer_base const& sym)
|
void add_metawriter_attributes(ptree &node, symbolizer_base const& sym)
|
||||||
|
|
|
@ -51,6 +51,7 @@ stroke::stroke()
|
||||||
opacity_(1.0),
|
opacity_(1.0),
|
||||||
line_cap_(BUTT_CAP),
|
line_cap_(BUTT_CAP),
|
||||||
line_join_(MITER_JOIN),
|
line_join_(MITER_JOIN),
|
||||||
|
gamma_(1.0),
|
||||||
dash_(),
|
dash_(),
|
||||||
dash_offset_(0) {}
|
dash_offset_(0) {}
|
||||||
|
|
||||||
|
@ -60,6 +61,7 @@ stroke::stroke(color const& c, double width)
|
||||||
opacity_(1.0),
|
opacity_(1.0),
|
||||||
line_cap_(BUTT_CAP),
|
line_cap_(BUTT_CAP),
|
||||||
line_join_(MITER_JOIN),
|
line_join_(MITER_JOIN),
|
||||||
|
gamma_(1.0),
|
||||||
dash_(),
|
dash_(),
|
||||||
dash_offset_(0.0) {}
|
dash_offset_(0.0) {}
|
||||||
|
|
||||||
|
@ -69,6 +71,7 @@ stroke::stroke(stroke const& other)
|
||||||
opacity_(other.opacity_),
|
opacity_(other.opacity_),
|
||||||
line_cap_(other.line_cap_),
|
line_cap_(other.line_cap_),
|
||||||
line_join_(other.line_join_),
|
line_join_(other.line_join_),
|
||||||
|
gamma_(other.gamma_),
|
||||||
dash_(other.dash_),
|
dash_(other.dash_),
|
||||||
dash_offset_(other.dash_offset_) {}
|
dash_offset_(other.dash_offset_) {}
|
||||||
|
|
||||||
|
@ -130,6 +133,16 @@ line_join_e stroke::get_line_join() const
|
||||||
return line_join_;
|
return line_join_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void stroke::set_gamma(double gamma)
|
||||||
|
{
|
||||||
|
gamma_ = gamma;
|
||||||
|
}
|
||||||
|
|
||||||
|
double stroke::get_gamma() const
|
||||||
|
{
|
||||||
|
return gamma_;
|
||||||
|
}
|
||||||
|
|
||||||
void stroke::add_dash(double dash, double gap)
|
void stroke::add_dash(double dash, double gap)
|
||||||
{
|
{
|
||||||
dash_.push_back(std::make_pair(dash,gap));
|
dash_.push_back(std::make_pair(dash,gap));
|
||||||
|
@ -152,7 +165,7 @@ double stroke::dash_offset() const
|
||||||
|
|
||||||
dash_array const& stroke::get_dash_array() const
|
dash_array const& stroke::get_dash_array() const
|
||||||
{
|
{
|
||||||
return dash_;
|
return dash_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void stroke::swap(const stroke& other) throw()
|
void stroke::swap(const stroke& other) throw()
|
||||||
|
@ -162,6 +175,8 @@ void stroke::swap(const stroke& other) throw()
|
||||||
opacity_=other.opacity_;
|
opacity_=other.opacity_;
|
||||||
line_cap_=other.line_cap_;
|
line_cap_=other.line_cap_;
|
||||||
line_join_=other.line_join_;
|
line_join_=other.line_join_;
|
||||||
|
gamma_=other.gamma_;
|
||||||
dash_ = other.dash_;
|
dash_ = other.dash_;
|
||||||
|
dash_offset_ = other.dash_offset_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
22
tests/data/good_maps/line_symbolizer.xml
Normal file
22
tests/data/good_maps/line_symbolizer.xml
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<Map background-color="steelblue" srs="+proj=longlat +ellps=airy +datum=OSGB36 +no_defs">
|
||||||
|
|
||||||
|
<Style name="test">
|
||||||
|
<Rule>
|
||||||
|
<!-- big, thick, aliased lines -->
|
||||||
|
<LineSymbolizer stroke="white" stroke-gamma="0" stroke-width="10"/>
|
||||||
|
|
||||||
|
<!-- small, clean, aliased lines -->
|
||||||
|
<LineSymbolizer stroke="red" stroke-gamma="1" stroke-width=".5"/>
|
||||||
|
|
||||||
|
</Rule>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Layer name="lay" srs="+proj=longlat +ellps=airy +datum=OSGB36 +no_defs">
|
||||||
|
<StyleName>test</StyleName>
|
||||||
|
<Datasource base="shp">
|
||||||
|
<Parameter name="type">shape</Parameter>
|
||||||
|
<Parameter name="file">../../data/shp/poly.shp</Parameter>
|
||||||
|
</Datasource>
|
||||||
|
</Layer>
|
||||||
|
|
||||||
|
</Map>
|
|
@ -153,12 +153,15 @@ def test_stroke_init():
|
||||||
eq_(s.color, mapnik2.Color('black'))
|
eq_(s.color, mapnik2.Color('black'))
|
||||||
eq_(s.line_cap, mapnik2.line_cap.BUTT_CAP)
|
eq_(s.line_cap, mapnik2.line_cap.BUTT_CAP)
|
||||||
eq_(s.line_join, mapnik2.line_join.MITER_JOIN)
|
eq_(s.line_join, mapnik2.line_join.MITER_JOIN)
|
||||||
|
eq_(s.gamma,1.0)
|
||||||
|
|
||||||
s = mapnik2.Stroke(mapnik2.Color('blue'), 5.0)
|
s = mapnik2.Stroke(mapnik2.Color('blue'), 5.0)
|
||||||
|
s.gamma = .5
|
||||||
|
|
||||||
eq_(s.width, 5)
|
eq_(s.width, 5)
|
||||||
eq_(s.opacity, 1)
|
eq_(s.opacity, 1)
|
||||||
eq_(s.color, mapnik2.Color('blue'))
|
eq_(s.color, mapnik2.Color('blue'))
|
||||||
|
eq_(s.gamma, .5)
|
||||||
eq_(s.line_cap, mapnik2.line_cap.BUTT_CAP)
|
eq_(s.line_cap, mapnik2.line_cap.BUTT_CAP)
|
||||||
eq_(s.line_join, mapnik2.line_join.MITER_JOIN)
|
eq_(s.line_join, mapnik2.line_join.MITER_JOIN)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue