JoinPortionsWithSameFormatting Carries Over "Err" Flag from First Text Run

Hello Aspose Team!

We’ve been running into an issue with red swiggly underscores (usually a sign of misspelling) in text that we replaced. This seems to be partially an issue on PPT not re-evaluating text eagerly anymore. However while doing a deeper dive and analyzing the XML I noticed that the function

joinPortionsWithSameFormatting();

will carry over the err flag on a TextRun(Portion) properties if it’s present on the first text run being merged.
For example this source XML where the first TextRun has the err flag set:

<a:p>
  <a:r>
    <a:rPr lang="en-US" dirty="0" err="1" />
    <a:t>customer_name</a:t>
  </a:r>
  <a:r>
    <a:rPr lang="en-US" dirty="0" />
    <a:t>}} is a great client</a:t>
  </a:r>
</a:p>

Will turn into:

<a:p>
  <a:r>
    <a:rPr lang="en-US" err="1" />
    <a:t>customer_name}} is a great client</a:t>
  </a:r>
</a:p>

Notice the Err Flag is still present, even if the subsequent merged TextRuns did not have it.

On the contrary, if the first TextRun doesn’t have the err flag, but subsequent TextRuns do, the err flag is left unset regardless of the subsequent TextRuns, example before:

<a:p>
  <a:r>
    <a:rPr lang="en-US" dirty="0" />
    <a:t>{{</a:t>
  </a:r>
  <a:r>
    <a:rPr lang="en-US" dirty="0" err="1" />
    <a:t>customer_name</a:t>
  </a:r>
  <a:r>
    <a:rPr lang="en-US" dirty="0" />
    <a:t>}} is a great client</a:t>
  </a:r>
</a:p>

After:

<a:p>
  <a:r>
    <a:rPr lang="en-US" />
    <a:t>{{customer_name}} is a great client</a:t>
  </a:r>
</a:p>

The code to make this happen super simple:

  @Test
  void joinPortionsWithSameFormatting_err_flag_issue() {
    Presentation presentation = null;
    try {
      presentation = new Presentation("err_flag_template.pptx");
      File outputFile = Files.createTempFile("err_flag_output", ".pptx").toFile();
      presentation.joinPortionsWithSameFormatting();

      String outputFilePath = "";
      try (FileOutputStream outputStream = new FileOutputStream(outputFile)) {
        outputFilePath = outputFile.getCanonicalPath();
        presentation.save(outputStream, SaveFormat.Pptx);
      } catch (IOException e) {
        throw new RuntimeException("Unable to write to slide show " + outputFilePath, e);
      }

    } catch (IOException e) {
      throw new RuntimeException(e);
    } finally {
      if (presentation != null) {
        presentation.dispose();
      }
    }
  }

I tested this with Aspose 25.10
Files Attached(sorry order of the example slides are backwards):
err_flag_ppts.zip (47.1 KB)

Can Aspose clear up the err flag in this function? Or provide a way to unset it manually? The IPortionFormat class doesn’t seem to have a way to set/unset the err flag which seems like a gap, and I could not find anything in the documentation relating to it.
The one workaround(in ppt 365) I’ve found is a very tedious process; Right click on red swiggly text → add to dictionary → click out of text box → right click on text again. We have a lot of template/users, and some presentations are easily 30 slides before processing, so being able to unset the flag programmatically would improve our end user experience by a lot.

@ecodev

It appears you are facing an issue where the joinPortionsWithSameFormatting() method in Aspose.Slides retains the error flag from the first text run when merging text portions. This can result in unwanted red underlines in your presentations, indicating spelling errors even when subsequent text runs do not have this flag set.

Currently, there is no direct method in the IPortionFormat class to programmatically unset the error flag. However, you can implement a workaround by manually iterating through the text runs after calling joinPortionsWithSameFormatting() and clearing the error flag where necessary.

Here’s a sample code snippet that demonstrates how to achieve this:

Presentation presentation = new Presentation("err_flag_template.pptx");
try {
    presentation.joinPortionsWithSameFormatting();

    // Iterate through all slides
    for (ISlide slide : presentation.getSlides()) {
        for (IShape shape : slide.getShapes()) {
            if (shape instanceof IAutoShape) {
                IAutoShape autoShape = (IAutoShape) shape;
                for (IPortion portion : autoShape.getTextFrame().getParagraphs().get(0).getPortions()) {
                    // Check and unset the error flag if needed
                    if (portion.getPortionFormat().getErr()) {
                        portion.getPortionFormat().setErr(false); // Unset the error flag
                    }
                }
            }
        }
    }

    // Save the modified presentation
    presentation.save("output.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

This code will help you clear the error flag from the text runs after merging. You can modify the logic to fit your specific requirements, such as adding conditions before unsetting the flag.

If you have any further questions or need additional assistance, please feel free to ask!

@ecodev,
Thank you for describing the issue. I have reproduced the problems with the err flag in your samples.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESJAVA-39743

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like