source: trunk/docx4j/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/MetafileEmfPart.java @ 1637

Revision 1637, 2.2 KB checked in by jharrop, 10 months ago (diff)

Alberto's patch of 3 August.

  • The ConversionImageHandler?.handleImage is declared now as throwing a Doc4jException
  • I have removed the dependencies on vfs

If the ConversionImageHandler?.handleImage throws an Exception, it will be logged as an error in the AbstractWordXmlPicture?, but it won’t be propagated. I’m not sure, but I think that an exception in handleImage should not stop the conversion process.

Removing the dependencies on vfs:

org.docx4j.model.images.DefaultConversionImageHandler? has been replaced with the following hierarchy:

org.docx4j.model.images.AbstractConversionImageHandler?

-> org.docx4j.extras.vfs.VFSConversionImageHandler

-> org.docx4j.model.images.FileConversionImageHandler?

-> org.docx4j.convert.out.html.HTMLConversionImageHandler

-> org.docx4j.convert.out.pdf.viaXSLFO.PDFConversionImageHandler

  • VFSConversionImageHandler offers the old functionality based on VFS
  • FileConversionImageHandler? is based on plain File(s), this means that it won’t be able to handle such cases where the target directory is on an ftp-server (or something comparable).
  • HTMLConversionImageHandler. In HTMLSettings there is a new Setting ‘imageTargetURI’ that allows to define a prefix for the image URI. If it is set, HTMLConversionImageHandler will use it as an prefix for the image URI, otherwise the image URI will just be the image name. This behavior replaces fixImgSrcURL.
  • PDFConversionImageHandler will always use the absolute path of the file as the image URI.

Apart from this there is a new setting in AbstractConversionSettings? (‘imageIncludeUUID’) that allows to switch on or off the UUID (default is on)

org.docx4j.openpackaging.io.LoadFromVFSZipFile
org.docx4j.openpackaging.io.SaveToVFSZipFile and
org.docx4j.utils.VFSUtils

have been moved to org.docx4j.extras.vfs, there is no replacement for them.

org.docx4j.convert.in.Doc has been split in org.docx4j.convert.in.Doc (without convert(org.apache.commons.vfs.FileObject? in)) and org.docx4j.extras.vfs.VFSDoc (with the method)

org.docx4j.openpackaging.io.ExternalResourceUtils? now uses an URLConnection instead of VFS

If you put the stuff in org.docx4j.extras.vfs in docx4j-extras, you should be able to compile docx4j without the dependency on VFS.

Some additional changes:

  • A small detail: WordXmlPictureE20, checked blip.getEmbed() == null and blip.getLink() == null, but those getters would return an empty string.
Line 
1package org.docx4j.openpackaging.parts.WordprocessingML;
2
3import org.docx4j.openpackaging.exceptions.InvalidFormatException;
4import org.docx4j.openpackaging.parts.ExternalTarget;
5import org.docx4j.openpackaging.parts.PartName;
6import org.docx4j.openpackaging.parts.relationships.Namespaces;
7
8/**
9 * Summary: At present, EMF files are best converted to SVG using OpenOffice.
10 *
11 * Note regarding options for converting EMF files to SVG and/or PNG
12 * (as at Feb 2010):
13
14        - com.adobe.dp.office
15        - wmf2svg
16        - batik
17        - freehep
18        - imagemagick
19        - openoffice
20       
21        (Could mono's libgdiplus help? Search for 'mono metafile')
22
23        wmf2tosvg is a good solution for WMF, but it has no EMF support.
24       
25        FreeHEP has EMF2SVG, but the output wasn't much good (perhaps
26        because office drawings aren't its primary focus). It would
27        also be a very complex dependency.
28       
29        Batik has WMFTranscoder, but not EMFTranscoder! It looks like
30        one could be added from package
31        org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.metafile
32        with a bit of work, but still, batik is no good on appengine since
33        it uses awt, and spawns threads. So avoid it..
34       
35        imagemagick has no support for EMF at all (other than on Windows).
36       
37        openoffice can be used to convert EMF; I found it worked well.
38       
39        Until the EMFParser in com.adobe.dp.office is fixed, this may be
40        a good option (depending on your environment).
41       
42        Maybe the code to use openoffice for EMF conversions could go in
43        src/docx4j-extras, so only those who wanted to use it would need
44        to worry about the dependencies.
45       
46        TODO: Have a look at cairo, which has java bindings.  Can it be used
47        to read EMF? See also pymfvu - UniCovertor will ultimately be able
48        to import EMF
49 *
50 */
51public class MetafileEmfPart extends MetafilePart {
52       
53        public MetafileEmfPart(PartName partName) throws InvalidFormatException {
54                super(partName);
55                init();
56        }
57       
58        public MetafileEmfPart(ExternalTarget externalTarget) {
59                super(externalTarget);
60                init();
61        }       
62       
63        public void init() {
64                // Used if this Part is added to [Content_Types].xml
65                setContentType(new  org.docx4j.openpackaging.contenttype.ContentType( 
66                                org.docx4j.openpackaging.contenttype.ContentTypes.IMAGE_EMF));
67
68                // Used when this Part is added to a rels
69                setRelationshipType(Namespaces.IMAGE);
70        }
71
72}
Note: See TracBrowser for help on using the repository browser.