Bugzilla 52255 - support adding TIFF,EPS and WPG pictures in OOXML documents
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1293748 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cc6e457d59
commit
a6aa1fd99e
@ -34,6 +34,7 @@
|
||||
|
||||
<changes>
|
||||
<release version="3.8-beta6" date="2012-??-??">
|
||||
<action dev="poi-developers" type="fix">52255 - support adding TIFF,EPS and WPG pictures in OOXML documents </action>
|
||||
<action dev="poi-developers" type="fix">52078 - avoid OutOfMemoryError when rendering groupped pictures in HSLF </action>
|
||||
<action dev="poi-developers" type="fix">52745 - fixed XSSFRichtextString.append to preserve leading / trailing spaces </action>
|
||||
<action dev="poi-developers" type="fix">52716 - tolerate hyperlinks that have neither location nor relation </action>
|
||||
|
@ -71,13 +71,34 @@ public final class XSLFPictureData extends POIXMLDocumentPart {
|
||||
*/
|
||||
public static final int PICTURE_TYPE_GIF = 8;
|
||||
|
||||
/**
|
||||
* Tag Image File (.tiff)
|
||||
*/
|
||||
public static final int PICTURE_TYPE_TIFF = 9;
|
||||
|
||||
/**
|
||||
* Encapsulated Postscript (.eps)
|
||||
*/
|
||||
public static final int PICTURE_TYPE_EPS = 10;
|
||||
|
||||
|
||||
/**
|
||||
* Windows Bitmap (.bmp)
|
||||
*/
|
||||
public static final int PICTURE_TYPE_BMP = 11;
|
||||
|
||||
/**
|
||||
* WordPerfect graphics (.wpg)
|
||||
*/
|
||||
public static final int PICTURE_TYPE_WPG = 12;
|
||||
|
||||
/**
|
||||
* Relationships for each known picture type
|
||||
*/
|
||||
protected static final POIXMLRelation[] RELATIONS;
|
||||
|
||||
static {
|
||||
RELATIONS = new POIXMLRelation[9];
|
||||
RELATIONS = new POIXMLRelation[13];
|
||||
RELATIONS[PICTURE_TYPE_EMF] = XSLFRelation.IMAGE_EMF;
|
||||
RELATIONS[PICTURE_TYPE_WMF] = XSLFRelation.IMAGE_WMF;
|
||||
RELATIONS[PICTURE_TYPE_PICT] = XSLFRelation.IMAGE_PICT;
|
||||
@ -85,6 +106,10 @@ public final class XSLFPictureData extends POIXMLDocumentPart {
|
||||
RELATIONS[PICTURE_TYPE_PNG] = XSLFRelation.IMAGE_PNG;
|
||||
RELATIONS[PICTURE_TYPE_DIB] = XSLFRelation.IMAGE_DIB;
|
||||
RELATIONS[PICTURE_TYPE_GIF] = XSLFRelation.IMAGE_GIF;
|
||||
RELATIONS[PICTURE_TYPE_TIFF] = XSLFRelation.IMAGE_TIFF;
|
||||
RELATIONS[PICTURE_TYPE_EPS] = XSLFRelation.IMAGE_EPS;
|
||||
RELATIONS[PICTURE_TYPE_BMP] = XSLFRelation.IMAGE_BMP;
|
||||
RELATIONS[PICTURE_TYPE_WPG] = XSLFRelation.IMAGE_WPG;
|
||||
}
|
||||
|
||||
private Long checksum = null;
|
||||
|
@ -182,6 +182,30 @@ public class XSLFRelation extends POIXMLRelation {
|
||||
"/ppt/media/image#.gif",
|
||||
XSLFPictureData.class
|
||||
);
|
||||
public static final XSLFRelation IMAGE_TIFF = new XSLFRelation(
|
||||
"image/tiff",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||
"/ppt/media/image#.tiff",
|
||||
XSLFPictureData.class
|
||||
);
|
||||
public static final XSLFRelation IMAGE_EPS = new XSLFRelation(
|
||||
"image/x-eps",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||
"/ppt/media/image#.eps",
|
||||
XSLFPictureData.class
|
||||
);
|
||||
public static final XSLFRelation IMAGE_BMP = new XSLFRelation(
|
||||
"image/x-ms-bmp",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||
"/ppt/media/image#.bmp",
|
||||
XSLFPictureData.class
|
||||
);
|
||||
public static final XSLFRelation IMAGE_WPG = new XSLFRelation(
|
||||
"image/x-wpg",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||
"/ppt/media/image#.wpg",
|
||||
XSLFPictureData.class
|
||||
);
|
||||
|
||||
public static final XSLFRelation IMAGES = new XSLFRelation(
|
||||
null,
|
||||
|
@ -39,13 +39,18 @@ public class XSSFPictureData extends POIXMLDocumentPart implements PictureData {
|
||||
*/
|
||||
protected static final POIXMLRelation[] RELATIONS;
|
||||
static {
|
||||
RELATIONS = new POIXMLRelation[8];
|
||||
RELATIONS = new POIXMLRelation[13];
|
||||
RELATIONS[Workbook.PICTURE_TYPE_EMF] = XSSFRelation.IMAGE_EMF;
|
||||
RELATIONS[Workbook.PICTURE_TYPE_WMF] = XSSFRelation.IMAGE_WMF;
|
||||
RELATIONS[Workbook.PICTURE_TYPE_PICT] = XSSFRelation.IMAGE_PICT;
|
||||
RELATIONS[Workbook.PICTURE_TYPE_JPEG] = XSSFRelation.IMAGE_JPEG;
|
||||
RELATIONS[Workbook.PICTURE_TYPE_PNG] = XSSFRelation.IMAGE_PNG;
|
||||
RELATIONS[Workbook.PICTURE_TYPE_DIB] = XSSFRelation.IMAGE_DIB;
|
||||
RELATIONS[XSSFWorkbook.PICTURE_TYPE_GIF] = XSSFRelation.IMAGE_GIF;
|
||||
RELATIONS[XSSFWorkbook.PICTURE_TYPE_TIFF] = XSSFRelation.IMAGE_TIFF;
|
||||
RELATIONS[XSSFWorkbook.PICTURE_TYPE_EPS] = XSSFRelation.IMAGE_EPS;
|
||||
RELATIONS[XSSFWorkbook.PICTURE_TYPE_BMP] = XSSFRelation.IMAGE_BMP;
|
||||
RELATIONS[XSSFWorkbook.PICTURE_TYPE_WPG] = XSSFRelation.IMAGE_WPG;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -191,6 +191,38 @@ public final class XSSFRelation extends POIXMLRelation {
|
||||
XSSFPictureData.class
|
||||
);
|
||||
|
||||
public static final XSSFRelation IMAGE_GIF = new XSSFRelation(
|
||||
"image/gif",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||
"/xl/media/image#.gif",
|
||||
XSSFPictureData.class
|
||||
);
|
||||
|
||||
public static final XSSFRelation IMAGE_TIFF = new XSSFRelation(
|
||||
"image/tiff",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||
"/xl/media/image#.tiff",
|
||||
XSSFPictureData.class
|
||||
);
|
||||
public static final XSSFRelation IMAGE_EPS = new XSSFRelation(
|
||||
"image/x-eps",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||
"/xl/media/image#.eps",
|
||||
XSSFPictureData.class
|
||||
);
|
||||
public static final XSSFRelation IMAGE_BMP = new XSSFRelation(
|
||||
"image/x-ms-bmp",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||
"/xl/media/image#.bmp",
|
||||
XSSFPictureData.class
|
||||
);
|
||||
public static final XSSFRelation IMAGE_WPG = new XSSFRelation(
|
||||
"image/x-wpg",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||
"/xl/media/image#.wpg",
|
||||
XSSFPictureData.class
|
||||
);
|
||||
|
||||
public static final XSSFRelation SHEET_COMMENTS = new XSSFRelation(
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
|
||||
|
@ -81,6 +81,15 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
||||
*/
|
||||
private static final int MAX_SENSITIVE_SHEET_NAME_LEN = 31;
|
||||
|
||||
/**
|
||||
* Images formats supported by XSSF but not by HSSF
|
||||
*/
|
||||
public static final int PICTURE_TYPE_GIF = 8;
|
||||
public static final int PICTURE_TYPE_TIFF = 9;
|
||||
public static final int PICTURE_TYPE_EPS = 10;
|
||||
public static final int PICTURE_TYPE_BMP = 11;
|
||||
public static final int PICTURE_TYPE_WPG = 12;
|
||||
|
||||
/**
|
||||
* The underlying XML bean
|
||||
*/
|
||||
|
@ -37,5 +37,25 @@ public interface Document {
|
||||
|
||||
/** GIF image format */
|
||||
public static final int PICTURE_TYPE_GIF = 8;
|
||||
|
||||
|
||||
/**
|
||||
* Tag Image File (.tiff)
|
||||
*/
|
||||
public static final int PICTURE_TYPE_TIFF = 9;
|
||||
|
||||
/**
|
||||
* Encapsulated Postscript (.eps)
|
||||
*/
|
||||
public static final int PICTURE_TYPE_EPS = 10;
|
||||
|
||||
|
||||
/**
|
||||
* Windows Bitmap (.bmp)
|
||||
*/
|
||||
public static final int PICTURE_TYPE_BMP = 11;
|
||||
|
||||
/**
|
||||
* WordPerfect graphics (.wpg)
|
||||
*/
|
||||
public static final int PICTURE_TYPE_WPG = 12;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class XWPFPictureData extends POIXMLDocumentPart {
|
||||
*/
|
||||
protected static final POIXMLRelation[] RELATIONS;
|
||||
static {
|
||||
RELATIONS = new POIXMLRelation[9];
|
||||
RELATIONS = new POIXMLRelation[13];
|
||||
RELATIONS[Document.PICTURE_TYPE_EMF] = XWPFRelation.IMAGE_EMF;
|
||||
RELATIONS[Document.PICTURE_TYPE_WMF] = XWPFRelation.IMAGE_WMF;
|
||||
RELATIONS[Document.PICTURE_TYPE_PICT] = XWPFRelation.IMAGE_PICT;
|
||||
@ -52,6 +52,10 @@ public class XWPFPictureData extends POIXMLDocumentPart {
|
||||
RELATIONS[Document.PICTURE_TYPE_PNG] = XWPFRelation.IMAGE_PNG;
|
||||
RELATIONS[Document.PICTURE_TYPE_DIB] = XWPFRelation.IMAGE_DIB;
|
||||
RELATIONS[Document.PICTURE_TYPE_GIF] = XWPFRelation.IMAGE_GIF;
|
||||
RELATIONS[Document.PICTURE_TYPE_TIFF] = XWPFRelation.IMAGE_TIFF;
|
||||
RELATIONS[Document.PICTURE_TYPE_EPS] = XWPFRelation.IMAGE_EPS;
|
||||
RELATIONS[Document.PICTURE_TYPE_BMP] = XWPFRelation.IMAGE_BMP;
|
||||
RELATIONS[Document.PICTURE_TYPE_WPG] = XWPFRelation.IMAGE_WPG;
|
||||
}
|
||||
|
||||
private Long checksum = null;
|
||||
|
@ -131,7 +131,10 @@ public final class XWPFRelation extends POIXMLRelation {
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Supported image formats
|
||||
*/
|
||||
public static final XWPFRelation IMAGE_EMF = new XWPFRelation(
|
||||
"image/x-emf",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||
@ -174,6 +177,31 @@ public final class XWPFRelation extends POIXMLRelation {
|
||||
"/word/media/image#.gif",
|
||||
XWPFPictureData.class
|
||||
);
|
||||
public static final XWPFRelation IMAGE_TIFF = new XWPFRelation(
|
||||
"image/tiff",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||
"/word/media/image#.tiff",
|
||||
XWPFPictureData.class
|
||||
);
|
||||
public static final XWPFRelation IMAGE_EPS = new XWPFRelation(
|
||||
"image/x-eps",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||
"/word/media/image#.eps",
|
||||
XWPFPictureData.class
|
||||
);
|
||||
public static final XWPFRelation IMAGE_BMP = new XWPFRelation(
|
||||
"image/x-ms-bmp",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||
"/word/media/image#.bmp",
|
||||
XWPFPictureData.class
|
||||
);
|
||||
public static final XWPFRelation IMAGE_WPG = new XWPFRelation(
|
||||
"image/x-wpg",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||
"/word/media/image#.wpg",
|
||||
XWPFPictureData.class
|
||||
);
|
||||
|
||||
public static final XWPFRelation IMAGES = new XWPFRelation(
|
||||
null,
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||
|
@ -138,6 +138,27 @@ public final class TestXWPFDocument extends TestCase {
|
||||
{
|
||||
assertEquals(newJpeg[i],jpeg[i]);
|
||||
}
|
||||
}
|
||||
public void testAllPictureFormats() throws IOException, InvalidFormatException {
|
||||
XWPFDocument doc = new XWPFDocument();
|
||||
|
||||
doc.addPictureData(new byte[10], XWPFDocument.PICTURE_TYPE_EMF);
|
||||
doc.addPictureData(new byte[11], XWPFDocument.PICTURE_TYPE_WMF);
|
||||
doc.addPictureData(new byte[12], XWPFDocument.PICTURE_TYPE_PICT);
|
||||
doc.addPictureData(new byte[13], XWPFDocument.PICTURE_TYPE_JPEG);
|
||||
doc.addPictureData(new byte[14], XWPFDocument.PICTURE_TYPE_PNG);
|
||||
doc.addPictureData(new byte[15], XWPFDocument.PICTURE_TYPE_DIB);
|
||||
doc.addPictureData(new byte[16], XWPFDocument.PICTURE_TYPE_GIF);
|
||||
doc.addPictureData(new byte[17], XWPFDocument.PICTURE_TYPE_TIFF);
|
||||
doc.addPictureData(new byte[18], XWPFDocument.PICTURE_TYPE_EPS);
|
||||
doc.addPictureData(new byte[19], XWPFDocument.PICTURE_TYPE_BMP);
|
||||
doc.addPictureData(new byte[20], XWPFDocument.PICTURE_TYPE_WPG);
|
||||
|
||||
assertEquals(11, doc.getAllPictures().size());
|
||||
|
||||
doc = XWPFTestDataSamples.writeOutAndReadBack(doc);
|
||||
assertEquals(11, doc.getAllPictures().size());
|
||||
|
||||
}
|
||||
|
||||
public void testRemoveBodyElement() throws IOException {
|
||||
|
Loading…
Reference in New Issue
Block a user