Hello,
I work on a project where we convert user-uploaded PPTX to our own document
format. I’ve got feedback for a file where some lines are missing. I’ve gone
down the rabbit hole and found where this comes down to:
- The source file has a FreeFormShape defined in a master slide. That
shape has a single CustomGeometry defined
- When reading the shape geometry with XSLFFreeformShape.getGeometry(),
it calls internally PresetGeometries.convertCustomGeometry(). When the shape
geometry is loaded with with p.parse(staxReader);, I can see in debug mode that
2 geometries are created for "XSLFFreeFormShape Freeform 6”. One with name
“noFill” that is completely empty (no paths, anchors etc.), and one with the
name “custom” that contains the path of my shape as defined in the XML. I don’t
know where the “noFill” geometry is coming from. There is an element
<a:NoFill/> in the shape definition, but that’s not a geometry, so it looks
like the parser is reading all elements until the end of the shape definition.
- Then PresetGeometries.convertCustomGeometry(XMLStreamReader
staxReader) selects the “first” value only (whatever that means, as there is no
guaranteed order in hashMap.values().stream.findFirst()), and I end up with the
“noFill” geometry, which has an empty path. And I can’t access the “real”
geometry of the shape.
I have changed a bit the logic in
PresetGeometries.convertCustomGeometry(XMLStreamReader staxReader) so it always
return the CustomGeometry created in the constructor of PresetParser and then
populated by the parser with the first xml element:
Existing code:
/**
* Convert a single CustomGeometry object, i.e. from xmlbeans
*/
public static CustomGeometry convertCustomGeometry(XMLStreamReader staxReader) {
try {
PresetParser p = new PresetParser(PresetParser.Mode.SHAPE);
p.parse(staxReader);
return p.getGeom().values().stream().findFirst().orElse(null);
} catch (XMLStreamException e) {
LOG.log(POILogger.ERROR, "Unable to parse single custom geometry", e);
return null;
}
}
Proposed change:
/**
* Convert a single CustomGeometry object, i.e. from xmlbeans
*/
public static CustomGeometry convertCustomGeometry(XMLStreamReader staxReader) {
try {
PresetParser p = new PresetParser(PresetParser.Mode.SHAPE);
var geometry = Iterables.getOnlyElement(p.getGeom().values());
p.parse(staxReader);
return geometry;
} catch (XMLStreamException e) {
LOG.log(POILogger.ERROR, "Unable to parse single custom geometry", e);
return null;
}
}
Let me know if I am analysing this correctly, and whether you are interested to
patch this, I’m happy to create the patch and send it for review.
Thanks,
Etienne Gautier.
--
**
** <https://www.canva.com/>Empowering the world to design
We're hiring,
apply here <https://www.canva.com/careers/>! Check out the latest news and
learnings from our team on the Canva Newsroom
<https://www.canva.com/newsroom/news/>.
<https://twitter.com/canva>
<https://facebook.com/canva> <https://au.linkedin.com/company/canva>
<https://twitter.com/canva> <https://facebook.com/canva>
<https://www.linkedin.com/company/canva>
<https://instagram.com/canva>
Presentation-custom-geometry-parsing.pptx
Description: MS-Powerpoint 2007 presentation
--------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
