aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/testcases/org
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2015-09-21 00:09:45 +0000
committerAndreas Beeker <kiwiwings@apache.org>2015-09-21 00:09:45 +0000
commitc7e9309e83af9a6bde15b625771137edbcfec8f2 (patch)
treea0ed878eb3deef8a4d01d129acb0b852422e38a9 /src/ooxml/testcases/org
parenteb6cc7eca19f55e07e4cac9bf8ebdea30573440e (diff)
downloadpoi-c7e9309e83af9a6bde15b625771137edbcfec8f2.tar.gz
poi-c7e9309e83af9a6bde15b625771137edbcfec8f2.zip
- #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 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1704206 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/testcases/org')
-rw-r--r--src/ooxml/testcases/org/apache/poi/sl/draw/TestDrawPictureShape.java71
-rw-r--r--src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java17
-rw-r--r--src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShowFactory.java66
-rw-r--r--src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java3
4 files changed, 149 insertions, 8 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/sl/draw/TestDrawPictureShape.java b/src/ooxml/testcases/org/apache/poi/sl/draw/TestDrawPictureShape.java
new file mode 100644
index 0000000000..2fd0be3139
--- /dev/null
+++ b/src/ooxml/testcases/org/apache/poi/sl/draw/TestDrawPictureShape.java
@@ -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);
+ }
+ }
+
+
+}
diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java
index 4a6e0ff2a0..f5d180121a 100644
--- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java
+++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java
@@ -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
diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShowFactory.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShowFactory.java
new file mode 100644
index 0000000000..8b9ac979f2
--- /dev/null
+++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShowFactory.java
@@ -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;
+ }
+}
diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java
index a2ddfadbbc..a57771080d 100644
--- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java
+++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java
@@ -25,7 +25,6 @@ import static org.junit.Assert.assertTrue;
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);