You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/09/21 02:09:58 UTC
svn commit: r1704206 [1/2] - in /poi/trunk/src:
examples/src/org/apache/poi/xslf/usermodel/
integrationtest/org/apache/poi/stress/ java/org/apache/poi/sl/draw/
java/org/apache/poi/sl/usermodel/ ooxml/java/org/apache/poi/xslf/usermodel/
ooxml/java/org/a...
Author: kiwiwings
Date: Mon Sep 21 00:09:45 2015
New Revision: 1704206
URL: http://svn.apache.org/viewvc?rev=1704206&view=rev
Log:
- #58216 - provide picture-shape resize that maintains the aspect ratio
- moved SlideShowFactory to Common SL
- changed get/setAnchor to Rectangle instead of Rectangle2D
- Fixed some Common SL generic definitions
- picture dimensions are now in points and an additional method exists for pixels
Added:
poi/trunk/src/java/org/apache/poi/sl/usermodel/RectAlign.java
poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java
- copied, changed from r1701688, poi/trunk/src/ooxml/java/org/apache/poi/sl/SlideShowFactory.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShowFactory.java
poi/trunk/src/ooxml/testcases/org/apache/poi/sl/
poi/trunk/src/ooxml/testcases/org/apache/poi/sl/draw/
poi/trunk/src/ooxml/testcases/org/apache/poi/sl/draw/TestDrawPictureShape.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShowFactory.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowFactory.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestHSLFSlideShowFactory.java
poi/trunk/src/testcases/org/apache/poi/sl/usermodel/
poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java
Modified:
poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial4.java
poi/trunk/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java
poi/trunk/src/java/org/apache/poi/sl/draw/DrawBackground.java
poi/trunk/src/java/org/apache/poi/sl/draw/DrawPictureShape.java
poi/trunk/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java
poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
poi/trunk/src/java/org/apache/poi/sl/usermodel/GroupShape.java
poi/trunk/src/java/org/apache/poi/sl/usermodel/PictureData.java
poi/trunk/src/java/org/apache/poi/sl/usermodel/PlaceableShape.java
poi/trunk/src/java/org/apache/poi/sl/usermodel/Shadow.java
poi/trunk/src/java/org/apache/poi/sl/usermodel/Shape.java
poi/trunk/src/java/org/apache/poi/sl/usermodel/SimpleShape.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShadow.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Metafile.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureData.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java
poi/trunk/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java
Modified: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial4.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial4.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial4.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial4.java Mon Sep 21 00:09:45 2015
@@ -20,7 +20,7 @@
package org.apache.poi.xslf.usermodel;
import java.awt.Color;
-import java.awt.geom.Rectangle2D;
+import java.awt.Rectangle;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -40,7 +40,7 @@ public class Tutorial4 {
XSLFSlide slide = ppt.createSlide();
XSLFTable tbl = slide.createTable();
- tbl.setAnchor(new Rectangle2D.Double(50, 50, 450, 300));
+ tbl.setAnchor(new Rectangle(50, 50, 450, 300));
int numColumns = 3;
int numRows = 5;
Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java Mon Sep 21 00:09:45 2015
@@ -29,14 +29,13 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.sl.SlideShowFactory;
import org.apache.poi.sl.draw.Drawable;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.sl.usermodel.Shape;
import org.apache.poi.sl.usermodel.ShapeContainer;
import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.sl.usermodel.SlideShow;
+import org.apache.poi.sl.usermodel.SlideShowFactory;
import org.apache.poi.sl.usermodel.TextParagraph;
import org.apache.poi.sl.usermodel.TextRun;
import org.apache.poi.sl.usermodel.TextShape;
@@ -55,12 +54,7 @@ public abstract class SlideShowHandler e
readContent(ss);
// read in the writen file
- SlideShow<?,?> read;
- try {
- read = SlideShowFactory.create(new ByteArrayInputStream(out.toByteArray()));
- } catch (InvalidFormatException e) {
- throw new IllegalStateException(e);
- }
+ SlideShow<?,?> read = SlideShowFactory.create(new ByteArrayInputStream(out.toByteArray()));
assertNotNull(read);
readContent(read);
Modified: poi/trunk/src/java/org/apache/poi/sl/draw/DrawBackground.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/DrawBackground.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/DrawBackground.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/DrawBackground.java Mon Sep 21 00:09:45 2015
@@ -20,6 +20,7 @@ package org.apache.poi.sl.draw;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Paint;
+import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import org.apache.poi.sl.usermodel.Background;
@@ -35,12 +36,12 @@ public class DrawBackground extends Draw
@SuppressWarnings("rawtypes")
public void draw(Graphics2D graphics) {
Dimension pg = shape.getSheet().getSlideShow().getPageSize();
- final Rectangle2D anchor = new Rectangle2D.Double(0, 0, pg.getWidth(), pg.getHeight());
+ final Rectangle anchor = new Rectangle(0, 0, (int)pg.getWidth(), (int)pg.getHeight());
PlaceableShape<?,?> ps = new PlaceableShape(){
public ShapeContainer<?,?> getParent() { return null; }
- public Rectangle2D getAnchor() { return anchor; }
- public void setAnchor(Rectangle2D anchor) {}
+ public Rectangle getAnchor() { return anchor; }
+ public void setAnchor(Rectangle newAnchor) {}
public double getRotation() { return 0; }
public void setRotation(double theta) {}
public void setFlipHorizontal(boolean flip) {}
Modified: poi/trunk/src/java/org/apache/poi/sl/draw/DrawPictureShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/DrawPictureShape.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/DrawPictureShape.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/DrawPictureShape.java Mon Sep 21 00:09:45 2015
@@ -17,13 +17,16 @@
package org.apache.poi.sl.draw;
+import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Insets;
+import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.io.IOException;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.sl.usermodel.PictureShape;
+import org.apache.poi.sl.usermodel.RectAlign;
public class DrawPictureShape extends DrawSimpleShape {
@@ -56,4 +59,117 @@ public class DrawPictureShape extends Dr
protected PictureShape<?,?> getShape() {
return (PictureShape<?,?>)shape;
}
+
+ /**
+ * Resize this picture to the default size.
+ *
+ * For PNG and JPEG resizes the image to 100%,
+ * for other types, if the size can't be determined it will be 200x200 pixels.
+ */
+ public void resize() {
+ PictureShape<?,?> ps = getShape();
+ Dimension dim = ps.getPictureData().getImageDimension();
+
+ Rectangle origRect = ps.getAnchor();
+ int x = (int)origRect.getX();
+ int y = (int)origRect.getY();
+ int w = (int)dim.getWidth();
+ int h = (int)dim.getHeight();
+ ps.setAnchor(new Rectangle(x, y, w, h));
+ }
+
+
+ /**
+ * Fit picture shape into the target rectangle, maintaining the aspect ratio
+ * and repositioning within the target rectangle with a centered alignment.
+ *
+ * @param target The target rectangle
+ */
+ public void resize(Rectangle target) {
+ resize(target, RectAlign.CENTER);
+ }
+
+
+ /**
+ * Fit picture shape into the target rectangle, maintaining the aspect ratio
+ * and repositioning within the target rectangle based on the specified
+ * alignment (gravity).
+ *
+ * @param target The target rectangle
+ * @param align
+ * The alignment within the target rectangle when resizing.
+ * A null value corresponds to RectAlign.CENTER
+ */
+ public void resize(Rectangle target, RectAlign align) {
+ PictureShape<?,?> ps = getShape();
+ Dimension dim = ps.getPictureData().getImageDimension();
+ if (dim.width <= 0 || dim.height <= 0) {
+ // nothing useful to be done for this case
+ ps.setAnchor(target);
+ return;
+ }
+
+ double w = target.getWidth();
+ double h = target.getHeight();
+
+ // scaling
+ double sx = w / dim.width;
+ double sy = h / dim.height;
+
+ // position adjustments
+ double dx = 0, dy = 0;
+
+ if (sx > sy) {
+ // use y-scaling for both, reposition x accordingly
+ w = sy * dim.width;
+ dx = target.getWidth() - w;
+ } else if (sy > sx) {
+ // use x-scaling for both, reposition y accordingly
+ h = sx * dim.height;
+ dy = target.getHeight() - h;
+ } else {
+ // uniform scaling, can use target values directly
+ ps.setAnchor(target);
+ return;
+ }
+
+ // the positioning
+ double x = target.getX();
+ double y = target.getY();
+ switch (align) {
+ case TOP: // X=balance, Y=ok
+ x += dx/2;
+ break;
+ case TOP_RIGHT: // X=shift, Y=ok
+ x += dx;
+ break;
+ case RIGHT: // X=shift, Y=balance
+ x += dx;
+ y += dy/2;
+ break;
+ case BOTTOM_RIGHT: // X=shift, Y=shift
+ x += dx;
+ y += dy;
+ break;
+ case BOTTOM: // X=balance, Y=shift
+ x += dx/2;
+ y += dy;
+ break;
+ case BOTTOM_LEFT: // X=ok, Y=shift
+ y += dy;
+ break;
+ case LEFT: // X=ok, Y=balance
+ y += dy/2;
+ break;
+ case TOP_LEFT: // X=ok, Y=ok
+ /* no-op */
+ break;
+ default: // CENTER: X=balance, Y=balance
+ x += dx/2;
+ y += dy/2;
+ break;
+ }
+
+ ps.setAnchor(new Rectangle((int)x, (int)y, (int)w, (int)h));
+ }
}
Modified: poi/trunk/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java Mon Sep 21 00:09:45 2015
@@ -25,10 +25,8 @@ import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Rectangle2D;
+import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -145,7 +143,7 @@ public class DrawSimpleShape extends Dra
double alpha = Math.atan(anchor.getHeight() / anchor.getWidth());
AffineTransform at = new AffineTransform();
- java.awt.Shape shape = null;
+ java.awt.Shape tailShape = null;
Path p = null;
Rectangle2D bounds;
final double scaleY = Math.pow(2, tailWidth.ordinal()+1);
@@ -153,8 +151,8 @@ public class DrawSimpleShape extends Dra
switch (deco.getTailShape()) {
case OVAL:
p = new Path();
- shape = new Ellipse2D.Double(0, 0, lineWidth * scaleX, lineWidth * scaleY);
- bounds = shape.getBounds2D();
+ tailShape = new Ellipse2D.Double(0, 0, lineWidth * scaleX, lineWidth * scaleY);
+ bounds = tailShape.getBounds2D();
at.translate(x2 - bounds.getWidth() / 2, y2 - bounds.getHeight() / 2);
at.rotate(alpha, bounds.getX() + bounds.getWidth() / 2, bounds.getY() + bounds.getHeight() / 2);
break;
@@ -165,7 +163,7 @@ public class DrawSimpleShape extends Dra
arrow.moveTo((float) (-lineWidth * scaleX), (float) (-lineWidth * scaleY / 2));
arrow.lineTo(0, 0);
arrow.lineTo((float) (-lineWidth * scaleX), (float) (lineWidth * scaleY / 2));
- shape = arrow;
+ tailShape = arrow;
at.translate(x2, y2);
at.rotate(alpha);
break;
@@ -176,7 +174,7 @@ public class DrawSimpleShape extends Dra
triangle.lineTo(0, 0);
triangle.lineTo((float) (-lineWidth * scaleX), (float) (lineWidth * scaleY / 2));
triangle.closePath();
- shape = triangle;
+ tailShape = triangle;
at.translate(x2, y2);
at.rotate(alpha);
break;
@@ -184,10 +182,10 @@ public class DrawSimpleShape extends Dra
break;
}
- if (shape != null) {
- shape = at.createTransformedShape(shape);
+ if (tailShape != null) {
+ tailShape = at.createTransformedShape(tailShape);
}
- return shape == null ? null : new Outline(shape, p);
+ return tailShape == null ? null : new Outline(tailShape, p);
}
protected Outline getHeadDecoration(Graphics2D graphics, LineDecoration deco, BasicStroke stroke) {
@@ -203,7 +201,7 @@ public class DrawSimpleShape extends Dra
double alpha = Math.atan(anchor.getHeight() / anchor.getWidth());
AffineTransform at = new AffineTransform();
- java.awt.Shape shape = null;
+ java.awt.Shape headShape = null;
Path p = null;
Rectangle2D bounds;
final double scaleY = Math.pow(2, headWidth.ordinal()+1);
@@ -211,8 +209,8 @@ public class DrawSimpleShape extends Dra
switch (deco.getHeadShape()) {
case OVAL:
p = new Path();
- shape = new Ellipse2D.Double(0, 0, lineWidth * scaleX, lineWidth * scaleY);
- bounds = shape.getBounds2D();
+ headShape = new Ellipse2D.Double(0, 0, lineWidth * scaleX, lineWidth * scaleY);
+ bounds = headShape.getBounds2D();
at.translate(x1 - bounds.getWidth() / 2, y1 - bounds.getHeight() / 2);
at.rotate(alpha, bounds.getX() + bounds.getWidth() / 2, bounds.getY() + bounds.getHeight() / 2);
break;
@@ -223,7 +221,7 @@ public class DrawSimpleShape extends Dra
arrow.moveTo((float) (lineWidth * scaleX), (float) (-lineWidth * scaleY / 2));
arrow.lineTo(0, 0);
arrow.lineTo((float) (lineWidth * scaleX), (float) (lineWidth * scaleY / 2));
- shape = arrow;
+ headShape = arrow;
at.translate(x1, y1);
at.rotate(alpha);
break;
@@ -234,7 +232,7 @@ public class DrawSimpleShape extends Dra
triangle.lineTo(0, 0);
triangle.lineTo((float) (lineWidth * scaleX), (float) (lineWidth * scaleY / 2));
triangle.closePath();
- shape = triangle;
+ headShape = triangle;
at.translate(x1, y1);
at.rotate(alpha);
break;
@@ -242,10 +240,10 @@ public class DrawSimpleShape extends Dra
break;
}
- if (shape != null) {
- shape = at.createTransformedShape(shape);
+ if (headShape != null) {
+ headShape = at.createTransformedShape(headShape);
}
- return shape == null ? null : new Outline(shape, p);
+ return headShape == null ? null : new Outline(headShape, p);
}
public BasicStroke getStroke() {
@@ -296,7 +294,7 @@ public class DrawSimpleShape extends Dra
, Paint fill
, Paint line
) {
- Shadow shadow = getShape().getShadow();
+ Shadow<?,?> shadow = getShape().getShadow();
if (shadow == null || (fill == null && line == null)) return;
SolidPaint shadowPaint = shadow.getFillStyle();
@@ -347,7 +345,6 @@ public class DrawSimpleShape extends Dra
String packageName = "org.apache.poi.sl.draw.binding";
InputStream presetIS = Drawable.class.getResourceAsStream("presetShapeDefinitions.xml");
- Reader xml = new InputStreamReader( presetIS, Charset.forName("UTF-8") );
// StAX:
EventFilter startElementFilter = new EventFilter() {
@@ -359,7 +356,7 @@ public class DrawSimpleShape extends Dra
try {
XMLInputFactory staxFactory = XMLInputFactory.newInstance();
- XMLEventReader staxReader = staxFactory.createXMLEventReader(xml);
+ XMLEventReader staxReader = staxFactory.createXMLEventReader(presetIS);
XMLEventReader staxFiltRd = staxFactory.createFilteredReader(staxReader, startElementFilter);
// Ignore StartElement:
staxFiltRd.nextEvent();
@@ -378,6 +375,12 @@ public class DrawSimpleShape extends Dra
}
} catch (Exception e) {
throw new RuntimeException("Unable to load preset geometries.", e);
+ } finally {
+ try {
+ presetIS.close();
+ } catch (IOException e) {
+ throw new RuntimeException("Unable to load preset geometries.", e);
+ }
}
}
Modified: poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java Mon Sep 21 00:09:45 2015
@@ -19,6 +19,7 @@ package org.apache.poi.sl.draw;
import java.awt.Graphics2D;
import java.awt.Paint;
+import java.awt.Rectangle;
import java.awt.font.FontRenderContext;
import java.awt.font.LineBreakMeasurer;
import java.awt.font.TextAttribute;
@@ -416,8 +417,8 @@ public class DrawTextParagraph implement
private PlaceableShape<?,?> getParagraphShape() {
PlaceableShape<?,?> ps = new PlaceableShape(){
public ShapeContainer<?,?> getParent() { return null; }
- public Rectangle2D getAnchor() { return paragraph.getParentShape().getAnchor(); }
- public void setAnchor(Rectangle2D anchor) {}
+ public Rectangle getAnchor() { return paragraph.getParentShape().getAnchor(); }
+ public void setAnchor(Rectangle anchor) {}
public double getRotation() { return 0; }
public void setRotation(double theta) {}
public void setFlipHorizontal(boolean flip) {}
Modified: poi/trunk/src/java/org/apache/poi/sl/usermodel/GroupShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/usermodel/GroupShape.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/usermodel/GroupShape.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/usermodel/GroupShape.java Mon Sep 21 00:09:45 2015
@@ -17,7 +17,7 @@
package org.apache.poi.sl.usermodel;
-import java.awt.geom.Rectangle2D;
+import java.awt.Rectangle;
public interface GroupShape<
S extends Shape<S,P>,
@@ -30,7 +30,7 @@ public interface GroupShape<
*
* @return the coordinate space of this group
*/
- Rectangle2D getInteriorAnchor();
+ Rectangle getInteriorAnchor();
/**
* Sets the coordinate space of this group. All children are constrained
@@ -38,5 +38,5 @@ public interface GroupShape<
*
* @param anchor the coordinate space of this group
*/
- void setInteriorAnchor(Rectangle2D anchor);
+ void setInteriorAnchor(Rectangle anchor);
}
Modified: poi/trunk/src/java/org/apache/poi/sl/usermodel/PictureData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/usermodel/PictureData.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/usermodel/PictureData.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/usermodel/PictureData.java Mon Sep 21 00:09:45 2015
@@ -106,10 +106,16 @@ public interface PictureData {
byte[] getChecksum();
/**
- * Return the original image dimensions
+ * Return the original image dimensions in points
* (for formats supported by BufferedImage).
*
- * Will return a Dimension with zero width/height if the format unsupported.
+ * Will return a Dimension with a default width of 200x200 if the format unsupported.
*/
Dimension getImageDimension();
+
+ /**
+ * Return the original image dimensions in pixels
+ * @see PictureData#getImageDimension()
+ */
+ Dimension getImageDimensionInPixels();
}
\ No newline at end of file
Modified: poi/trunk/src/java/org/apache/poi/sl/usermodel/PlaceableShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/usermodel/PlaceableShape.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/usermodel/PlaceableShape.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/usermodel/PlaceableShape.java Mon Sep 21 00:09:45 2015
@@ -17,7 +17,7 @@
package org.apache.poi.sl.usermodel;
-import java.awt.geom.Rectangle2D;
+import java.awt.Rectangle;
public interface PlaceableShape<
S extends Shape<S,P>,
@@ -29,13 +29,13 @@ public interface PlaceableShape<
* @return the position of this shape within the drawing canvas.
* The coordinates are expressed in points
*/
- Rectangle2D getAnchor();
+ Rectangle getAnchor();
/**
* @param anchor the position of this shape within the drawing canvas.
* The coordinates are expressed in points
*/
- void setAnchor(Rectangle2D anchor);
+ void setAnchor(Rectangle anchor);
/**
* Rotation angle in degrees
Added: poi/trunk/src/java/org/apache/poi/sl/usermodel/RectAlign.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/usermodel/RectAlign.java?rev=1704206&view=auto
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/usermodel/RectAlign.java (added)
+++ poi/trunk/src/java/org/apache/poi/sl/usermodel/RectAlign.java Mon Sep 21 00:09:45 2015
@@ -0,0 +1,74 @@
+/*
+ * ====================================================================
+ * 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.usermodel;
+
+/**
+ * Specifies possible rectangle alignment types.
+ *
+ * @see {@link org.openxmlformats.schemas.drawingml.x2006.main.STRectAlignment}
+ * @see {@link org.apache.poi.sl.draw.binding.STRectAlignment}
+ */
+public enum RectAlign {
+ /** Top-Left rectangle alignment */
+ TOP_LEFT("tl"),
+
+ /** Top rectangle alignment */
+ TOP("t"),
+
+ /** Top-Right rectangle alignment */
+ TOP_RIGHT("tr"),
+
+ /** Left rectangle alignment */
+ LEFT("l"),
+
+ /** Center rectangle alignment */
+ CENTER("ctr"),
+
+ /** Right rectangle alignment */
+ RIGHT("r"),
+
+ /** Bottom-Left rectangle alignment */
+ BOTTOM_LEFT("bl"),
+
+ /** Bottom rectangle alignment */
+ BOTTOM("b"),
+
+ /** Bottom-Right rectangle alignment */
+ BOTTOM_RIGHT("br");
+
+ /** The corresponding xml enum value */
+ private final String dir;
+
+ private RectAlign(String dir) {
+ this.dir = dir;
+ }
+
+
+ /**
+ * The string representation,
+ * which corresponds to the internal XML enum value
+ */
+ @Override
+ public String toString() {
+ return dir;
+ }
+
+}
+
+/* ************************************************************************** */
Modified: poi/trunk/src/java/org/apache/poi/sl/usermodel/Shadow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/usermodel/Shadow.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/usermodel/Shadow.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/usermodel/Shadow.java Mon Sep 21 00:09:45 2015
@@ -21,8 +21,11 @@ import org.apache.poi.sl.usermodel.Paint
-public interface Shadow {
- SimpleShape getShadowParent();
+public interface Shadow<
+S extends Shape<S,P>,
+P extends TextParagraph<S,P,?>
+> {
+ SimpleShape<S,P> getShadowParent();
/**
* @return the offset of this shadow in points
Modified: poi/trunk/src/java/org/apache/poi/sl/usermodel/Shape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/usermodel/Shape.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/usermodel/Shape.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/usermodel/Shape.java Mon Sep 21 00:09:45 2015
@@ -17,6 +17,7 @@
package org.apache.poi.sl.usermodel;
+import java.awt.Rectangle;
public interface Shape<
S extends Shape<S,P>,
@@ -29,4 +30,12 @@ public interface Shape<
* @return the sheet this shape belongs to
*/
Sheet<S,P> getSheet();
+
+ /**
+ * Returns the anchor (the bounding box rectangle) of this shape.
+ * All coordinates are expressed in points (72 dpi).
+ *
+ * @return the anchor of this shape
+ */
+ Rectangle getAnchor();
}
Modified: poi/trunk/src/java/org/apache/poi/sl/usermodel/SimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/usermodel/SimpleShape.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/usermodel/SimpleShape.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/usermodel/SimpleShape.java Mon Sep 21 00:09:45 2015
@@ -35,5 +35,5 @@ public interface SimpleShape<
boolean isPlaceholder();
- Shadow getShadow();
+ Shadow<S,P> getShadow();
}
Copied: poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java (from r1701688, poi/trunk/src/ooxml/java/org/apache/poi/sl/SlideShowFactory.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java?p2=poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java&p1=poi/trunk/src/ooxml/java/org/apache/poi/sl/SlideShowFactory.java&r1=1701688&r2=1704206&rev=1704206&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/sl/SlideShowFactory.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java Mon Sep 21 00:09:45 2015
@@ -14,70 +14,55 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-package org.apache.poi.sl;
+package org.apache.poi.sl.usermodel;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.security.GeneralSecurityException;
-import org.apache.poi.EmptyFileException;
import org.apache.poi.EncryptedDocumentException;
-import org.apache.poi.POIXMLDocument;
-import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.openxml4j.opc.OPCPackage;
-import org.apache.poi.openxml4j.opc.PackageAccess;
import org.apache.poi.poifs.crypt.Decryptor;
import org.apache.poi.poifs.crypt.EncryptionInfo;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.util.IOUtils;
-import org.apache.poi.xslf.usermodel.XMLSlideShow;
public class SlideShowFactory {
+ /** The first 4 bytes of an OOXML file, used in detection */
+ private static final byte[] OOXML_FILE_HEADER = { 0x50, 0x4b, 0x03, 0x04 };
+
/**
- * Creates a HSLFSlideShow from the given POIFSFileSystem
- * <p>Note that in order to properly release resources the
- * SlideShow should be closed after use.
- */
- public static SlideShow create(POIFSFileSystem fs) throws IOException {
- return new HSLFSlideShow(fs);
- }
-
- /**
- * Creates a HSLFSlideShow from the given NPOIFSFileSystem
- * <p>Note that in order to properly release resources the
- * SlideShow should be closed after use.
+ * Creates a SlideShow from the given NPOIFSFileSystem.
+ *
+ * @param fs The {@link NPOIFSFileSystem} to read the document from
+ *
+ * @return The created SlideShow
+ *
+ * @throws IOException if an error occurs while reading the data
*/
- public static SlideShow create(NPOIFSFileSystem fs) throws IOException {
- try {
- return create(fs, null);
- } catch (InvalidFormatException e) {
- // Special case of OOXML-in-POIFS which is broken
- throw new IOException(e);
- }
+ public static SlideShow<?,?> create(NPOIFSFileSystem fs) throws IOException {
+ return create(fs, null);
}
/**
* Creates a SlideShow from the given NPOIFSFileSystem, which may
- * be password protected
+ * be password protected
*
- * @param fs The {@link NPOIFSFileSystem} to read the document from
- * @param password The password that should be used or null if no password is necessary.
+ * @param fs The {@link NPOIFSFileSystem} to read the document from
+ * @param password The password that should be used or null if no password is necessary.
*
- * @return The created SlideShow
+ * @return The created SlideShow
*
- * @throws IOException if an error occurs while reading the data
- * @throws InvalidFormatException if the contents of the file cannot be parsed into a {@link SlideShow}
+ * @throws IOException if an error occurs while reading the data
*/
- private static SlideShow create(NPOIFSFileSystem fs, String password) throws IOException, InvalidFormatException {
+ public static SlideShow<?,?> create(NPOIFSFileSystem fs, String password) throws IOException {
DirectoryNode root = fs.getRoot();
// Encrypted OOXML files go inside OLE2 containers, is this one?
@@ -97,19 +82,20 @@ public class SlideShowFactory {
if (passwordCorrect) {
stream = d.getDataStream(root);
}
+
+ if (!passwordCorrect) {
+ String err = (password != null)
+ ? "Password incorrect"
+ : "The supplied spreadsheet is protected, but no password was supplied";
+ throw new EncryptedDocumentException(err);
+ }
+
+ return createXSLFSlideShow(stream);
} catch (GeneralSecurityException e) {
throw new IOException(e);
+ } finally {
+ if (stream != null) stream.close();
}
-
- if (! passwordCorrect) {
- if (password != null)
- throw new EncryptedDocumentException("Password incorrect");
- else
- throw new EncryptedDocumentException("The supplied spreadsheet is protected, but no password was supplied");
- }
-
- OPCPackage pkg = OPCPackage.open(stream);
- return create(pkg);
}
// If we get here, it isn't an encrypted PPTX file
@@ -117,25 +103,11 @@ public class SlideShowFactory {
if (password != null) {
Biff8EncryptionKey.setCurrentUserPassword(password);
}
- SlideShow wb = new HSLFSlideShow(root);
- Biff8EncryptionKey.setCurrentUserPassword(null);
- return wb;
- }
-
- /**
- * Creates a XMLSlideShow from the given OOXML Package
- *
- * <p>Note that in order to properly release resources the
- * SlideShow should be closed after use.</p>
- *
- * @param pkg The {@link OPCPackage} opened for reading data.
- *
- * @return The created SlideShow
- *
- * @throws IOException if an error occurs while reading the data
- */
- public static SlideShow create(OPCPackage pkg) throws IOException {
- return new XMLSlideShow(pkg);
+ try {
+ return createHSLFSlideShow(fs);
+ } finally {
+ Biff8EncryptionKey.setCurrentUserPassword(null);
+ }
}
/**
@@ -157,10 +129,9 @@ public class SlideShowFactory {
* @return The created SlideShow
*
* @throws IOException if an error occurs while reading the data
- * @throws InvalidFormatException if the contents of the file cannot be parsed into a {@link SlideShow}
* @throws EncryptedDocumentException If the SlideShow given is password protected
*/
- public static SlideShow create(InputStream inp) throws IOException, InvalidFormatException, EncryptedDocumentException {
+ public static SlideShow<?,?> create(InputStream inp) throws IOException, EncryptedDocumentException {
return create(inp, null);
}
@@ -183,11 +154,10 @@ public class SlideShowFactory {
* @return The created SlideShow
*
* @throws IOException if an error occurs while reading the data
- * @throws InvalidFormatException if the contents of the file cannot be parsed into a {@link SlideShow}
* @throws EncryptedDocumentException If the wrong password is given for a protected file
- * @throws EmptyFileException If an empty stream is given
*/
- public static SlideShow create(InputStream inp, String password) throws IOException, InvalidFormatException, EncryptedDocumentException {
+ @SuppressWarnings("resource")
+ public static SlideShow<?,?> create(InputStream inp, String password) throws IOException, EncryptedDocumentException {
// If clearly doesn't do mark/reset, wrap up
if (! inp.markSupported()) {
inp = new PushbackInputStream(inp, 8);
@@ -201,8 +171,8 @@ public class SlideShowFactory {
NPOIFSFileSystem fs = new NPOIFSFileSystem(inp);
return create(fs, password);
}
- if (POIXMLDocument.hasOOXMLHeader(inp)) {
- return new XMLSlideShow(OPCPackage.open(inp));
+ if (hasOOXMLHeader(inp)) {
+ return createXSLFSlideShow(inp);
}
throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream");
}
@@ -218,10 +188,9 @@ public class SlideShowFactory {
* @return The created SlideShow
*
* @throws IOException if an error occurs while reading the data
- * @throws InvalidFormatException if the contents of the file cannot be parsed into a {@link SlideShow}
* @throws EncryptedDocumentException If the SlideShow given is password protected
*/
- public static SlideShow create(File file) throws IOException, InvalidFormatException, EncryptedDocumentException {
+ public static SlideShow<?,?> create(File file) throws IOException, EncryptedDocumentException {
return create(file, null);
}
@@ -238,11 +207,9 @@ public class SlideShowFactory {
* @return The created SlideShow
*
* @throws IOException if an error occurs while reading the data
- * @throws InvalidFormatException if the contents of the file cannot be parsed into a {@link SlideShow}
* @throws EncryptedDocumentException If the wrong password is given for a protected file
- * @throws EmptyFileException If an empty stream is given
*/
- public static SlideShow create(File file, String password) throws IOException, InvalidFormatException, EncryptedDocumentException {
+ public static SlideShow<?,?> create(File file, String password) throws IOException, EncryptedDocumentException {
return create(file, password, false);
}
@@ -261,12 +228,11 @@ public class SlideShowFactory {
* @return The created SlideShow
*
* @throws IOException if an error occurs while reading the data
- * @throws InvalidFormatException if the contents of the file cannot be parsed into a {@link SlideShow}
* @throws EncryptedDocumentException If the wrong password is given for a protected file
- * @throws EmptyFileException If an empty stream is given
*/
- public static SlideShow create(File file, String password, boolean readOnly) throws IOException, InvalidFormatException, EncryptedDocumentException {
- if (! file.exists()) {
+ @SuppressWarnings("resource")
+ public static SlideShow<?,?> create(File file, String password, boolean readOnly) throws IOException, EncryptedDocumentException {
+ if (!file.exists()) {
throw new FileNotFoundException(file.toString());
}
@@ -274,25 +240,76 @@ public class SlideShowFactory {
NPOIFSFileSystem fs = new NPOIFSFileSystem(file, readOnly);
return create(fs, password);
} catch(OfficeXmlFileException e) {
- // opening as .ppt failed => try opening as .pptx
- OPCPackage pkg = OPCPackage.open(file, readOnly ? PackageAccess.READ : PackageAccess.READ_WRITE);
- try {
- return new XMLSlideShow(pkg);
-// } catch (IOException ioe) {
-// // ensure that file handles are closed (use revert() to not re-write the file)
-// pkg.revert();
-// //pkg.close();
-//
-// // rethrow exception
-// throw ioe;
- } catch (IllegalArgumentException ioe) {
- // ensure that file handles are closed (use revert() to not re-write the file)
- pkg.revert();
- //pkg.close();
-
- // rethrow exception
- throw ioe;
+ return createXSLFSlideShow(file, readOnly);
+ }
+ }
+
+ protected static SlideShow<?,?> createHSLFSlideShow(Object... args) throws IOException, EncryptedDocumentException {
+ return createSlideShow("org.apache.poi.hslf.usermodel.HSLFSlideShowFactory", args);
+ }
+
+ protected static SlideShow<?,?> createXSLFSlideShow(Object... args) throws IOException, EncryptedDocumentException {
+ return createSlideShow("org.apache.poi.xslf.usermodel.XSLFSlideShowFactory", args);
+ }
+
+ protected static SlideShow<?,?> createSlideShow(String factoryClass, Object args[]) throws IOException, EncryptedDocumentException {
+ try {
+ Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(factoryClass);
+ Class<?> argsClz[] = new Class<?>[args.length];
+ int i=0;
+ for (Object o : args) {
+ Class<?> c = o.getClass();
+ if (Boolean.class.isAssignableFrom(c)) {
+ c = boolean.class;
+ } else if (InputStream.class.isAssignableFrom(c)) {
+ c = InputStream.class;
+ }
+ argsClz[i++] = c;
}
+ Method m = clazz.getMethod("createSlideShow", argsClz);
+ return (SlideShow<?,?>)m.invoke(null, args);
+ } catch (InvocationTargetException e) {
+ Throwable t = e.getCause();
+ if (t instanceof IOException) {
+ throw (IOException)t;
+ } else if (t instanceof EncryptedDocumentException) {
+ throw (EncryptedDocumentException)t;
+ } else {
+ throw new IOException(t);
+ }
+ } catch (Exception e) {
+ throw new IOException(e);
}
}
+
+ /**
+ * This copied over from ooxml, because we can't rely on these classes in the main package
+ *
+ * @see org.apache.poi.POIXMLDocument#hasOOXMLHeader(InputStream)
+ */
+ protected static boolean hasOOXMLHeader(InputStream inp) throws IOException {
+ // We want to peek at the first 4 bytes
+ inp.mark(4);
+
+ byte[] header = new byte[4];
+ int bytesRead = IOUtils.readFully(inp, header);
+
+ // Wind back those 4 bytes
+ if(inp instanceof PushbackInputStream) {
+ PushbackInputStream pin = (PushbackInputStream)inp;
+ pin.unread(header, 0, bytesRead);
+ } else {
+ inp.reset();
+ }
+
+ // Did it match the ooxml zip signature?
+ return (
+ bytesRead == 4 &&
+ header[0] == OOXML_FILE_HEADER[0] &&
+ header[1] == OOXML_FILE_HEADER[1] &&
+ header[2] == OOXML_FILE_HEADER[2] &&
+ header[3] == OOXML_FILE_HEADER[3]
+ );
+ }
+
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java Mon Sep 21 00:09:45 2015
@@ -19,7 +19,7 @@ package org.apache.poi.xslf.usermodel;
import java.awt.Color;
import java.awt.Dimension;
-import java.awt.geom.Rectangle2D;
+import java.awt.Rectangle;
import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.usermodel.Background;
@@ -43,9 +43,9 @@ public class XSLFBackground extends XSLF
}
@Override
- public Rectangle2D getAnchor(){
+ public Rectangle getAnchor(){
Dimension pg = getSheet().getSlideShow().getPageSize();
- return new Rectangle2D.Double(0, 0, pg.getWidth(), pg.getHeight());
+ return new Rectangle(0, 0, (int)pg.getWidth(), (int)pg.getHeight());
}
@Override
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java Mon Sep 21 00:09:45 2015
@@ -19,6 +19,7 @@
package org.apache.poi.xslf.usermodel;
+import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.geom.PathIterator;
@@ -60,7 +61,7 @@ public class XSLFFreeformShape extends X
public int setPath(GeneralPath path) {
CTPath2D ctPath = CTPath2D.Factory.newInstance();
- Rectangle2D bounds = path.getBounds2D();
+ Rectangle bounds = path.getBounds();
int x0 = Units.toEMU(bounds.getX());
int y0 = Units.toEMU(bounds.getY());
PathIterator it = path.getPathIterator(new AffineTransform());
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java Mon Sep 21 00:09:45 2015
@@ -19,7 +19,7 @@
package org.apache.poi.xslf.usermodel;
-import java.awt.geom.Rectangle2D;
+import java.awt.Rectangle;
import javax.xml.namespace.QName;
@@ -53,20 +53,19 @@ public class XSLFGraphicFrame extends XS
throw new UnsupportedOperationException();
}
- public Rectangle2D getAnchor(){
+ @Override
+ public Rectangle getAnchor(){
CTTransform2D xfrm = ((CTGraphicalObjectFrame)getXmlObject()).getXfrm();
CTPoint2D off = xfrm.getOff();
- long x = off.getX();
- long y = off.getY();
+ int x = (int)Units.toPoints(off.getX());
+ int y = (int)Units.toPoints(off.getY());
CTPositiveSize2D ext = xfrm.getExt();
- long cx = ext.getCx();
- long cy = ext.getCy();
- return new Rectangle2D.Double(
- Units.toPoints(x), Units.toPoints(y),
- Units.toPoints(cx), Units.toPoints(cy));
+ int cx = (int)Units.toPoints(ext.getCx());
+ int cy = (int)Units.toPoints(ext.getCy());
+ return new Rectangle(x, y, cx, cy);
}
- public void setAnchor(Rectangle2D anchor){
+ public void setAnchor(Rectangle anchor){
CTTransform2D xfrm = ((CTGraphicalObjectFrame)getXmlObject()).getXfrm();
CTPoint2D off = xfrm.isSetOff() ? xfrm.getOff() : xfrm.addNewOff();
long x = Units.toEMU(anchor.getX());
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java Mon Sep 21 00:09:45 2015
@@ -19,7 +19,7 @@
package org.apache.poi.xslf.usermodel;
-import java.awt.geom.Rectangle2D;
+import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -27,6 +27,7 @@ import java.util.List;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.TargetMode;
+import org.apache.poi.sl.draw.DrawPictureShape;
import org.apache.poi.sl.usermodel.GroupShape;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.util.Beta;
@@ -78,21 +79,19 @@ implements XSLFShapeContainer, GroupShap
}
@Override
- public Rectangle2D getAnchor(){
+ public Rectangle getAnchor(){
CTGroupTransform2D xfrm = getXfrm();
CTPoint2D off = xfrm.getOff();
- long x = off.getX();
- long y = off.getY();
+ int x = (int)Units.toPoints(off.getX());
+ int y = (int)Units.toPoints(off.getY());
CTPositiveSize2D ext = xfrm.getExt();
- long cx = ext.getCx();
- long cy = ext.getCy();
- return new Rectangle2D.Double(
- Units.toPoints(x), Units.toPoints(y),
- Units.toPoints(cx), Units.toPoints(cy));
+ int cx = (int)Units.toPoints(ext.getCx());
+ int cy = (int)Units.toPoints(ext.getCy());
+ return new Rectangle(x,y,cx,cy);
}
@Override
- public void setAnchor(Rectangle2D anchor){
+ public void setAnchor(Rectangle anchor){
CTGroupTransform2D xfrm = getSafeXfrm();
CTPoint2D off = xfrm.isSetOff() ? xfrm.getOff() : xfrm.addNewOff();
long x = Units.toEMU(anchor.getX());
@@ -112,17 +111,15 @@ implements XSLFShapeContainer, GroupShap
* used for calculations of grouping, scaling, and rotation
* behavior of shapes placed within a group.
*/
- public Rectangle2D getInteriorAnchor(){
+ public Rectangle getInteriorAnchor(){
CTGroupTransform2D xfrm = getXfrm();
CTPoint2D off = xfrm.getChOff();
- long x = off.getX();
- long y = off.getY();
+ int x = (int)Units.toPoints(off.getX());
+ int y = (int)Units.toPoints(off.getY());
CTPositiveSize2D ext = xfrm.getChExt();
- long cx = ext.getCx();
- long cy = ext.getCy();
- return new Rectangle2D.Double(
- Units.toPoints(x), Units.toPoints(y),
- Units.toPoints(cx), Units.toPoints(cy));
+ int cx = (int)Units.toPoints(ext.getCx());
+ int cy = (int)Units.toPoints(ext.getCy());
+ return new Rectangle(x, y, cx, cy);
}
/**
@@ -131,7 +128,7 @@ implements XSLFShapeContainer, GroupShap
* used for calculations of grouping, scaling, and rotation
* behavior of shapes placed within a group.
*/
- public void setInteriorAnchor(Rectangle2D anchor) {
+ public void setInteriorAnchor(Rectangle anchor) {
CTGroupTransform2D xfrm = getSafeXfrm();
CTPoint2D off = xfrm.isSetChOff() ? xfrm.getChOff() : xfrm.addNewChOff();
long x = Units.toEMU(anchor.getX());
@@ -250,7 +247,7 @@ implements XSLFShapeContainer, GroupShap
pic.getPartName(), TargetMode.INTERNAL, XSLFRelation.IMAGES.getRelation());
XSLFPictureShape sh = getDrawing().createPicture(rel.getId());
- sh.resize();
+ new DrawPictureShape(sh).resize();
_shapes.add(sh);
sh.setParent(this);
return sh;
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java Mon Sep 21 00:09:45 2015
@@ -42,6 +42,7 @@ import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Units;
/**
* Instantiates sub-classes of POIXMLDocumentPart depending on their relationship type
@@ -134,6 +135,15 @@ public final class XSLFPictureData exten
return _origSize;
}
+ @Override
+ public Dimension getImageDimensionInPixels() {
+ Dimension dim = getImageDimension();
+ return new Dimension(
+ Units.pointsToPixel(dim.getWidth()),
+ Units.pointsToPixel(dim.getHeight())
+ );
+ }
+
/**
* Determine and cache image properties
*/
@@ -155,14 +165,19 @@ public final class XSLFPictureData exten
_origSize = new PICT.NativeHeader(data, 0).getSize();
break;
default:
+ BufferedImage img = null;
try {
- BufferedImage img = ImageIO.read(new ByteArrayInputStream(data));
- _origSize = (img == null) ? new Dimension() : new Dimension(img.getWidth(), img.getHeight());
+ img = ImageIO.read(new ByteArrayInputStream(data));
} catch (IOException e) {
logger.log(POILogger.WARN, "Can't determine image dimensions", e);
- // failed to get information, set dummy size
- _origSize = new Dimension(200,200);
}
+ // set dummy size, in case of dummy dimension can't be set
+ _origSize = (img == null)
+ ? new Dimension(200,200)
+ : new Dimension(
+ (int)Units.pixelToPoints(img.getWidth()),
+ (int)Units.pixelToPoints(img.getHeight())
+ );
break;
}
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java Mon Sep 21 00:09:45 2015
@@ -19,10 +19,9 @@
package org.apache.poi.xslf.usermodel;
-import java.awt.Dimension;
import java.awt.Insets;
-import java.awt.Rectangle;
import java.net.URI;
+
import javax.xml.namespace.QName;
import org.apache.poi.POIXMLException;
@@ -83,24 +82,6 @@ public class XSLFPictureShape extends XS
return ct;
}
- /**
- * Resize this picture to the default size.
- *
- * For PNG and JPEG resizes the image to 100%,
- * for other types sets the default size to 200x200 pixels.
- */
- public void resize() {
- Dimension dim = getPictureData().getImageDimension();
- if (dim.width > 0 && dim.height > 0)
- {
- setAnchor(new Rectangle(0, 0, dim.width, dim.height));
- }
- else
- {
- // unsupported/unknown formats
- setAnchor(new Rectangle(50, 50, 200, 200));
- }
- }
/**
* Is this an internal picture (image data included within
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShadow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShadow.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShadow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShadow.java Mon Sep 21 00:09:45 2015
@@ -18,7 +18,7 @@
package org.apache.poi.xslf.usermodel;
import java.awt.Color;
-import java.awt.geom.Rectangle2D;
+import java.awt.Rectangle;
import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
@@ -32,7 +32,7 @@ import org.openxmlformats.schemas.drawin
*
* @author Yegor Kozlov
*/
-public class XSLFShadow extends XSLFShape implements Shadow {
+public class XSLFShadow extends XSLFShape implements Shadow<XSLFShape,XSLFTextParagraph> {
private XSLFSimpleShape _parent;
@@ -47,11 +47,12 @@ public class XSLFShadow extends XSLFShap
return _parent;
}
- public Rectangle2D getAnchor(){
+ @Override
+ public Rectangle getAnchor(){
return _parent.getAnchor();
}
- public void setAnchor(Rectangle2D anchor){
+ public void setAnchor(Rectangle anchor){
throw new IllegalStateException("You can't set anchor of a shadow");
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java Mon Sep 21 00:09:45 2015
@@ -36,6 +36,7 @@ import org.apache.poi.openxml4j.opc.Pack
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.sl.draw.DrawFactory;
+import org.apache.poi.sl.draw.DrawPictureShape;
import org.apache.poi.sl.draw.Drawable;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.sl.usermodel.Sheet;
@@ -213,7 +214,7 @@ implements XSLFShapeContainer, Sheet<XSL
addRelation(rel.getId(), new XSLFPictureData(pic, rel));
XSLFPictureShape sh = getDrawing().createPicture(rel.getId());
- sh.resize();
+ new DrawPictureShape(sh).resize();
getShapes().add(sh);
sh.setParent(this);
return sh;
@@ -537,6 +538,7 @@ implements XSLFShapeContainer, Sheet<XSL
* @param packagePart package part containing the data to import
* @return ID of the created relationship
*/
+ @SuppressWarnings("resource")
String importBlip(String blipId, PackagePart packagePart) {
PackageRelationship blipRel = packagePart.getRelationship(blipId);
PackagePart blipPart;
@@ -561,6 +563,7 @@ implements XSLFShapeContainer, Sheet<XSL
/**
* Import a package part into this sheet.
*/
+ @SuppressWarnings("resource")
PackagePart importPart(PackageRelationship srcRel, PackagePart srcPafrt) {
PackagePart destPP = getPackagePart();
PackagePartName srcPPName = srcPafrt.getPartName();
@@ -574,10 +577,11 @@ implements XSLFShapeContainer, Sheet<XSL
destPP.addRelationship(srcPPName, TargetMode.INTERNAL, srcRel.getRelationshipType());
PackagePart part = pkg.createPart(srcPPName, srcPafrt.getContentType());
- OutputStream out = part.getOutputStream();
try {
+ OutputStream out = part.getOutputStream();
InputStream is = srcPafrt.getInputStream();
IOUtils.copy(is, out);
+ is.close();
out.close();
} catch (IOException e){
throw new POIXMLException(e);
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java Mon Sep 21 00:09:45 2015
@@ -20,7 +20,7 @@
package org.apache.poi.xslf.usermodel;
import java.awt.Color;
-import java.awt.geom.Rectangle2D;
+import java.awt.Rectangle;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
@@ -45,7 +45,33 @@ import org.apache.poi.util.Beta;
import org.apache.poi.util.Units;
import org.apache.poi.xslf.model.PropertyFetcher;
import org.apache.xmlbeans.XmlObject;
-import org.openxmlformats.schemas.drawingml.x2006.main.*;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTBaseStyles;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTEffectStyleItem;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTGeomGuide;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTLineEndProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTLineStyleList;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetLineDashProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrix;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
+import org.openxmlformats.schemas.drawingml.x2006.main.STCompoundLine;
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineCap;
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndLength;
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndType;
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndWidth;
+import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal;
+import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType;
import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
/**
@@ -97,23 +123,21 @@ public abstract class XSLFSimpleShape ex
}
@Override
- public Rectangle2D getAnchor() {
+ public Rectangle getAnchor() {
CTTransform2D xfrm = getXfrm();
CTPoint2D off = xfrm.getOff();
- long x = off.getX();
- long y = off.getY();
+ int x = (int)Units.toPoints(off.getX());
+ int y = (int)Units.toPoints(off.getY());
CTPositiveSize2D ext = xfrm.getExt();
- long cx = ext.getCx();
- long cy = ext.getCy();
- return new Rectangle2D.Double(
- Units.toPoints(x), Units.toPoints(y),
- Units.toPoints(cx), Units.toPoints(cy));
+ int cx = (int)Units.toPoints(ext.getCx());
+ int cy = (int)Units.toPoints(ext.getCy());
+ return new Rectangle(x, y, cx, cy);
}
@Override
- public void setAnchor(Rectangle2D anchor) {
+ public void setAnchor(Rectangle anchor) {
CTTransform2D xfrm = getSafeXfrm();
CTPoint2D off = xfrm.isSetOff() ? xfrm.getOff() : xfrm.addNewOff();
long x = Units.toEMU(anchor.getX());
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShowFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShowFactory.java?rev=1704206&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShowFactory.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShowFactory.java Mon Sep 21 00:09:45 2015
@@ -0,0 +1,100 @@
+/* ====================================================================
+ 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.xslf.usermodel;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.poi.EncryptedDocumentException;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackageAccess;
+import org.apache.poi.sl.usermodel.SlideShow;
+import org.apache.poi.sl.usermodel.SlideShowFactory;
+import org.apache.poi.util.Internal;
+
+@Internal
+public class XSLFSlideShowFactory extends SlideShowFactory {
+
+ /**
+ * Creates a XMLSlideShow from the given OOXML Package
+ *
+ * <p>Note that in order to properly release resources the
+ * SlideShow should be closed after use.</p>
+ *
+ * @param pkg The {@link OPCPackage} opened for reading data.
+ *
+ * @return The created SlideShow
+ *
+ * @throws IOException if an error occurs while reading the data
+ * @throws InvalidFormatException
+ */
+ public static SlideShow<?,?> createSlideShow(OPCPackage pkg) throws IOException {
+ try {
+ return new XMLSlideShow(pkg);
+ } catch (IllegalArgumentException ioe) {
+ // ensure that file handles are closed (use revert() to not re-write the file)
+ pkg.revert();
+ //pkg.close();
+
+ // rethrow exception
+ throw ioe;
+ }
+ }
+
+ /**
+ * Creates the XMLSlideShow from the given File, which must exist and be readable.
+ * <p>Note that in order to properly release resources theSlideShow should be closed after use.
+ *
+ * @param file The file to read data from.
+ * @param readOnly If the SlideShow should be opened in read-only mode to avoid writing back
+ * changes when the document is closed.
+ *
+ * @return The created SlideShow
+ *
+ * @throws IOException if an error occurs while reading the data
+ * @throws EncryptedDocumentException If the wrong password is given for a protected file
+ */
+ @SuppressWarnings("resource")
+ public static SlideShow<?,?> createSlideShow(File file, boolean readOnly)
+ throws IOException, InvalidFormatException {
+ OPCPackage pkg = OPCPackage.open(file, readOnly ? PackageAccess.READ : PackageAccess.READ_WRITE);
+ return createSlideShow(pkg);
+ }
+
+ /**
+ * Creates a XMLSlideShow from the given InputStream
+ *
+ * <p>Note that in order to properly release resources the
+ * SlideShow should be closed after use.</p>
+ *
+ * @param stream The {@link InputStream} to read data from.
+ *
+ * @return The created SlideShow
+ *
+ * @throws IOException if an error occurs while reading the data
+ * @throws InvalidFormatException
+ */
+ @SuppressWarnings("resource")
+ public static SlideShow<?,?> createSlideShow(InputStream stream) throws IOException, InvalidFormatException {
+ OPCPackage pkg = OPCPackage.open(stream);
+ return createSlideShow(pkg);
+ }
+
+}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java Mon Sep 21 00:09:45 2015
@@ -19,7 +19,7 @@
package org.apache.poi.xslf.usermodel;
-import java.awt.geom.Rectangle2D;
+import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -466,8 +466,8 @@ public abstract class XSLFTextShape exte
*
* @return a <code>Rectangle2D</code> that is the bounds of this shape.
*/
- public Rectangle2D resizeToFitText(){
- Rectangle2D anchor = getAnchor();
+ public Rectangle resizeToFitText(){
+ Rectangle anchor = getAnchor();
if(anchor.getWidth() == 0.) throw new POIXMLException(
"Anchor of the shape was not set.");
double height = getTextHeight();
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java Mon Sep 21 00:09:45 2015
@@ -31,10 +31,10 @@ import java.util.Map;
import javax.imageio.ImageIO;
-import org.apache.poi.sl.SlideShowFactory;
import org.apache.poi.sl.draw.Drawable;
import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.sl.usermodel.SlideShow;
+import org.apache.poi.sl.usermodel.SlideShowFactory;
import org.apache.poi.util.JvmBugs;
/**
Added: poi/trunk/src/ooxml/testcases/org/apache/poi/sl/draw/TestDrawPictureShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/sl/draw/TestDrawPictureShape.java?rev=1704206&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/sl/draw/TestDrawPictureShape.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/sl/draw/TestDrawPictureShape.java Mon Sep 21 00:09:45 2015
@@ -0,0 +1,71 @@
+/*
+ * ====================================================================
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.awt.Dimension;
+import java.awt.Rectangle;
+
+import org.apache.poi.POIDataSamples;
+import org.apache.poi.sl.usermodel.PictureData;
+import org.apache.poi.sl.usermodel.PictureShape;
+import org.apache.poi.sl.usermodel.RectAlign;
+import org.apache.poi.sl.usermodel.Shape;
+import org.apache.poi.sl.usermodel.Slide;
+import org.apache.poi.sl.usermodel.SlideShow;
+import org.apache.poi.sl.usermodel.SlideShowFactory;
+import org.junit.Test;
+
+public class TestDrawPictureShape {
+ final static POIDataSamples ssSamples = POIDataSamples.getSlideShowInstance();
+
+ @Test
+ public void testResize() throws Exception {
+ String files[] = { "pictures.ppt", "shapes.pptx" };
+ for (String file : files) {
+ SlideShow<?,?> ss = SlideShowFactory.create(ssSamples.getFile(file));
+ Slide<?,?> slide = ss.getSlides().get(0);
+ PictureShape<?,?> picShape = null;
+ for (Shape<?,?> shape : slide.getShapes()) {
+ if (shape instanceof PictureShape) {
+ picShape = (PictureShape<?,?>)shape;
+ break;
+ }
+ }
+ assertNotNull(picShape);
+ PictureData pd = picShape.getPictureData();
+ Dimension dimPd = pd.getImageDimension();
+ new DrawPictureShape(picShape).resize();
+ Dimension dimShape = picShape.getAnchor().getSize();
+ assertEquals(dimPd, dimShape);
+
+ int newWidth = (int)(dimPd.getWidth()*(100d/dimPd.getHeight()));
+ // ... -1 is a rounding error
+ Rectangle expRect = new Rectangle(50+300-newWidth-1, 50, newWidth, 100);
+ Rectangle target = new Rectangle(50,50,300,100);
+ new DrawPictureShape(picShape).resize(target, RectAlign.BOTTOM_RIGHT);
+ Rectangle actRect = picShape.getAnchor();
+ assertEquals(expRect, actRect);
+ }
+ }
+
+
+}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java Mon Sep 21 00:09:45 2015
@@ -16,10 +16,12 @@
==================================================================== */
package org.apache.poi.xslf.usermodel;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
import java.awt.Dimension;
-import java.awt.geom.Rectangle2D;
+import java.awt.Rectangle;
import org.junit.Test;
@@ -29,7 +31,7 @@ import org.junit.Test;
public class TestXSLFGroupShape {
@Test
- public void testCreateShapes() {
+ public void testCreateShapes() throws Exception {
XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide = ppt.createSlide();
@@ -38,11 +40,11 @@ public class TestXSLFGroupShape {
XSLFGroupShape group = slide.createGroup();
assertEquals(1, slide.getShapes().size());
- Rectangle2D interior = new Rectangle2D.Double(-10, -10, 20, 20);
+ Rectangle interior = new Rectangle(-10, -10, 20, 20);
group.setInteriorAnchor(interior);
assertEquals(interior, group.getInteriorAnchor());
- Rectangle2D anchor = new Rectangle2D.Double(0, 0, 792, 612);
+ Rectangle anchor = new Rectangle(0, 0, 792, 612);
group.setAnchor(anchor);
assertEquals(anchor, group.getAnchor());
@@ -83,10 +85,12 @@ public class TestXSLFGroupShape {
group.removeShape(shape1);
group.removeShape(shape4);
assertTrue(group.getShapes().isEmpty());
+
+ ppt.close();
}
@Test
- public void testRemoveShapes() {
+ public void testRemoveShapes() throws Exception {
XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide = ppt.createSlide();
@@ -99,5 +103,6 @@ public class TestXSLFGroupShape {
slide.removeShape(group2);
slide.removeShape(group3);
+ ppt.close();
}
}
\ No newline at end of file
Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShowFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShowFactory.java?rev=1704206&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShowFactory.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShowFactory.java Mon Sep 21 00:09:45 2015
@@ -0,0 +1,66 @@
+/* ====================================================================
+ 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.xslf.usermodel;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.GeneralSecurityException;
+
+import org.apache.poi.POIDataSamples;
+import org.apache.poi.poifs.crypt.EncryptionInfo;
+import org.apache.poi.poifs.crypt.EncryptionMode;
+import org.apache.poi.poifs.crypt.Encryptor;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import org.apache.poi.sl.usermodel.BaseTestSlideShowFactory;
+import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.TempFile;
+import org.junit.Test;
+
+public final class TestXSLFSlideShowFactory extends BaseTestSlideShowFactory {
+ private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
+
+ @Test
+ public void testFactory() throws Exception {
+ File pFile = createProtected("SampleShow.pptx", "foobaa");
+ testFactory("SampleShow.pptx", pFile.getAbsolutePath(), "foobaa");
+ }
+
+ private static File createProtected(String basefile, String password)
+ throws IOException, GeneralSecurityException {
+ NPOIFSFileSystem fs = new NPOIFSFileSystem();
+ EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile);
+ Encryptor enc = info.getEncryptor();
+ enc.confirmPassword(password);
+ InputStream fis = _slTests.openResourceAsStream("SampleShow.pptx");
+ OutputStream os = enc.getDataStream(fs);
+ IOUtils.copy(fis, os);
+ os.close();
+ fis.close();
+
+ File tf = TempFile.createTempFile("test-xslf-slidefactory", "pptx");
+ FileOutputStream fos = new FileOutputStream(tf);
+ fs.writeFilesystem(fos);
+ fos.close();
+ fs.close();
+
+ return tf;
+ }
+}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java Mon Sep 21 00:09:45 2015
@@ -25,7 +25,6 @@ import static org.junit.Assert.assertTru
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
-import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.List;
@@ -75,7 +74,7 @@ public class TestXSLFTextParagraph {
"of text within a shape. Properties here apply to all text " +
"residing within the corresponding paragraph.");
- Rectangle2D anchor = new Rectangle(50, 50, 300, 200);
+ Rectangle anchor = new Rectangle(50, 50, 300, 200);
sh.setAnchor(anchor);
DrawTextParagraphProxy dtp = new DrawTextParagraphProxy(p);
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java Mon Sep 21 00:09:45 2015
@@ -26,6 +26,7 @@ import java.io.IOException;
import javax.imageio.ImageIO;
import org.apache.poi.hslf.usermodel.HSLFPictureData;
+import org.apache.poi.util.Units;
/**
* Represents a bitmap picture data: JPEG or PNG.
@@ -55,10 +56,14 @@ public abstract class Bitmap extends HSL
setRawData(out.toByteArray());
}
+ @Override
public Dimension getImageDimension() {
try {
BufferedImage bi = ImageIO.read(new ByteArrayInputStream(getData()));
- return new Dimension(bi.getWidth(), bi.getHeight());
+ return new Dimension(
+ (int)Units.pixelToPoints(bi.getWidth()),
+ (int)Units.pixelToPoints(bi.getHeight())
+ );
} catch (IOException e) {
return new Dimension(200,200);
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Metafile.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Metafile.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Metafile.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Metafile.java Mon Sep 21 00:09:45 2015
@@ -126,7 +126,7 @@ public abstract class Metafile extends H
return out.toByteArray();
}
-
+ @Override
public Dimension getImageDimension() {
int prefixLen = 16*uidInstanceCount;
Header header = new Header();
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java?rev=1704206&r1=1704205&r2=1704206&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java Mon Sep 21 00:09:45 2015
@@ -42,7 +42,6 @@ import java.awt.geom.Arc2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
-import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
@@ -327,7 +326,7 @@ public final class PPGraphics2D extends
Java graphics sets string coordinates by the baseline of the first character
so we need to shift down by the height of the textbox
*/
- txt.setAnchor(new Rectangle2D.Float(x, y, width, height));
+ txt.setAnchor(new Rectangle((int)x, (int)y, (int)width, (int)height));
_group.addShape(txt);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org