diff options
author | PJ Fanning <fanningpj@apache.org> | 2022-08-19 08:40:32 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2022-08-19 08:40:32 +0000 |
commit | f1692cc04133c41f584871dd883a7533e904deed (patch) | |
tree | 902a030b4f9aacaa2e95ce3f0b3f7f294cedc6ba | |
parent | 114f8b8fde6caaca093a499c077b556bf6426809 (diff) | |
download | poi-f1692cc04133c41f584871dd883a7533e904deed.tar.gz poi-f1692cc04133c41f584871dd883a7533e904deed.zip |
[bug-65473] when copy slide, new slide uses old textrun object reference. Thanks to FlyingPigQAQ. This closes #371
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903558 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java | 15 | ||||
-rw-r--r-- | poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideShow.java | 23 | ||||
-rw-r--r-- | test-data/slideshow/templatePPTWithOnlyOneText.pptx | bin | 0 -> 33671 bytes |
3 files changed, 20 insertions, 18 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java index c43e0e973a..0eaf4ea775 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java @@ -799,20 +799,11 @@ public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagr thisP.removeFld(i-1); } - try (XmlCursor thisC = thisP.newCursor()) { - thisC.toEndToken(); - try (XmlCursor otherC = otherP.newCursor()) { - otherC.copyXmlContents(thisC); - } - } - for (XSLFTextRun tr : other.getTextRuns()) { - XmlObject xo = tr.getXmlObject(); - XSLFTextRun run = (xo instanceof CTTextLineBreak) - ? newTextRun((CTTextLineBreak)xo) - : newTextRun(xo); + XmlObject xo = tr.getXmlObject().copy(); + XSLFTextRun run = addNewTextRun(); + run.getXmlObject().set(xo); run.copy(tr); - _runs.add(run); } // set properties again, in case we are based on a different diff --git a/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideShow.java b/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideShow.java index c606c4a95a..e66a2bec8d 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideShow.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideShow.java @@ -26,13 +26,9 @@ import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.sl.usermodel.ShapeType; -import org.apache.poi.xslf.usermodel.XMLSlideShow; -import org.apache.poi.xslf.usermodel.XSLFAutoShape; -import org.apache.poi.xslf.usermodel.XSLFBackground; -import org.apache.poi.xslf.usermodel.XSLFRelation; -import org.apache.poi.xslf.usermodel.XSLFSlide; -import org.apache.poi.xslf.usermodel.XSLFSlideShow; +import org.apache.poi.xslf.usermodel.*; import org.apache.xmlbeans.XmlException; +import org.apache.xmlbeans.XmlObject; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -156,4 +152,19 @@ class TestXSLFSlideShow { ppt2.close(); } + + @Test + void testSlideImportContent() throws IOException{ + try (XMLSlideShow ppt = new XMLSlideShow(slTests.openResourceAsStream("templatePPTWithOnlyOneText.pptx"))) { + XSLFSlide templateSlide = ppt.getSlides().get(0); + XSLFTextShape templateTextShape = (XSLFTextShape) templateSlide.getShapes().get(0); + XmlObject templateTextRunXmlObject = templateTextShape.getTextParagraphs().get(0).getTextRuns().get(0).getXmlObject(); + + XSLFSlide copySlide = ppt.createSlide(); + copySlide.importContent(templateSlide); + XSLFTextShape copyTextShape = (XSLFTextShape) copySlide.getShapes().get(0); + XmlObject copyTextRunXmlObject = copyTextShape.getTextParagraphs().get(0).getTextRuns().get(0).getXmlObject(); + assertNotEquals(templateTextRunXmlObject, copyTextRunXmlObject); + } + } } diff --git a/test-data/slideshow/templatePPTWithOnlyOneText.pptx b/test-data/slideshow/templatePPTWithOnlyOneText.pptx Binary files differnew file mode 100644 index 0000000000..7a0e1e70fd --- /dev/null +++ b/test-data/slideshow/templatePPTWithOnlyOneText.pptx |