Browse Source

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
tags/REL_3_8_FINAL
Yegor Kozlov 12 years ago
parent
commit
a5375147a1

+ 1
- 0
src/documentation/content/xdocs/status.xml View File

@@ -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>

+ 26
- 1
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java View File

@@ -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;

+ 24
- 0
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java View File

@@ -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,

+ 6
- 1
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java View File

@@ -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;
}

/**

+ 32
- 0
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java View File

@@ -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",

+ 9
- 0
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java View File

@@ -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
*/

+ 21
- 1
src/ooxml/java/org/apache/poi/xwpf/usermodel/Document.java View File

@@ -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;
}

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

@@ -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;

+ 29
- 1
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java View File

@@ -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",

+ 21
- 0
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java View File

@@ -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…
Cancel
Save