fix load from buffer
This commit is contained in:
parent
153886d2eb
commit
56e45545d3
8
TODO
8
TODO
@ -1,4 +1,10 @@
|
|||||||
- test suite is failing for svg load from buffer, strange
|
- make vips_foreign_load_svg_is_a_buffer() much faster
|
||||||
|
|
||||||
|
test for first line starts "<?xml"
|
||||||
|
and second line starts "<svg"
|
||||||
|
|
||||||
|
will this be too fragile? what about extra whitespace, case, DOS files etc
|
||||||
|
etc.
|
||||||
|
|
||||||
- gif loader?
|
- gif loader?
|
||||||
|
|
||||||
|
@ -356,6 +356,21 @@ typedef VipsForeignLoadSvgClass VipsForeignLoadSvgBufferClass;
|
|||||||
G_DEFINE_TYPE( VipsForeignLoadSvgBuffer, vips_foreign_load_svg_buffer,
|
G_DEFINE_TYPE( VipsForeignLoadSvgBuffer, vips_foreign_load_svg_buffer,
|
||||||
vips_foreign_load_svg_get_type() );
|
vips_foreign_load_svg_get_type() );
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
vips_foreign_load_svg_is_a_buffer( const void *buf, size_t len )
|
||||||
|
{
|
||||||
|
char *str = (char *) buf;
|
||||||
|
|
||||||
|
/* Ouch! So slow!! This can easily end up parsing the entire document.
|
||||||
|
*/
|
||||||
|
if( (page = rsvg_handle_new_from_data( buf, len, NULL )) ) {
|
||||||
|
g_object_unref( page );
|
||||||
|
return( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vips_foreign_load_svg_buffer_header( VipsForeignLoad *load )
|
vips_foreign_load_svg_buffer_header( VipsForeignLoad *load )
|
||||||
{
|
{
|
||||||
@ -380,6 +395,7 @@ vips_foreign_load_svg_buffer_class_init(
|
|||||||
{
|
{
|
||||||
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
|
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
|
||||||
VipsObjectClass *object_class = (VipsObjectClass *) class;
|
VipsObjectClass *object_class = (VipsObjectClass *) class;
|
||||||
|
VipsForeignClass *foreign_class = (VipsForeignClass *) class;
|
||||||
VipsForeignLoadClass *load_class = (VipsForeignLoadClass *) class;
|
VipsForeignLoadClass *load_class = (VipsForeignLoadClass *) class;
|
||||||
|
|
||||||
gobject_class->set_property = vips_object_set_property;
|
gobject_class->set_property = vips_object_set_property;
|
||||||
@ -388,6 +404,12 @@ vips_foreign_load_svg_buffer_class_init(
|
|||||||
object_class->nickname = "svgload_buffer";
|
object_class->nickname = "svgload_buffer";
|
||||||
object_class->description = _( "load SVG with rsvg" );
|
object_class->description = _( "load SVG with rsvg" );
|
||||||
|
|
||||||
|
/* is_a() is not quick, it must parse the whole document ...
|
||||||
|
* lower the priority.
|
||||||
|
*/
|
||||||
|
foreign_class->priority = -50;
|
||||||
|
|
||||||
|
load_class->is_a_buffer = vips_foreign_load_svg_is_a_buffer;
|
||||||
load_class->header = vips_foreign_load_svg_buffer_header;
|
load_class->header = vips_foreign_load_svg_buffer_header;
|
||||||
|
|
||||||
VIPS_ARG_BOXED( class, "buffer", 1,
|
VIPS_ARG_BOXED( class, "buffer", 1,
|
||||||
|
@ -371,7 +371,6 @@ class TestForeign(unittest.TestCase):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def svg_valid(self, im):
|
def svg_valid(self, im):
|
||||||
im.write_to_file("x.v")
|
|
||||||
a = im(10, 10)
|
a = im(10, 10)
|
||||||
self.assertAlmostEqualObjects(a, [0, 0, 77, 255])
|
self.assertAlmostEqualObjects(a, [0, 0, 77, 255])
|
||||||
self.assertEqual(im.width, 360)
|
self.assertEqual(im.width, 360)
|
||||||
|
Loading…
Reference in New Issue
Block a user