2011-05-27 10:35:44 -04:00
|
|
|
/* ====================================================================
|
|
|
|
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;
|
|
|
|
|
2014-10-26 20:00:05 -04:00
|
|
|
import static org.apache.poi.POITestCase.assertContains;
|
2016-03-28 18:52:01 -04:00
|
|
|
import static org.junit.Assert.assertArrayEquals;
|
2016-05-22 19:58:07 -04:00
|
|
|
import static org.junit.Assert.assertEquals;
|
2016-03-28 18:52:01 -04:00
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
import static org.junit.Assert.fail;
|
2014-10-26 20:00:05 -04:00
|
|
|
|
|
|
|
import java.awt.Color;
|
|
|
|
import java.awt.Dimension;
|
|
|
|
import java.awt.Graphics2D;
|
|
|
|
import java.awt.RenderingHints;
|
|
|
|
import java.awt.geom.AffineTransform;
|
|
|
|
import java.awt.geom.Rectangle2D;
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.io.File;
|
2015-08-06 20:17:55 -04:00
|
|
|
import java.io.IOException;
|
2013-06-25 20:45:18 -04:00
|
|
|
import java.net.URI;
|
2016-01-01 14:05:50 -05:00
|
|
|
import java.util.Collection;
|
2013-06-25 20:45:18 -04:00
|
|
|
|
2014-10-26 20:00:05 -04:00
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
2016-05-08 09:28:11 -04:00
|
|
|
import org.apache.poi.POIDataSamples;
|
2011-09-19 11:38:59 -04:00
|
|
|
import org.apache.poi.POIXMLDocumentPart;
|
2016-01-10 15:44:17 -05:00
|
|
|
import org.apache.poi.POIXMLDocumentPart.RelationPart;
|
2016-11-10 17:54:07 -05:00
|
|
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
2016-05-24 19:39:23 -04:00
|
|
|
import org.apache.poi.sl.draw.DrawPaint;
|
|
|
|
import org.apache.poi.sl.usermodel.PaintStyle;
|
2016-05-22 19:58:07 -04:00
|
|
|
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
|
2016-10-19 19:25:51 -04:00
|
|
|
import org.apache.poi.sl.usermodel.PaintStyle.TexturePaint;
|
2016-05-08 09:28:11 -04:00
|
|
|
import org.apache.poi.sl.usermodel.PictureData;
|
2015-08-02 16:21:35 -04:00
|
|
|
import org.apache.poi.sl.usermodel.PictureData.PictureType;
|
2016-05-22 19:58:07 -04:00
|
|
|
import org.apache.poi.sl.usermodel.ShapeType;
|
2016-05-24 19:39:23 -04:00
|
|
|
import org.apache.poi.sl.usermodel.VerticalAlignment;
|
2016-10-26 18:32:46 -04:00
|
|
|
import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
|
2011-05-27 10:35:44 -04:00
|
|
|
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
2016-05-22 19:58:07 -04:00
|
|
|
import org.apache.poi.xslf.usermodel.XSLFAutoShape;
|
2016-05-08 09:28:11 -04:00
|
|
|
import org.apache.poi.xslf.usermodel.XSLFHyperlink;
|
2014-08-04 17:34:51 -04:00
|
|
|
import org.apache.poi.xslf.usermodel.XSLFPictureData;
|
|
|
|
import org.apache.poi.xslf.usermodel.XSLFPictureShape;
|
2011-09-19 11:38:59 -04:00
|
|
|
import org.apache.poi.xslf.usermodel.XSLFRelation;
|
2014-08-04 17:34:51 -04:00
|
|
|
import org.apache.poi.xslf.usermodel.XSLFShape;
|
2011-05-27 10:35:44 -04:00
|
|
|
import org.apache.poi.xslf.usermodel.XSLFSlide;
|
2011-09-19 11:38:59 -04:00
|
|
|
import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
|
2015-08-06 20:17:55 -04:00
|
|
|
import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
|
2016-05-24 19:39:23 -04:00
|
|
|
import org.apache.poi.xslf.usermodel.XSLFTextRun;
|
2014-10-26 20:00:05 -04:00
|
|
|
import org.junit.Ignore;
|
|
|
|
import org.junit.Test;
|
2015-08-02 16:21:35 -04:00
|
|
|
|
|
|
|
|
2014-10-26 20:00:05 -04:00
|
|
|
public class TestXSLFBugs {
|
2016-05-08 09:28:11 -04:00
|
|
|
private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
|
|
|
|
2014-10-26 20:00:05 -04:00
|
|
|
@Test
|
|
|
|
public void bug51187() throws Exception {
|
2015-09-19 22:25:35 -04:00
|
|
|
XMLSlideShow ss1 = XSLFTestDataSamples.openSampleDocument("51187.pptx");
|
2011-05-27 10:35:44 -04:00
|
|
|
|
2015-09-19 22:25:35 -04:00
|
|
|
assertEquals(1, ss1.getSlides().size());
|
2011-05-27 10:35:44 -04:00
|
|
|
|
|
|
|
// Check the relations on it
|
|
|
|
// Note - rId3 is a self reference
|
2015-09-30 19:06:39 -04:00
|
|
|
XSLFSlide slide0 = ss1.getSlides().get(0);
|
2016-01-01 14:05:50 -05:00
|
|
|
|
|
|
|
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
|
|
|
assertRelation(slide0, "/ppt/slideLayouts/slideLayout12.xml", "rId1");
|
|
|
|
assertRelation(slide0, "/ppt/notesSlides/notesSlide1.xml", "rId2");
|
|
|
|
assertRelation(slide0, "/ppt/slides/slide1.xml", "rId3");
|
|
|
|
assertRelation(slide0, "/ppt/media/image1.png", "rId4");
|
2011-05-27 10:35:44 -04:00
|
|
|
|
|
|
|
// Save and re-load
|
2015-09-19 22:25:35 -04:00
|
|
|
XMLSlideShow ss2 = XSLFTestDataSamples.writeOutAndReadBack(ss1);
|
|
|
|
ss1.close();
|
|
|
|
assertEquals(1, ss2.getSlides().size());
|
2011-05-27 10:35:44 -04:00
|
|
|
|
2015-09-30 19:06:39 -04:00
|
|
|
slide0 = ss2.getSlides().get(0);
|
2016-01-01 14:05:50 -05:00
|
|
|
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
|
|
|
assertRelation(slide0, "/ppt/slideLayouts/slideLayout12.xml", "rId1");
|
|
|
|
assertRelation(slide0, "/ppt/notesSlides/notesSlide1.xml", "rId2");
|
2011-05-27 10:35:44 -04:00
|
|
|
// TODO Fix this
|
2016-01-01 14:05:50 -05:00
|
|
|
assertRelation(slide0, "/ppt/slides/slide1.xml", "rId3");
|
|
|
|
assertRelation(slide0, "/ppt/media/image1.png", "rId4");
|
2015-09-19 22:25:35 -04:00
|
|
|
|
|
|
|
ss2.close();
|
2011-05-27 10:35:44 -04:00
|
|
|
}
|
2011-09-14 10:39:20 -04:00
|
|
|
|
2016-01-01 14:05:50 -05:00
|
|
|
private static void assertRelation(XSLFSlide slide, String exp, String rId) {
|
|
|
|
POIXMLDocumentPart pd = (rId != null) ? slide.getRelationById(rId) : slide;
|
|
|
|
assertEquals(exp, pd.getPackagePart().getPartName().getName());
|
|
|
|
}
|
|
|
|
|
2011-09-14 10:39:20 -04:00
|
|
|
/**
|
|
|
|
* Slide relations with anchors in them
|
|
|
|
*/
|
2014-10-26 20:00:05 -04:00
|
|
|
@Test
|
2015-09-19 22:25:35 -04:00
|
|
|
public void tika705() throws Exception {
|
2011-09-14 10:39:20 -04:00
|
|
|
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("with_japanese.pptx");
|
2011-09-19 11:38:59 -04:00
|
|
|
|
|
|
|
// Should have one slide
|
2015-04-27 16:13:43 -04:00
|
|
|
assertEquals(1, ss.getSlides().size());
|
|
|
|
XSLFSlide slide = ss.getSlides().get(0);
|
2011-09-19 11:38:59 -04:00
|
|
|
|
|
|
|
// Check the relations from this
|
2016-01-10 15:44:17 -05:00
|
|
|
Collection<RelationPart> rels = slide.getRelationParts();
|
2011-09-19 11:38:59 -04:00
|
|
|
|
|
|
|
// Should have 6 relations:
|
|
|
|
// 1 external hyperlink (skipped from list)
|
|
|
|
// 4 internal hyperlinks
|
|
|
|
// 1 slide layout
|
|
|
|
assertEquals(5, rels.size());
|
|
|
|
int layouts = 0;
|
|
|
|
int hyperlinks = 0;
|
2016-01-10 15:44:17 -05:00
|
|
|
for(RelationPart p : rels) {
|
|
|
|
if(p.getRelationship().getRelationshipType().equals(XSLFRelation.HYPERLINK.getRelation())) {
|
2011-09-19 11:38:59 -04:00
|
|
|
hyperlinks++;
|
2016-01-10 15:44:17 -05:00
|
|
|
} else if(p.getDocumentPart() instanceof XSLFSlideLayout) {
|
2011-09-19 11:38:59 -04:00
|
|
|
layouts++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assertEquals(1, layouts);
|
|
|
|
assertEquals(4, hyperlinks);
|
|
|
|
|
|
|
|
// Hyperlinks should all be to #_ftn1 or #ftnref1
|
2016-01-10 15:44:17 -05:00
|
|
|
for(RelationPart p : rels) {
|
|
|
|
if(p.getRelationship().getRelationshipType().equals(XSLFRelation.HYPERLINK.getRelation())) {
|
|
|
|
URI target = p.getRelationship().getTargetURI();
|
2011-09-19 11:38:59 -04:00
|
|
|
|
|
|
|
if(target.getFragment().equals("_ftn1") ||
|
|
|
|
target.getFragment().equals("_ftnref1")) {
|
|
|
|
// Good
|
|
|
|
} else {
|
|
|
|
fail("Invalid target " + target.getFragment() + " on " + target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-19 22:25:35 -04:00
|
|
|
ss.close();
|
2011-09-14 10:39:20 -04:00
|
|
|
}
|
2013-06-25 20:45:18 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A slideshow can have more than one rID pointing to a given
|
|
|
|
* slide, eg presentation.xml rID1 -> slide1.xml, but slide1.xml
|
|
|
|
* rID2 -> slide3.xml
|
|
|
|
*/
|
2014-10-26 20:00:05 -04:00
|
|
|
@Test
|
|
|
|
public void bug54916() throws Exception {
|
2013-06-25 20:45:18 -04:00
|
|
|
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("OverlappingRelations.pptx");
|
|
|
|
XSLFSlide slide;
|
|
|
|
|
|
|
|
// Should find 4 slides
|
2015-04-27 16:13:43 -04:00
|
|
|
assertEquals(4, ss.getSlides().size());
|
2013-06-25 20:45:18 -04:00
|
|
|
|
|
|
|
// Check the text, to see we got them in order
|
2015-04-27 16:13:43 -04:00
|
|
|
slide = ss.getSlides().get(0);
|
2016-01-01 14:05:50 -05:00
|
|
|
assertContains(getSlideText(slide), "POI cannot read this");
|
2013-06-25 20:45:18 -04:00
|
|
|
|
2015-04-27 16:13:43 -04:00
|
|
|
slide = ss.getSlides().get(1);
|
2016-01-01 14:05:50 -05:00
|
|
|
assertContains(getSlideText(slide), "POI can read this");
|
|
|
|
assertContains(getSlideText(slide), "Has a relationship to another slide");
|
2013-06-25 20:45:18 -04:00
|
|
|
|
2015-04-27 16:13:43 -04:00
|
|
|
slide = ss.getSlides().get(2);
|
2016-01-01 14:05:50 -05:00
|
|
|
assertContains(getSlideText(slide), "POI can read this");
|
2013-06-25 20:45:18 -04:00
|
|
|
|
2015-04-27 16:13:43 -04:00
|
|
|
slide = ss.getSlides().get(3);
|
2016-01-01 14:05:50 -05:00
|
|
|
assertContains(getSlideText(slide), "POI can read this");
|
2015-09-19 22:25:35 -04:00
|
|
|
|
|
|
|
ss.close();
|
2013-06-25 20:45:18 -04:00
|
|
|
}
|
|
|
|
|
2014-08-04 17:34:51 -04:00
|
|
|
/**
|
|
|
|
* When the picture is not embedded but inserted only as a "link to file",
|
|
|
|
* there is no data available and XSLFPictureShape.getPictureData()
|
|
|
|
* gives a NPE, see bug #56812
|
|
|
|
*/
|
2014-10-26 20:00:05 -04:00
|
|
|
@Test
|
|
|
|
public void bug56812() throws Exception {
|
2014-08-04 17:34:51 -04:00
|
|
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("56812.pptx");
|
|
|
|
|
2014-08-04 18:00:47 -04:00
|
|
|
int internalPictures = 0;
|
|
|
|
int externalPictures = 0;
|
2014-08-04 17:34:51 -04:00
|
|
|
for (XSLFSlide slide : ppt.getSlides()){
|
|
|
|
for (XSLFShape shape : slide.getShapes()){
|
|
|
|
assertNotNull(shape);
|
|
|
|
|
|
|
|
if (shape instanceof XSLFPictureShape) {
|
2014-08-04 18:00:47 -04:00
|
|
|
XSLFPictureShape picture = (XSLFPictureShape)shape;
|
|
|
|
if (picture.isExternalLinkedPicture()) {
|
|
|
|
externalPictures++;
|
|
|
|
|
|
|
|
assertNotNull(picture.getPictureLink());
|
|
|
|
} else {
|
|
|
|
internalPictures++;
|
|
|
|
|
|
|
|
XSLFPictureData data = picture.getPictureData();
|
|
|
|
assertNotNull(data);
|
|
|
|
assertNotNull(data.getFileName());
|
|
|
|
}
|
2014-08-04 17:34:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-04 18:00:47 -04:00
|
|
|
assertEquals(2, internalPictures);
|
|
|
|
assertEquals(1, externalPictures);
|
2015-09-19 22:25:35 -04:00
|
|
|
ppt.close();
|
2014-08-04 17:34:51 -04:00
|
|
|
}
|
2014-10-26 20:00:05 -04:00
|
|
|
|
|
|
|
@Test
|
|
|
|
@Ignore("Similar to TestFontRendering it doesn't make sense to compare images because of tiny rendering differences in windows/unix")
|
|
|
|
public void bug54542() throws Exception {
|
|
|
|
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("54542_cropped_bitmap.pptx");
|
|
|
|
|
|
|
|
Dimension pgsize = ss.getPageSize();
|
|
|
|
|
2015-04-27 16:13:43 -04:00
|
|
|
XSLFSlide slide = ss.getSlides().get(0);
|
2014-10-26 20:00:05 -04:00
|
|
|
|
|
|
|
// render it
|
|
|
|
double zoom = 1;
|
|
|
|
AffineTransform at = new AffineTransform();
|
|
|
|
at.setToScale(zoom, zoom);
|
|
|
|
|
|
|
|
BufferedImage imgActual = new BufferedImage((int)Math.ceil(pgsize.width*zoom), (int)Math.ceil(pgsize.height*zoom), BufferedImage.TYPE_3BYTE_BGR);
|
|
|
|
Graphics2D graphics = imgActual.createGraphics();
|
|
|
|
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
|
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
|
|
|
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
|
|
|
|
graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
|
|
|
graphics.setTransform(at);
|
|
|
|
graphics.setPaint(Color.white);
|
|
|
|
graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
|
|
|
|
slide.draw(graphics);
|
|
|
|
|
|
|
|
ImageIO.write(imgActual, "PNG", new File("bug54542.png"));
|
2015-09-19 22:25:35 -04:00
|
|
|
ss.close();
|
2014-10-26 20:00:05 -04:00
|
|
|
}
|
2014-08-04 17:34:51 -04:00
|
|
|
|
2013-06-25 20:45:18 -04:00
|
|
|
protected String getSlideText(XSLFSlide slide) {
|
2016-10-26 18:32:46 -04:00
|
|
|
return XSLFPowerPointExtractor.getText(slide, true, false, false);
|
2013-06-25 20:45:18 -04:00
|
|
|
}
|
2014-12-07 10:28:01 -05:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void bug57250() throws Exception {
|
|
|
|
XMLSlideShow ss = new XMLSlideShow();
|
|
|
|
for (String s : new String[]{"Slide1","Slide2"}) {
|
|
|
|
ss.createSlide().createTextBox().setText(s);
|
|
|
|
}
|
|
|
|
validateSlides(ss, false, "Slide1","Slide2");
|
|
|
|
|
|
|
|
XSLFSlide slide = ss.createSlide();
|
|
|
|
slide.createTextBox().setText("New slide");
|
|
|
|
validateSlides(ss, true, "Slide1","Slide2","New slide");
|
|
|
|
|
|
|
|
// Move backward
|
|
|
|
ss.setSlideOrder(slide, 0);
|
|
|
|
validateSlides(ss, true, "New slide","Slide1","Slide2");
|
|
|
|
|
|
|
|
// Move forward
|
|
|
|
ss.setSlideOrder(slide, 1);
|
|
|
|
validateSlides(ss, true, "Slide1","New slide","Slide2");
|
|
|
|
|
|
|
|
// Move to end
|
|
|
|
ss.setSlideOrder(slide, 0);
|
|
|
|
ss.setSlideOrder(slide, 2);
|
|
|
|
validateSlides(ss, true, "Slide1","Slide2","New slide");
|
2015-09-19 22:25:35 -04:00
|
|
|
ss.close();
|
2014-12-07 10:28:01 -05:00
|
|
|
}
|
2015-04-29 14:31:12 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* When working with >9 images, make sure the sorting ensures
|
|
|
|
* that image10.foo isn't between image1.foo and image2.foo
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void test57552() throws Exception {
|
|
|
|
XMLSlideShow ss = new XMLSlideShow();
|
|
|
|
for (String s : new String[]{"Slide1","Slide2"}) {
|
|
|
|
ss.createSlide().createTextBox().setText(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Slide starts with just layout relation
|
2015-07-19 15:00:32 -04:00
|
|
|
XSLFSlide slide = ss.getSlides().get(0);
|
2015-09-19 22:25:35 -04:00
|
|
|
assertEquals(0, ss.getPictureData().size());
|
2015-07-19 15:00:32 -04:00
|
|
|
assertEquals(1, slide.getShapes().size());
|
2015-04-29 14:31:12 -04:00
|
|
|
|
|
|
|
assertEquals(1, slide.getRelations().size());
|
|
|
|
assertRelationEquals(XSLFRelation.SLIDE_LAYOUT, slide.getRelations().get(0));
|
|
|
|
|
|
|
|
// Some dummy pictures
|
|
|
|
byte[][] pics = new byte[15][3];
|
|
|
|
for (int i=0; i<pics.length; i++) {
|
|
|
|
for (int j=0; j<pics[i].length; j++) {
|
|
|
|
pics[i][j] = (byte)i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a few pictures
|
|
|
|
for (int i=0; i<10; i++) {
|
2015-08-02 16:21:35 -04:00
|
|
|
XSLFPictureData data = ss.addPicture(pics[i], PictureType.JPEG);
|
|
|
|
assertEquals(i, data.getIndex());
|
2015-09-19 22:25:35 -04:00
|
|
|
assertEquals(i+1, ss.getPictureData().size());
|
2015-04-29 14:31:12 -04:00
|
|
|
|
2015-08-02 16:21:35 -04:00
|
|
|
XSLFPictureShape shape = slide.createPicture(data);
|
2015-04-29 14:31:12 -04:00
|
|
|
assertNotNull(shape.getPictureData());
|
|
|
|
assertArrayEquals(pics[i], shape.getPictureData().getData());
|
2015-07-19 15:00:32 -04:00
|
|
|
assertEquals(i+2, slide.getShapes().size());
|
2015-04-29 14:31:12 -04:00
|
|
|
}
|
|
|
|
// Re-fetch the pictures and check
|
|
|
|
for (int i=0; i<10; i++) {
|
2015-07-19 15:00:32 -04:00
|
|
|
XSLFPictureShape shape = (XSLFPictureShape)slide.getShapes().get(i+1);
|
2015-04-29 14:31:12 -04:00
|
|
|
assertNotNull(shape.getPictureData());
|
|
|
|
assertArrayEquals(pics[i], shape.getPictureData().getData());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add past 10
|
|
|
|
for (int i=10; i<15; i++) {
|
2015-08-02 16:21:35 -04:00
|
|
|
XSLFPictureData data = ss.addPicture(pics[i], PictureType.JPEG);
|
|
|
|
assertEquals(i, data.getIndex());
|
2015-09-19 22:25:35 -04:00
|
|
|
assertEquals(i+1, ss.getPictureData().size());
|
2015-04-29 14:31:12 -04:00
|
|
|
|
2015-08-02 16:21:35 -04:00
|
|
|
XSLFPictureShape shape = slide.createPicture(data);
|
2015-04-29 14:31:12 -04:00
|
|
|
assertNotNull(shape.getPictureData());
|
|
|
|
assertArrayEquals(pics[i], shape.getPictureData().getData());
|
2015-07-19 15:00:32 -04:00
|
|
|
assertEquals(i+2, slide.getShapes().size());
|
2015-04-29 14:31:12 -04:00
|
|
|
}
|
|
|
|
// Check all pictures
|
|
|
|
for (int i=0; i<15; i++) {
|
2015-07-19 15:00:32 -04:00
|
|
|
XSLFPictureShape shape = (XSLFPictureShape)slide.getShapes().get(i+1);
|
2015-04-29 14:31:12 -04:00
|
|
|
assertNotNull(shape.getPictureData());
|
|
|
|
assertArrayEquals(pics[i], shape.getPictureData().getData());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a duplicate, check the right one is picked
|
2015-08-02 16:21:35 -04:00
|
|
|
XSLFPictureData data = ss.addPicture(pics[3], PictureType.JPEG);
|
|
|
|
assertEquals(3, data.getIndex());
|
2015-09-19 22:25:35 -04:00
|
|
|
assertEquals(15, ss.getPictureData().size());
|
2015-04-29 14:31:12 -04:00
|
|
|
|
2015-08-02 16:21:35 -04:00
|
|
|
XSLFPictureShape shape = slide.createPicture(data);
|
2015-04-29 14:31:12 -04:00
|
|
|
assertNotNull(shape.getPictureData());
|
|
|
|
assertArrayEquals(pics[3], shape.getPictureData().getData());
|
2015-07-19 15:00:32 -04:00
|
|
|
assertEquals(17, slide.getShapes().size());
|
2015-04-29 14:31:12 -04:00
|
|
|
|
|
|
|
|
|
|
|
// Save and re-load
|
2015-08-06 20:17:55 -04:00
|
|
|
XMLSlideShow ss2 = XSLFTestDataSamples.writeOutAndReadBack(ss);
|
|
|
|
slide = ss2.getSlides().get(0);
|
2015-04-29 14:31:12 -04:00
|
|
|
|
|
|
|
// Check the 15 individual ones added
|
|
|
|
for (int i=0; i<15; i++) {
|
2015-07-19 15:00:32 -04:00
|
|
|
shape = (XSLFPictureShape)slide.getShapes().get(i+1);
|
2015-04-29 14:31:12 -04:00
|
|
|
assertNotNull(shape.getPictureData());
|
|
|
|
assertArrayEquals(pics[i], shape.getPictureData().getData());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the duplicate
|
2015-07-19 15:00:32 -04:00
|
|
|
shape = (XSLFPictureShape)slide.getShapes().get(16);
|
2015-04-29 14:31:12 -04:00
|
|
|
assertNotNull(shape.getPictureData());
|
|
|
|
assertArrayEquals(pics[3], shape.getPictureData().getData());
|
|
|
|
|
|
|
|
// Add another duplicate
|
2015-08-06 20:17:55 -04:00
|
|
|
data = ss2.addPicture(pics[5], PictureType.JPEG);
|
2015-08-02 16:21:35 -04:00
|
|
|
assertEquals(5, data.getIndex());
|
2015-09-19 22:25:35 -04:00
|
|
|
assertEquals(15, ss2.getPictureData().size());
|
2015-04-29 14:31:12 -04:00
|
|
|
|
2015-08-02 16:21:35 -04:00
|
|
|
shape = slide.createPicture(data);
|
2015-04-29 14:31:12 -04:00
|
|
|
assertNotNull(shape.getPictureData());
|
|
|
|
assertArrayEquals(pics[5], shape.getPictureData().getData());
|
2015-07-19 15:00:32 -04:00
|
|
|
assertEquals(18, slide.getShapes().size());
|
2015-08-06 20:17:55 -04:00
|
|
|
|
|
|
|
ss2.close();
|
|
|
|
ss.close();
|
2015-04-29 14:31:12 -04:00
|
|
|
}
|
2014-12-07 10:28:01 -05:00
|
|
|
|
2015-09-19 22:25:35 -04:00
|
|
|
private void validateSlides(XMLSlideShow ss, boolean saveAndReload, String... slideTexts) throws IOException {
|
2014-12-07 10:28:01 -05:00
|
|
|
if (saveAndReload) {
|
2015-09-19 22:25:35 -04:00
|
|
|
XMLSlideShow ss2 = XSLFTestDataSamples.writeOutAndReadBack(ss);
|
|
|
|
validateSlides(ss, slideTexts);
|
|
|
|
ss2.close();
|
|
|
|
} else {
|
|
|
|
validateSlides(ss, slideTexts);
|
2014-12-07 10:28:01 -05:00
|
|
|
}
|
2015-09-19 22:25:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void validateSlides(XMLSlideShow ss, String... slideTexts) throws IOException {
|
2015-04-27 16:13:43 -04:00
|
|
|
assertEquals(slideTexts.length, ss.getSlides().size());
|
2014-12-07 10:28:01 -05:00
|
|
|
|
|
|
|
for (int i = 0; i < slideTexts.length; i++) {
|
2015-04-27 16:13:43 -04:00
|
|
|
XSLFSlide slide = ss.getSlides().get(i);
|
2014-12-07 10:28:01 -05:00
|
|
|
assertContains(getSlideText(slide), slideTexts[i]);
|
|
|
|
}
|
|
|
|
}
|
2015-09-19 22:25:35 -04:00
|
|
|
|
2015-04-29 14:31:12 -04:00
|
|
|
private void assertRelationEquals(XSLFRelation expected, POIXMLDocumentPart relation) {
|
|
|
|
assertEquals(expected.getContentType(), relation.getPackagePart().getContentType());
|
|
|
|
assertEquals(expected.getFileName(expected.getFileNameIndex(relation)), relation.getPackagePart().getPartName().getName());
|
|
|
|
}
|
2015-08-06 20:17:55 -04:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void bug58205() throws IOException {
|
|
|
|
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("themes.pptx");
|
|
|
|
|
|
|
|
int i = 1;
|
|
|
|
for (XSLFSlideMaster sm : ss.getSlideMasters()) {
|
|
|
|
assertEquals("rId"+(i++), ss.getRelationId(sm));
|
|
|
|
}
|
|
|
|
|
|
|
|
ss.close();
|
|
|
|
}
|
2016-03-13 17:30:27 -04:00
|
|
|
|
|
|
|
@Test
|
2016-05-08 09:28:11 -04:00
|
|
|
public void bug55791a() throws IOException {
|
2016-03-13 17:30:27 -04:00
|
|
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("45541_Footer.pptx");
|
|
|
|
removeAndCreateSlide(ppt);
|
2016-05-08 09:28:11 -04:00
|
|
|
ppt.close();
|
2016-03-13 17:30:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2016-05-08 09:28:11 -04:00
|
|
|
public void bug55791b() throws IOException {
|
2016-03-13 17:30:27 -04:00
|
|
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("SampleShow.pptx");
|
|
|
|
removeAndCreateSlide(ppt);
|
2016-05-08 09:28:11 -04:00
|
|
|
ppt.close();
|
2016-03-13 17:30:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void removeAndCreateSlide(XMLSlideShow ppt) {
|
|
|
|
assertTrue(ppt.getSlides().size() > 1);
|
|
|
|
ppt.removeSlide(1);
|
|
|
|
assertNotNull(ppt.createSlide());
|
|
|
|
}
|
2016-03-28 18:52:01 -04:00
|
|
|
|
|
|
|
@Test
|
2016-05-08 09:28:11 -04:00
|
|
|
public void blibFillAlternateContent() throws IOException {
|
2016-03-28 18:52:01 -04:00
|
|
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("2411-Performance_Up.pptx");
|
|
|
|
XSLFPictureShape ps = (XSLFPictureShape)ppt.getSlides().get(4).getShapes().get(0);
|
|
|
|
assertNotNull(ps.getPictureData());
|
|
|
|
ppt.close();
|
|
|
|
}
|
2016-05-08 09:28:11 -04:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void bug59434() throws IOException {
|
|
|
|
String url1 = "http://poi.apache.org/changes.html";
|
|
|
|
String url2 = "http://poi.apache.org/faq.html";
|
|
|
|
XMLSlideShow ppt1 = new XMLSlideShow();
|
|
|
|
PictureData pd1 = ppt1.addPicture(slTests.readFile("tomcat.png"), PictureType.PNG);
|
|
|
|
PictureData pd2 = ppt1.addPicture(slTests.readFile("santa.wmf"), PictureType.WMF);
|
|
|
|
XSLFSlide slide = ppt1.createSlide();
|
|
|
|
XSLFPictureShape ps1 = slide.createPicture(pd1);
|
|
|
|
ps1.setAnchor(new Rectangle2D.Double(20, 20, 100, 100));
|
|
|
|
XSLFHyperlink hl1 = ps1.createHyperlink();
|
|
|
|
hl1.linkToUrl(url1);
|
|
|
|
XSLFPictureShape ps2 = slide.createPicture(pd2);
|
|
|
|
ps2.setAnchor(new Rectangle2D.Double(120, 120, 100, 100));
|
|
|
|
XSLFHyperlink hl2 = ps2.createHyperlink();
|
|
|
|
hl2.linkToUrl(url2);
|
|
|
|
XMLSlideShow ppt2 = XSLFTestDataSamples.writeOutAndReadBack(ppt1);
|
|
|
|
ppt1.close();
|
|
|
|
slide = ppt2.getSlides().get(0);
|
|
|
|
ps1 = (XSLFPictureShape)slide.getShapes().get(0);
|
|
|
|
ps2 = (XSLFPictureShape)slide.getShapes().get(1);
|
|
|
|
assertEquals(url1, ps1.getHyperlink().getAddress());
|
|
|
|
assertEquals(url2, ps2.getHyperlink().getAddress());
|
|
|
|
|
|
|
|
ppt2.close();
|
|
|
|
}
|
2016-05-22 19:58:07 -04:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void bug58217() throws IOException {
|
2016-05-24 19:39:23 -04:00
|
|
|
Color fillColor = new Color(1f,1f,0f,0.1f);
|
|
|
|
Color lineColor = new Color(25.3f/255f,1f,0f,0.4f);
|
|
|
|
Color textColor = new Color(1f,1f,0f,0.6f);
|
|
|
|
|
2016-05-22 19:58:07 -04:00
|
|
|
XMLSlideShow ppt1 = new XMLSlideShow();
|
|
|
|
XSLFSlide sl = ppt1.createSlide();
|
|
|
|
XSLFAutoShape as = sl.createAutoShape();
|
|
|
|
as.setShapeType(ShapeType.STAR_10);
|
|
|
|
as.setAnchor(new Rectangle2D.Double(100,100,300,300));
|
2016-05-24 19:39:23 -04:00
|
|
|
as.setFillColor(fillColor);
|
|
|
|
as.setLineColor(lineColor);
|
2016-05-22 19:58:07 -04:00
|
|
|
as.setText("Alpha");
|
2016-05-24 19:39:23 -04:00
|
|
|
as.setVerticalAlignment(VerticalAlignment.MIDDLE);
|
|
|
|
as.setHorizontalCentered(true);
|
|
|
|
XSLFTextRun tr = as.getTextParagraphs().get(0).getTextRuns().get(0);
|
|
|
|
tr.setFontSize(32d);
|
|
|
|
tr.setFontColor(textColor);
|
2016-05-22 19:58:07 -04:00
|
|
|
XMLSlideShow ppt2 = XSLFTestDataSamples.writeOutAndReadBack(ppt1);
|
|
|
|
ppt1.close();
|
|
|
|
sl = ppt2.getSlides().get(0);
|
|
|
|
as = (XSLFAutoShape)sl.getShapes().get(0);
|
2016-05-24 19:39:23 -04:00
|
|
|
checkColor(fillColor, as.getFillStyle().getPaint());
|
|
|
|
checkColor(lineColor, as.getStrokeStyle().getPaint());
|
|
|
|
checkColor(textColor, as.getTextParagraphs().get(0).getTextRuns().get(0).getFontColor());
|
2016-05-22 19:58:07 -04:00
|
|
|
ppt2.close();
|
|
|
|
}
|
2016-05-24 19:39:23 -04:00
|
|
|
|
|
|
|
private static void checkColor(Color expected, PaintStyle actualStyle) {
|
|
|
|
assertTrue(actualStyle instanceof SolidPaint);
|
|
|
|
SolidPaint ps = (SolidPaint)actualStyle;
|
|
|
|
Color actual = DrawPaint.applyColorTransform(ps.getSolidColor());
|
|
|
|
float expRGB[] = expected.getRGBComponents(null);
|
|
|
|
float actRGB[] = actual.getRGBComponents(null);
|
|
|
|
assertArrayEquals(expRGB, actRGB, 0.0001f);
|
|
|
|
}
|
2016-10-19 19:25:51 -04:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void bug55714() throws IOException {
|
|
|
|
XMLSlideShow srcPptx = XSLFTestDataSamples.openSampleDocument("pptx2svg.pptx");
|
|
|
|
XMLSlideShow newPptx = new XMLSlideShow();
|
|
|
|
XSLFSlide srcSlide = srcPptx.getSlides().get(0);
|
|
|
|
XSLFSlide newSlide = newPptx.createSlide();
|
|
|
|
|
|
|
|
XSLFSlideLayout srcSlideLayout = srcSlide.getSlideLayout();
|
|
|
|
XSLFSlideLayout newSlideLayout = newSlide.getSlideLayout();
|
|
|
|
newSlideLayout.importContent(srcSlideLayout);
|
|
|
|
|
|
|
|
XSLFSlideMaster srcSlideMaster = srcSlide.getSlideMaster();
|
|
|
|
XSLFSlideMaster newSlideMaster = newSlide.getSlideMaster();
|
|
|
|
newSlideMaster.importContent(srcSlideMaster);
|
|
|
|
|
|
|
|
newSlide.importContent(srcSlide);
|
|
|
|
XMLSlideShow rwPptx = XSLFTestDataSamples.writeOutAndReadBack(newPptx);
|
|
|
|
|
|
|
|
PaintStyle ps = rwPptx.getSlides().get(0).getBackground().getFillStyle().getPaint();
|
|
|
|
assertTrue(ps instanceof TexturePaint);
|
|
|
|
|
|
|
|
rwPptx.close();
|
|
|
|
newPptx.close();
|
|
|
|
srcPptx.close();
|
|
|
|
}
|
2016-11-10 17:54:07 -05:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void bug59273() throws IOException {
|
|
|
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("bug59273.potx");
|
|
|
|
ppt.getPackage().replaceContentType(
|
|
|
|
XSLFRelation.PRESENTATIONML_TEMPLATE.getContentType(),
|
|
|
|
XSLFRelation.MAIN.getContentType()
|
|
|
|
);
|
|
|
|
|
|
|
|
XMLSlideShow rwPptx = XSLFTestDataSamples.writeOutAndReadBack(ppt);
|
|
|
|
OPCPackage pkg = rwPptx.getPackage();
|
|
|
|
int size = pkg.getPartsByContentType(XSLFRelation.MAIN.getContentType()).size();
|
|
|
|
assertEquals(1, size);
|
|
|
|
size = pkg.getPartsByContentType(XSLFRelation.PRESENTATIONML_TEMPLATE.getContentType()).size();
|
|
|
|
assertEquals(0, size);
|
|
|
|
|
|
|
|
rwPptx.close();
|
|
|
|
ppt.close();
|
|
|
|
}
|
2011-05-27 10:35:44 -04:00
|
|
|
}
|