Author: fanningpj
Date: Fri Aug 19 08:40:32 2022
New Revision: 1903558
URL: http://svn.apache.org/viewvc?rev=1903558&view=rev
Log:
[bug-65473] when copy slide, new slide uses old textrun object reference.
Thanks to FlyingPigQAQ. This closes #371
Added:
poi/trunk/test-data/slideshow/templatePPTWithOnlyOneText.pptx (with props)
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideShow.java
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java?rev=1903558&r1=1903557&r2=1903558&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java
(original)
+++
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java
Fri Aug 19 08:40:32 2022
@@ -799,20 +799,11 @@ public class XSLFTextParagraph implement
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
Modified:
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideShow.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideShow.java?rev=1903558&r1=1903557&r2=1903558&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideShow.java
(original)
+++
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideShow.java
Fri Aug 19 08:40:32 2022
@@ -26,13 +26,9 @@ import org.apache.poi.openxml4j.exceptio
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);
+ }
+ }
}
Added: poi/trunk/test-data/slideshow/templatePPTWithOnlyOneText.pptx
URL:
http://svn.apache.org/viewvc/poi/trunk/test-data/slideshow/templatePPTWithOnlyOneText.pptx?rev=1903558&view=auto
==============================================================================
Binary file - no diff available.
Propchange: poi/trunk/test-data/slideshow/templatePPTWithOnlyOneText.pptx
------------------------------------------------------------------------------
--- svn:mime-type (added)
+++ svn:mime-type Fri Aug 19 08:40:32 2022
@@ -0,0 +1 @@
+application/vnd.openxmlformats-officedocument.presentationml.presentation
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]