From: Alain BĂ©arez Date: Mon, 8 Feb 2021 20:34:14 +0000 (+0000) Subject: Import slide notes when importing slide content X-Git-Tag: REL_5_1_0~386 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4cf6b5b071f53e884a9ef1cd2fb7c74046fb878d;p=poi.git Import slide notes when importing slide content git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886338 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java index f84e30699e..5a267595e2 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java @@ -143,7 +143,10 @@ public abstract class XSLFShape implements Shape { 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 { protected XmlObject getShapeProperties() { return getChild(CTShapeProperties.class, PML_NS, "spPr"); } -} \ No newline at end of file +} diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java index 1bf2b60fbf..c126afdd7a 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java @@ -295,6 +295,11 @@ implements Slide { 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) { diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFNotes.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFNotes.java index 9b5efa3cf2..526abab2c9 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFNotes.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFNotes.java @@ -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(); + } }