Browse Source

[github-607] Support SVGs in XWPF. Thanks to Etienne Gautier. This closes #607

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1916582 13f79535-47bb-0310-9956-ffa450edef68
pull/613/head
PJ Fanning 1 month ago
parent
commit
c715f9ee1d

+ 5
- 0
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/Document.java View File

* WordPerfect graphics (.wpg) * WordPerfect graphics (.wpg)
*/ */
public static final int PICTURE_TYPE_WPG = PictureType.WPG.ooxmlId; public static final int PICTURE_TYPE_WPG = PictureType.WPG.ooxmlId;

/**
* SVG graphics (.svg)
*/
public static final int PICTURE_TYPE_SVG = PictureType.SVG.ooxmlId;
} }

+ 3
- 1
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java View File

protected static final POIXMLRelation[] RELATIONS; protected static final POIXMLRelation[] RELATIONS;


static { static {
RELATIONS = new POIXMLRelation[14];
RELATIONS = new POIXMLRelation[15];
RELATIONS[PictureType.EMF.ooxmlId] = XWPFRelation.IMAGE_EMF; RELATIONS[PictureType.EMF.ooxmlId] = XWPFRelation.IMAGE_EMF;
RELATIONS[PictureType.WMF.ooxmlId] = XWPFRelation.IMAGE_WMF; RELATIONS[PictureType.WMF.ooxmlId] = XWPFRelation.IMAGE_WMF;
RELATIONS[PictureType.PICT.ooxmlId] = XWPFRelation.IMAGE_PICT; RELATIONS[PictureType.PICT.ooxmlId] = XWPFRelation.IMAGE_PICT;
RELATIONS[PictureType.BMP.ooxmlId] = XWPFRelation.IMAGE_BMP; RELATIONS[PictureType.BMP.ooxmlId] = XWPFRelation.IMAGE_BMP;
RELATIONS[PictureType.WPG.ooxmlId] = XWPFRelation.IMAGE_WPG; RELATIONS[PictureType.WPG.ooxmlId] = XWPFRelation.IMAGE_WPG;
RELATIONS[PictureType.WDP.ooxmlId] = XWPFRelation.HDPHOTO_WDP; RELATIONS[PictureType.WDP.ooxmlId] = XWPFRelation.HDPHOTO_WDP;
RELATIONS[PictureType.SVG.ooxmlId] = XWPFRelation.IMAGE_SVG;
} }


private Long checksum; private Long checksum;
* @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_PNG * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_PNG
* @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_GIF * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_GIF
* @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_DIB * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_DIB
* @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_SVG
* @see #getPictureTypeEnum() * @see #getPictureTypeEnum()
*/ */
public int getPictureType() { public int getPictureType() {

+ 6
- 0
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java View File

"/ppt/media/hdphoto#.wdp", "/ppt/media/hdphoto#.wdp",
XWPFPictureData::new, XWPFPictureData::new XWPFPictureData::new, XWPFPictureData::new
); );
public static final XWPFRelation IMAGE_SVG = new XWPFRelation(
PictureType.SVG.contentType,
IMAGE_PART,
"/word/media/image#.svg",
XWPFPictureData::new, XWPFPictureData::new
);
public static final XWPFRelation IMAGES = new XWPFRelation( public static final XWPFRelation IMAGES = new XWPFRelation(
null, null,
IMAGE_PART, IMAGE_PART,

+ 1
- 0
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java View File

* @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_PNG * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_PNG
* @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_GIF * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_GIF
* @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_DIB * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_DIB
* @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_SVG
* @see #addPicture(InputStream, PictureType, String, int, int) * @see #addPicture(InputStream, PictureType, String, int, int)
*/ */
public XWPFPicture addPicture(InputStream pictureData, int pictureType, String filename, int width, int height) public XWPFPicture addPicture(InputStream pictureData, int pictureType, String filename, int width, int height)

+ 3
- 2
poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java View File

doc.addPictureData(new byte[18], Document.PICTURE_TYPE_EPS); doc.addPictureData(new byte[18], Document.PICTURE_TYPE_EPS);
doc.addPictureData(new byte[19], Document.PICTURE_TYPE_BMP); doc.addPictureData(new byte[19], Document.PICTURE_TYPE_BMP);
doc.addPictureData(new byte[20], Document.PICTURE_TYPE_WPG); doc.addPictureData(new byte[20], Document.PICTURE_TYPE_WPG);
doc.addPictureData(new byte[21], Document.PICTURE_TYPE_SVG);


assertEquals(11, doc.getAllPictures().size());
assertEquals(12, doc.getAllPictures().size());


try (XWPFDocument doc2 = XWPFTestDataSamples.writeOutAndReadBack(doc)) { try (XWPFDocument doc2 = XWPFTestDataSamples.writeOutAndReadBack(doc)) {
assertEquals(11, doc2.getAllPictures().size());
assertEquals(12, doc2.getAllPictures().size());
} }
} }
} }

+ 1
- 1
poi/src/main/java/org/apache/poi/common/usermodel/PictureType.java View File

/** Microsoft Windows Media Photo image (.wdp) */ /** Microsoft Windows Media Photo image (.wdp) */
WDP("image/vnd.ms-photo", ".wdp", 13), WDP("image/vnd.ms-photo", ".wdp", 13),
/** Scalable vector graphics (.svg) - supported by Office 2016 and higher */ /** Scalable vector graphics (.svg) - supported by Office 2016 and higher */
SVG("image/svg+xml", ".svg", -1),
SVG("image/svg+xml", ".svg", 14),
/** Unknown picture type - specific to escher bse record */ /** Unknown picture type - specific to escher bse record */
UNKNOWN("", ".dat", -1), UNKNOWN("", ".dat", -1),
/** Picture type error - specific to escher bse record */ /** Picture type error - specific to escher bse record */

Loading…
Cancel
Save