Cleanups.

This commit is contained in:
Daniel Patterson 2015-06-17 21:04:36 -07:00
parent 3059cbf231
commit 776436db6e
3 changed files with 16 additions and 22 deletions

View file

@ -62,21 +62,21 @@ inline boost::optional<std::string> type_from_bytes(char const* data, size_t siz
return result_type("webp");
}
}
// NOTE: Limit search to first 300 bytes. Totally arbitrary, but don't
// want to search through whole buffer
const size_t max_svg_search = std::min(static_cast<size_t>(300), size);
for(int i=0; i < static_cast<signed>(max_svg_search)-4; i++)
{
if (data[i] == '<' &&
(data[i+1] == 's' || data[i+1] == 'S') &&
(data[i+2] == 'v' || data[i+2] == 'V') &&
(data[i+1] == 's' || data[i+1] == 'S') &&
(data[i+2] == 'v' || data[i+2] == 'V') &&
(data[i+3] == 'g' || data[i+3] == 'G'))
{
return result_type("svg");
}
}
return result_type();
}

View file

@ -147,14 +147,13 @@ void svg_reader<T>::init()
svg_converter_type svg(svg_path, marker_path->attributes());
svg_parser p(svg);
p.parse_from_stream(stream_);
//svg.arrange_orientations();
double lox,loy,hix,hiy;
svg.bounding_rect(&lox, &loy, &hix, &hiy);
marker_path->set_bounding_box(lox,loy,hix,hiy);
marker_path->set_dimensions(svg.width(),svg.height());
marker = std::make_shared<mapnik::marker_svg>(marker_path);
width_=svg.width();
height_=svg.height();
}
@ -174,7 +173,7 @@ unsigned svg_reader<T>::height() const
template <typename T>
boost::optional<box2d<double> > svg_reader<T>::bounding_box() const
{
// TODO: return bbox
// TODO: does this need to be implemented?
return boost::optional<box2d<double> >();
}
@ -190,7 +189,7 @@ void svg_reader<T>::read(unsigned x0, unsigned y0,image_rgba8& image)
double opacity = 1;
int w = width_;
int h = height_;
// 10 pixel buffer to avoid edge clipping of 100% svg's
mapnik::image_rgba8 im(w+0,h+0);
agg::rendering_buffer buf(im.bytes(), im.width(), im.height(), im.row_size());
@ -215,9 +214,8 @@ void svg_reader<T>::read(unsigned x0, unsigned y0,image_rgba8& image)
svg_renderer_this.render(ras_ptr, sl, renb, mtx, opacity, bbox);
demultiply_alpha(im);
image = im;
}

View file

@ -12,10 +12,6 @@
TEST_CASE("image class svg features") {
SECTION("test magic number search") {
} // END SECTION
SECTION("svg_blank")
{
std::string imagedata = "";
@ -29,7 +25,7 @@ SECTION("svg_invalid")
CHECK(reader.get());
unsigned width = reader->width();
unsigned height = reader->height();
CHECK(width == 0);
CHECK(height == 0);
}
@ -41,7 +37,7 @@ SECTION("svg_empty")
CHECK(reader.get());
unsigned width = reader->width();
unsigned height = reader->height();
CHECK(width == 0);
CHECK(height == 0);
}
@ -53,17 +49,17 @@ SECTION("svg_blank")
CHECK(reader.get());
unsigned width = reader->width();
unsigned height = reader->height();
CHECK(width == 100);
CHECK(height == 100);
mapnik::image_any im = reader->read(0,0,width,height);
mapnik::image_rgba8 raw = im.get<mapnik::image_rgba8>();
std::string pngdata = mapnik::save_to_string<mapnik::image_rgba8>(raw,"png");
CHECK(pngdata.length() == 1270 );
CHECK(pngdata.length() == 1270);
} // END SECTION
} // END TEST CASE