aboutsummaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2015-07-25 19:24:51 +0000
committerAndreas Beeker <kiwiwings@apache.org>2015-07-25 19:24:51 +0000
commit0bbbad5da6318e00826b8e87740e4b169ce1127c (patch)
treec8ed8f68a1f47f8858e8d3dfcfe2635f90c9d379 /src/java
parent7b7274bdcb00a646d9e0ea4feb73bf02e9129115 (diff)
downloadpoi-0bbbad5da6318e00826b8e87740e4b169ce1127c.tar.gz
poi-0bbbad5da6318e00826b8e87740e4b169ce1127c.zip
Annotation for unimplemented drawing handlers.
Ignore unsupported image types (e.g. wmf). git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1692640 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r--src/java/org/apache/poi/sl/draw/DrawFactory.java22
-rw-r--r--src/java/org/apache/poi/sl/draw/DrawNotImplemented.java35
-rw-r--r--src/java/org/apache/poi/sl/draw/DrawNothing.java47
-rw-r--r--src/java/org/apache/poi/sl/draw/ImageRenderer.java19
4 files changed, 118 insertions, 5 deletions
diff --git a/src/java/org/apache/poi/sl/draw/DrawFactory.java b/src/java/org/apache/poi/sl/draw/DrawFactory.java
index 97b3f52147..9d2f05ca4f 100644
--- a/src/java/org/apache/poi/sl/draw/DrawFactory.java
+++ b/src/java/org/apache/poi/sl/draw/DrawFactory.java
@@ -23,7 +23,23 @@ import java.awt.Graphics2D;
import java.awt.font.TextLayout;
import java.text.AttributedString;
-import org.apache.poi.sl.usermodel.*;
+import org.apache.poi.sl.usermodel.Background;
+import org.apache.poi.sl.usermodel.ConnectorShape;
+import org.apache.poi.sl.usermodel.FreeformShape;
+import org.apache.poi.sl.usermodel.GroupShape;
+import org.apache.poi.sl.usermodel.MasterSheet;
+import org.apache.poi.sl.usermodel.Notes;
+import org.apache.poi.sl.usermodel.PictureShape;
+import org.apache.poi.sl.usermodel.PlaceableShape;
+import org.apache.poi.sl.usermodel.Shape;
+import org.apache.poi.sl.usermodel.Sheet;
+import org.apache.poi.sl.usermodel.Slide;
+import org.apache.poi.sl.usermodel.SlideShow;
+import org.apache.poi.sl.usermodel.TableShape;
+import org.apache.poi.sl.usermodel.TextBox;
+import org.apache.poi.sl.usermodel.TextParagraph;
+import org.apache.poi.sl.usermodel.TextRun;
+import org.apache.poi.sl.usermodel.TextShape;
public class DrawFactory {
protected static ThreadLocal<DrawFactory> defaultFactory = new ThreadLocal<DrawFactory>();
@@ -85,8 +101,10 @@ public class DrawFactory {
return getDrawable((MasterSheet<? extends Shape, ? extends SlideShow>)shape);
} else if (shape instanceof Sheet) {
return getDrawable((Sheet<? extends Shape, ? extends SlideShow>)shape);
+ } else if (shape.getClass().isAnnotationPresent(DrawNotImplemented.class)) {
+ return new DrawNothing<Shape>(shape);
}
-
+
throw new IllegalArgumentException("Unsupported shape type: "+shape.getClass());
}
diff --git a/src/java/org/apache/poi/sl/draw/DrawNotImplemented.java b/src/java/org/apache/poi/sl/draw/DrawNotImplemented.java
new file mode 100644
index 0000000000..45b80eaaa1
--- /dev/null
+++ b/src/java/org/apache/poi/sl/draw/DrawNotImplemented.java
@@ -0,0 +1,35 @@
+/* ====================================================================
+ 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.sl.draw;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import org.apache.poi.util.Internal;
+
+
+/**
+ * This is a marker annotation for classes which don't have a defined
+ * draw implementation.
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Internal
+public @interface DrawNotImplemented {
+}
diff --git a/src/java/org/apache/poi/sl/draw/DrawNothing.java b/src/java/org/apache/poi/sl/draw/DrawNothing.java
new file mode 100644
index 0000000000..eb32888809
--- /dev/null
+++ b/src/java/org/apache/poi/sl/draw/DrawNothing.java
@@ -0,0 +1,47 @@
+/* ====================================================================
+ 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.sl.draw;
+
+import java.awt.Graphics2D;
+
+import org.apache.poi.sl.usermodel.Shape;
+
+
+public class DrawNothing<T extends Shape> implements Drawable {
+
+ protected final T shape;
+
+ public DrawNothing(T shape) {
+ this.shape = shape;
+ }
+
+ /**
+ * Apply 2-D transforms before drawing this shape. This includes rotation and flipping.
+ *
+ * @param graphics the graphics whos transform matrix will be modified
+ */
+ public void applyTransform(Graphics2D graphics) {
+ }
+
+
+ public void draw(Graphics2D graphics) {
+ }
+
+ public void drawContent(Graphics2D context) {
+ }
+}
diff --git a/src/java/org/apache/poi/sl/draw/ImageRenderer.java b/src/java/org/apache/poi/sl/draw/ImageRenderer.java
index 87561aedd4..ae8eccf98b 100644
--- a/src/java/org/apache/poi/sl/draw/ImageRenderer.java
+++ b/src/java/org/apache/poi/sl/draw/ImageRenderer.java
@@ -27,6 +27,9 @@ import java.io.*;
import javax.imageio.ImageIO;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
+
/**
* For now this class renders only images supported by the javax.imageio.ImageIO
* framework. Subclasses can override this class to support other formats, for
@@ -77,6 +80,8 @@ import javax.imageio.ImageIO;
* </pre>
*/
public class ImageRenderer {
+ private final static POILogger LOG = POILogFactory.getLogger(ImageRenderer.class);
+
protected BufferedImage img;
/**
@@ -86,7 +91,7 @@ public class ImageRenderer {
* @param contentType the content type
*/
public void loadImage(InputStream data, String contentType) throws IOException {
- img = convertBufferedImage(ImageIO.read(data));
+ img = convertBufferedImage(ImageIO.read(data), contentType);
}
/**
@@ -96,10 +101,18 @@ public class ImageRenderer {
* @param contentType the content type
*/
public void loadImage(byte data[], String contentType) throws IOException {
- img = convertBufferedImage(ImageIO.read(new ByteArrayInputStream(data)));
+ img = convertBufferedImage(ImageIO.read(new ByteArrayInputStream(data)), contentType);
}
- protected static BufferedImage convertBufferedImage(BufferedImage img) {
+ /**
+ * Add alpha channel to buffered image
+ */
+ private static BufferedImage convertBufferedImage(BufferedImage img, String contentType) {
+ if (img == null) {
+ LOG.log(POILogger.WARN, "Content-type: "+contentType+" is not support. Image ignored.");
+ return null;
+ }
+
BufferedImage bi = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics g = bi.getGraphics();
g.drawImage(img, 0, 0, null);