We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Portion (Format Effective) Data Missing

Hi,

I am writing to you about a problem we encountered in working with MSO PowerPoint document using the Aspose Slides for Java library (v21.10).

Specifically, when we try to delete and then immediately add a Portion object (new one, custom made, similar to the original) to the same Paragraph portion list of a SmartArt shape object Node, there is a problem, more precisely throwing an exception (NullPointerException), when trying to read the next Portion object format effective data (in this case, it is a Portion object that belongs to even a different Node object).

If no change is applied to the first mentioned Portion object, the data for the second is read without problems (try to comment lines of deleting, making and adding new portion for the first Node object).

I am enclosing the zip file with test code, as well as the source PP file.

In the hope that together we will quickly overcome the problem!
Best regards!

Nenad

test code and file.zip (52.6 KB)

@zpredojevic,
Thank you for the issue description.

I’ve reproduced the problem with the NullPointerException error and added a ticket with ID SLIDESJAVA-38693 in our issue tracking system. Our development team will investigate this case. You will be notified when the issue is resolved.

@zpredojevic,
Our development team has investigated the issue you described above. This exception occurs because you are trying to work with the SmartArt object in Paragraph-Portion logic. But SmartArt object is a complex object, not just Paragraphs and Portions. Unfortunately, the issue description does not contain what you wanted to achieve, but we fixed your code, now it works without exceptions.

String presentationPath = "file/source.pptx";

Presentation presentation = loadPresentationDocument(presentationPath);

ISmartArt shape = (SmartArt) presentation.getSlides().get_Item(0).getShapes().get_Item(1);

/*** FIRST NODE PORTION ***/

ISmartArtNode firstNode = shape.getAllNodes().get_Item(0);
IParagraph firstNodeParagraph = firstNode.getTextFrame().getParagraphs().get_Item(0);
IPortion firstNodePortion = firstNodeParagraph.getPortions().get_Item(0);

assertEquals("Kaitseringkond", firstNodePortion.getText());

IPortionFormatEffectiveData effective = firstNodePortion.getPortionFormat().getEffective();
assertNotNull(effective);

System.out.println("First node paragraph's portion data read properly (before changes).");

// reading Portion's format data
double fontSize = effective.getFontHeight();
Color color = effective.getFillFormat().getSolidFillColor();
String fontName = effective.getLatinFont().getFontName();
String portionText = firstNodePortion.getText();

// deleting Portion from Paragraph
firstNodeParagraph.getPortions().clear();
assertEquals(0, firstNodeParagraph.getPortions().getCount());

// creating new Portion and formatting it
IPortion newFirstPortion = new Portion();
// adding to Paragraph
firstNodeParagraph.getPortions().add(newFirstPortion);
assertEquals(1, firstNodeParagraph.getPortions().getCount());

// formating
newFirstPortion.getPortionFormat().setFontHeight((float) fontSize);
newFirstPortion.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
newFirstPortion.getPortionFormat().getFillFormat().getSolidFillColor().setColorType(ColorType.RGB);
newFirstPortion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(color);
newFirstPortion.getPortionFormat().setLatinFont(new FontData(fontName));
// writing text and checking it
firstNode.getTextFrame().setText(portionText);
assertEquals("Kaitseringkond", newFirstPortion.getText());

// checking the existence of first Node Paragraph's new Portion
effective = firstNodePortion.getPortionFormat().getEffective();
assertNotNull(effective);

System.out.println("First node paragraph's portion data read properly (after changes).");


/*** SECOND NODE PORTION ***/

ISmartArtNode secondNode = shape.getAllNodes().get_Item(1);
IParagraph secondNodeParagraph = secondNode.getTextFrame().getParagraphs().get_Item(0);
IPortion secondNodePortion = secondNodeParagraph.getPortions().get_Item(0);

assertEquals("Kaitseringkonna staap", secondNodePortion.getText());

// IF THERE IS ANY CHANGE ON PREVIOUS (FIRST) PORTION
// (regardless of the fact that it does not even belong to the same Node object),
// IT LEADS TO IMPOSSIBILITY TO READ THIS (SECOND) PORTION'S FORMAT EFFECTIVE DATA
// AND THROWS AN NULL_POINTER_EXCEPTION
// (if the previous change, on the first Portion object, is commented there will be no problem)
effective = secondNodePortion.getPortionFormat().getEffective();
assertNotNull(effective);

System.out.println("Second node paragraph's portion data read properly (before changes).");

fontSize = effective.getFontHeight();
color = effective.getFillFormat().getSolidFillColor();
fontName = effective.getLatinFont().getFontName();
portionText = secondNodePortion.getText();

secondNodeParagraph.getPortions().clear();
assertEquals(0, secondNodeParagraph.getPortions().getCount());

// creating new Portion and formatting it
IPortion newSecondPortion = new Portion();
// adding to Paragraph
secondNodeParagraph.getPortions().add(newSecondPortion);
assertEquals(1, secondNodeParagraph.getPortions().getCount());

// formating
newSecondPortion.getPortionFormat().setFontHeight((float) fontSize);
newSecondPortion.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
newSecondPortion.getPortionFormat().getFillFormat().getSolidFillColor().setColorType(ColorType.RGB);
newSecondPortion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(color);
newSecondPortion.getPortionFormat().setLatinFont(new FontData(fontName));
// writing text and checking it
secondNode.getTextFrame().setText(portionText);
assertEquals("Kaitseringkond", newSecondPortion.getText());

// checking the existence of first Node Paragraph's new Portion
effective = firstNodePortion.getPortionFormat().getEffective();
assertNotNull(effective);

System.out.println("Second node paragraph's portion data read properly (after changes).");

try {
    File tempTargetFile = File.createTempFile("target", ".pptx");
    presentation.save(tempTargetFile.getAbsolutePath(), SaveFormat.Pptx);
} catch (Exception e) {
    fail("There is problem saving document.");
}

Documents:
Manage SmartArt
Manage SmartArt Shape
Manage SmartArt Shape Node