mirror of https://github.com/apache/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
This commit is contained in:
parent
7b7274bdcb
commit
0bbbad5da6
|
@ -23,7 +23,23 @@ import java.awt.Graphics2D;
|
||||||
import java.awt.font.TextLayout;
|
import java.awt.font.TextLayout;
|
||||||
import java.text.AttributedString;
|
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 {
|
public class DrawFactory {
|
||||||
protected static ThreadLocal<DrawFactory> defaultFactory = new ThreadLocal<DrawFactory>();
|
protected static ThreadLocal<DrawFactory> defaultFactory = new ThreadLocal<DrawFactory>();
|
||||||
|
@ -85,6 +101,8 @@ public class DrawFactory {
|
||||||
return getDrawable((MasterSheet<? extends Shape, ? extends SlideShow>)shape);
|
return getDrawable((MasterSheet<? extends Shape, ? extends SlideShow>)shape);
|
||||||
} else if (shape instanceof Sheet) {
|
} else if (shape instanceof Sheet) {
|
||||||
return getDrawable((Sheet<? extends Shape, ? extends SlideShow>)shape);
|
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());
|
throw new IllegalArgumentException("Unsupported shape type: "+shape.getClass());
|
||||||
|
|
|
@ -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 {
|
||||||
|
}
|
|
@ -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) {
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,6 +27,9 @@ import java.io.*;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
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
|
* For now this class renders only images supported by the javax.imageio.ImageIO
|
||||||
* framework. Subclasses can override this class to support other formats, for
|
* framework. Subclasses can override this class to support other formats, for
|
||||||
|
@ -77,6 +80,8 @@ import javax.imageio.ImageIO;
|
||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public class ImageRenderer {
|
public class ImageRenderer {
|
||||||
|
private final static POILogger LOG = POILogFactory.getLogger(ImageRenderer.class);
|
||||||
|
|
||||||
protected BufferedImage img;
|
protected BufferedImage img;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,7 +91,7 @@ public class ImageRenderer {
|
||||||
* @param contentType the content type
|
* @param contentType the content type
|
||||||
*/
|
*/
|
||||||
public void loadImage(InputStream data, String contentType) throws IOException {
|
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
|
* @param contentType the content type
|
||||||
*/
|
*/
|
||||||
public void loadImage(byte data[], String contentType) throws IOException {
|
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);
|
BufferedImage bi = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||||
Graphics g = bi.getGraphics();
|
Graphics g = bi.getGraphics();
|
||||||
g.drawImage(img, 0, 0, null);
|
g.drawImage(img, 0, 0, null);
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.poi.POIXMLException;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
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.sl.usermodel.ShapeType;
|
||||||
import org.apache.poi.util.Beta;
|
import org.apache.poi.util.Beta;
|
||||||
import org.apache.poi.util.Units;
|
import org.apache.poi.util.Units;
|
||||||
|
@ -42,6 +43,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFra
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
@Beta
|
@Beta
|
||||||
|
@DrawNotImplemented
|
||||||
public class XSLFGraphicFrame extends XSLFShape {
|
public class XSLFGraphicFrame extends XSLFShape {
|
||||||
/*package*/ XSLFGraphicFrame(CTGraphicalObjectFrame shape, XSLFSheet sheet){
|
/*package*/ XSLFGraphicFrame(CTGraphicalObjectFrame shape, XSLFSheet sheet){
|
||||||
super(shape,sheet);
|
super(shape,sheet);
|
||||||
|
|
Loading…
Reference in New Issue