]> source.dussan.org Git - poi.git/commitdiff
Bugzilla 52255 - support adding TIFF,EPS and WPG pictures in OOXML documents
authorYegor Kozlov <yegor@apache.org>
Sun, 26 Feb 2012 06:22:09 +0000 (06:22 +0000)
committerYegor Kozlov <yegor@apache.org>
Sun, 26 Feb 2012 06:22:09 +0000 (06:22 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1293748 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
src/ooxml/java/org/apache/poi/xwpf/usermodel/Document.java
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java

index 45a875eb1fe06a6d7ef0dae51bbe8296eaabe27b..721c503758648b844b86a783f158a3e65329ca1c 100644 (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>
index 5bf3703621eca32cf533b7330285db65064112a1..d51e1c0d26cced5156cbbec1083bc458225b703b 100644 (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;
index a1d1b51100ac44666f2482fd63c9d00b2bb0685e..e23b5a3361454010907efd2e9033af7fc357860c 100644 (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,
index 814ef73354bd49e656c690b21713b0ca46b9e87d..391db1ea4e7f6fe14e3f4bb13beb3d2bd6bb684c 100644 (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;
     }
 
     /**
index 21094c4597ab60316e3978216dd58cc2224f3bf3..1f5c5120a99a801e4601588d61f7f1bbd4d9d640 100644 (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",
index 81e79ba51c96774152cd27e42d36eea46f6449d3..0c40d26fb15cad141b04dc26660029b915bfd0de 100644 (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
      */
index cf051e4516b360ee9ddedba757dd1981524aa6b8..2df6f577f5b64218a29afbbeb48e0e7d40f833d3 100644 (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;
 }
index 667143841740dd6bd9517c30d9c8d93e99079c65..532d40b00f098d2264e9d511235d51abb73a025d 100644 (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;
index 89524de671c0686e60bf4f5131679f9153020ffb..1ff2bd89438abf1f96028c0c590a91912bd3a3ef 100644 (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",
index 712b2333ce7087b0d017e925ed9fbcd89c6e0740..7f87bff921921215855331b1535017c377e408c0 100644 (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 {