Bug 65935 - removed textruns remain visible in slideshow
Summary: removed textruns remain visible in slideshow
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSLF (show other bugs)
Version: 5.2.0-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-03-07 08:28 UTC by bugzilla-apache
Modified: 2022-03-12 10:14 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bugzilla-apache 2022-03-07 08:28:38 UTC
When a textrun is deleted, programmatically it seems as if the deletion has been applied. However, the textrun is still visible in the slide of the slideshow. (The same problem occurs with textparagraphs, cf. another filed bug 65934.)

Steps to reproduce:

  @Test
  void removeTextRun() throws IOException {
    final XMLSlideShow ppt = new XMLSlideShow();

    final XSLFSlide slide = ppt.createSlide();;

    final XSLFTextBox textBox = slide.createTextBox();
    textBox.setAnchor(new Rectangle(0,0,250,100));

    final XSLFTextParagraph textParagraph = textBox.getTextParagraphs().get(0);

    textParagraph.getTextRuns().get(0).setText("lorem ");
    textParagraph.addNewTextRun().setText("ipsum ");
    textParagraph.addNewTextRun().setText("dolor");

    assertEquals(1, textBox.getTextParagraphs().size());
    assertEquals(3, textBox.getTextParagraphs().get(0).getTextRuns().size());

    assertEquals("lorem ipsum dolor", textBox.getText());
    assertEquals("lorem ipsum dolor", textBox.getTextParagraphs().get(0).getText());
    assertEquals("lorem ", textBox.getTextParagraphs().get(0).getTextRuns().get(0).getRawText());
    assertEquals("ipsum ", textBox.getTextParagraphs().get(0).getTextRuns().get(1).getRawText());
    assertEquals("dolor", textBox.getTextParagraphs().get(0).getTextRuns().get(2).getRawText());

    textBox.getTextParagraphs().get(0).getTextRuns().remove(textBox.getTextParagraphs().get(0).getTextRuns().get(1));

    assertEquals(1, textBox.getTextParagraphs().size());
    assertEquals(2, textBox.getTextParagraphs().get(0).getTextRuns().size());

    assertEquals("lorem dolor", textBox.getText());
    assertEquals("lorem dolor", textBox.getTextParagraphs().get(0).getText());
    assertEquals("lorem ", textBox.getTextParagraphs().get(0).getTextRuns().get(0).getRawText());
    assertEquals("dolor", textBox.getTextParagraphs().get(0).getTextRuns().get(1).getRawText());

    String filepath = System.getProperty("java.io.tmpdir") + "tmp.pptx";

    FileOutputStream fos = new FileOutputStream(filepath);
    ppt.write(fos);

    fos.close();

    System.out.println("file written to " + filepath);
  }
Comment 1 PJ Fanning 2022-03-07 11:05:32 UTC
added r1898672
Comment 2 bugzilla-apache 2022-03-09 10:05:12 UTC
I was able to verify that the change works.

The above test initially failed with an UnsupportedOperationException. Great idea to change the list of textruns to Collections.unmodifiableList. :-)

After replacing the line

  textBox.getTextParagraphs().get(0).getTextRuns().remove(textBox.getTextParagraphs().get(0).getTextRuns().get(1));

with

  textBox.getTextParagraphs().get(0).removeTextRun(textBox.getTextParagraphs().get(0).getTextRuns().get(1));

the test passed again and the slide finally looks as expected.

Thanks for fixing the issue!