MathPortion and TextAutofitType.Shape Do Not Work Well Together

When I mix a math portion with a regular text portion in a paragraph, the text frame containing the paragraph does not reshape correctly with TextAutofitType.Shape. The result frame is very small and the text is barely visible. Removing the MathPortion or changing to autofit type would result in a better looking slide.

Did I do something wrong. Here is my code demonstrating the problem.

   public void test() throws IOException {
       // temp file directory
       String tmpdir = System.getProperty("java.io.tmpdir");
       Files.createDirectories(Paths.get(tmpdir + "/test"));

       // new presentation
       Presentation presentation = new Presentation();
       ISlideCollection slides = presentation.getSlides();

       // get the default slide
       ISlide slide = slides.get_Item(0);

       // add a rectangle
       IAutoShape autoShape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 100, 600, 400);

       // add a new paragraph
       Paragraph paragraph = new Paragraph();
       autoShape.getTextFrame().getParagraphs().add(paragraph);

       // add some text to the paragraph via a portion
       Portion portion = new Portion();
       paragraph.getPortions().add(portion);
       portion.setText("test-------");

       // add math text to the paragraph via a math portion
       MathPortion mathPortion = new MathPortion();
       paragraph.getPortions().add(mathPortion);
       MathBlock mathBlock = new MathBlock();
       mathPortion.getMathParagraph().add(mathBlock);
       mathBlock.add(new MathematicalText("abc"));

       // reshape the rectangle
       autoShape.getTextFrame().getTextFrameFormat().setAutofitType(TextAutofitType.Shape);

       presentation.save(tmpdir + "/test/test.pptx", SaveFormat.Pptx);
   }

@fzeng2012,
Thank you for reporting the issue.

Your code example is correct. I’ve reproduced the problem with resizing the shape and added a ticket with ID SLIDESJAVA-38951 to our issue tracking system. We apologize for any inconvenience. Our development team will investigate the case. You will be notified when a new release of Aspose.Slides with a fix is published.

It would be great if you could share the following additional information:

  • OS version on which the code was executed
  • JDK version in your app

We will then also test a solution in an environment similar to yours.

Thank you for validating my test case. Here is the information about the environment.

  • OS version on which the code was executed: Windows 10
  • JDK version in your app: JDK 1.8

@fzeng2012,
Thank you for the additional information. I’ve forwarded it to our developers.