add XSLFPictureShape getName

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894504 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-10-23 09:18:17 +00:00
parent b3a64e0bca
commit 03fc88b18b
2 changed files with 32 additions and 4 deletions

View File

@ -273,6 +273,29 @@ public class XSLFPictureShape extends XSLFSimpleShape
return getSvgImage();
}
/**
* @return picture name, can be null
* @since POI 5.1.0
*/
public String getName() {
String name = null;
XmlObject xmlObject = getXmlObject();
if (xmlObject instanceof CTPicture) {
CTPicture ctPicture = (CTPicture)xmlObject;
CTPictureNonVisual nvSpPr = ctPicture.getNvPicPr();
if (nvSpPr != null) {
CTNonVisualDrawingProps cnv = nvSpPr.getCNvPr();
if (cnv != null) {
name = cnv.getName();
}
}
}
return name;
}
/**
* @return SVG image data -- can return null if no SVG image is found
*/
public XSLFPictureData getSvgImage() {
CTBlip blip = getBlip();
if (blip == null) {
@ -299,7 +322,7 @@ public class XSLFPictureShape extends XSLFSimpleShape
}
/**
* Convienence method for adding SVG images, which generates the preview image
* Convenience method for adding SVG images, which generates the preview image
* @param sheet the sheet to add
* @param svgPic the svg picture to add
* @param previewType the preview picture type or null (defaults to PNG) - currently only JPEG,GIF,PNG are allowed
@ -351,7 +374,7 @@ public class XSLFPictureShape extends XSLFSimpleShape
@Override
void copy(XSLFShape sh){
void copy(XSLFShape sh) {
super.copy(sh);
XSLFPictureShape p = (XSLFPictureShape)sh;

View File

@ -83,8 +83,13 @@ class TestXSLFPictureShape {
assertArrayEquals(data2, pics.get(1).getData());
List<XSLFShape> shapes = ppt2.getSlides().get(0).getShapes();
assertArrayEquals(data1, ((XSLFPictureShape) shapes.get(0)).getPictureData().getData());
assertArrayEquals(data2, ((XSLFPictureShape) shapes.get(1)).getPictureData().getData());
assertEquals(2, shapes.size());
XSLFPictureShape xlsfShape0 = (XSLFPictureShape) shapes.get(0);
XSLFPictureShape xlsfShape1 = (XSLFPictureShape) shapes.get(1);
assertArrayEquals(data1, xlsfShape0.getPictureData().getData());
assertArrayEquals(data2, xlsfShape1.getPictureData().getData());
assertEquals("Picture 2", xlsfShape0.getName());
assertEquals("Picture 3", xlsfShape1.getName());
}
}
}