+ add stroke-dashoffset property
+ replace <CssParameter name='xxx'>yyy</CssParameter> element with 'xxx'=yyy attribute
This commit is contained in:
parent
1acc288349
commit
5fcc311764
4 changed files with 769 additions and 791 deletions
|
@ -33,7 +33,7 @@ namespace mapnik
|
|||
{
|
||||
using std::pair;
|
||||
using std::vector;
|
||||
typedef vector<pair<float,float> > dash_array;
|
||||
typedef vector<pair<double,double> > dash_array;
|
||||
|
||||
// if you add new tokens, don't forget to add them to the corresponding
|
||||
// string array in the cpp file.
|
||||
|
@ -63,14 +63,15 @@ namespace mapnik
|
|||
class MAPNIK_DECL stroke
|
||||
{
|
||||
color c_;
|
||||
float width_;
|
||||
float opacity_; // 0.0 - 1.0
|
||||
double width_;
|
||||
double opacity_; // 0.0 - 1.0
|
||||
line_cap_e line_cap_;
|
||||
line_join_e line_join_;
|
||||
dash_array dash_;
|
||||
double dash_offset_;
|
||||
public:
|
||||
explicit stroke();
|
||||
stroke(color const& c, float width=1.0);
|
||||
stroke(color const& c, double width=1.0);
|
||||
stroke(stroke const& other);
|
||||
stroke& operator=(const stroke& rhs);
|
||||
|
||||
|
@ -78,11 +79,11 @@ namespace mapnik
|
|||
|
||||
color const& get_color() const;
|
||||
|
||||
float get_width() const;
|
||||
void set_width(float w);
|
||||
void set_opacity(float opacity);
|
||||
double get_width() const;
|
||||
void set_width(double w);
|
||||
void set_opacity(double opacity);
|
||||
|
||||
float get_opacity() const;
|
||||
double get_opacity() const;
|
||||
|
||||
void set_line_cap(line_cap_e line_cap);
|
||||
line_cap_e get_line_cap() const;
|
||||
|
@ -90,8 +91,10 @@ namespace mapnik
|
|||
void set_line_join(line_join_e line_join);
|
||||
line_join_e get_line_join() const;
|
||||
|
||||
void add_dash(float dash,float gap);
|
||||
void add_dash(double dash,double gap);
|
||||
bool has_dash() const;
|
||||
void set_dash_offset(double offset);
|
||||
double dash_offset() const;
|
||||
|
||||
dash_array const& get_dash_array() const;
|
||||
|
||||
|
|
|
@ -1258,59 +1258,43 @@ namespace mapnik
|
|||
try
|
||||
{
|
||||
stroke strk;
|
||||
ptree::const_iterator cssIter = sym.begin();
|
||||
ptree::const_iterator endCss = sym.end();
|
||||
|
||||
for(; cssIter != endCss; ++cssIter)
|
||||
// stroke color
|
||||
optional<color> c= get_opt_attr<color>(sym, "stroke");
|
||||
if (c) strk.set_color(*c);
|
||||
// stroke-width
|
||||
optional<double> width = get_opt_attr<double>(sym, "stroke-width");
|
||||
if (width) strk.set_width(*width);
|
||||
// stroke-opacity
|
||||
optional<double> opacity = get_opt_attr<double>(sym, "stroke-opacity");
|
||||
if (opacity) strk.set_opacity(*opacity);
|
||||
// stroke-linejoin
|
||||
optional<line_join_e> line_join = get_opt_attr<line_join_e>(sym, "stroke-linejoin");
|
||||
if (line_join) strk.set_line_join(*line_join);
|
||||
// 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);
|
||||
// stroke-dashaffset
|
||||
optional<double> offset = get_opt_attr<double>(sym, "stroke-dashoffet");
|
||||
if (offset) strk.set_dash_offset(*offset);
|
||||
// stroke-dasharray
|
||||
optional<string> str = get_opt_attr<string>(sym,"stroke-dasharray");
|
||||
if (str)
|
||||
{
|
||||
ptree::value_type const& css_tag = *cssIter;
|
||||
ptree const & css = cssIter->second;
|
||||
|
||||
if (css_tag.first == "CssParameter")
|
||||
{
|
||||
std::string css_name = get_attr<string>(css, "name");
|
||||
if (css_name == "stroke")
|
||||
{
|
||||
color c = get_css<color>(css, css_name);
|
||||
strk.set_color(c);
|
||||
}
|
||||
else if (css_name == "stroke-width")
|
||||
{
|
||||
float width = get_css<float>(css, css_name);
|
||||
strk.set_width(width);
|
||||
}
|
||||
else if (css_name == "stroke-opacity")
|
||||
{
|
||||
float opacity = get_css<float>(css, css_name);
|
||||
strk.set_opacity(opacity);
|
||||
}
|
||||
else if (css_name == "stroke-linejoin")
|
||||
{
|
||||
line_join_e line_join = get_css<line_join_e>(css, css_name);
|
||||
strk.set_line_join( line_join );
|
||||
}
|
||||
else if (css_name == "stroke-linecap")
|
||||
{
|
||||
line_cap_e line_cap = get_css<line_cap_e>(css, css_name);
|
||||
strk.set_line_cap( line_cap );
|
||||
}
|
||||
else if (css_name == "stroke-dasharray")
|
||||
{
|
||||
tokenizer<> tok ( css.data() );
|
||||
std::vector<float> dash_array;
|
||||
tokenizer<> tok (*str);
|
||||
std::vector<double> dash_array;
|
||||
tokenizer<>::iterator itr = tok.begin();
|
||||
for (; itr != tok.end(); ++itr)
|
||||
{
|
||||
try
|
||||
{
|
||||
float f = boost::lexical_cast<float>(*itr);
|
||||
double f = boost::lexical_cast<double>(*itr);
|
||||
dash_array.push_back(f);
|
||||
}
|
||||
catch ( boost::bad_lexical_cast &)
|
||||
{
|
||||
throw config_error(std::string("Failed to parse CSS ") +
|
||||
"parameter '" + css_name + "'. Expected a " +
|
||||
"list of floats but got '" + css.data() + "'");
|
||||
throw config_error(std::string("Failed to parse dasharray ") +
|
||||
"'. Expected a " +
|
||||
"list of floats but got '" + (*str) + "'");
|
||||
}
|
||||
}
|
||||
if (dash_array.size())
|
||||
|
@ -1323,7 +1307,7 @@ namespace mapnik
|
|||
dash_array.push_back(dash_array[i]);
|
||||
}
|
||||
}
|
||||
std::vector<float>::const_iterator pos = dash_array.begin();
|
||||
std::vector<double>::const_iterator pos = dash_array.begin();
|
||||
while (pos != dash_array.end())
|
||||
{
|
||||
strk.add_dash(*pos,*(pos + 1));
|
||||
|
@ -1331,19 +1315,6 @@ namespace mapnik
|
|||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw config_error(std::string("Failed to parse unknown CSS ") +
|
||||
"parameter '" + css_name + "'");
|
||||
}
|
||||
}
|
||||
else if (css_tag.first != "<xmlcomment>" &&
|
||||
css_tag.first != "<xmlattr>" )
|
||||
{
|
||||
throw config_error(std::string("Unknown child node. ") +
|
||||
"Expected 'CssParameter' but got '" + css_tag.first + "'");
|
||||
}
|
||||
}
|
||||
rule.append(line_symbolizer(strk));
|
||||
}
|
||||
catch (const config_error & ex)
|
||||
|
|
|
@ -129,6 +129,10 @@ namespace mapnik
|
|||
}
|
||||
set_css( sym_node, "stroke-dasharray", os.str() );
|
||||
}
|
||||
if ( strk.dash_offset() != dfl.dash_offset() || explicit_defaults_ )
|
||||
{
|
||||
set_css( sym_node, "stroke-dashoffset", strk.dash_offset());
|
||||
}
|
||||
}
|
||||
|
||||
void operator () ( const line_pattern_symbolizer & sym )
|
||||
|
|
Loading…
Add table
Reference in a new issue