Commit 86e8bba5 authored by Rafael Monnerat's avatar Rafael Monnerat

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.
parent 7ab4b81d
...@@ -158,16 +158,7 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin, ...@@ -158,16 +158,7 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin,
filename = self.getFilename() filename = self.getFilename()
if mime_type == 'text/html': if mime_type == 'text/html':
mime_type = 'text/x-html-safe' mime_type = 'text/x-html-safe'
if format in VALID_IMAGE_FORMAT_LIST: if src_mimetype != "image/svg+xml":
# 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:
result = portal_transforms.convertToData(mime_type, text_content, result = portal_transforms.convertToData(mime_type, text_content,
object=self, context=self, object=self, context=self,
filename=filename, filename=filename,
...@@ -178,6 +169,17 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin, ...@@ -178,6 +169,17 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin,
'portal_transforms failed to convert ' 'portal_transforms failed to convert '
'from %r to %s: %r' % 'from %r to %s: %r' %
(src_mimetype, mime_type, self)) (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) self.setConversion(result, original_mime_type, **kw)
else: else:
......
...@@ -953,11 +953,6 @@ return True ...@@ -953,11 +953,6 @@ return True
""" """
self._testImageConversionFromSVGToPNG_empty_file("File") 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): def test_ImageConversionFromSVGToPNG_file_url(self):
""" Test Convert one SVG Image with an image using local path (file) """ Test Convert one SVG Image with an image using local path (file)
at the url of the image tag. ie: at the url of the image tag. ie:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment