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

(-)a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFSheet.java (+26 lines)
Lines 89-94 Link Here
89
                assertNotNull(((XSLFGraphicFrame) shape1).getChart(), "chart found in slide1?");
89
                assertNotNull(((XSLFGraphicFrame) shape1).getChart(), "chart found in slide1?");
90
            }
90
            }
91
        }
91
        }
92
93
        // test importing charts with blip fills
94
        try (
95
            XMLSlideShow textureSlideShow = openSampleDocument("chart-texture-bg.pptx");
96
            XMLSlideShow pictureSlideShow = openSampleDocument("chart-picture-bg.pptx");
97
        ) {
98
            XMLSlideShow[] sourceSlideShows = new XMLSlideShow[] { textureSlideShow, pictureSlideShow };
99
            XMLSlideShow targetSlideShow = textureSlideShow;
100
            for (XMLSlideShow sourceSlideShow : sourceSlideShows) {
101
                Boolean sameSlideShow = sourceSlideShow == targetSlideShow;
102
                String assertMessage = "importing charts " + (sameSlideShow ? "within the same slide show" : "from another slideshow") + ": ";
103
                XSLFSlide sourceSlide = sourceSlideShow.getSlides().get(0);
104
                XSLFSlide slide = targetSlideShow.createSlide();
105
                slide.importContent(sourceSlide);
106
107
                XSLFShape shape = slide.getShapes().get(0);
108
                assertNotNull(shape, assertMessage + "the shape is not copied");
109
                assertInstanceOf(XSLFGraphicFrame.class, shape, assertMessage + "the shape is not XSLFGraphicFrame");
110
111
                XSLFChart chart = ((XSLFGraphicFrame) shape).getChart();
112
                assertNotNull(chart, assertMessage + "the shape doesn't have the chart");
113
114
                String blipId1 = chart.getCTChartSpace().getSpPr().getBlipFill().getBlip().getEmbed();
115
                assertNotNull(slide.getRelationById(blipId1), assertMessage + "the shape chart doesn't have the blip fill");
116
            }
117
        }
92
    }
118
    }
93
119
94
}
120
}
(-)a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java (+32 lines)
Lines 633-636 Link Here
633
    public List<XSLFFontInfo> getFonts() {
633
    public List<XSLFFontInfo> getFonts() {
634
        return XSLFFontInfo.getFonts(this);
634
        return XSLFFontInfo.getFonts(this);
635
    }
635
    }
636
637
    /**
638
     * Import a picture data from a document part.
639
     *
640
     * @param blipId        the ID of the package relationship to retrieve
641
     * @param parent        the parent document part containing the data to import
642
     * @param target        the target document part to import the data to
643
     * @return              the ID of the created relationship
644
     */
645
    String importBlip(String blipId, POIXMLDocumentPart parent, POIXMLDocumentPart target) {
646
        OPCPackage targetPackage = target.getPackagePart().getPackage();
647
        if (targetPackage != getPackage()) {
648
            throw new RuntimeException("the target document part is not a child of this package");
649
        }
650
        final POIXMLDocumentPart docPart = parent.getRelationPartById(blipId).getDocumentPart();
651
        XSLFPictureData parData;
652
        if (docPart instanceof XSLFPictureData) {
653
            parData = (XSLFPictureData)docPart;
654
        } else {
655
            throw new RuntimeException("cannot import blip " + blipId + " - its document part is not XSLFPictureData");
656
        }
657
        final XSLFPictureData pictureData;
658
        if (targetPackage == parent.getPackagePart().getPackage()) {
659
            // handle ref counter correct, if the parent document is the same as this
660
            pictureData = parData;
661
        } else {
662
            pictureData = addPicture(parData.getData(), parData.getType());
663
        }
664
665
        RelationPart rp = target.addRelation(null, XSLFRelation.IMAGES, pictureData);
666
        return rp.getRelationship().getId();
667
    }
636
}
668
}
(-)a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java (+14 lines)
Lines 40-50 Link Here
40
import org.apache.xmlbeans.XmlCursor;
40
import org.apache.xmlbeans.XmlCursor;
41
import org.apache.xmlbeans.XmlException;
41
import org.apache.xmlbeans.XmlException;
42
import org.apache.xmlbeans.XmlObject;
42
import org.apache.xmlbeans.XmlObject;
43
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace;
43
import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject;
44
import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject;
44
import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData;
45
import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData;
45
import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
46
import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
46
import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
47
import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
47
import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
48
import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
49
import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip;
48
import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
50
import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
49
import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;
51
import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;
50
52
Lines 235-240 Link Here
235
                chartCopy.importContent(srcChart);
237
                chartCopy.importContent(srcChart);
236
                chartCopy.setWorkbook(srcChart.getWorkbook());
238
                chartCopy.setWorkbook(srcChart.getWorkbook());
237
                c.setAttributeText(idQualifiedName, slide.getRelationId(chartCopy));
239
                c.setAttributeText(idQualifiedName, slide.getRelationId(chartCopy));
240
241
                // duplicate the blip fill if set
242
                CTChartSpace chartSpaceCopy = chartCopy.getCTChartSpace();
243
                if (chartSpaceCopy != null) {
244
                    XSLFPropertiesDelegate.XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(chartSpaceCopy.getSpPr());
245
                    if (fp != null && fp.isSetBlipFill()) {
246
                        CTBlip blip = fp.getBlipFill().getBlip();
247
                        String blipId = blip.getEmbed();
248
                        String relId = slide.getSlideShow().importBlip(blipId, srcChart, chartCopy);
249
                        blip.setEmbed(relId);
250
                    }
251
                }
238
            } catch (InvalidFormatException | IOException e) {
252
            } catch (InvalidFormatException | IOException e) {
239
                throw new POIXMLException(e);
253
                throw new POIXMLException(e);
240
            }
254
            }
(-)a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSheet.java (-18 / +1 lines)
Lines 648-671 Link Here
648
     * @return ID of the created relationship
648
     * @return ID of the created relationship
649
     */
649
     */
650
    String importBlip(String blipId, POIXMLDocumentPart parent) {
650
    String importBlip(String blipId, POIXMLDocumentPart parent) {
651
        final POIXMLDocumentPart docPart = parent.getRelationPartById(blipId).getDocumentPart();
651
        return getSlideShow().importBlip(blipId, parent, this);
652
        XSLFPictureData parData;
653
        if (docPart instanceof XSLFPictureData) {
654
            parData = (XSLFPictureData)docPart;
655
        } else {
656
            throw new RuntimeException("cannot import blip " + blipId + " - document part is not XSLFPictureData type");
657
        }
658
        final XSLFPictureData pictureData;
659
        if (getPackagePart().getPackage() == parent.getPackagePart().getPackage()) {
660
            // handle ref counter correct, if the parent document is the same as this
661
            pictureData = parData;
662
        } else {
663
            XMLSlideShow ppt = getSlideShow();
664
            pictureData = ppt.addPicture(parData.getData(), parData.getType());
665
        }
666
667
        RelationPart rp = addRelation(null, XSLFRelation.IMAGES, pictureData);
668
        return rp.getRelationship().getId();
669
    }
652
    }
670
653
671
    /**
654
    /**

Return to bug 65718