diff options
Diffstat (limited to 'src/java/org/apache')
-rw-r--r-- | src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java | 3 | ||||
-rw-r--r-- | src/java/org/apache/poi/sl/draw/DrawPaint.java | 58 | ||||
-rw-r--r-- | src/java/org/apache/poi/sl/draw/DrawPictureShape.java | 7 | ||||
-rw-r--r-- | src/java/org/apache/poi/sl/draw/DrawSimpleShape.java | 17 | ||||
-rw-r--r-- | src/java/org/apache/poi/sl/draw/ImageRenderer.java | 6 | ||||
-rw-r--r-- | src/java/org/apache/poi/util/Units.java | 13 |
6 files changed, 50 insertions, 54 deletions
diff --git a/src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java b/src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java index 145791f401..140fc777f2 100644 --- a/src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java +++ b/src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java @@ -23,6 +23,7 @@ import java.awt.Graphics2D; import java.awt.Insets; import java.awt.Shape; import java.awt.geom.AffineTransform; +import java.awt.geom.Dimension2D; import java.awt.geom.Rectangle2D; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; @@ -237,7 +238,7 @@ public class BitmapImageRenderer implements ImageRenderer { } @Override - public BufferedImage getImage(Dimension dim) { + public BufferedImage getImage(Dimension2D dim) { double w_old = img.getWidth(); double h_old = img.getHeight(); BufferedImage scaled = new BufferedImage((int)w_old, (int)h_old, BufferedImage.TYPE_INT_ARGB); diff --git a/src/java/org/apache/poi/sl/draw/DrawPaint.java b/src/java/org/apache/poi/sl/draw/DrawPaint.java index f012161b3c..fea1da4661 100644 --- a/src/java/org/apache/poi/sl/draw/DrawPaint.java +++ b/src/java/org/apache/poi/sl/draw/DrawPaint.java @@ -234,46 +234,50 @@ public class DrawPaint { @SuppressWarnings("WeakerAccess") protected Paint getTexturePaint(TexturePaint fill, Graphics2D graphics) { - InputStream is = fill.getImageData(); - if (is == null) { - return TRANSPARENT; - } assert(graphics != null); - ImageRenderer renderer = DrawPictureShape.getImageRenderer(graphics, fill.getContentType()); + final String contentType = fill.getContentType(); - try { - try { - renderer.loadImage(is, fill.getContentType()); - } finally { - is.close(); - } - } catch (IOException e) { - LOG.log(POILogger.ERROR, "Can't load image data - using transparent color", e); - return TRANSPARENT; - } + ImageRenderer renderer = DrawPictureShape.getImageRenderer(graphics, contentType); int alpha = fill.getAlpha(); if (0 <= alpha && alpha < 100000) { renderer.setAlpha(alpha/100000.f); } + // TODO: handle tile settings, currently the pattern is always streched 100% in height/width Rectangle2D textAnchor = shape.getAnchor(); - BufferedImage image; - if ("image/x-wmf".equals(fill.getContentType())) { - // don't rely on wmf dimensions, use dimension of anchor - // TODO: check pixels vs. points for image dimension - image = renderer.getImage(new Dimension((int)textAnchor.getWidth(), (int)textAnchor.getHeight())); - } else { - image = renderer.getImage(); - } - if(image == null) { - LOG.log(POILogger.ERROR, "Can't load image data"); + try (InputStream is = fill.getImageData()) { + if (is == null) { + return TRANSPARENT; + } + + renderer.loadImage(is, contentType); + + final BufferedImage image; + switch (contentType) { + case "image/x-wmf": + case "image/x-emf": + // don't rely on wmf dimensions, use dimension of anchor + // TODO: check pixels vs. points for image dimension + image = renderer.getImage(new Dimension((int)textAnchor.getWidth(), (int)textAnchor.getHeight())); + break; + default: + image = renderer.getImage(); + break; + } + + if(image == null) { + LOG.log(POILogger.ERROR, "Can't load image data"); + return TRANSPARENT; + } + + return new java.awt.TexturePaint(image, textAnchor); + } catch (IOException e) { + LOG.log(POILogger.ERROR, "Can't load image data - using transparent color", e); return TRANSPARENT; } - - return new java.awt.TexturePaint(image, textAnchor); } /** diff --git a/src/java/org/apache/poi/sl/draw/DrawPictureShape.java b/src/java/org/apache/poi/sl/draw/DrawPictureShape.java index 84e7c91b33..84d3ab785a 100644 --- a/src/java/org/apache/poi/sl/draw/DrawPictureShape.java +++ b/src/java/org/apache/poi/sl/draw/DrawPictureShape.java @@ -56,9 +56,10 @@ public class DrawPictureShape extends DrawSimpleShape { } try { - ImageRenderer renderer = getImageRenderer(graphics, data.getContentType()); - if (renderer.canRender(data.getContentType())) { - renderer.loadImage(data.getData(), data.getContentType()); + String ct = data.getContentType(); + ImageRenderer renderer = getImageRenderer(graphics, ct); + if (renderer.canRender(ct)) { + renderer.loadImage(data.getData(), ct); renderer.drawImage(graphics, anchor, insets); return; } diff --git a/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java b/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java index d535d71fa6..3b32fb3152 100644 --- a/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java +++ b/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java @@ -27,23 +27,10 @@ import java.awt.geom.AffineTransform; import java.awt.geom.Ellipse2D; import java.awt.geom.Path2D; import java.awt.geom.Rectangle2D; -import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.List; -import java.util.Map; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.Unmarshaller; -import javax.xml.stream.EventFilter; -import javax.xml.stream.XMLEventReader; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.events.StartElement; -import javax.xml.stream.events.XMLEvent; - -import org.apache.poi.sl.draw.binding.CTCustomGeometry2D; + import org.apache.poi.sl.draw.geom.Context; import org.apache.poi.sl.draw.geom.CustomGeometry; import org.apache.poi.sl.draw.geom.Outline; @@ -54,8 +41,6 @@ import org.apache.poi.sl.usermodel.LineDecoration.DecorationSize; import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint; import org.apache.poi.sl.usermodel.Shadow; import org.apache.poi.sl.usermodel.SimpleShape; -import org.apache.poi.util.IOUtils; -import org.apache.poi.util.StaxHelper; import org.apache.poi.util.Units; diff --git a/src/java/org/apache/poi/sl/draw/ImageRenderer.java b/src/java/org/apache/poi/sl/draw/ImageRenderer.java index 330c02ab01..dd4e875b10 100644 --- a/src/java/org/apache/poi/sl/draw/ImageRenderer.java +++ b/src/java/org/apache/poi/sl/draw/ImageRenderer.java @@ -18,9 +18,9 @@ */ package org.apache.poi.sl.draw; -import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Insets; +import java.awt.geom.Dimension2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.IOException; @@ -101,7 +101,7 @@ public interface ImageRenderer { /** * @return the dimension of the buffered image */ - Dimension getDimension(); + Dimension2D getDimension(); /** * @param alpha the alpha [0..1] to be added to the image (possibly already containing an alpha channel) @@ -119,7 +119,7 @@ public interface ImageRenderer { * * @since POI 3.15-beta2 */ - BufferedImage getImage(Dimension dim); + BufferedImage getImage(Dimension2D dim); /** * Render picture data into the supplied graphics diff --git a/src/java/org/apache/poi/util/Units.java b/src/java/org/apache/poi/util/Units.java index 709e3f10cc..a2e85e0aa0 100644 --- a/src/java/org/apache/poi/util/Units.java +++ b/src/java/org/apache/poi/util/Units.java @@ -16,9 +16,8 @@ ==================================================================== */ package org.apache.poi.util; -/** - * @author Yegor Kozlov - */ +import java.awt.geom.Dimension2D; + public class Units { /** * In Escher absolute distances are specified in @@ -146,7 +145,13 @@ public class Units { points /= PIXEL_DPI; return points; } - + + public static Dimension2D pointsToPixel(Dimension2D pointsDim) { + double width = pointsDim.getWidth() * PIXEL_DPI / POINT_DPI; + double height = pointsDim.getHeight() * PIXEL_DPI / POINT_DPI; + return new Dimension2DDouble(width, height); + } + public static int charactersToEMU(double characters) { return (int) characters * EMU_PER_CHARACTER; } |