Commit e160079a authored by Jean-Paul Smets's avatar Jean-Paul Smets

Quick patch to provide image display in small size for text documents.

convert must be better written to support all image class features.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18974 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e8421255
...@@ -341,6 +341,7 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -341,6 +341,7 @@ class OOoDocument(File, ConversionCacheMixin):
# Make sure we can support html and pdf by default # Make sure we can support html and pdf by default
is_html = 0 is_html = 0
requires_pdf_first = 0
original_format = format original_format = format
if format == 'base-data': if format == 'base-data':
if not self.hasBaseData(): if not self.hasBaseData():
...@@ -353,6 +354,13 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -353,6 +354,13 @@ class OOoDocument(File, ConversionCacheMixin):
elif format in STANDARD_IMAGE_FORMAT_LIST: elif format in STANDARD_IMAGE_FORMAT_LIST:
format_list = [x for x in self.getTargetFormatList() format_list = [x for x in self.getTargetFormatList()
if x.endswith(format)] if x.endswith(format)]
if len(format_list):
format = format_list[0]
else:
# We must fist make a PDF
requires_pdf_first = 1
format_list = [x for x in self.getTargetFormatList()
if x.endswith('pdf')]
format = format_list[0] format = format_list[0]
elif format == 'html': elif format == 'html':
format_list = [x for x in self.getTargetFormatList() format_list = [x for x in self.getTargetFormatList()
...@@ -373,7 +381,15 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -373,7 +381,15 @@ class OOoDocument(File, ConversionCacheMixin):
if not self.hasBaseData(): if not self.hasBaseData():
raise NotConvertedError raise NotConvertedError
# Return converted file # Return converted file
if display is None or original_format not in STANDARD_IMAGE_FORMAT_LIST: if requires_pdf_first:
# We should use original_format whenever we wish to
# display an image version of a document which needs to go
# through PDF
if display is None:
has_format = self.hasConversion(format=original_format)
else:
has_format = self.hasConversion(format=original_format, display=display)
elif display is None or original_format not in STANDARD_IMAGE_FORMAT_LIST:
has_format = self.hasConversion(format=format) has_format = self.hasConversion(format=format)
else: else:
has_format = self.hasConversion(format=format, display=display) has_format = self.hasConversion(format=format, display=display)
...@@ -395,7 +411,8 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -395,7 +411,8 @@ class OOoDocument(File, ConversionCacheMixin):
self.populateContent(zip_file=z) self.populateContent(zip_file=z)
z.close() z.close()
cs.close() cs.close()
if display is None or original_format not in STANDARD_IMAGE_FORMAT_LIST: if (display is None or original_format not in STANDARD_IMAGE_FORMAT_LIST) \
and not requires_pdf_first:
self.setConversion(data, mime, format=format) self.setConversion(data, mime, format=format)
else: else:
temp_image = self.portal_contributions.newContent( temp_image = self.portal_contributions.newContent(
...@@ -403,7 +420,18 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -403,7 +420,18 @@ class OOoDocument(File, ConversionCacheMixin):
temp_object=1) temp_object=1)
temp_image._setData(data) temp_image._setData(data)
mime, data = temp_image.convert(original_format, display=display) mime, data = temp_image.convert(original_format, display=display)
if requires_pdf_first:
if display is None:
self.setConversion(data, mime, format=original_format)
else:
self.setConversion(data, mime, format=original_format, display=display)
else:
if display is None:
self.setConversion(data, mime, format=format)
else:
self.setConversion(data, mime, format=format, display=display) self.setConversion(data, mime, format=format, display=display)
if requires_pdf_first:
format = original_format
if display is None or original_format not in STANDARD_IMAGE_FORMAT_LIST: if display is None or original_format not in STANDARD_IMAGE_FORMAT_LIST:
return self.getConversion(format=format) return self.getConversion(format=format)
else: else:
...@@ -436,15 +464,25 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -436,15 +464,25 @@ class OOoDocument(File, ConversionCacheMixin):
must_close = 1 must_close = 1
else: else:
must_close = 0 must_close = 0
first_page = True
for f in zip_file.infolist(): for f in zip_file.infolist():
file_name = f.filename file_name = f.filename
if not file_name.endswith('html'): # XXX - we must add here more values in order to if file_name.endswith('html') and self.getPortalType() != 'Presentation':
# support multi-page HTML conversions #if file_name.endswith('html'):
# such as for presentations. continue
#if first_page and file_name.endswith('html'):
# first_page = False
# break
LOG('file_name', 0, file_name)
document = self.get(file_name, None) document = self.get(file_name, None)
if document is not None: if document is not None:
self.manage_delObjects([file_name]) self.manage_delObjects([file_name])
newContent = UnrestrictedMethod(self.portal_contributions.newContent) newContent = UnrestrictedMethod(self.portal_contributions.newContent)
if file_name.endswith('html'):
newContent(id=file_name, container=self, portal_type='Web Page',
file_name=file_name,
data=zip_file.read(file_name))
else:
newContent(id=file_name, container=self, newContent(id=file_name, container=self,
file_name=file_name, file_name=file_name,
data=zip_file.read(file_name)) data=zip_file.read(file_name))
......
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