add .svg.gz suffix
allow .x.y suffixes
This commit is contained in:
parent
9c75fc709b
commit
e439c5f78f
2
TODO
2
TODO
@ -1,5 +1,3 @@
|
||||
- can we hjave .svg.gz as a suffix? should be possible
|
||||
|
||||
- try:
|
||||
|
||||
$ vips avg broken.jpg[fail]
|
||||
|
@ -338,6 +338,7 @@ static const char *vips_foreign_svg_suffs[] = {
|
||||
*/
|
||||
#if LIBRSVG_CHECK_FEATURE(SVGZ)
|
||||
".svgz",
|
||||
".svg.gz",
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
@ -482,7 +483,7 @@ vips_foreign_load_svg_is_a_buffer( const void *buf, size_t len )
|
||||
return( FALSE );
|
||||
|
||||
for( i = 0; i < 200 && i < len - 5; i++ )
|
||||
if( strncasecmp( str + i, "<svg", 4 ) == 0 )
|
||||
if( g_ascii_strncasecmp( str + i, "<svg", 4 ) == 0 )
|
||||
return( TRUE );
|
||||
|
||||
return( FALSE );
|
||||
|
@ -207,6 +207,7 @@ void *vips_hash_table_map( GHashTable *hash,
|
||||
char *vips_strncpy( char *dest, const char *src, int n );
|
||||
char *vips_strrstr( const char *haystack, const char *needle );
|
||||
gboolean vips_ispostfix( const char *a, const char *b );
|
||||
gboolean vips_iscasepostfix( const char *a, const char *b );
|
||||
gboolean vips_isprefix( const char *a, const char *b );
|
||||
char *vips_break_token( char *str, const char *brk );
|
||||
|
||||
|
@ -319,6 +319,20 @@ vips_ispostfix( const char *a, const char *b )
|
||||
return( strcmp( a + m - n, b ) == 0 );
|
||||
}
|
||||
|
||||
/* Case-insensitive test for string b ends string a. ASCII strings only.
|
||||
*/
|
||||
gboolean
|
||||
vips_iscasepostfix( const char *a, const char *b )
|
||||
{
|
||||
int m = strlen( a );
|
||||
int n = strlen( b );
|
||||
|
||||
if( n > m )
|
||||
return( FALSE );
|
||||
|
||||
return( strcasecmp( a + m - n, b ) == 0 );
|
||||
}
|
||||
|
||||
/* Test for string a starts string b. a is a known-good string, b may be
|
||||
* random data.
|
||||
*/
|
||||
@ -461,30 +475,22 @@ int
|
||||
vips_filename_suffix_match( const char *path, const char *suffixes[] )
|
||||
{
|
||||
char *basename;
|
||||
char *suffix;
|
||||
char *q;
|
||||
const char **p;
|
||||
int result;
|
||||
const char **p;
|
||||
|
||||
/* Drop any directory components, we want ignore any '.' in there.
|
||||
/* Drop any directory components.
|
||||
*/
|
||||
basename = g_path_get_basename( path );
|
||||
|
||||
/* Zap any trailing options.
|
||||
/* Zap any trailing [] options.
|
||||
*/
|
||||
if( (q = (char *) vips__find_rightmost_brackets( basename )) )
|
||||
*q = '\0';
|
||||
|
||||
/* And select just the '.' and to the right.
|
||||
*/
|
||||
if( (q = strrchr( basename, '.' )) )
|
||||
suffix = q;
|
||||
else
|
||||
suffix = basename;
|
||||
|
||||
result = 0;
|
||||
for( p = suffixes; *p; p++ )
|
||||
if( g_ascii_strcasecmp( suffix, *p ) == 0 ) {
|
||||
for( p = suffixes; *p; p++ )
|
||||
if( vips_iscasepostfix( basename, *p ) ) {
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
|
BIN
test/images/vips-profile.svg.gz
Normal file
BIN
test/images/vips-profile.svg.gz
Normal file
Binary file not shown.
@ -51,6 +51,7 @@ class TestForeign(unittest.TestCase):
|
||||
self.cmyk_pdf_file = "images/cmyktest.pdf"
|
||||
self.svg_file = "images/vips-profile.svg"
|
||||
self.svgz_file = "images/vips-profile.svgz"
|
||||
self.svg_gz_file = "images/vips-profile.svg.gz"
|
||||
|
||||
self.colour = Vips.Image.jpegload(self.jpeg_file)
|
||||
self.mono = self.colour.extract_band(1)
|
||||
@ -501,6 +502,8 @@ class TestForeign(unittest.TestCase):
|
||||
self.file_loader("svgload", self.svgz_file, svg_valid)
|
||||
self.buffer_loader("svgload_buffer", self.svgz_file, svg_valid)
|
||||
|
||||
self.file_loader("svgload", self.svg_gz_file, svg_valid)
|
||||
|
||||
im = Vips.Image.new_from_file(self.svg_file)
|
||||
x = Vips.Image.new_from_file(self.svg_file, scale = 2)
|
||||
self.assertLess(abs(im.width * 2 - x.width), 2)
|
||||
|
Loading…
Reference in New Issue
Block a user