mirror of https://github.com/apache/poi.git
use common PictureType
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1902911 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2a0c1b82c7
commit
072aec8ad2
|
@ -255,7 +255,7 @@ public final class XSLFPictureData extends POIXMLDocumentPart implements Picture
|
|||
case EPS: return XSLFRelation.IMAGE_EPS;
|
||||
case BMP: return XSLFRelation.IMAGE_BMP;
|
||||
case WPG: return XSLFRelation.IMAGE_WPG;
|
||||
case WDP: return XSLFRelation.IMAGE_WDP;
|
||||
case WDP: return XSLFRelation.HDPHOTO_WDP;
|
||||
case TIFF: return XSLFRelation.IMAGE_TIFF;
|
||||
case SVG: return XSLFRelation.IMAGE_SVG;
|
||||
default: return null;
|
||||
|
|
|
@ -16,60 +16,62 @@
|
|||
==================================================================== */
|
||||
package org.apache.poi.xwpf.usermodel;
|
||||
|
||||
import org.apache.poi.common.usermodel.PictureType;
|
||||
|
||||
public interface Document {
|
||||
/**
|
||||
* Extended windows meta file
|
||||
*/
|
||||
public static final int PICTURE_TYPE_EMF = 2;
|
||||
public static final int PICTURE_TYPE_EMF = PictureType.EMF.ooxmlId;
|
||||
|
||||
/**
|
||||
* Windows Meta File
|
||||
*/
|
||||
public static final int PICTURE_TYPE_WMF = 3;
|
||||
public static final int PICTURE_TYPE_WMF = PictureType.WMF.ooxmlId;
|
||||
|
||||
/**
|
||||
* Mac PICT format
|
||||
*/
|
||||
public static final int PICTURE_TYPE_PICT = 4;
|
||||
public static final int PICTURE_TYPE_PICT = PictureType.PICT.ooxmlId;
|
||||
|
||||
/**
|
||||
* JPEG format
|
||||
*/
|
||||
public static final int PICTURE_TYPE_JPEG = 5;
|
||||
public static final int PICTURE_TYPE_JPEG = PictureType.JPEG.ooxmlId;
|
||||
|
||||
/**
|
||||
* PNG format
|
||||
*/
|
||||
public static final int PICTURE_TYPE_PNG = 6;
|
||||
public static final int PICTURE_TYPE_PNG = PictureType.PNG.ooxmlId;
|
||||
|
||||
/**
|
||||
* Device independent bitmap
|
||||
*/
|
||||
public static final int PICTURE_TYPE_DIB = 7;
|
||||
public static final int PICTURE_TYPE_DIB = PictureType.DIB.ooxmlId;
|
||||
|
||||
/**
|
||||
* GIF image format
|
||||
*/
|
||||
public static final int PICTURE_TYPE_GIF = 8;
|
||||
public static final int PICTURE_TYPE_GIF = PictureType.GIF.ooxmlId;
|
||||
|
||||
/**
|
||||
* Tag Image File (.tiff)
|
||||
*/
|
||||
public static final int PICTURE_TYPE_TIFF = 9;
|
||||
public static final int PICTURE_TYPE_TIFF = PictureType.TIFF.ooxmlId;
|
||||
|
||||
/**
|
||||
* Encapsulated Postscript (.eps)
|
||||
*/
|
||||
public static final int PICTURE_TYPE_EPS = 10;
|
||||
public static final int PICTURE_TYPE_EPS = PictureType.EPS.ooxmlId;
|
||||
|
||||
|
||||
/**
|
||||
* Windows Bitmap (.bmp)
|
||||
*/
|
||||
public static final int PICTURE_TYPE_BMP = 11;
|
||||
public static final int PICTURE_TYPE_BMP = PictureType.BMP.ooxmlId;
|
||||
|
||||
/**
|
||||
* WordPerfect graphics (.wpg)
|
||||
*/
|
||||
public static final int PICTURE_TYPE_WPG = 12;
|
||||
public static final int PICTURE_TYPE_WPG = PictureType.WPG.ooxmlId;
|
||||
}
|
||||
|
|
|
@ -1,102 +0,0 @@
|
|||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
package org.apache.poi.xwpf.usermodel;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @since POI 5.2.3
|
||||
*/
|
||||
public enum PictureType {
|
||||
/**
|
||||
* Extended windows meta file
|
||||
*/
|
||||
EMF(Document.PICTURE_TYPE_EMF),
|
||||
/**
|
||||
* Windows Meta File
|
||||
*/
|
||||
WMF(Document.PICTURE_TYPE_WMF),
|
||||
/**
|
||||
* Mac PICT format
|
||||
*/
|
||||
PICT(Document.PICTURE_TYPE_PICT),
|
||||
/**
|
||||
* JPEG format
|
||||
*/
|
||||
JPEG(Document.PICTURE_TYPE_JPEG),
|
||||
/**
|
||||
* JPEG format
|
||||
*/
|
||||
PNG(Document.PICTURE_TYPE_PNG),
|
||||
/**
|
||||
* Device independent bitmap
|
||||
*/
|
||||
DIB(Document.PICTURE_TYPE_DIB),
|
||||
/**
|
||||
* GIF image format
|
||||
*/
|
||||
GIF(Document.PICTURE_TYPE_GIF),
|
||||
/**
|
||||
* Tag Image File (.tiff)
|
||||
*/
|
||||
TIFF(Document.PICTURE_TYPE_TIFF),
|
||||
/**
|
||||
* Encapsulated Postscript (.eps)
|
||||
*/
|
||||
EPS(Document.PICTURE_TYPE_EPS),
|
||||
/**
|
||||
* Windows Bitmap (.bmp)
|
||||
*/
|
||||
BMP(Document.PICTURE_TYPE_BMP),
|
||||
/**
|
||||
* WordPerfect graphics (.wpg)
|
||||
*/
|
||||
WPG(Document.PICTURE_TYPE_WPG);
|
||||
|
||||
/**
|
||||
* Map relating the old API constant values to their corresponding
|
||||
* enumeration value
|
||||
*/
|
||||
private static final Map<Integer, PictureType> PICTURE_TYPE_BY_ID;
|
||||
|
||||
static {
|
||||
PICTURE_TYPE_BY_ID = new HashMap<>();
|
||||
|
||||
for (PictureType pictureType : values()) {
|
||||
PICTURE_TYPE_BY_ID.put(pictureType.id, pictureType);
|
||||
}
|
||||
}
|
||||
|
||||
private int id;
|
||||
|
||||
PictureType(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id for PictureType
|
||||
* @return PictureType, null if id does not match any PictureTypes
|
||||
*/
|
||||
public static PictureType findById(int id) {
|
||||
return PICTURE_TYPE_BY_ID.get(id);
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package org.apache.poi.xwpf.usermodel;
|
||||
|
||||
import org.apache.poi.common.usermodel.PictureType;
|
||||
import org.apache.poi.ooxml.POIXMLDocumentPart;
|
||||
import org.apache.poi.ooxml.POIXMLException;
|
||||
import org.apache.poi.ooxml.POIXMLRelation;
|
||||
|
@ -100,7 +101,7 @@ public class XWPFComments extends POIXMLDocumentPart {
|
|||
* Adds a picture to the comments.
|
||||
*
|
||||
* @param is The stream to read image from
|
||||
* @param format The format of the picture.
|
||||
* @param format The format of the picture, see {@link Document}
|
||||
* @return the index to this picture (0 based), the added picture can be
|
||||
* obtained from {@link #getAllPictures()} .
|
||||
* @throws InvalidFormatException If the format of the picture is not known.
|
||||
|
@ -132,13 +133,13 @@ public class XWPFComments extends POIXMLDocumentPart {
|
|||
* Adds a picture to the comments.
|
||||
*
|
||||
* @param pictureData The picture data
|
||||
* @param format The format of the picture.
|
||||
* @param format The format of the picture, see {@link Document}
|
||||
* @return the index to this picture (0 based), the added picture can be
|
||||
* obtained from {@link #getAllPictures()} .
|
||||
* @throws InvalidFormatException If the format of the picture is not known.
|
||||
*/
|
||||
public String addPictureData(byte[] pictureData, int format) throws InvalidFormatException {
|
||||
return addPictureData(pictureData, PictureType.findById(format));
|
||||
return addPictureData(pictureData, PictureType.findByOoxmlId(format));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -153,10 +154,10 @@ public class XWPFComments extends POIXMLDocumentPart {
|
|||
*/
|
||||
public String addPictureData(byte[] pictureData, PictureType pictureType) throws InvalidFormatException {
|
||||
if (pictureType == null) {
|
||||
throw new InvalidFormatException("pictureType parameter is invalid");
|
||||
throw new InvalidFormatException("pictureType is not supported");
|
||||
}
|
||||
XWPFPictureData xwpfPicData = document.findPackagePictureData(pictureData);
|
||||
POIXMLRelation relDesc = XWPFPictureData.RELATIONS[pictureType.getId()];
|
||||
POIXMLRelation relDesc = XWPFPictureData.RELATIONS[pictureType.ooxmlId];
|
||||
|
||||
if (xwpfPicData == null) {
|
||||
/* Part doesn't exist, create a new one */
|
||||
|
|
|
@ -39,6 +39,7 @@ import javax.xml.namespace.QName;
|
|||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.poi.common.usermodel.PictureType;
|
||||
import org.apache.poi.ooxml.POIXMLDocument;
|
||||
import org.apache.poi.ooxml.POIXMLDocumentPart;
|
||||
import org.apache.poi.ooxml.POIXMLException;
|
||||
|
@ -1486,7 +1487,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||
* @see #addPictureData(byte[], PictureType)
|
||||
*/
|
||||
public String addPictureData(byte[] pictureData, int format) throws InvalidFormatException {
|
||||
return addPictureData(pictureData, PictureType.findById(format));
|
||||
return addPictureData(pictureData, PictureType.findByOoxmlId(format));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1501,10 +1502,10 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||
*/
|
||||
public String addPictureData(byte[] pictureData, PictureType pictureType) throws InvalidFormatException {
|
||||
if (pictureType == null) {
|
||||
throw new InvalidFormatException("pictureType parameter is invalid");
|
||||
throw new InvalidFormatException("pictureType is not supported");
|
||||
}
|
||||
XWPFPictureData xwpfPicData = findPackagePictureData(pictureData);
|
||||
POIXMLRelation relDesc = XWPFPictureData.RELATIONS[pictureType.getId()];
|
||||
POIXMLRelation relDesc = XWPFPictureData.RELATIONS[pictureType.ooxmlId];
|
||||
|
||||
if (xwpfPicData == null) {
|
||||
/* Part doesn't exist, create a new one */
|
||||
|
@ -1584,7 +1585,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||
* @see #getNextPicNameNumber(PictureType)
|
||||
*/
|
||||
public int getNextPicNameNumber(int format) throws InvalidFormatException {
|
||||
return getNextPicNameNumber(PictureType.findById(format));
|
||||
return getNextPicNameNumber(PictureType.findByOoxmlId(format));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1597,14 +1598,14 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||
*/
|
||||
public int getNextPicNameNumber(PictureType pictureType) throws InvalidFormatException {
|
||||
if (pictureType == null) {
|
||||
throw new InvalidFormatException("pictureType parameter is invalid");
|
||||
throw new InvalidFormatException("pictureType is not supported");
|
||||
}
|
||||
int img = getAllPackagePictures().size() + 1;
|
||||
String proposal = XWPFPictureData.RELATIONS[pictureType.getId()].getFileName(img);
|
||||
String proposal = XWPFPictureData.RELATIONS[pictureType.ooxmlId].getFileName(img);
|
||||
PackagePartName createPartName = PackagingURIHelper.createPartName(proposal);
|
||||
while (this.getPackage().getPart(createPartName) != null) {
|
||||
img++;
|
||||
proposal = XWPFPictureData.RELATIONS[pictureType.getId()].getFileName(img);
|
||||
proposal = XWPFPictureData.RELATIONS[pictureType.ooxmlId].getFileName(img);
|
||||
createPartName = PackagingURIHelper.createPartName(proposal);
|
||||
}
|
||||
return img;
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.common.usermodel.PictureType;
|
||||
import org.apache.poi.ooxml.POIXMLDocumentPart;
|
||||
import org.apache.poi.ooxml.POIXMLException;
|
||||
import org.apache.poi.ooxml.POIXMLRelation;
|
||||
|
@ -236,7 +237,7 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo
|
|||
* @see #addPictureData(byte[], PictureType)
|
||||
*/
|
||||
public String addPictureData(byte[] pictureData, int format) throws InvalidFormatException {
|
||||
return addPictureData(pictureData, PictureType.findById(format));
|
||||
return addPictureData(pictureData, PictureType.findByOoxmlId(format));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -250,10 +251,10 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo
|
|||
*/
|
||||
public String addPictureData(byte[] pictureData, PictureType pictureType) throws InvalidFormatException {
|
||||
if (pictureType == null) {
|
||||
throw new InvalidFormatException("pictureType parameter is invalid");
|
||||
throw new InvalidFormatException("pictureType is not supported");
|
||||
}
|
||||
XWPFPictureData xwpfPicData = document.findPackagePictureData(pictureData);
|
||||
POIXMLRelation relDesc = XWPFPictureData.RELATIONS[pictureType.getId()];
|
||||
POIXMLRelation relDesc = XWPFPictureData.RELATIONS[pictureType.ooxmlId];
|
||||
|
||||
if (xwpfPicData == null) {
|
||||
/* Part doesn't exist, create a new one */
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.poi.common.usermodel.PictureType;
|
||||
import org.apache.poi.ooxml.POIXMLDocumentPart;
|
||||
import org.apache.poi.ooxml.POIXMLException;
|
||||
import org.apache.poi.ooxml.POIXMLRelation;
|
||||
|
@ -57,18 +58,19 @@ public class XWPFPictureData extends POIXMLDocumentPart {
|
|||
protected static final POIXMLRelation[] RELATIONS;
|
||||
|
||||
static {
|
||||
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;
|
||||
RELATIONS[Document.PICTURE_TYPE_JPEG] = XWPFRelation.IMAGE_JPEG;
|
||||
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;
|
||||
RELATIONS = new POIXMLRelation[14];
|
||||
RELATIONS[PictureType.EMF.ooxmlId] = XWPFRelation.IMAGE_EMF;
|
||||
RELATIONS[PictureType.WMF.ooxmlId] = XWPFRelation.IMAGE_WMF;
|
||||
RELATIONS[PictureType.PICT.ooxmlId] = XWPFRelation.IMAGE_PICT;
|
||||
RELATIONS[PictureType.JPEG.ooxmlId] = XWPFRelation.IMAGE_JPEG;
|
||||
RELATIONS[PictureType.PNG.ooxmlId] = XWPFRelation.IMAGE_PNG;
|
||||
RELATIONS[PictureType.DIB.ooxmlId] = XWPFRelation.IMAGE_DIB;
|
||||
RELATIONS[PictureType.GIF.ooxmlId] = XWPFRelation.IMAGE_GIF;
|
||||
RELATIONS[PictureType.TIFF.ooxmlId] = XWPFRelation.IMAGE_TIFF;
|
||||
RELATIONS[PictureType.EPS.ooxmlId] = XWPFRelation.IMAGE_EPS;
|
||||
RELATIONS[PictureType.BMP.ooxmlId] = XWPFRelation.IMAGE_BMP;
|
||||
RELATIONS[PictureType.WPG.ooxmlId] = XWPFRelation.IMAGE_WPG;
|
||||
RELATIONS[PictureType.WDP.ooxmlId] = XWPFRelation.HDPHOTO_WDP;
|
||||
}
|
||||
|
||||
private Long checksum;
|
||||
|
@ -170,7 +172,7 @@ public class XWPFPictureData extends POIXMLDocumentPart {
|
|||
* @since POI 5.2.3
|
||||
*/
|
||||
public PictureType getPictureTypeEnum() {
|
||||
return PictureType.findById(getPictureType());
|
||||
return PictureType.findByOoxmlId(getPictureType());
|
||||
}
|
||||
|
||||
public Long getChecksum() {
|
||||
|
|
|
@ -20,12 +20,13 @@ package org.apache.poi.xwpf.usermodel;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.poi.common.usermodel.PictureType;
|
||||
import org.apache.poi.ooxml.POIXMLDocument;
|
||||
import org.apache.poi.ooxml.POIXMLRelation;
|
||||
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
|
||||
import org.apache.poi.sl.usermodel.PictureData;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import static org.apache.poi.openxml4j.opc.PackageRelationshipTypes.HDPHOTO_PART;
|
||||
import static org.apache.poi.openxml4j.opc.PackageRelationshipTypes.IMAGE_PART;
|
||||
|
||||
public final class XWPFRelation extends POIXMLRelation {
|
||||
|
@ -158,71 +159,77 @@ public final class XWPFRelation extends POIXMLRelation {
|
|||
* Supported image formats
|
||||
*/
|
||||
public static final XWPFRelation IMAGE_EMF = new XWPFRelation(
|
||||
PictureData.PictureType.EMF.contentType,
|
||||
PictureType.EMF.contentType,
|
||||
IMAGE_PART,
|
||||
"/word/media/image#.emf",
|
||||
XWPFPictureData::new, XWPFPictureData::new
|
||||
);
|
||||
public static final XWPFRelation IMAGE_WMF = new XWPFRelation(
|
||||
PictureData.PictureType.WMF.contentType,
|
||||
PictureType.WMF.contentType,
|
||||
IMAGE_PART,
|
||||
"/word/media/image#.wmf",
|
||||
XWPFPictureData::new, XWPFPictureData::new
|
||||
);
|
||||
public static final XWPFRelation IMAGE_PICT = new XWPFRelation(
|
||||
PictureData.PictureType.PICT.contentType,
|
||||
PictureType.PICT.contentType,
|
||||
IMAGE_PART,
|
||||
"/word/media/image#.pict",
|
||||
XWPFPictureData::new, XWPFPictureData::new
|
||||
);
|
||||
public static final XWPFRelation IMAGE_JPEG = new XWPFRelation(
|
||||
PictureData.PictureType.JPEG.contentType,
|
||||
PictureType.JPEG.contentType,
|
||||
IMAGE_PART,
|
||||
"/word/media/image#.jpeg",
|
||||
XWPFPictureData::new, XWPFPictureData::new
|
||||
);
|
||||
public static final XWPFRelation IMAGE_PNG = new XWPFRelation(
|
||||
PictureData.PictureType.PNG.contentType,
|
||||
PictureType.PNG.contentType,
|
||||
IMAGE_PART,
|
||||
"/word/media/image#.png",
|
||||
XWPFPictureData::new, XWPFPictureData::new
|
||||
);
|
||||
public static final XWPFRelation IMAGE_DIB = new XWPFRelation(
|
||||
PictureData.PictureType.DIB.contentType,
|
||||
PictureType.DIB.contentType,
|
||||
IMAGE_PART,
|
||||
"/word/media/image#.dib",
|
||||
XWPFPictureData::new, XWPFPictureData::new
|
||||
);
|
||||
public static final XWPFRelation IMAGE_GIF = new XWPFRelation(
|
||||
PictureData.PictureType.GIF.contentType,
|
||||
PictureType.GIF.contentType,
|
||||
IMAGE_PART,
|
||||
"/word/media/image#.gif",
|
||||
XWPFPictureData::new, XWPFPictureData::new
|
||||
);
|
||||
public static final XWPFRelation IMAGE_TIFF = new XWPFRelation(
|
||||
PictureData.PictureType.TIFF.contentType,
|
||||
PictureType.TIFF.contentType,
|
||||
IMAGE_PART,
|
||||
"/word/media/image#.tiff",
|
||||
XWPFPictureData::new, XWPFPictureData::new
|
||||
);
|
||||
public static final XWPFRelation IMAGE_EPS = new XWPFRelation(
|
||||
PictureData.PictureType.EPS.contentType,
|
||||
PictureType.EPS.contentType,
|
||||
IMAGE_PART,
|
||||
"/word/media/image#.eps",
|
||||
XWPFPictureData::new, XWPFPictureData::new
|
||||
);
|
||||
public static final XWPFRelation IMAGE_BMP = new XWPFRelation(
|
||||
PictureData.PictureType.BMP.contentType,
|
||||
PictureType.BMP.contentType,
|
||||
IMAGE_PART,
|
||||
"/word/media/image#.bmp",
|
||||
XWPFPictureData::new, XWPFPictureData::new
|
||||
);
|
||||
public static final XWPFRelation IMAGE_WPG = new XWPFRelation(
|
||||
PictureData.PictureType.WPG.contentType,
|
||||
PictureType.WPG.contentType,
|
||||
IMAGE_PART,
|
||||
"/word/media/image#.wpg",
|
||||
XWPFPictureData::new, XWPFPictureData::new
|
||||
);
|
||||
public static final XWPFRelation HDPHOTO_WDP = new XWPFRelation(
|
||||
PictureType.WDP.contentType,
|
||||
HDPHOTO_PART,
|
||||
"/ppt/media/hdphoto#.wdp",
|
||||
XWPFPictureData::new, XWPFPictureData::new
|
||||
);
|
||||
public static final XWPFRelation IMAGES = new XWPFRelation(
|
||||
null,
|
||||
IMAGE_PART,
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.util.List;
|
|||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.apache.poi.common.usermodel.PictureType;
|
||||
import org.apache.poi.ooxml.POIXMLException;
|
||||
import org.apache.poi.ooxml.util.DocumentHelper;
|
||||
import org.apache.poi.ooxml.util.POIXMLUnits;
|
||||
|
@ -1072,7 +1073,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
|
|||
*/
|
||||
public XWPFPicture addPicture(InputStream pictureData, int pictureType, String filename, int width, int height)
|
||||
throws InvalidFormatException, IOException {
|
||||
return addPicture(pictureData, PictureType.findById(pictureType), filename, width, height);
|
||||
return addPicture(pictureData, PictureType.findByOoxmlId(pictureType), filename, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1090,7 +1091,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
|
|||
public XWPFPicture addPicture(InputStream pictureData, PictureType pictureType, String filename, int width, int height)
|
||||
throws InvalidFormatException, IOException {
|
||||
if (pictureType == null) {
|
||||
throw new InvalidFormatException("pictureType parameter is invalid");
|
||||
throw new InvalidFormatException("pictureType is not supported");
|
||||
}
|
||||
String relationId;
|
||||
XWPFPictureData picData;
|
||||
|
|
|
@ -22,6 +22,7 @@ import javax.xml.namespace.QName;
|
|||
|
||||
import com.microsoft.schemas.office.office.CTSignatureLine;
|
||||
import com.microsoft.schemas.vml.CTImageData;
|
||||
import org.apache.poi.common.usermodel.PictureType;
|
||||
import org.apache.poi.ooxml.util.XPathHelper;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.poifs.crypt.dsig.SignatureLine;
|
||||
|
@ -83,6 +84,8 @@ public class XWPFSignatureLine extends SignatureLine {
|
|||
return PictureType.WMF;
|
||||
case WPG:
|
||||
return PictureType.WPG;
|
||||
case WDP:
|
||||
return PictureType.WDP;
|
||||
default:
|
||||
throw new InvalidFormatException("Unsupported picture format "+type);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.io.IOException;
|
|||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.common.usermodel.PictureType;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.util.LocaleUtil;
|
||||
import org.apache.poi.util.Units;
|
||||
|
|
|
@ -19,53 +19,70 @@ package org.apache.poi.common.usermodel;
|
|||
|
||||
import org.apache.poi.poifs.filesystem.FileMagic;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* General enum class to define a picture format/type
|
||||
*
|
||||
* @since POI 5.0
|
||||
*/
|
||||
public enum PictureType {
|
||||
|
||||
/** Extended windows meta file */
|
||||
EMF("image/x-emf",".emf"),
|
||||
EMF("image/x-emf", ".emf", 2),
|
||||
/** Windows Meta File */
|
||||
WMF("image/x-wmf",".wmf"),
|
||||
WMF("image/x-wmf", ".wmf", 3),
|
||||
/** Mac PICT format */
|
||||
PICT("image/x-pict",".pict"),
|
||||
PICT("image/x-pict", ".pict", 4),
|
||||
/** JPEG format */
|
||||
JPEG("image/jpeg",".jpg"),
|
||||
JPEG("image/jpeg", ".jpg", 5),
|
||||
/** PNG format */
|
||||
PNG("image/png",".png"),
|
||||
PNG("image/png", ".png", 6),
|
||||
/** Device independent bitmap */
|
||||
DIB("image/dib",".dib"),
|
||||
DIB("image/dib", ".dib", 7),
|
||||
/** GIF image format */
|
||||
GIF("image/gif",".gif"),
|
||||
GIF("image/gif", ".gif", 8),
|
||||
/** Tag Image File (.tiff) */
|
||||
TIFF("image/tiff",".tif"),
|
||||
TIFF("image/tiff", ".tif", 9),
|
||||
/** Encapsulated Postscript (.eps) */
|
||||
EPS("image/x-eps",".eps"),
|
||||
EPS("image/x-eps", ".eps", 10),
|
||||
/** Windows Bitmap (.bmp) */
|
||||
BMP("image/x-ms-bmp",".bmp"),
|
||||
BMP("image/x-ms-bmp", ".bmp", 11),
|
||||
/** WordPerfect graphics (.wpg) */
|
||||
WPG("image/x-wpg",".wpg"),
|
||||
WPG("image/x-wpg", ".wpg", 12),
|
||||
/** Microsoft Windows Media Photo image (.wdp) */
|
||||
WDP("image/vnd.ms-photo",".wdp"),
|
||||
WDP("image/vnd.ms-photo", ".wdp", 13),
|
||||
/** Scalable vector graphics (.svg) - supported by Office 2016 and higher */
|
||||
SVG("image/svg+xml", ".svg"),
|
||||
SVG("image/svg+xml", ".svg", -1),
|
||||
/** Unknown picture type - specific to escher bse record */
|
||||
UNKNOWN("", ".dat"),
|
||||
UNKNOWN("", ".dat", -1),
|
||||
/** Picture type error - specific to escher bse record */
|
||||
ERROR("", ".dat"),
|
||||
ERROR("", ".dat", -1),
|
||||
/** JPEG in the YCCK or CMYK color space. */
|
||||
CMYKJPEG("image/jpeg", ".jpg"),
|
||||
CMYKJPEG("image/jpeg", ".jpg", -1),
|
||||
/** client defined blip type - native-id 32 to 255 */
|
||||
CLIENT("", ".dat")
|
||||
CLIENT("", ".dat", -1)
|
||||
;
|
||||
|
||||
public final String contentType,extension;
|
||||
private static final HashMap<Integer, PictureType> PICTURE_TYPE_BY_OOXML_ID;
|
||||
|
||||
PictureType(String contentType,String extension) {
|
||||
static {
|
||||
PICTURE_TYPE_BY_OOXML_ID = new HashMap<>();
|
||||
|
||||
for (PictureType pictureType : values()) {
|
||||
if (pictureType.ooxmlId >= -1) {
|
||||
PICTURE_TYPE_BY_OOXML_ID.put(pictureType.ooxmlId, pictureType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final String contentType, extension;
|
||||
public final int ooxmlId;
|
||||
|
||||
PictureType(String contentType, String extension, int ooxmlId) {
|
||||
this.contentType = contentType;
|
||||
this.extension = extension;
|
||||
this.ooxmlId = ooxmlId;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
|
@ -76,6 +93,10 @@ public enum PictureType {
|
|||
return extension;
|
||||
}
|
||||
|
||||
public int getOoxmlId() {
|
||||
return ooxmlId;
|
||||
}
|
||||
|
||||
public static PictureType valueOf(FileMagic fm) {
|
||||
switch (fm) {
|
||||
case BMP:
|
||||
|
@ -100,4 +121,12 @@ public enum PictureType {
|
|||
return PictureType.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ooxmlId for PictureType
|
||||
* @return PictureType, null if ooxmlId does not match any PictureTypes
|
||||
*/
|
||||
public static PictureType findByOoxmlId(int ooxmlId) {
|
||||
return PICTURE_TYPE_BY_OOXML_ID.get(ooxmlId);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue