]> source.dussan.org Git - poi.git/commitdiff
add basic support for hdphoto/wdp images in slideshows
authorPJ Fanning <fanningpj@apache.org>
Fri, 27 Aug 2021 17:33:39 +0000 (17:33 +0000)
committerPJ Fanning <fanningpj@apache.org>
Fri, 27 Aug 2021 17:33:39 +0000 (17:33 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1892653 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackageRelationshipTypes.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFRelation.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFBugs.java
test-data/slideshow/bug65523.pptx [new file with mode: 0644]

index c328849e0839e725bd76574f4bf71263ffbbec9d..b5a13f875bde8ccfcaf1242e91316dbb5d66901d 100644 (file)
@@ -101,6 +101,11 @@ public interface PackageRelationshipTypes {
      */
     String IMAGE_PART = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
 
+    /**
+     * hdphoto type.
+     */
+    String HDPHOTO_PART = "http://schemas.microsoft.com/office/2007/relationships/hdphoto";
+
     /**
      * Hyperlink type.
      */
index 5139e6278ce52506af24c41db217fd6567729211..19d0c3d10f66f4cbd40bf4a4ff4e60a544296cbd 100644 (file)
@@ -16,6 +16,7 @@
 ==================================================================== */
 package org.apache.poi.xslf.usermodel;
 
+import static org.apache.poi.openxml4j.opc.PackageRelationshipTypes.HDPHOTO_PART;
 import static org.apache.poi.openxml4j.opc.PackageRelationshipTypes.IMAGE_PART;
 
 import java.util.HashMap;
@@ -221,7 +222,12 @@ public final class XSLFRelation extends POIXMLRelation {
         "/ppt/media/image#.wdp",
         XSLFPictureData::new, XSLFPictureData::new
     );
-
+    public static final XSLFRelation HDPHOTO_WDP = new XSLFRelation(
+        PictureType.WDP.contentType,
+        HDPHOTO_PART,
+        "/ppt/media/hdphoto#.wdp",
+        XSLFPictureData::new, XSLFPictureData::new
+    );
     public static final XSLFRelation IMAGE_SVG = new XSLFRelation(
         PictureType.SVG.contentType,
         IMAGE_PART,
index 3c367dd9bb8f0f7ea4bedba6ffffb3638ec62686..47be24663afabe85cdd1c0cef82096816472694a 100644 (file)
@@ -648,7 +648,13 @@ implements XSLFShapeContainer, Sheet<XSLFShape,XSLFTextParagraph> {
      * @return ID of the created relationship
      */
     String importBlip(String blipId, POIXMLDocumentPart parent) {
-        final XSLFPictureData parData = parent.getRelationPartById(blipId).getDocumentPart();
+        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
index 5b239a8ad645b3dfcea5574206b2f0c9c1f9f092..a87738d08684e56117893a5a513a5a67b3d0da7b 100644 (file)
@@ -32,9 +32,7 @@ import static org.junit.jupiter.api.Assumptions.assumeFalse;
 
 import java.awt.Color;
 import java.awt.geom.Rectangle2D;
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.URI;
 import java.text.AttributedCharacterIterator;
 import java.text.AttributedCharacterIterator.Attribute;
@@ -49,6 +47,7 @@ import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.common.usermodel.HyperlinkType;
 import org.apache.poi.ooxml.POIXMLDocumentPart;
@@ -75,7 +74,6 @@ import org.apache.poi.sl.usermodel.SlideShowFactory;
 import org.apache.poi.sl.usermodel.TextRun;
 import org.apache.poi.sl.usermodel.TextShape;
 import org.apache.poi.sl.usermodel.VerticalAlignment;
-import org.apache.poi.util.IOUtils;
 import org.apache.commons.io.output.NullPrintStream;
 import org.apache.poi.xslf.usermodel.*;
 import org.apache.poi.xslf.util.DummyGraphics2d;
@@ -1044,4 +1042,21 @@ class TestXSLFBugs {
             assertEquals(TextRun.TextCap.ALL, act);
         }
     }
+
+    @Test
+    public void bug65523() throws IOException {
+        try (XMLSlideShow sourcePresentation = openSampleDocument("bug65523.pptx")) {
+            XMLSlideShow targetPresentation = new XMLSlideShow();
+            XSLFSlide targetPresentationSlide = targetPresentation.createSlide();
+
+            XSLFSlide sourceSlide = sourcePresentation.getSlides().get(0);
+
+            targetPresentationSlide.getSlideMaster().importContent(sourceSlide.getSlideMaster());
+            targetPresentationSlide.getSlideLayout().importContent(sourceSlide.getSlideLayout());
+
+            targetPresentationSlide.importContent(sourceSlide);
+
+            targetPresentation.write(new UnsynchronizedByteArrayOutputStream());
+        }
+    }
 }
diff --git a/test-data/slideshow/bug65523.pptx b/test-data/slideshow/bug65523.pptx
new file mode 100644 (file)
index 0000000..3d737d7
Binary files /dev/null and b/test-data/slideshow/bug65523.pptx differ