svg2png : use SVG dimensions as a fallback when bounding box has zero width or height (e.g horizontal or vertical line)

This commit is contained in:
artemp 2016-01-08 10:20:50 +00:00
parent b1c22ba853
commit c8932b3df3
2 changed files with 12 additions and 3 deletions

View file

@ -108,7 +108,7 @@ public:
marker_svg(marker_svg && rhs) noexcept marker_svg(marker_svg && rhs) noexcept
: vector_data_(rhs.vector_data_) {} : vector_data_(rhs.vector_data_) {}
box2d<double> bounding_box() const inline box2d<double> bounding_box() const
{ {
return vector_data_->bounding_box(); return vector_data_->bounding_box();
} }
@ -122,11 +122,15 @@ public:
return vector_data_->bounding_box().height(); return vector_data_->bounding_box().height();
} }
mapnik::svg_path_ptr get_data() const inline mapnik::svg_path_ptr get_data() const
{ {
return vector_data_; return vector_data_;
} }
inline std::tuple<double,double> dimensions() const
{
return std::make_tuple(vector_data_->width(), vector_data_->height());
}
private: private:
mapnik::svg_path_ptr vector_data_; mapnik::svg_path_ptr vector_data_;
@ -136,7 +140,7 @@ struct marker_null
{ {
marker_null() = default; marker_null() = default;
public: public:
box2d<double> bounding_box() const inline box2d<double> bounding_box() const
{ {
return box2d<double>(); return box2d<double>();
} }

View file

@ -67,6 +67,11 @@ struct main_marker_visitor
double opacity = 1; double opacity = 1;
int w = marker.width(); int w = marker.width();
int h = marker.height(); int h = marker.height();
if (w == 0 || h == 0)
{
// fallback to svg width/height or viewBox
std::tie(w, h) = marker.dimensions();
}
if (verbose_) if (verbose_)
{ {
std::clog << "found width of '" << w << "' and height of '" << h << "'\n"; std::clog << "found width of '" << w << "' and height of '" << h << "'\n";