aboutsummaryrefslogtreecommitdiffstats
path: root/poi
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2022-07-21 13:41:49 +0000
committerPJ Fanning <fanningpj@apache.org>2022-07-21 13:41:49 +0000
commit072aec8ad2462adcdf86e7446d47f4e3b1ea4a45 (patch)
tree2f028ab79bf015a6433cd98201c6fa2f2b7ef709 /poi
parent2a0c1b82c7c09b265a760e4ee9458ca4a89a20fb (diff)
downloadpoi-072aec8ad2462adcdf86e7446d47f4e3b1ea4a45.tar.gz
poi-072aec8ad2462adcdf86e7446d47f4e3b1ea4a45.zip
use common PictureType
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1902911 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi')
-rw-r--r--poi/src/main/java/org/apache/poi/common/usermodel/PictureType.java67
1 files changed, 48 insertions, 19 deletions
diff --git a/poi/src/main/java/org/apache/poi/common/usermodel/PictureType.java b/poi/src/main/java/org/apache/poi/common/usermodel/PictureType.java
index 2a5c6625fb..d8497125ac 100644
--- a/poi/src/main/java/org/apache/poi/common/usermodel/PictureType.java
+++ b/poi/src/main/java/org/apache/poi/common/usermodel/PictureType.java
@@ -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;
+
+ 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);
+ }
+ }
+ }
- PictureType(String contentType,String extension) {
+ 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);
+ }
}