From: Andreas Beeker Date: Sat, 25 Jul 2015 19:24:51 +0000 (+0000) Subject: Annotation for unimplemented drawing handlers. X-Git-Tag: REL_3_13_FINAL~205 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0bbbad5da6318e00826b8e87740e4b169ce1127c;p=poi.git 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 --- 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 defaultFactory = new ThreadLocal(); @@ -85,8 +101,10 @@ public class DrawFactory { return getDrawable((MasterSheet)shape); } else if (shape instanceof Sheet) { return getDrawable((Sheet)shape); + } else if (shape.getClass().isAnnotationPresent(DrawNotImplemented.class)) { + return new DrawNothing(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 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; * */ 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); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java index b17799a82f..82a3fe1f63 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java @@ -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.presentationml.x2006.main.CTGraphicalObjectFra * @author Yegor Kozlov */ @Beta +@DrawNotImplemented public class XSLFGraphicFrame extends XSLFShape { /*package*/ XSLFGraphicFrame(CTGraphicalObjectFrame shape, XSLFSheet sheet){ super(shape,sheet);