Commit 666d020e authored by Romain Courteaud's avatar Romain Courteaud

Allow image to text convertion by using portal_transforms.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24292 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e4d23e5d
......@@ -50,8 +50,9 @@ from OFS.Image import Image as OFSImage
from OFS.Image import getImageInfo
from OFS.content_types import guess_content_type
from zLOG import LOG
from zLOG import LOG, WARNING
from Products.CMFCore.utils import getToolByName
default_displays_id_list = ('nano', 'micro', 'thumbnail',
'xsmall', 'small', 'medium',
......@@ -310,7 +311,25 @@ class Image(File, OFSImage):
Implementation of conversion for PDF files
"""
if format in ('text', 'txt', 'html', 'base_html', 'stripped-html'):
return None, None
mime_type = getToolByName(self, 'mimetypes_registry').\
lookupExtension('name.%s' % format)
src_mimetype = self.getContentType()
content = '%s' % self.getData()
if content is not None:
portal_transforms = getToolByName(self, 'portal_transforms')
result = portal_transforms.convertToData(mime_type, content,
object=self, context=self,
filename=self.title_or_id(),
mimetype=src_mimetype)
if result is None:
# portal_transforms fails to convert.
LOG('TextDocument.convert', WARNING,
'portal_transforms failed to convert to %s: %r' % (mime_type, self))
result = ''
return mime_type, result
else:
# text_content is not set, return empty string instead of None
return mime_type, ''
image_size = self.getSizeFromImageDisplay(display)
if (display is not None or resolution is not None or quality != 75 or format != ''\
or frame is not None) and image_size:
......@@ -328,6 +347,17 @@ class Image(File, OFSImage):
return mime, image.data
return self.getContentType(), self.getData()
security.declareProtected(Permissions.View, 'getSearchableText')
def getSearchableText(self, md=None):
"""
Converts the content of the document to a textual representation.
"""
mime, data = self.convert(format='txt')
return str(data)
# Compatibility with CMF Catalog
SearchableText = getSearchableText
# Display
security.declareProtected('View', 'index_html')
def index_html(self, REQUEST, RESPONSE, display=None, format='', quality=75,
......
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