You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2022/03/07 10:19:13 UTC
svn commit: r1898668 - in /poi/trunk/poi-ooxml/src: main/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java test/java/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java
Author: fanningpj
Date: Mon Mar 7 10:19:13 2022
New Revision: 1898668
URL: http://svn.apache.org/viewvc?rev=1898668&view=rev
Log:
[bug-65934] add removeTextParagraph
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java
Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java?rev=1898668&r1=1898667&r2=1898668&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java Mon Mar 7 10:19:13 2022
@@ -22,6 +22,7 @@ package org.apache.poi.xslf.usermodel;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
@@ -203,9 +204,15 @@ public abstract class XSLFTextShape exte
return run;
}
+ /**
+ * Get the TextParagraphs for this text box. Removing an item from this list will not reliably remove
+ * the item from the underlying document. Use <code>removeTextParagraph</code> for that.
+ *
+ * @return the TextParagraphs for this text box
+ */
@Override
public List<XSLFTextParagraph> getTextParagraphs() {
- return _paragraphs;
+ return Collections.unmodifiableList(_paragraphs);
}
/**
@@ -229,6 +236,29 @@ public abstract class XSLFTextShape exte
return paragraph;
}
+ /**
+ * @param paragraph paragraph to remove
+ * @return whether the paragraph was removed
+ * @since POI 5.2.2
+ */
+ public boolean removeTextParagraph(XSLFTextParagraph paragraph) {
+ CTTextParagraph ctTextParagraph = paragraph.getXmlObject();
+ CTTextBody txBody = getTextBody(false);
+ if (txBody != null) {
+ if (_paragraphs.remove(paragraph)) {
+ for (int i = 0; i < txBody.sizeOfPArray(); i++) {
+ if (txBody.getPArray(i).equals(ctTextParagraph)) {
+ txBody.removeP(i);
+ return true;
+ }
+ }
+ }
+ return false;
+ } else {
+ return false;
+ }
+ }
+
@Override
public void setVerticalAlignment(VerticalAlignment anchor) {
CTTextBodyProperties bodyPr = getTextBodyPr(true);
Modified: poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java?rev=1898668&r1=1898667&r2=1898668&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java (original)
+++ poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java Mon Mar 7 10:19:13 2022
@@ -146,12 +146,33 @@ class TestXSLFTextParagraph {
assertEquals(expectedWidth, dtp.getWrappingWidth(false, null), 0);
ppt.close();
- }
+ }
- /**
- * test breaking test into lines.
- * This test requires that the Arial font is available and will run only on windows
- */
+ @Test
+ void testRemoveTextParagraph() throws IOException {
+ try (XMLSlideShow ppt = new XMLSlideShow()) {
+ XSLFSlide slide = ppt.createSlide();
+ XSLFTextShape sh = slide.createAutoShape();
+ sh.setLineColor(Color.black);
+
+ XSLFTextParagraph p = sh.addNewTextParagraph();
+ p.addNewTextRun().setText(
+ "Paragraph formatting allows for more granular control " +
+ "of text within a shape. Properties here apply to all text " +
+ "residing within the corresponding paragraph.");
+
+ assertTrue(sh.removeTextParagraph(p));
+
+ assertTrue(sh.getTextParagraphs().isEmpty());
+
+ assertEquals(0, sh.getTextBody(true).sizeOfPArray());
+ }
+ }
+
+ /**
+ * test breaking test into lines.
+ * This test requires that the Arial font is available and will run only on windows
+ */
@Test
void testBreakLines() throws IOException {
String os = System.getProperty("os.name");
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org