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 ...@@ -48,6 +48,8 @@ from Products.ERP5Type.Utils import guessEncodingFromText
from lxml import html as etree_html from lxml import html as etree_html
from lxml import etree from lxml import etree
from Products.ERP5Type.ImageUtil import transformUrlToDataURI
class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin, class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin,
TextContent, File): TextContent, File):
"""A TextDocument impletents IDocument, IFile, IBaseConvertable, ICachedconvertable """A TextDocument impletents IDocument, IFile, IBaseConvertable, ICachedconvertable
...@@ -156,6 +158,16 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin, ...@@ -156,6 +158,16 @@ 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:
# 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,
...@@ -167,15 +179,6 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin, ...@@ -167,15 +179,6 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin,
'from %r to %s: %r' % 'from %r to %s: %r' %
(src_mimetype, mime_type, self)) (src_mimetype, mime_type, self))
if format in VALID_IMAGE_FORMAT_LIST:
# do resize by temporary image
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:
mime_type, result = self.getConversion(**kw) 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