]> source.dussan.org Git - poi.git/commitdiff
Import slide notes when importing slide content
authorAlain Béarez <abearez@apache.org>
Mon, 8 Feb 2021 20:34:14 +0000 (20:34 +0000)
committerAlain Béarez <abearez@apache.org>
Mon, 8 Feb 2021 20:34:14 +0000 (20:34 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886338 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java
src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFNotes.java

index f84e30699ebb6cef16f3e9fed8926ad15de16598..5a267595e2deec4c36882cacd007df86e6895cb5 100644 (file)
@@ -143,7 +143,10 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
 
         if (this instanceof PlaceableShape) {
             PlaceableShape<?,?> ps = (PlaceableShape<?,?>)this;
-            ps.setAnchor(sh.getAnchor());
+            Rectangle2D anchor = sh.getAnchor();
+            if (anchor != null) {
+                ps.setAnchor(anchor);
+            }
         }
 
 
@@ -485,4 +488,4 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
     protected XmlObject getShapeProperties() {
         return getChild(CTShapeProperties.class, PML_NS, "spPr");
     }
-}
\ No newline at end of file
+}
index 1bf2b60fbfc0aa4895de7c35384cb13f46f78f7e..c126afdd7ad94940ff009d1c5e85c5ecbfd501d7 100644 (file)
@@ -295,6 +295,11 @@ implements Slide<XSLFShape,XSLFTextParagraph> {
             return this;
         }
 
+        XSLFNotes srcNotes = ((XSLFSlide)src).getNotes();
+        if (srcNotes != null) {
+            getSlideShow().getNotesSlide(this).importContent(srcNotes);
+        }
+
         // only copy direct backgrounds - not backgrounds of master sheet
         CTBackground bgOther = ((XSLFSlide)src)._slide.getCSld().getBg();
         if (bgOther == null) {
index 9b5efa3cf240d03a9a793fe1ac62e009f46d1407..526abab2c9c744beb33caf37941e128c54a7c7a0 100644 (file)
@@ -103,4 +103,25 @@ class TestXSLFNotes {
 
         ppt.close();
     }
+
+    @Test
+    void importNotes() throws IOException {
+
+        XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("sample.pptx");
+        XMLSlideShow newShow = new XMLSlideShow();
+
+        for (XSLFSlide slide : ppt.getSlides()) {
+            XSLFNotes slideNotes = slide.getNotes();
+            assertNotNull(slideNotes);
+            XSLFNotes notesSlide = ppt.getNotesSlide(slide);
+            assertNotNull(notesSlide);
+            assertEquals(notesSlide, slideNotes);
+
+            XSLFSlide newSlide = newShow.createSlide().importContent(slide);
+            XSLFNotes newNotes = newSlide.getNotes();
+            assertNotNull(newNotes);
+        }
+
+        ppt.close();
+    }
 }