+ 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
|
@ -31,73 +31,76 @@
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik
|
||||||
{
|
{
|
||||||
using std::pair;
|
using std::pair;
|
||||||
using std::vector;
|
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
|
// if you add new tokens, don't forget to add them to the corresponding
|
||||||
// string array in the cpp file.
|
// string array in the cpp file.
|
||||||
enum line_cap_enum
|
enum line_cap_enum
|
||||||
{
|
{
|
||||||
BUTT_CAP,
|
BUTT_CAP,
|
||||||
SQUARE_CAP,
|
SQUARE_CAP,
|
||||||
ROUND_CAP,
|
ROUND_CAP,
|
||||||
line_cap_enum_MAX
|
line_cap_enum_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
DEFINE_ENUM( line_cap_e, line_cap_enum );
|
DEFINE_ENUM( line_cap_e, line_cap_enum );
|
||||||
|
|
||||||
// if you add new tokens, don't forget to add them to the corresponding
|
// if you add new tokens, don't forget to add them to the corresponding
|
||||||
// string array in the cpp file.
|
// string array in the cpp file.
|
||||||
enum line_join_enum
|
enum line_join_enum
|
||||||
{
|
{
|
||||||
MITER_JOIN,
|
MITER_JOIN,
|
||||||
MITER_REVERT_JOIN,
|
MITER_REVERT_JOIN,
|
||||||
ROUND_JOIN,
|
ROUND_JOIN,
|
||||||
BEVEL_JOIN,
|
BEVEL_JOIN,
|
||||||
line_join_enum_MAX
|
line_join_enum_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
DEFINE_ENUM( line_join_e, line_join_enum );
|
DEFINE_ENUM( line_join_e, line_join_enum );
|
||||||
|
|
||||||
class MAPNIK_DECL stroke
|
class MAPNIK_DECL stroke
|
||||||
{
|
{
|
||||||
color c_;
|
color c_;
|
||||||
float width_;
|
double width_;
|
||||||
float opacity_; // 0.0 - 1.0
|
double opacity_; // 0.0 - 1.0
|
||||||
line_cap_e line_cap_;
|
line_cap_e line_cap_;
|
||||||
line_join_e line_join_;
|
line_join_e line_join_;
|
||||||
dash_array dash_;
|
dash_array dash_;
|
||||||
public:
|
double dash_offset_;
|
||||||
explicit stroke();
|
public:
|
||||||
stroke(color const& c, float width=1.0);
|
explicit stroke();
|
||||||
stroke(stroke const& other);
|
stroke(color const& c, double width=1.0);
|
||||||
stroke& operator=(const stroke& rhs);
|
stroke(stroke const& other);
|
||||||
|
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;
|
||||||
|
|
||||||
float get_width() const;
|
double get_width() const;
|
||||||
void set_width(float w);
|
void set_width(double w);
|
||||||
void set_opacity(float opacity);
|
void set_opacity(double opacity);
|
||||||
|
|
||||||
float 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);
|
||||||
line_cap_e get_line_cap() const;
|
line_cap_e get_line_cap() const;
|
||||||
|
|
||||||
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 add_dash(float dash,float gap);
|
void add_dash(double dash,double gap);
|
||||||
bool has_dash() const;
|
bool has_dash() const;
|
||||||
|
void set_dash_offset(double offset);
|
||||||
|
double dash_offset() const;
|
||||||
|
|
||||||
|
dash_array const& get_dash_array() const;
|
||||||
|
|
||||||
dash_array const& get_dash_array() const;
|
private:
|
||||||
|
void swap(const stroke& other) throw();
|
||||||
private:
|
};
|
||||||
void swap(const stroke& other) throw();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //STROKE_HPP
|
#endif //STROKE_HPP
|
||||||
|
|
|
@ -347,7 +347,7 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
|
||||||
renderer ren(renb);
|
renderer ren(renb);
|
||||||
ras_ptr->reset();
|
ras_ptr->reset();
|
||||||
ras_ptr->gamma(agg::gamma_linear());
|
ras_ptr->gamma(agg::gamma_linear());
|
||||||
|
|
||||||
agg::scanline_p8 sl;
|
agg::scanline_p8 sl;
|
||||||
|
|
||||||
for (unsigned i=0;i<feature.num_geometries();++i)
|
for (unsigned i=0;i<feature.num_geometries();++i)
|
||||||
|
@ -390,7 +390,7 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
|
||||||
|
|
||||||
stroke.generator().miter_limit(4.0);
|
stroke.generator().miter_limit(4.0);
|
||||||
stroke.generator().width(stroke_.get_width());
|
stroke.generator().width(stroke_.get_width());
|
||||||
|
|
||||||
ras_ptr->add_path(stroke);
|
ras_ptr->add_path(stroke);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
149
src/load_map.cpp
149
src/load_map.cpp
|
@ -1007,12 +1007,12 @@ namespace mapnik
|
||||||
|
|
||||||
// max_char_angle_delta
|
// max_char_angle_delta
|
||||||
optional<double> max_char_angle_delta =
|
optional<double> max_char_angle_delta =
|
||||||
get_opt_attr<double>(sym, "max_char_angle_delta");
|
get_opt_attr<double>(sym, "max_char_angle_delta");
|
||||||
if (max_char_angle_delta)
|
if (max_char_angle_delta)
|
||||||
{
|
{
|
||||||
text_symbol.set_max_char_angle_delta( * max_char_angle_delta);
|
text_symbol.set_max_char_angle_delta( * max_char_angle_delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
// horizontal alignment
|
// horizontal alignment
|
||||||
horizontal_alignment_e halign = get_attr<horizontal_alignment_e>(sym, "horizontal_alignment", H_MIDDLE);
|
horizontal_alignment_e halign = get_attr<horizontal_alignment_e>(sym, "horizontal_alignment", H_MIDDLE);
|
||||||
text_symbol.set_horizontal_alignment(halign);
|
text_symbol.set_horizontal_alignment(halign);
|
||||||
|
@ -1258,92 +1258,63 @@ namespace mapnik
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
stroke strk;
|
stroke strk;
|
||||||
ptree::const_iterator cssIter = sym.begin();
|
// stroke color
|
||||||
ptree::const_iterator endCss = sym.end();
|
optional<color> c= get_opt_attr<color>(sym, "stroke");
|
||||||
|
if (c) strk.set_color(*c);
|
||||||
for(; cssIter != endCss; ++cssIter)
|
// stroke-width
|
||||||
{
|
optional<double> width = get_opt_attr<double>(sym, "stroke-width");
|
||||||
ptree::value_type const& css_tag = *cssIter;
|
if (width) strk.set_width(*width);
|
||||||
ptree const & css = cssIter->second;
|
// stroke-opacity
|
||||||
|
optional<double> opacity = get_opt_attr<double>(sym, "stroke-opacity");
|
||||||
if (css_tag.first == "CssParameter")
|
if (opacity) strk.set_opacity(*opacity);
|
||||||
{
|
// stroke-linejoin
|
||||||
std::string css_name = get_attr<string>(css, "name");
|
optional<line_join_e> line_join = get_opt_attr<line_join_e>(sym, "stroke-linejoin");
|
||||||
if (css_name == "stroke")
|
if (line_join) strk.set_line_join(*line_join);
|
||||||
{
|
// stroke-linecap
|
||||||
color c = get_css<color>(css, css_name);
|
optional<line_cap_e> line_cap = get_opt_attr<line_cap_e>(sym, "stroke-linecap");
|
||||||
strk.set_color(c);
|
if (line_cap) strk.set_line_cap(*line_cap);
|
||||||
}
|
// stroke-dashaffset
|
||||||
else if (css_name == "stroke-width")
|
optional<double> offset = get_opt_attr<double>(sym, "stroke-dashoffet");
|
||||||
{
|
if (offset) strk.set_dash_offset(*offset);
|
||||||
float width = get_css<float>(css, css_name);
|
// stroke-dasharray
|
||||||
strk.set_width(width);
|
optional<string> str = get_opt_attr<string>(sym,"stroke-dasharray");
|
||||||
}
|
if (str)
|
||||||
else if (css_name == "stroke-opacity")
|
{
|
||||||
{
|
tokenizer<> tok (*str);
|
||||||
float opacity = get_css<float>(css, css_name);
|
std::vector<double> dash_array;
|
||||||
strk.set_opacity(opacity);
|
tokenizer<>::iterator itr = tok.begin();
|
||||||
}
|
for (; itr != tok.end(); ++itr)
|
||||||
else if (css_name == "stroke-linejoin")
|
{
|
||||||
{
|
try
|
||||||
line_join_e line_join = get_css<line_join_e>(css, css_name);
|
{
|
||||||
strk.set_line_join( line_join );
|
double f = boost::lexical_cast<double>(*itr);
|
||||||
}
|
dash_array.push_back(f);
|
||||||
else if (css_name == "stroke-linecap")
|
}
|
||||||
{
|
catch ( boost::bad_lexical_cast &)
|
||||||
line_cap_e line_cap = get_css<line_cap_e>(css, css_name);
|
{
|
||||||
strk.set_line_cap( line_cap );
|
throw config_error(std::string("Failed to parse dasharray ") +
|
||||||
}
|
"'. Expected a " +
|
||||||
else if (css_name == "stroke-dasharray")
|
"list of floats but got '" + (*str) + "'");
|
||||||
{
|
}
|
||||||
tokenizer<> tok ( css.data() );
|
}
|
||||||
std::vector<float> dash_array;
|
if (dash_array.size())
|
||||||
tokenizer<>::iterator itr = tok.begin();
|
{
|
||||||
for (; itr != tok.end(); ++itr)
|
size_t size = dash_array.size();
|
||||||
{
|
if ( size % 2)
|
||||||
try
|
{
|
||||||
{
|
for (size_t i=0; i < size ;++i)
|
||||||
float f = boost::lexical_cast<float>(*itr);
|
{
|
||||||
dash_array.push_back(f);
|
dash_array.push_back(dash_array[i]);
|
||||||
}
|
}
|
||||||
catch ( boost::bad_lexical_cast &)
|
}
|
||||||
{
|
std::vector<double>::const_iterator pos = dash_array.begin();
|
||||||
throw config_error(std::string("Failed to parse CSS ") +
|
while (pos != dash_array.end())
|
||||||
"parameter '" + css_name + "'. Expected a " +
|
{
|
||||||
"list of floats but got '" + css.data() + "'");
|
strk.add_dash(*pos,*(pos + 1));
|
||||||
}
|
pos +=2;
|
||||||
}
|
}
|
||||||
if (dash_array.size())
|
}
|
||||||
{
|
}
|
||||||
size_t size = dash_array.size();
|
|
||||||
if ( size % 2)
|
|
||||||
{
|
|
||||||
for (size_t i=0; i < size ;++i)
|
|
||||||
{
|
|
||||||
dash_array.push_back(dash_array[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::vector<float>::const_iterator pos = dash_array.begin();
|
|
||||||
while (pos != dash_array.end())
|
|
||||||
{
|
|
||||||
strk.add_dash(*pos,*(pos + 1));
|
|
||||||
pos +=2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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));
|
rule.append(line_symbolizer(strk));
|
||||||
}
|
}
|
||||||
catch (const config_error & ex)
|
catch (const config_error & ex)
|
||||||
|
@ -1353,7 +1324,7 @@ namespace mapnik
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void map_parser::parse_polygon_symbolizer( rule_type & rule, ptree const & sym )
|
void map_parser::parse_polygon_symbolizer( rule_type & rule, ptree const & sym )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
1296
src/save_map.cpp
1296
src/save_map.cpp
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue