From 86e8bba596fd954c9b4b6f6ca1415b350d82fa96 Mon Sep 17 00:00:00 2001
From: Rafael Monnerat <rafael@nexedi.com>
Date: Wed, 25 Apr 2012 16:22:31 -0300
Subject: [PATCH] The only image exception is svg used as TextDocument

SVG has a special treatment on this case, because is the only format which
is a real image. The others formats are non-image cases.

When it is SVG, rely only on Image API Conversion.
---
 product/ERP5/Document/TextDocument.py    | 22 ++++++++++++----------
 product/ERP5/tests/testERP5WebWithDms.py |  5 -----
 2 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/product/ERP5/Document/TextDocument.py b/product/ERP5/Document/TextDocument.py
index 4d744beee4..69f0d10db6 100644
--- a/product/ERP5/Document/TextDocument.py
+++ b/product/ERP5/Document/TextDocument.py
@@ -158,16 +158,7 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin,
           filename = self.getFilename()
           if mime_type == 'text/html':
             mime_type = 'text/x-html-safe'
-          if format in VALID_IMAGE_FORMAT_LIST:
-            # Include extra parameter for image conversions
-            temp_image = self.portal_contributions.newContent(
-                                       portal_type='Image',
-                                       file=cStringIO.StringIO(),
-                                       filename=self.getId(),
-                                       temp_object=1)
-            temp_image._setData(text_content)
-            mime, result = temp_image.convert(**kw)
-          else:
+          if src_mimetype != "image/svg+xml":
             result = portal_transforms.convertToData(mime_type, text_content,
                                                    object=self, context=self,
                                                    filename=filename,
@@ -178,6 +169,17 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin,
                                     'portal_transforms failed to convert '
                                     'from %r to %s: %r' % 
                                     (src_mimetype, mime_type, self))
+          else:
+            result = text_content
+          if format in VALID_IMAGE_FORMAT_LIST:
+            # Include extra parameter for image conversions
+            temp_image = self.portal_contributions.newContent(
+                                       portal_type='Image',
+                                       file=cStringIO.StringIO(),
+                                       filename=self.getId(),
+                                       temp_object=1)
+            temp_image._setData(result)
+            mime, result = temp_image.convert(**kw)
 
           self.setConversion(result, original_mime_type, **kw)
         else:
diff --git a/product/ERP5/tests/testERP5WebWithDms.py b/product/ERP5/tests/testERP5WebWithDms.py
index db98893316..64f3042ac3 100644
--- a/product/ERP5/tests/testERP5WebWithDms.py
+++ b/product/ERP5/tests/testERP5WebWithDms.py
@@ -953,11 +953,6 @@ return True
     """
     self._testImageConversionFromSVGToPNG_empty_file("File")
 
-  def test_WebPageConversionFromSVGToPNG_empty_file(self):
-    """ Test Convert one SVG Image with an empty svg
-    """
-    self._testImageConversionFromSVGToPNG_empty_file("Web Page")
-
   def test_ImageConversionFromSVGToPNG_file_url(self):
     """ Test Convert one SVG Image with an image using local path (file)
         at the url of the image tag. ie:
-- 
2.30.9