incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1230531 - /incubator/ooo/trunk/main/svtools/source/filter/filter.cxx
Date Thu, 12 Jan 2012 13:39:34 GMT
Author: alg
Date: Thu Jan 12 13:39:34 2012
New Revision: 1230531

URL: http://svn.apache.org/viewvc?rev=1230531&view=rev
Log:
#118728# Extended Svg file detection

Modified:
    incubator/ooo/trunk/main/svtools/source/filter/filter.cxx

Modified: incubator/ooo/trunk/main/svtools/source/filter/filter.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/svtools/source/filter/filter.cxx?rev=1230531&r1=1230530&r2=1230531&view=diff
==============================================================================
--- incubator/ooo/trunk/main/svtools/source/filter/filter.cxx (original)
+++ incubator/ooo/trunk/main/svtools/source/filter/filter.cxx Thu Jan 12 13:39:34 2012
@@ -678,14 +678,51 @@ static sal_Bool ImpPeekGraphicFormat( Sv
     //--------------------------- SVG ------------------------------------
 	if( !bTest )
 	{
+        // check for Xml
         if( ImplSearchEntry( sFirstBytes, (sal_uInt8*)"<?xml", 256, 5 ) // is it xml
-            && ImplSearchEntry( sFirstBytes, (sal_uInt8*)"version", 256, 7 ) // does
it have a version (required for xml)
-            && ImplSearchEntry( sFirstBytes, (sal_uInt8*)"www.w3.org", 256, 10 )
// does it have to do with w3 (part of namespace definition)
-            && ImplSearchEntry( sFirstBytes, (sal_uInt8*)"<svg", 256, 4 ) ) //
does it have svg nodes
-		{
-			rFormatExtension = UniString::CreateFromAscii( "SVG", 3 );
-			return sal_True;
-		}
+            && ImplSearchEntry( sFirstBytes, (sal_uInt8*)"version", 256, 7 )) //
does it have a version (required for xml)
+        {
+            bool bIsSvg(false);
+
+            // check for DOCTYPE svg combination
+            if( ImplSearchEntry( sFirstBytes, (sal_uInt8*)"DOCTYPE", 256, 7 ) // 'DOCTYPE'
is there
+                && ImplSearchEntry( sFirstBytes, (sal_uInt8*)"svg", 256, 3 )) //
'svg' is there
+            {
+                bIsSvg = true;
+            }
+
+            // check for svg element in 1st 256 bytes
+            if(!bIsSvg && ImplSearchEntry( sFirstBytes, (sal_uInt8*)"<svg", 256,
4 )) // '<svg'
+            {
+                bIsSvg = true;
+            }
+
+            if(!bIsSvg)
+            {
+                // it's a xml, look for '<svg' in full file. Should not happen too
+                // often since the tests above will handle most cases, but can happen
+                // with Svg files containing big comment headers or Svg as the host
+                // language
+                const sal_uLong nSize((nStreamLen > 2048) ? 2048 : nStreamLen);
+                sal_uInt8* pBuf = new sal_uInt8[nSize];
+
+                rStream.Seek(nStreamPos);
+                rStream.Read(pBuf, nSize);
+
+                if(ImplSearchEntry(pBuf, (sal_uInt8*)"<svg", nSize, 4)) // '<svg'
+                {
+                    bIsSvg = true;
+                }
+
+                delete[] pBuf;
+            }
+
+            if(bIsSvg)
+            {
+                rFormatExtension = UniString::CreateFromAscii( "SVG", 3 );
+                return sal_True;
+            }
+        }
 	}
 	else if( rFormatExtension.CompareToAscii( "SVG", 3 ) == COMPARE_EQUAL )
 	{



Mime
View raw message