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

Revision 1637, 2.5 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 java.io.InputStream;
4
5import net.arnx.wmf2svg.gdi.svg.SvgGdi;
6import net.arnx.wmf2svg.gdi.wmf.WmfParser;
7
8import org.docx4j.openpackaging.exceptions.InvalidFormatException;
9import org.docx4j.openpackaging.parts.ExternalTarget;
10import org.docx4j.openpackaging.parts.PartName;
11import org.docx4j.openpackaging.parts.relationships.Namespaces;
12import org.docx4j.utils.BufferUtil;
13import org.w3c.dom.Document;
14
15/**
16 * Summary: docx4j can convert WMF files to SVG using pure Java approach.
17 *
18 * Note regarding options for converting WMF files to SVG and/or PNG
19 * (as at Feb 2010):
20
21        - com.adobe.dp.office
22        - wmf2svg
23        - batik
24        - freehep
25        - imagemagick
26        - openoffice
27       
28        wmf2tosvg is a good solution for WMF (although it has no EMF support).
29       
30        For WMF, we'll use it. This can be revisited if/when com.adobe.dp.office
31        improves.
32       
33        (EMF is the real problem - see note in MetafileEmfPart)
34               
35        Batik has WMFTranscoder, but not EMFTranscoder! Even if it did,
36        Batik is best avoided as it is no good on appengine since it uses
37        awt, and spawns threads.
38       
39        imagemagick does a nice job with WMF, but has no support for EMF at all
40        (other than on Windows). So given that we are stuck with a partial
41        solution, its best to use pure Java.
42       
43        For completeness, a note that openoffice can be used to convert EMF
44        and WMF; I found it worked well.       
45
46*/
47public class MetafileWmfPart extends MetafilePart {
48       
49       
50        public MetafileWmfPart(PartName partName) throws InvalidFormatException {
51                super(partName);
52                init();
53        }
54       
55        public MetafileWmfPart(ExternalTarget externalTarget) {
56                super(externalTarget);
57                init();
58        }       
59       
60        public void init() {
61                // Used if this Part is added to [Content_Types].xml
62                setContentType(new  org.docx4j.openpackaging.contenttype.ContentType( 
63                                org.docx4j.openpackaging.contenttype.ContentTypes.IMAGE_WMF));
64
65                // Used when this Part is added to a rels
66                setRelationshipType(Namespaces.IMAGE);
67        }
68       
69       
70        public SvgDocument toSVG() throws Exception {
71               
72                InputStream is = BufferUtil.newInputStream(this.getBuffer() );
73                return new SvgDocument(is);
74                // net.arnx.wmf2svg.Main.output(doc, out);
75               
76        }
77       
78        public static class SvgDocument {
79               
80                Document doc = null;
81                public Document getDomDocument() {
82                        return doc;
83                }
84
85                public SvgDocument(InputStream wmfStream) throws Exception {
86
87                        WmfParser parser = new WmfParser();
88                        SvgGdi gdi = new SvgGdi();
89                        parser.parse(wmfStream, gdi);
90                        doc = gdi.getDocument();
91                }
92               
93               
94               
95        }
96       
97
98}
Note: See TracBrowser for help on using the repository browser.