import java.awt.font.TextLayout;\r
import java.text.AttributedString;\r
\r
-import org.apache.poi.sl.usermodel.*;\r
+import org.apache.poi.sl.usermodel.Background;\r
+import org.apache.poi.sl.usermodel.ConnectorShape;\r
+import org.apache.poi.sl.usermodel.FreeformShape;\r
+import org.apache.poi.sl.usermodel.GroupShape;\r
+import org.apache.poi.sl.usermodel.MasterSheet;\r
+import org.apache.poi.sl.usermodel.Notes;\r
+import org.apache.poi.sl.usermodel.PictureShape;\r
+import org.apache.poi.sl.usermodel.PlaceableShape;\r
+import org.apache.poi.sl.usermodel.Shape;\r
+import org.apache.poi.sl.usermodel.Sheet;\r
+import org.apache.poi.sl.usermodel.Slide;\r
+import org.apache.poi.sl.usermodel.SlideShow;\r
+import org.apache.poi.sl.usermodel.TableShape;\r
+import org.apache.poi.sl.usermodel.TextBox;\r
+import org.apache.poi.sl.usermodel.TextParagraph;\r
+import org.apache.poi.sl.usermodel.TextRun;\r
+import org.apache.poi.sl.usermodel.TextShape;\r
\r
public class DrawFactory {\r
protected static ThreadLocal<DrawFactory> defaultFactory = new ThreadLocal<DrawFactory>();\r
return getDrawable((MasterSheet<? extends Shape, ? extends SlideShow>)shape);\r
} else if (shape instanceof Sheet) {\r
return getDrawable((Sheet<? extends Shape, ? extends SlideShow>)shape);\r
+ } else if (shape.getClass().isAnnotationPresent(DrawNotImplemented.class)) {\r
+ return new DrawNothing<Shape>(shape);\r
}\r
-\r
+ \r
throw new IllegalArgumentException("Unsupported shape type: "+shape.getClass());\r
}\r
\r
--- /dev/null
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.sl.draw;\r
+\r
+import java.lang.annotation.Documented;\r
+import java.lang.annotation.Retention;\r
+import java.lang.annotation.RetentionPolicy;\r
+\r
+import org.apache.poi.util.Internal;\r
+\r
+\r
+/**\r
+ * This is a marker annotation for classes which don't have a defined\r
+ * draw implementation.\r
+ */\r
+@Documented\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@Internal\r
+public @interface DrawNotImplemented {\r
+}\r
--- /dev/null
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.sl.draw;\r
+\r
+import java.awt.Graphics2D;\r
+\r
+import org.apache.poi.sl.usermodel.Shape;\r
+\r
+\r
+public class DrawNothing<T extends Shape> implements Drawable {\r
+\r
+ protected final T shape;\r
+ \r
+ public DrawNothing(T shape) {\r
+ this.shape = shape;\r
+ }\r
+ \r
+ /**\r
+ * Apply 2-D transforms before drawing this shape. This includes rotation and flipping.\r
+ *\r
+ * @param graphics the graphics whos transform matrix will be modified\r
+ */\r
+ public void applyTransform(Graphics2D graphics) {\r
+ }\r
+\r
+\r
+ public void draw(Graphics2D graphics) {\r
+ }\r
+\r
+ public void drawContent(Graphics2D context) {\r
+ }\r
+}\r
\r
import javax.imageio.ImageIO;\r
\r
+import org.apache.poi.util.POILogFactory;\r
+import org.apache.poi.util.POILogger;\r
+\r
/**\r
* For now this class renders only images supported by the javax.imageio.ImageIO\r
* framework. Subclasses can override this class to support other formats, for\r
* </pre>\r
*/\r
public class ImageRenderer {\r
+ private final static POILogger LOG = POILogFactory.getLogger(ImageRenderer.class);\r
+ \r
protected BufferedImage img;\r
\r
/**\r
* @param contentType the content type\r
*/\r
public void loadImage(InputStream data, String contentType) throws IOException {\r
- img = convertBufferedImage(ImageIO.read(data));\r
+ img = convertBufferedImage(ImageIO.read(data), contentType);\r
}\r
\r
/**\r
* @param contentType the content type\r
*/\r
public void loadImage(byte data[], String contentType) throws IOException {\r
- img = convertBufferedImage(ImageIO.read(new ByteArrayInputStream(data)));\r
+ img = convertBufferedImage(ImageIO.read(new ByteArrayInputStream(data)), contentType);\r
}\r
\r
- protected static BufferedImage convertBufferedImage(BufferedImage img) {\r
+ /**\r
+ * Add alpha channel to buffered image \r
+ */\r
+ private static BufferedImage convertBufferedImage(BufferedImage img, String contentType) {\r
+ if (img == null) {\r
+ LOG.log(POILogger.WARN, "Content-type: "+contentType+" is not support. Image ignored.");\r
+ return null;\r
+ }\r
+ \r
BufferedImage bi = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB);\r
Graphics g = bi.getGraphics();\r
g.drawImage(img, 0, 0, null);\r
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;\r
import org.apache.poi.openxml4j.opc.PackagePart;\r
import org.apache.poi.openxml4j.opc.PackageRelationship;\r
+import org.apache.poi.sl.draw.DrawNotImplemented;\r
import org.apache.poi.sl.usermodel.ShapeType;\r
import org.apache.poi.util.Beta;\r
import org.apache.poi.util.Units;\r
* @author Yegor Kozlov\r
*/\r
@Beta\r
+@DrawNotImplemented\r
public class XSLFGraphicFrame extends XSLFShape {\r
/*package*/ XSLFGraphicFrame(CTGraphicalObjectFrame shape, XSLFSheet sheet){\r
super(shape,sheet);\r