Commit 500c6f12 authored by Julien Muchembled's avatar Julien Muchembled

* Accept single quotes for attributes in <office:include> and <office:include_img>.

* Use mimetypes.guess_extension to get the extension from the content_type.
* Recognize BMP files in Image documents.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@23644 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent cc97ebbb
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
import os import os
import string import string
import struct
import sys import sys
import time import time
import subprocess import subprocess
...@@ -118,10 +119,16 @@ class Image(File, OFSImage): ...@@ -118,10 +119,16 @@ class Image(File, OFSImage):
TODO: TODO:
- use image magick or PIL - use image magick or PIL
""" """
self.size = len(self.data)
content_type, width, height = getImageInfo(self.data) content_type, width, height = getImageInfo(self.data)
if not content_type:
if self.size >= 30 and self.data[:2] == 'BM':
header = struct.unpack('<III', self.data[14:26])
if header[0] >= 12:
content_type = 'image/x-bmp'
width, height = header[1:]
self.height = height self.height = height
self.width = width self.width = width
self.size = len(self.data)
self._setContentType(content_type) self._setContentType(content_type)
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
############################################################################## ##############################################################################
from types import StringType from types import StringType
from mimetypes import guess_extension
from zLOG import LOG from zLOG import LOG
from zLOG import PROBLEM from zLOG import PROBLEM
from OFS.Image import File from OFS.Image import File
...@@ -242,7 +243,7 @@ class OOoTemplate(ZopePageTemplate): ...@@ -242,7 +243,7 @@ class OOoTemplate(ZopePageTemplate):
def renderIncludes(self, here, text, sub_document=None): def renderIncludes(self, here, text, sub_document=None):
attached_files_dict = {} attached_files_dict = {}
arguments_re = re.compile('(\S+?)\s*=\s*"(.*?)"\s*',re.DOTALL) arguments_re = re.compile('''(\S+?)\s*=\s*('|")(.*?)\\2\s*''',re.DOTALL)
def getLengthInfos( opts_dict, opts_names ): def getLengthInfos( opts_dict, opts_names ):
ret = [] ret = []
for opt_name in opts_names: for opt_name in opts_names:
...@@ -257,9 +258,8 @@ class OOoTemplate(ZopePageTemplate): ...@@ -257,9 +258,8 @@ class OOoTemplate(ZopePageTemplate):
return ret return ret
def replaceIncludes(match): def replaceIncludes(match):
tag_string = match.group(1)
# Build a dictionary with tag parameters # Build a dictionary with tag parameters
options_dict = dict(arguments_re.findall(tag_string)) options_dict = dict((x[0], x[2]) for x in arguments_re.findall(match.group(1)))
# Find the page template based on the path and remove path from dict # Find the page template based on the path and remove path from dict
document = self._resolvePath(options_dict['path'].encode()) document = self._resolvePath(options_dict['path'].encode())
document_text = ZopePageTemplate.pt_render(document) # extra_context is missing document_text = ZopePageTemplate.pt_render(document) # extra_context is missing
...@@ -339,7 +339,7 @@ xmlns:config="http://openoffice.org/2001/config" office:version="1.0"> ...@@ -339,7 +339,7 @@ xmlns:config="http://openoffice.org/2001/config" office:version="1.0">
def replaceIncludesImg(match): def replaceIncludesImg(match):
options_dict = { 'text:anchor-type': 'paragraph' } options_dict = { 'text:anchor-type': 'paragraph' }
options_dict.update(arguments_re.findall(match.group(1))) options_dict.update((x[0], x[2]) for x in arguments_re.findall(match.group(1)))
for old_name, name, default in (('x', 'svg:x', '0cm'), for old_name, name, default in (('x', 'svg:x', '0cm'),
('y', 'svg:y', '0cm'), ('y', 'svg:y', '0cm'),
('style', 'draw:style-name', 'fr1')): ('style', 'draw:style-name', 'fr1')):
...@@ -373,9 +373,6 @@ xmlns:config="http://openoffice.org/2001/config" office:version="1.0"> ...@@ -373,9 +373,6 @@ xmlns:config="http://openoffice.org/2001/config" office:version="1.0">
if not is_standard_filetype: if not is_standard_filetype:
picture_type = picture_type() picture_type = picture_type()
if '/' not in picture_type:
picture_type = 'image/' + picture_type
w, h, maxwidth, maxheight = getLengthInfos(options_dict, w, h, maxwidth, maxheight = getLengthInfos(options_dict,
('width', 'height', 'maxwidth', 'maxheight')) ('width', 'height', 'maxwidth', 'maxheight'))
...@@ -407,7 +404,8 @@ xmlns:config="http://openoffice.org/2001/config" office:version="1.0"> ...@@ -407,7 +404,8 @@ xmlns:config="http://openoffice.org/2001/config" office:version="1.0">
w = h * aspect_ratio w = h * aspect_ratio
actual_idx = self.document_counter.next() actual_idx = self.document_counter.next()
pic_name = 'Pictures/picture%d.%s' % (actual_idx, picture_type.split('/')[-1]) pic_name = 'Pictures/picture%d%s' \
% (actual_idx, guess_extension(picture_type) or '')
# XXX: Pictures directory not managed (seems facultative) # XXX: Pictures directory not managed (seems facultative)
# <manifest:file-entry manifest:media-type="" manifest:full-path="ObjBFE4F50D/Pictures/"/> # <manifest:file-entry manifest:media-type="" manifest:full-path="ObjBFE4F50D/Pictures/"/>
......
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