You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/07/25 21:24:51 UTC
svn commit: r1692640 - in /poi/trunk/src: java/org/apache/poi/sl/draw/
ooxml/java/org/apache/poi/xslf/usermodel/
Author: kiwiwings
Date: Sat Jul 25 19:24:51 2015
New Revision: 1692640
URL: http://svn.apache.org/r1692640
Log:
Annotation for unimplemented drawing handlers.
Ignore unsupported image types (e.g. wmf).
Added:
poi/trunk/src/java/org/apache/poi/sl/draw/DrawNotImplemented.java
poi/trunk/src/java/org/apache/poi/sl/draw/DrawNothing.java
Modified:
poi/trunk/src/java/org/apache/poi/sl/draw/DrawFactory.java
poi/trunk/src/java/org/apache/poi/sl/draw/ImageRenderer.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
Modified: poi/trunk/src/java/org/apache/poi/sl/draw/DrawFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/DrawFactory.java?rev=1692640&r1=1692639&r2=1692640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/DrawFactory.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/DrawFactory.java Sat Jul 25 19:24:51 2015
@@ -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());
}
Added: poi/trunk/src/java/org/apache/poi/sl/draw/DrawNotImplemented.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/DrawNotImplemented.java?rev=1692640&view=auto
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/DrawNotImplemented.java (added)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/DrawNotImplemented.java Sat Jul 25 19:24:51 2015
@@ -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 {
+}
Added: poi/trunk/src/java/org/apache/poi/sl/draw/DrawNothing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/DrawNothing.java?rev=1692640&view=auto
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/DrawNothing.java (added)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/DrawNothing.java Sat Jul 25 19:24:51 2015
@@ -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) {
+ }
+}
Modified: poi/trunk/src/java/org/apache/poi/sl/draw/ImageRenderer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/ImageRenderer.java?rev=1692640&r1=1692639&r2=1692640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/ImageRenderer.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/ImageRenderer.java Sat Jul 25 19:24:51 2015
@@ -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);
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java?rev=1692640&r1=1692639&r2=1692640&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java Sat Jul 25 19:24:51 2015
@@ -27,6 +27,7 @@ import org.apache.poi.POIXMLException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.sl.draw.DrawNotImplemented;
import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Units;
@@ -42,6 +43,7 @@ import org.openxmlformats.schemas.presen
* @author Yegor Kozlov
*/
@Beta
+@DrawNotImplemented
public class XSLFGraphicFrame extends XSLFShape {
/*package*/ XSLFGraphicFrame(CTGraphicalObjectFrame shape, XSLFSheet sheet){
super(shape,sheet);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org