From 4cf6b5b071f53e884a9ef1cd2fb7c74046fb878d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alain=20B=C3=A9arez?= Date: Mon, 8 Feb 2021 20:34:14 +0000 Subject: [PATCH] Import slide notes when importing slide content git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886338 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/xslf/usermodel/XSLFShape.java | 7 +++++-- .../apache/poi/xslf/usermodel/XSLFSlide.java | 5 +++++ .../poi/xslf/usermodel/TestXSLFNotes.java | 21 +++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) 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(); + } } -- 2.39.5