View | Details | Raw Unified | Return to bug 62365
Collapse All | Expand All

(-)a/build.xml (-1 / +3 lines)
Lines 52-57 under the License. Link Here
52
    <property name="ooxml.lib" location="ooxml-lib"/>
52
    <property name="ooxml.lib" location="ooxml-lib"/>
53
    <property name="compile.lib" location="compile-lib"/>
53
    <property name="compile.lib" location="compile-lib"/>
54
    <property name="forrest.home" value="${env.FORREST_HOME}"/>
54
    <property name="forrest.home" value="${env.FORREST_HOME}"/>
55
	<property name="batik.dir" location="/Volumes/Neumann/Users/ritesh/local/share/java/batik-1.9"/>
55
56
56
    <!-- compiler options options -->
57
    <!-- compiler options options -->
57
    <property name="jdk.version.source" value="1.8" description="JDK version of source code"/>
58
    <property name="jdk.version.source" value="1.8" description="JDK version of source code"/>
Lines 264-270 under the License. Link Here
264
    <property name="build.site.src" location="build/tmp/site"/>
265
    <property name="build.site.src" location="build/tmp/site"/>
265
    <property name="apidocs.report.dir" location="${build.site}/apidocs"/>
266
    <property name="apidocs.report.dir" location="${build.site}/apidocs"/>
266
    <property name="dist.dir" location="build/dist"/>
267
    <property name="dist.dir" location="build/dist"/>
267
    <property name="halt.on.test.failure" value="true"/>
268
    <property name="halt.on.test.failure" value="false"/>
268
269
269
    <!-- helper jars for pgp signing, building and nexus staging -->
270
    <!-- helper jars for pgp signing, building and nexus staging -->
270
    <property name="dist.bouncycastle-prov.jar" location="${compile.lib}/bcprov-ext-jdk15on-1.59.jar"/>
271
    <property name="dist.bouncycastle-prov.jar" location="${compile.lib}/bcprov-ext-jdk15on-1.59.jar"/>
Lines 324-329 under the License. Link Here
324
        <pathelement location="${main.commons-codec.jar}"/>
325
        <pathelement location="${main.commons-codec.jar}"/>
325
        <pathelement location="${main.commons-collections4.jar}"/>
326
        <pathelement location="${main.commons-collections4.jar}"/>
326
        <pathelement location="${main.commons-math3.jar}"/>
327
        <pathelement location="${main.commons-math3.jar}"/>
328
		<fileset dir="${batik.dir}" includes="**/*.jar"/>
327
    </path>
329
    </path>
328
330
329
    <!-- some libraries should only be required for compiling/running tests -->
331
    <!-- some libraries should only be required for compiling/running tests -->
(-)a/src/java/org/apache/poi/sl/usermodel/PictureData.java (-2 / +4 lines)
Lines 46-52 public interface PictureData { Link Here
46
        /** WordPerfect graphics (.wpg) */
46
        /** WordPerfect graphics (.wpg) */
47
        WPG(-1,12,"image/x-wpg",".wpg"),
47
        WPG(-1,12,"image/x-wpg",".wpg"),
48
        /** Microsoft Windows Media Photo image (.wdp) */
48
        /** Microsoft Windows Media Photo image (.wdp) */
49
        WDP(-1,13,"image/vnd.ms-photo",".wdp");
49
        WDP(-1,13,"image/vnd.ms-photo",".wdp"),
50
        /** Scalable Vector Graphics (.svg) */
51
        SVG(14,14,"image/svg+xml",".svg");
50
        
52
        
51
        public final int nativeId, ooxmlId;
53
        public final int nativeId, ooxmlId;
52
        public final String contentType,extension;
54
        public final String contentType,extension;
Lines 118-121 public interface PictureData { Link Here
118
     * @see PictureData#getImageDimension()
120
     * @see PictureData#getImageDimension()
119
     */
121
     */
120
	Dimension getImageDimensionInPixels();
122
	Dimension getImageDimensionInPixels();
121
}
123
}
(-)a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java (-2 / +2 lines)
Lines 105-113 public class XSLFDrawing { Link Here
105
        return shape;
105
        return shape;
106
    }
106
    }
107
107
108
    public XSLFPictureShape createPicture(String rel){
108
    public XSLFPictureShape createPicture(String rel, String rel2){
109
        CTPicture obj = _spTree.addNewPic();
109
        CTPicture obj = _spTree.addNewPic();
110
        obj.set(XSLFPictureShape.prototype(_shapeId++, rel));
110
        obj.set(XSLFPictureShape.prototype(_shapeId++, rel, rel2));
111
        XSLFPictureShape shape = new XSLFPictureShape(obj, _sheet);
111
        XSLFPictureShape shape = new XSLFPictureShape(obj, _sheet);
112
        shape.setAnchor(new Rectangle2D.Double());
112
        shape.setAnchor(new Rectangle2D.Double());
113
        return shape;
113
        return shape;
(-)a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java (-2 / +3 lines)
Lines 269-276 implements XSLFShapeContainer, GroupShape<XSLFShape,XSLFTextParagraph> { Link Here
269
269
270
        PackageRelationship rel = getSheet().getPackagePart().addRelationship(
270
        PackageRelationship rel = getSheet().getPackagePart().addRelationship(
271
                pic.getPartName(), TargetMode.INTERNAL, XSLFRelation.IMAGES.getRelation());
271
                pic.getPartName(), TargetMode.INTERNAL, XSLFRelation.IMAGES.getRelation());
272
272
        
273
        XSLFPictureShape sh = getDrawing().createPicture(rel.getId());
273
        String relId2 = null;
274
        XSLFPictureShape sh = getDrawing().createPicture(rel.getId(), relId2);
274
        new DrawPictureShape(sh).resize();
275
        new DrawPictureShape(sh).resize();
275
        _shapes.add(sh);
276
        _shapes.add(sh);
276
        sh.setParent(this);
277
        sh.setParent(this);
(-)a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java (-1 / +4 lines)
Lines 218-223 public final class XSLFPictureData extends POIXMLDocumentPart implements Picture Link Here
218
            return PictureType.WDP;
218
            return PictureType.WDP;
219
        } else if (XSLFRelation.IMAGE_TIFF.getContentType().equals(ct)) {
219
        } else if (XSLFRelation.IMAGE_TIFF.getContentType().equals(ct)) {
220
            return PictureType.TIFF;
220
            return PictureType.TIFF;
221
        } else if (XSLFRelation.IMAGE_SVG.getContentType().equals(ct)) {
222
            return PictureType.SVG;
221
        } else {
223
        } else {
222
            return null;
224
            return null;
223
        }
225
        }
Lines 237-242 public final class XSLFPictureData extends POIXMLDocumentPart implements Picture Link Here
237
            case WPG: return XSLFRelation.IMAGE_WPG;
239
            case WPG: return XSLFRelation.IMAGE_WPG;
238
            case WDP: return XSLFRelation.IMAGE_WDP;
240
            case WDP: return XSLFRelation.IMAGE_WDP;
239
            case TIFF: return XSLFRelation.IMAGE_TIFF;
241
            case TIFF: return XSLFRelation.IMAGE_TIFF;
242
            case SVG: return XSLFRelation.IMAGE_SVG;
240
            default: return null;
243
            default: return null;
241
        }
244
        }
242
    }
245
    }
Lines 254-257 public final class XSLFPictureData extends POIXMLDocumentPart implements Picture Link Here
254
    public void setIndex(int index) {
257
    public void setIndex(int index) {
255
        this.index = index;
258
        this.index = index;
256
    }
259
    }
257
}
260
}
(-)a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java (-3 / +57 lines)
Lines 35-40 import org.apache.xmlbeans.XmlException; Link Here
35
import org.apache.xmlbeans.XmlObject;
35
import org.apache.xmlbeans.XmlObject;
36
import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip;
36
import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip;
37
import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties;
37
import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties;
38
import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData;
38
import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
39
import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
39
import org.openxmlformats.schemas.drawingml.x2006.main.CTOfficeArtExtension;
40
import org.openxmlformats.schemas.drawingml.x2006.main.CTOfficeArtExtension;
40
import org.openxmlformats.schemas.drawingml.x2006.main.CTOfficeArtExtensionList;
41
import org.openxmlformats.schemas.drawingml.x2006.main.CTOfficeArtExtensionList;
Lines 43-57 import org.openxmlformats.schemas.drawingml.x2006.main.CTRelativeRect; Link Here
43
import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
44
import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
44
import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType;
45
import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType;
45
import org.openxmlformats.schemas.presentationml.x2006.main.CTApplicationNonVisualDrawingProps;
46
import org.openxmlformats.schemas.presentationml.x2006.main.CTApplicationNonVisualDrawingProps;
47
import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
48
import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrameNonVisual;
46
import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;
49
import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;
47
import org.openxmlformats.schemas.presentationml.x2006.main.CTPictureNonVisual;
50
import org.openxmlformats.schemas.presentationml.x2006.main.CTPictureNonVisual;
48
51
52
53
49
/**
54
/**
50
 * Represents a picture shape
55
 * Represents a picture shape
51
 */
56
 */
52
@Beta
57
@Beta
53
public class XSLFPictureShape extends XSLFSimpleShape
58
public class XSLFPictureShape extends XSLFSimpleShape
54
    implements PictureShape<XSLFShape,XSLFTextParagraph> {
59
    implements PictureShape<XSLFShape,XSLFTextParagraph> {
60
    
61
    /* package */ static final String SVG_URI = "http://schemas.microsoft.com/office/drawing/2016/SVG/main";
62
    /* package */ static final String REL_URI = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
63
    /* package */ static final String DML_URI = "http://schemas.microsoft.com/office/drawing/2010/main";
64
    
55
    private XSLFPictureData _data;
65
    private XSLFPictureData _data;
56
66
57
    /*package*/ XSLFPictureShape(CTPicture shape, XSLFSheet sheet) {
67
    /*package*/ XSLFPictureShape(CTPicture shape, XSLFSheet sheet) {
Lines 63-69 public class XSLFPictureShape extends XSLFSimpleShape Link Here
63
     * @param shapeId 1-based shapeId
73
     * @param shapeId 1-based shapeId
64
     * @param rel     relationship to the picture data in the ooxml package
74
     * @param rel     relationship to the picture data in the ooxml package
65
     */
75
     */
66
    static CTPicture prototype(int shapeId, String rel) {
76
    static CTPicture prototype(int shapeId, String rel, String rel2) {
77
        
78
        CTGraphicalObjectFrame frame = CTGraphicalObjectFrame.Factory.newInstance();
79
        CTGraphicalObjectFrameNonVisual nvGr = frame.addNewNvGraphicFramePr();
80
81
        // add empty property elements otherwise Powerpoint doesn't load the file ...
82
        nvGr.addNewCNvGraphicFramePr();
83
        nvGr.addNewNvPr();
84
        
67
        CTPicture ct = CTPicture.Factory.newInstance();
85
        CTPicture ct = CTPicture.Factory.newInstance();
68
        CTPictureNonVisual nvSpPr = ct.addNewNvPicPr();
86
        CTPictureNonVisual nvSpPr = ct.addNewNvPicPr();
69
        CTNonVisualDrawingProps cnv = nvSpPr.addNewCNvPr();
87
        CTNonVisualDrawingProps cnv = nvSpPr.addNewCNvPr();
Lines 74-80 public class XSLFPictureShape extends XSLFSimpleShape Link Here
74
92
75
        CTBlipFillProperties blipFill = ct.addNewBlipFill();
93
        CTBlipFillProperties blipFill = ct.addNewBlipFill();
76
        CTBlip blip = blipFill.addNewBlip();
94
        CTBlip blip = blipFill.addNewBlip();
77
        blip.setEmbed(rel);
95
        
96
        /*
97
        frame.addNewXfrm();
98
        CTGraphicalObjectData gr = frame.addNewGraphic().addNewGraphicData();
99
        gr.setUri(SVG_URI);
100
        XmlCursor grCur = gr.newCursor();
101
        grCur.toEndToken();
102
        grCur.beginElement(new QName(SVG_URI, "svgBlip", "asvg"));
103
        grCur.insertAttributeWithValue(new QName(PML_NS, "embed", "r"), "rID3");
104
         */
105
                
106
        if (rel2 == null) {
107
            blip.setEmbed(rel);
108
        }
109
        else {
110
            blip.setEmbed(rel2);
111
            // add PNG and SVG          
112
            CTOfficeArtExtensionList extLst =  blip.addNewExtLst();
113
            
114
            // add PNG          
115
            CTOfficeArtExtension ext =  extLst.addNewExt();
116
            ext.setUri("{28A0092B-C50C-407E-A947-70E740481C1C}");
117
            XmlCursor cur = ext.newCursor();
118
            cur.toEndToken();
119
            cur.beginElement(new QName(DML_URI, "useLocalDpi", "a14"));
120
            cur.insertAttributeWithValue("val", "0");
121
            
122
            // add SVG image         
123
            ext =  extLst.addNewExt();
124
            ext.setUri("{96DAC541-7B7A-43D3-8B79-37D633B846F1}");
125
            cur = ext.newCursor();
126
            cur.toEndToken();
127
            cur.beginElement(new QName(SVG_URI, "svgBlip", "asvg"));
128
            cur.insertAttributeWithValue(new QName(REL_URI, "embed", "rel"), rel);
129
        }
130
       
78
        blipFill.addNewStretch().addNewFillRect();
131
        blipFill.addNewStretch().addNewFillRect();
79
132
80
        CTShapeProperties spPr = ct.addNewSpPr();
133
        CTShapeProperties spPr = ct.addNewSpPr();
Lines 84-90 public class XSLFPictureShape extends XSLFSimpleShape Link Here
84
        return ct;
137
        return ct;
85
    }
138
    }
86
139
87
140
    
141
    
88
    /**
142
    /**
89
     * Is this an internal picture (image data included within
143
     * Is this an internal picture (image data included within
90
     *  the PowerPoint file), or an external linked picture
144
     *  the PowerPoint file), or an external linked picture
(-)a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java (+6 lines)
Lines 207-212 public class XSLFRelation extends POIXMLRelation { Link Here
207
            "/ppt/media/image#.eps",
207
            "/ppt/media/image#.eps",
208
            XSLFPictureData.class
208
            XSLFPictureData.class
209
    );
209
    );
210
    public static final XSLFRelation IMAGE_SVG = new XSLFRelation(
211
            PictureType.SVG.contentType,
212
            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
213
            "/ppt/media/image#.svg",
214
            XSLFPictureData.class
215
    );
210
    public static final XSLFRelation IMAGE_BMP = new XSLFRelation(
216
    public static final XSLFRelation IMAGE_BMP = new XSLFRelation(
211
            PictureType.BMP.contentType,
217
            PictureType.BMP.contentType,
212
            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
218
            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
(-)a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java (-3 / +84 lines)
Lines 24-29 import java.awt.Graphics2D; Link Here
24
import java.io.IOException;
24
import java.io.IOException;
25
import java.io.InputStream;
25
import java.io.InputStream;
26
import java.io.OutputStream;
26
import java.io.OutputStream;
27
import java.io.ByteArrayOutputStream;
27
import java.util.ArrayList;
28
import java.util.ArrayList;
28
import java.util.HashMap;
29
import java.util.HashMap;
29
import java.util.Iterator;
30
import java.util.Iterator;
Lines 31-36 import java.util.List; Link Here
31
import java.util.Map;
32
import java.util.Map;
32
import java.util.Optional;
33
import java.util.Optional;
33
34
35
import org.apache.batik.transcoder.image.JPEGTranscoder;
36
import org.apache.batik.transcoder.image.PNGTranscoder;
37
import org.apache.batik.transcoder.TranscoderInput;
38
import org.apache.batik.transcoder.TranscoderOutput;
39
34
import org.apache.poi.POIXMLDocumentPart;
40
import org.apache.poi.POIXMLDocumentPart;
35
import org.apache.poi.POIXMLException;
41
import org.apache.poi.POIXMLException;
36
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
42
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
Lines 234-249 implements XSLFShapeContainer, Sheet<XSLFShape,XSLFTextParagraph> { Link Here
234
        }
240
        }
235
        XSLFPictureData xPictureData = (XSLFPictureData)pictureData;
241
        XSLFPictureData xPictureData = (XSLFPictureData)pictureData;
236
        PackagePart pic = xPictureData.getPackagePart();
242
        PackagePart pic = xPictureData.getPackagePart();
237
243
        
238
        RelationPart rp = addRelation(null, XSLFRelation.IMAGES, new XSLFPictureData(pic));
244
        RelationPart rp = addRelation(null, XSLFRelation.IMAGES, new XSLFPictureData(pic));
245
        String relId = rp.getRelationship().getId();
246
247
        String relId2 = null;
248
        if (xPictureData.getType() == PictureData.PictureType.SVG) {
249
            // convert SVG to PNG, add to document, and create relationship
250
            
251
            InputStream pd_svg = null;
252
            try {
253
                pd_svg = xPictureData.getInputStream();
254
            } catch (IOException e) {
255
                // TODO Auto-generated catch block
256
                e.printStackTrace();
257
            }
258
            
259
            ByteArrayOutputStream pd_png = new ByteArrayOutputStream();
260
            try {
261
                generateJPEG(pd_svg, pd_png);
262
            } catch (Exception e) {
263
                // TODO Auto-generated catch block
264
                e.printStackTrace();
265
            }
239
266
240
        XSLFPictureShape sh = getDrawing().createPicture(rp.getRelationship().getId());
267
            PictureData pictureData2 = getSlideShow().addPicture(pd_png.toByteArray(), XSLFPictureData.PictureType.PNG); 
268
            XSLFPictureData xPictureData2 = (XSLFPictureData)pictureData2;
269
            PackagePart pic2 = xPictureData2.getPackagePart();
270
            
271
            RelationPart rp2 = addRelation(null, XSLFRelation.IMAGES, new XSLFPictureData(pic2));
272
            relId2 = rp2.getRelationship().getId();
273
        }
274
        
275
                
276
        XSLFPictureShape sh = getDrawing().createPicture(relId, relId2);
241
        new DrawPictureShape(sh).resize();
277
        new DrawPictureShape(sh).resize();
242
        getShapes().add(sh);
278
        getShapes().add(sh);
243
        sh.setParent(this);
279
        sh.setParent(this);
244
        return sh;
280
        return sh;
245
    }
281
    }
246
282
283
    static void generateJPEG(InputStream pd_in, OutputStream pd_out) throws Exception {
284
285
        // Create a JPEG transcoder
286
        JPEGTranscoder t = new JPEGTranscoder();
287
288
        // Set the transcoding hints.
289
        t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,
290
                   new Float(.8));
291
292
        // Create the transcoder input.
293
        TranscoderInput input = new TranscoderInput(pd_in);
294
295
        // Create the transcoder output.
296
        TranscoderOutput output = new TranscoderOutput(pd_out);
297
298
        // Save the image.
299
        t.transcode(input, output);
300
301
        // Flush and close the stream.
302
        pd_out.flush();
303
        pd_out.close();
304
    }
305
306
    static void generatePNG(InputStream pd_in, OutputStream pd_out) throws Exception {
307
308
        // Create a JPEG transcoder
309
        PNGTranscoder t = new PNGTranscoder();
310
311
        // Set the transcoding hints.
312
        //t.addTranscodingHint(PNGTranscoder.KEY_QUALITY,
313
        //           new Float(.8));
314
315
        // Create the transcoder input.
316
        TranscoderInput input = new TranscoderInput(pd_in);
317
318
        // Create the transcoder output.
319
        TranscoderOutput output = new TranscoderOutput(pd_out);
320
321
        // Save the image.
322
        t.transcode(input, output);
323
324
        // Flush and close the stream.
325
        pd_out.flush();
326
        pd_out.close();
327
    }    
328
    
247
    public XSLFTable createTable(){
329
    public XSLFTable createTable(){
248
        XSLFTable sh = getDrawing().createTable();
330
        XSLFTable sh = getDrawing().createTable();
249
        getShapes().add(sh);
331
        getShapes().add(sh);
250
- 

Return to bug 62365