You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/12/02 10:10:17 UTC

svn commit: r1895487 - in /poi/trunk: poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/ poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/ test-data/slideshow/

Author: fanningpj
Date: Thu Dec  2 10:10:17 2021
New Revision: 1895487

URL: http://svn.apache.org/viewvc?rev=1895487&view=rev
Log:
[bug-65718] Charts imported without blip fills

Added:
    poi/trunk/test-data/slideshow/chart-picture-bg.pptx
    poi/trunk/test-data/slideshow/chart-texture-bg.pptx
Modified:
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
    poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFSheet.java

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java?rev=1895487&r1=1895486&r2=1895487&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java Thu Dec  2 10:10:17 2021
@@ -633,4 +633,36 @@ public class XMLSlideShow extends POIXML
     public List<XSLFFontInfo> getFonts() {
         return XSLFFontInfo.getFonts(this);
     }
+
+    /**
+     * Import a picture data from a document part.
+     *
+     * @param blipId        the ID of the package relationship to retrieve
+     * @param parent        the parent document part containing the data to import
+     * @param target        the target document part to import the data to
+     * @return              the ID of the created relationship
+     */
+    String importBlip(String blipId, POIXMLDocumentPart parent, POIXMLDocumentPart target) {
+        OPCPackage targetPackage = target.getPackagePart().getPackage();
+        if (targetPackage != getPackage()) {
+            throw new RuntimeException("the target document part is not a child of this package");
+        }
+        final POIXMLDocumentPart docPart = parent.getRelationPartById(blipId).getDocumentPart();
+        XSLFPictureData parData;
+        if (docPart instanceof XSLFPictureData) {
+            parData = (XSLFPictureData)docPart;
+        } else {
+            throw new RuntimeException("cannot import blip " + blipId + " - its document part is not XSLFPictureData");
+        }
+        final XSLFPictureData pictureData;
+        if (targetPackage == parent.getPackagePart().getPackage()) {
+            // handle ref counter correct, if the parent document is the same as this
+            pictureData = parData;
+        } else {
+            pictureData = addPicture(parData.getData(), parData.getType());
+        }
+
+        RelationPart rp = target.addRelation(null, XSLFRelation.IMAGES, pictureData);
+        return rp.getRelationship().getId();
+    }
 }

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java?rev=1895487&r1=1895486&r2=1895487&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java Thu Dec  2 10:10:17 2021
@@ -40,11 +40,13 @@ import org.apache.poi.util.Units;
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlObject;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;
 
@@ -235,6 +237,18 @@ public class XSLFGraphicFrame extends XS
                 chartCopy.importContent(srcChart);
                 chartCopy.setWorkbook(srcChart.getWorkbook());
                 c.setAttributeText(idQualifiedName, slide.getRelationId(chartCopy));
+
+                // duplicate the blip fill if set
+                CTChartSpace chartSpaceCopy = chartCopy.getCTChartSpace();
+                if (chartSpaceCopy != null) {
+                    XSLFPropertiesDelegate.XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(chartSpaceCopy.getSpPr());
+                    if (fp != null && fp.isSetBlipFill()) {
+                        CTBlip blip = fp.getBlipFill().getBlip();
+                        String blipId = blip.getEmbed();
+                        String relId = slide.getSlideShow().importBlip(blipId, srcChart, chartCopy);
+                        blip.setEmbed(relId);
+                    }
+                }
             } catch (InvalidFormatException | IOException e) {
                 throw new POIXMLException(e);
             }

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSheet.java?rev=1895487&r1=1895486&r2=1895487&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSheet.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSheet.java Thu Dec  2 10:10:17 2021
@@ -648,24 +648,7 @@ implements XSLFShapeContainer, Sheet<XSL
      * @return ID of the created relationship
      */
     String importBlip(String blipId, POIXMLDocumentPart parent) {
-        final POIXMLDocumentPart docPart = parent.getRelationPartById(blipId).getDocumentPart();
-        XSLFPictureData parData;
-        if (docPart instanceof XSLFPictureData) {
-            parData = (XSLFPictureData)docPart;
-        } else {
-            throw new RuntimeException("cannot import blip " + blipId + " - document part is not XSLFPictureData type");
-        }
-        final XSLFPictureData pictureData;
-        if (getPackagePart().getPackage() == parent.getPackagePart().getPackage()) {
-            // handle ref counter correct, if the parent document is the same as this
-            pictureData = parData;
-        } else {
-            XMLSlideShow ppt = getSlideShow();
-            pictureData = ppt.addPicture(parData.getData(), parData.getType());
-        }
-
-        RelationPart rp = addRelation(null, XSLFRelation.IMAGES, pictureData);
-        return rp.getRelationship().getId();
+        return getSlideShow().importBlip(blipId, parent, this);
     }
 
     /**

Modified: poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFSheet.java?rev=1895487&r1=1895486&r2=1895487&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFSheet.java (original)
+++ poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFSheet.java Thu Dec  2 10:10:17 2021
@@ -89,6 +89,32 @@ class TestXSLFSheet {
                 assertNotNull(((XSLFGraphicFrame) shape1).getChart(), "chart found in slide1?");
             }
         }
+
+        // test importing charts with blip fills
+        try (
+            XMLSlideShow textureSlideShow = openSampleDocument("chart-texture-bg.pptx");
+            XMLSlideShow pictureSlideShow = openSampleDocument("chart-picture-bg.pptx");
+        ) {
+            XMLSlideShow[] sourceSlideShows = new XMLSlideShow[] { textureSlideShow, pictureSlideShow };
+            XMLSlideShow targetSlideShow = textureSlideShow;
+            for (XMLSlideShow sourceSlideShow : sourceSlideShows) {
+                Boolean sameSlideShow = sourceSlideShow == targetSlideShow;
+                String assertMessage = "importing charts " + (sameSlideShow ? "within the same slide show" : "from another slideshow") + ": ";
+                XSLFSlide sourceSlide = sourceSlideShow.getSlides().get(0);
+                XSLFSlide slide = targetSlideShow.createSlide();
+                slide.importContent(sourceSlide);
+
+                XSLFShape shape = slide.getShapes().get(0);
+                assertNotNull(shape, assertMessage + "the shape is not copied");
+                assertInstanceOf(XSLFGraphicFrame.class, shape, assertMessage + "the shape is not XSLFGraphicFrame");
+
+                XSLFChart chart = ((XSLFGraphicFrame) shape).getChart();
+                assertNotNull(chart, assertMessage + "the shape doesn't have the chart");
+
+                String blipId1 = chart.getCTChartSpace().getSpPr().getBlipFill().getBlip().getEmbed();
+                assertNotNull(slide.getRelationById(blipId1), assertMessage + "the shape chart doesn't have the blip fill");
+            }
+        }
     }
 
 }
\ No newline at end of file

Added: poi/trunk/test-data/slideshow/chart-picture-bg.pptx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/slideshow/chart-picture-bg.pptx?rev=1895487&view=auto
==============================================================================
Binary files poi/trunk/test-data/slideshow/chart-picture-bg.pptx (added) and poi/trunk/test-data/slideshow/chart-picture-bg.pptx Thu Dec  2 10:10:17 2021 differ

Added: poi/trunk/test-data/slideshow/chart-texture-bg.pptx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/slideshow/chart-texture-bg.pptx?rev=1895487&view=auto
==============================================================================
Binary files poi/trunk/test-data/slideshow/chart-texture-bg.pptx (added) and poi/trunk/test-data/slideshow/chart-texture-bg.pptx Thu Dec  2 10:10:17 2021 differ



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org