ASF Bugzilla – Attachment 32958 Details for
Bug 58207
[PATCH] Provide user access to the original image dimensions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
patch with proposed changes
0001-Provide-user-access-to-the-original-image-dimensions.patch (text/plain), 4.74 KB, created by
mark.o
on 2015-08-04 15:52:35 UTC
(
hide
)
Description:
patch with proposed changes
Filename:
MIME Type:
Creator:
mark.o
Created:
2015-08-04 15:52:35 UTC
Size:
4.74 KB
patch
obsolete
>From 0d7301f25aed425322956517967a498099aa6ebd Mon Sep 17 00:00:00 2001 >From: Mark Olesen <Mark.Olesen@faurecia.com> >Date: Tue, 4 Aug 2015 17:29:39 +0200 >Subject: [PATCH] Provide user access to the original image dimensions. > >- useful information when resizing anchors. > >- simply moved some code from XSLFPictureShape to XSLFPictureData > and cache the values there. >--- > .../apache/poi/xslf/usermodel/XSLFPictureData.java | 34 ++++++++++++++++++++ > .../poi/xslf/usermodel/XSLFPictureShape.java | 25 +++++++------- > 2 files changed, 47 insertions(+), 12 deletions(-) > >diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java >index e6fc0fd..9dc667c 100644 >--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java >+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java >@@ -19,9 +19,12 @@ > > package org.apache.poi.xslf.usermodel; > >+import java.awt.Dimension; >+import java.awt.image.BufferedImage; > import java.io.IOException; > import java.io.InputStream; > import java.io.OutputStream; >+import javax.imageio.ImageIO; > > import org.apache.poi.POIXMLDocumentPart; > import org.apache.poi.POIXMLException; >@@ -37,6 +40,9 @@ import org.apache.poi.util.IOUtils; > @Beta > public final class XSLFPictureData extends POIXMLDocumentPart implements PictureData { > private Long checksum = null; >+ >+ // original image dimensions (for formats supported by BufferedImage) >+ private Dimension _origSize = null; > private int index = -1; > > /** >@@ -115,6 +121,32 @@ public final class XSLFPictureData extends POIXMLDocumentPart implements Picture > } > > /** >+ * Return the original image dimensions >+ * (for formats supported by BufferedImage). >+ * >+ * Will return a Dimension with zero width/height if the format unsupported. >+ */ >+ public Dimension getImageDimension() >+ { >+ if (_origSize == null) >+ { >+ try >+ { >+ BufferedImage img = ImageIO.read(getInputStream()); >+ _origSize = new Dimension(img.getWidth(), img.getHeight()); >+ } >+ catch (Exception failed) >+ { >+ // failed to get information, set as zero size >+ _origSize = new Dimension(); >+ } >+ } >+ >+ return _origSize; >+ } >+ >+ >+ /** > * *PictureData objects store the actual content in the part directly without keeping a > * copy like all others therefore we need to handle them differently. > */ >@@ -134,6 +166,8 @@ public final class XSLFPictureData extends POIXMLDocumentPart implements Picture > os.close(); > // recalculate now since we already have the data bytes available anyhow > checksum = IOUtils.calculateChecksum(data); >+ >+ _origSize = null; // need to recalculate image size > } > > @Override >diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java >index 73ec45b..6b6b56c 100644 >--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java >+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java >@@ -19,12 +19,10 @@ > > package org.apache.poi.xslf.usermodel; > >+import java.awt.Dimension; > import java.awt.Insets; >-import java.awt.geom.Rectangle2D; >-import java.awt.image.BufferedImage; >+import java.awt.Rectangle; > import java.net.URI; >- >-import javax.imageio.ImageIO; > import javax.xml.namespace.QName; > > import org.apache.poi.POIXMLException; >@@ -86,20 +84,23 @@ public class XSLFPictureShape extends XSLFSimpleShape implements PictureShape { > > /** > * Resize this picture to the default size. >+ * > * For PNG and JPEG resizes the image to 100%, >- * for other types sets the default size of 200x200 pixels. >+ * for other types sets the default size to 200x200 pixels. > */ > public void resize() { >- try { >- BufferedImage img = ImageIO.read(getPictureData().getInputStream()); >- setAnchor(new Rectangle2D.Double(0, 0, img.getWidth(), img.getHeight())); >+ Dimension dim = getPictureData().getImageDimension(); >+ if (dim.width > 0 && dim.height > 0) >+ { >+ setAnchor(new Rectangle(0, 0, dim.width, dim.height)); > } >- catch (Exception e) { >- //default size is 200x200 >- setAnchor(new java.awt.Rectangle(50, 50, 200, 200)); >+ else >+ { >+ // unsupported/unknown formats >+ setAnchor(new Rectangle(50, 50, 200, 200)); > } > } >- >+ > /** > * Is this an internal picture (image data included within > * the PowerPoint file), or an external linked picture >-- >1.7.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 58207
:
32957
| 32958