Commit 5421188e authored by Rafael Monnerat's avatar Rafael Monnerat

Rely only into Image.convert to convert images

If a TextDocument is used as image (ie.: like in Web Illustration to SVG),
the conversion API should be from Image to prevent code duplications.
parent 036a066d
......@@ -48,6 +48,8 @@ from Products.ERP5Type.Utils import guessEncodingFromText
from lxml import html as etree_html
from lxml import etree
from Products.ERP5Type.ImageUtil import transformUrlToDataURI
class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin,
TextContent, File):
"""A TextDocument impletents IDocument, IFile, IBaseConvertable, ICachedconvertable
......@@ -156,26 +158,27 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin,
filename = self.getFilename()
if mime_type == 'text/html':
mime_type = 'text/x-html-safe'
result = portal_transforms.convertToData(mime_type, text_content,
object=self, context=self,
filename=filename,
mimetype=src_mimetype,
**convert_kw)
if result is None:
raise ConversionError('TextDocument conversion error. '
'portal_transforms failed to convert '
'from %r to %s: %r' %
(src_mimetype, mime_type, self))
if format in VALID_IMAGE_FORMAT_LIST:
# do resize by temporary image
# 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)
temp_image._setData(text_content)
mime, result = temp_image.convert(**kw)
else:
result = portal_transforms.convertToData(mime_type, text_content,
object=self, context=self,
filename=filename,
mimetype=src_mimetype,
**convert_kw)
if result is None:
raise ConversionError('TextDocument conversion error. '
'portal_transforms failed to convert '
'from %r to %s: %r' %
(src_mimetype, mime_type, self))
self.setConversion(result, original_mime_type, **kw)
else:
mime_type, result = self.getConversion(**kw)
......
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