mirror of https://github.com/apache/poi.git
[bug-61515] fix xlsf issue with relationships [from Alain Bearez] This closes #70
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1808294 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b29668bb9e
commit
e6d9be197c
|
@ -251,6 +251,7 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> {
|
||||||
slideId.setId2(rp.getRelationship().getId());
|
slideId.setId2(rp.getRelationship().getId());
|
||||||
|
|
||||||
layout.copyLayout(slide);
|
layout.copyLayout(slide);
|
||||||
|
slide.getPackagePart().clearRelationships();
|
||||||
slide.addRelation(null, XSLFRelation.SLIDE_LAYOUT, layout);
|
slide.addRelation(null, XSLFRelation.SLIDE_LAYOUT, layout);
|
||||||
|
|
||||||
_slides.add(slide);
|
_slides.add(slide);
|
||||||
|
|
|
@ -16,6 +16,27 @@
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf;
|
package org.apache.poi.xslf;
|
||||||
|
|
||||||
|
import static org.apache.poi.POITestCase.assertContains;
|
||||||
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
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;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.POIXMLDocumentPart;
|
import org.apache.poi.POIXMLDocumentPart;
|
||||||
import org.apache.poi.POIXMLDocumentPart.RelationPart;
|
import org.apache.poi.POIXMLDocumentPart.RelationPart;
|
||||||
|
@ -29,28 +50,28 @@ import org.apache.poi.sl.usermodel.PictureData.PictureType;
|
||||||
import org.apache.poi.sl.usermodel.ShapeType;
|
import org.apache.poi.sl.usermodel.ShapeType;
|
||||||
import org.apache.poi.sl.usermodel.VerticalAlignment;
|
import org.apache.poi.sl.usermodel.VerticalAlignment;
|
||||||
import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
|
import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
|
||||||
import org.apache.poi.xslf.usermodel.*;
|
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFAutoShape;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFGroupShape;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFHyperlink;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFNotes;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFPictureData;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFPictureShape;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFRelation;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFShape;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFSlide;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFTable;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFTableCell;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFTableRow;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFTextParagraph;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFTextRun;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
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;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import static org.apache.poi.POITestCase.assertContains;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
|
|
||||||
public class TestXSLFBugs {
|
public class TestXSLFBugs {
|
||||||
private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||||
|
@ -58,24 +79,24 @@ public class TestXSLFBugs {
|
||||||
@Test
|
@Test
|
||||||
public void bug51187() throws Exception {
|
public void bug51187() throws Exception {
|
||||||
XMLSlideShow ss1 = XSLFTestDataSamples.openSampleDocument("51187.pptx");
|
XMLSlideShow ss1 = XSLFTestDataSamples.openSampleDocument("51187.pptx");
|
||||||
|
|
||||||
assertEquals(1, ss1.getSlides().size());
|
assertEquals(1, ss1.getSlides().size());
|
||||||
|
|
||||||
// Check the relations on it
|
// Check the relations on it
|
||||||
// Note - rId3 is a self reference
|
// Note - rId3 is a self reference
|
||||||
XSLFSlide slide0 = ss1.getSlides().get(0);
|
XSLFSlide slide0 = ss1.getSlides().get(0);
|
||||||
|
|
||||||
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
||||||
assertRelation(slide0, "/ppt/slideLayouts/slideLayout12.xml", "rId1");
|
assertRelation(slide0, "/ppt/slideLayouts/slideLayout12.xml", "rId1");
|
||||||
assertRelation(slide0, "/ppt/notesSlides/notesSlide1.xml", "rId2");
|
assertRelation(slide0, "/ppt/notesSlides/notesSlide1.xml", "rId2");
|
||||||
assertRelation(slide0, "/ppt/slides/slide1.xml", "rId3");
|
assertRelation(slide0, "/ppt/slides/slide1.xml", "rId3");
|
||||||
assertRelation(slide0, "/ppt/media/image1.png", "rId4");
|
assertRelation(slide0, "/ppt/media/image1.png", "rId4");
|
||||||
|
|
||||||
// Save and re-load
|
// Save and re-load
|
||||||
XMLSlideShow ss2 = XSLFTestDataSamples.writeOutAndReadBack(ss1);
|
XMLSlideShow ss2 = XSLFTestDataSamples.writeOutAndReadBack(ss1);
|
||||||
ss1.close();
|
ss1.close();
|
||||||
assertEquals(1, ss2.getSlides().size());
|
assertEquals(1, ss2.getSlides().size());
|
||||||
|
|
||||||
slide0 = ss2.getSlides().get(0);
|
slide0 = ss2.getSlides().get(0);
|
||||||
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
||||||
assertRelation(slide0, "/ppt/slideLayouts/slideLayout12.xml", "rId1");
|
assertRelation(slide0, "/ppt/slideLayouts/slideLayout12.xml", "rId1");
|
||||||
|
@ -83,30 +104,30 @@ public class TestXSLFBugs {
|
||||||
// TODO Fix this
|
// TODO Fix this
|
||||||
assertRelation(slide0, "/ppt/slides/slide1.xml", "rId3");
|
assertRelation(slide0, "/ppt/slides/slide1.xml", "rId3");
|
||||||
assertRelation(slide0, "/ppt/media/image1.png", "rId4");
|
assertRelation(slide0, "/ppt/media/image1.png", "rId4");
|
||||||
|
|
||||||
ss2.close();
|
ss2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertRelation(XSLFSlide slide, String exp, String rId) {
|
private static void assertRelation(XSLFSlide slide, String exp, String rId) {
|
||||||
POIXMLDocumentPart pd = (rId != null) ? slide.getRelationById(rId) : slide;
|
POIXMLDocumentPart pd = (rId != null) ? slide.getRelationById(rId) : slide;
|
||||||
assertNotNull(pd);
|
assertNotNull(pd);
|
||||||
assertEquals(exp, pd.getPackagePart().getPartName().getName());
|
assertEquals(exp, pd.getPackagePart().getPartName().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Slide relations with anchors in them
|
* Slide relations with anchors in them
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void tika705() throws Exception {
|
public void tika705() throws Exception {
|
||||||
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("with_japanese.pptx");
|
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("with_japanese.pptx");
|
||||||
|
|
||||||
// Should have one slide
|
// Should have one slide
|
||||||
assertEquals(1, ss.getSlides().size());
|
assertEquals(1, ss.getSlides().size());
|
||||||
XSLFSlide slide = ss.getSlides().get(0);
|
XSLFSlide slide = ss.getSlides().get(0);
|
||||||
|
|
||||||
// Check the relations from this
|
// Check the relations from this
|
||||||
Collection<RelationPart> rels = slide.getRelationParts();
|
Collection<RelationPart> rels = slide.getRelationParts();
|
||||||
|
|
||||||
// Should have 6 relations:
|
// Should have 6 relations:
|
||||||
// 1 external hyperlink (skipped from list)
|
// 1 external hyperlink (skipped from list)
|
||||||
// 4 internal hyperlinks
|
// 4 internal hyperlinks
|
||||||
|
@ -123,7 +144,7 @@ public class TestXSLFBugs {
|
||||||
}
|
}
|
||||||
assertEquals(1, layouts);
|
assertEquals(1, layouts);
|
||||||
assertEquals(4, hyperlinks);
|
assertEquals(4, hyperlinks);
|
||||||
|
|
||||||
// Hyperlinks should all be to #_ftn1 or #ftnref1
|
// Hyperlinks should all be to #_ftn1 or #ftnref1
|
||||||
for(RelationPart p : rels) {
|
for(RelationPart p : rels) {
|
||||||
if(p.getRelationship().getRelationshipType().equals(XSLFRelation.HYPERLINK.getRelation())) {
|
if(p.getRelationship().getRelationshipType().equals(XSLFRelation.HYPERLINK.getRelation())) {
|
||||||
|
@ -140,61 +161,61 @@ public class TestXSLFBugs {
|
||||||
}
|
}
|
||||||
ss.close();
|
ss.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A slideshow can have more than one rID pointing to a given
|
* A slideshow can have more than one rID pointing to a given
|
||||||
* slide, eg presentation.xml rID1 -> slide1.xml, but slide1.xml
|
* slide, eg presentation.xml rID1 -> slide1.xml, but slide1.xml
|
||||||
* rID2 -> slide3.xml
|
* rID2 -> slide3.xml
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug54916() throws Exception {
|
public void bug54916() throws Exception {
|
||||||
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("OverlappingRelations.pptx");
|
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("OverlappingRelations.pptx");
|
||||||
XSLFSlide slide;
|
XSLFSlide slide;
|
||||||
|
|
||||||
// Should find 4 slides
|
// Should find 4 slides
|
||||||
assertEquals(4, ss.getSlides().size());
|
assertEquals(4, ss.getSlides().size());
|
||||||
|
|
||||||
// Check the text, to see we got them in order
|
// Check the text, to see we got them in order
|
||||||
slide = ss.getSlides().get(0);
|
slide = ss.getSlides().get(0);
|
||||||
assertContains(getSlideText(slide), "POI cannot read this");
|
assertContains(getSlideText(slide), "POI cannot read this");
|
||||||
|
|
||||||
slide = ss.getSlides().get(1);
|
slide = ss.getSlides().get(1);
|
||||||
assertContains(getSlideText(slide), "POI can read this");
|
assertContains(getSlideText(slide), "POI can read this");
|
||||||
assertContains(getSlideText(slide), "Has a relationship to another slide");
|
assertContains(getSlideText(slide), "Has a relationship to another slide");
|
||||||
|
|
||||||
slide = ss.getSlides().get(2);
|
slide = ss.getSlides().get(2);
|
||||||
assertContains(getSlideText(slide), "POI can read this");
|
assertContains(getSlideText(slide), "POI can read this");
|
||||||
|
|
||||||
slide = ss.getSlides().get(3);
|
slide = ss.getSlides().get(3);
|
||||||
assertContains(getSlideText(slide), "POI can read this");
|
assertContains(getSlideText(slide), "POI can read this");
|
||||||
|
|
||||||
ss.close();
|
ss.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When the picture is not embedded but inserted only as a "link to file",
|
* When the picture is not embedded but inserted only as a "link to file",
|
||||||
* there is no data available and XSLFPictureShape.getPictureData()
|
* there is no data available and XSLFPictureShape.getPictureData()
|
||||||
* gives a NPE, see bug #56812
|
* gives a NPE, see bug #56812
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug56812() throws Exception {
|
public void bug56812() throws Exception {
|
||||||
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("56812.pptx");
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("56812.pptx");
|
||||||
|
|
||||||
int internalPictures = 0;
|
int internalPictures = 0;
|
||||||
int externalPictures = 0;
|
int externalPictures = 0;
|
||||||
for (XSLFSlide slide : ppt.getSlides()){
|
for (XSLFSlide slide : ppt.getSlides()){
|
||||||
for (XSLFShape shape : slide.getShapes()){
|
for (XSLFShape shape : slide.getShapes()){
|
||||||
assertNotNull(shape);
|
assertNotNull(shape);
|
||||||
|
|
||||||
if (shape instanceof XSLFPictureShape) {
|
if (shape instanceof XSLFPictureShape) {
|
||||||
XSLFPictureShape picture = (XSLFPictureShape)shape;
|
XSLFPictureShape picture = (XSLFPictureShape)shape;
|
||||||
if (picture.isExternalLinkedPicture()) {
|
if (picture.isExternalLinkedPicture()) {
|
||||||
externalPictures++;
|
externalPictures++;
|
||||||
|
|
||||||
assertNotNull(picture.getPictureLink());
|
assertNotNull(picture.getPictureLink());
|
||||||
} else {
|
} else {
|
||||||
internalPictures++;
|
internalPictures++;
|
||||||
|
|
||||||
XSLFPictureData data = picture.getPictureData();
|
XSLFPictureData data = picture.getPictureData();
|
||||||
assertNotNull(data);
|
assertNotNull(data);
|
||||||
assertNotNull(data.getFileName());
|
assertNotNull(data.getFileName());
|
||||||
|
@ -202,7 +223,7 @@ public class TestXSLFBugs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(2, internalPictures);
|
assertEquals(2, internalPictures);
|
||||||
assertEquals(1, externalPictures);
|
assertEquals(1, externalPictures);
|
||||||
ppt.close();
|
ppt.close();
|
||||||
|
@ -212,31 +233,31 @@ public class TestXSLFBugs {
|
||||||
@Ignore("Similar to TestFontRendering it doesn't make sense to compare images because of tiny rendering differences in windows/unix")
|
@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 {
|
public void bug54542() throws Exception {
|
||||||
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("54542_cropped_bitmap.pptx");
|
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("54542_cropped_bitmap.pptx");
|
||||||
|
|
||||||
Dimension pgsize = ss.getPageSize();
|
Dimension pgsize = ss.getPageSize();
|
||||||
|
|
||||||
XSLFSlide slide = ss.getSlides().get(0);
|
XSLFSlide slide = ss.getSlides().get(0);
|
||||||
|
|
||||||
// render it
|
// render it
|
||||||
double zoom = 1;
|
double zoom = 1;
|
||||||
AffineTransform at = new AffineTransform();
|
AffineTransform at = new AffineTransform();
|
||||||
at.setToScale(zoom, zoom);
|
at.setToScale(zoom, zoom);
|
||||||
|
|
||||||
BufferedImage imgActual = new BufferedImage((int)Math.ceil(pgsize.width*zoom), (int)Math.ceil(pgsize.height*zoom), BufferedImage.TYPE_3BYTE_BGR);
|
BufferedImage imgActual = new BufferedImage((int)Math.ceil(pgsize.width*zoom), (int)Math.ceil(pgsize.height*zoom), BufferedImage.TYPE_3BYTE_BGR);
|
||||||
Graphics2D graphics = imgActual.createGraphics();
|
Graphics2D graphics = imgActual.createGraphics();
|
||||||
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||||
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
|
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
|
||||||
graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
||||||
graphics.setTransform(at);
|
graphics.setTransform(at);
|
||||||
graphics.setPaint(Color.white);
|
graphics.setPaint(Color.white);
|
||||||
graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
|
graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
|
||||||
slide.draw(graphics);
|
slide.draw(graphics);
|
||||||
|
|
||||||
ImageIO.write(imgActual, "PNG", new File("bug54542.png"));
|
ImageIO.write(imgActual, "PNG", new File("bug54542.png"));
|
||||||
ss.close();
|
ss.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getSlideText(XSLFSlide slide) {
|
protected String getSlideText(XSLFSlide slide) {
|
||||||
return XSLFPowerPointExtractor.getText(slide, true, false, false);
|
return XSLFPowerPointExtractor.getText(slide, true, false, false);
|
||||||
}
|
}
|
||||||
|
@ -267,7 +288,7 @@ public class TestXSLFBugs {
|
||||||
validateSlides(ss, true, "Slide1","Slide2","New slide");
|
validateSlides(ss, true, "Slide1","Slide2","New slide");
|
||||||
ss.close();
|
ss.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When working with >9 images, make sure the sorting ensures
|
* When working with >9 images, make sure the sorting ensures
|
||||||
* that image10.foo isn't between image1.foo and image2.foo
|
* that image10.foo isn't between image1.foo and image2.foo
|
||||||
|
@ -278,15 +299,15 @@ public class TestXSLFBugs {
|
||||||
for (String s : new String[]{"Slide1","Slide2"}) {
|
for (String s : new String[]{"Slide1","Slide2"}) {
|
||||||
ss.createSlide().createTextBox().setText(s);
|
ss.createSlide().createTextBox().setText(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slide starts with just layout relation
|
// Slide starts with just layout relation
|
||||||
XSLFSlide slide = ss.getSlides().get(0);
|
XSLFSlide slide = ss.getSlides().get(0);
|
||||||
assertEquals(0, ss.getPictureData().size());
|
assertEquals(0, ss.getPictureData().size());
|
||||||
assertEquals(1, slide.getShapes().size());
|
assertEquals(1, slide.getShapes().size());
|
||||||
|
|
||||||
assertEquals(1, slide.getRelations().size());
|
assertEquals(1, slide.getRelations().size());
|
||||||
assertRelationEquals(XSLFRelation.SLIDE_LAYOUT, slide.getRelations().get(0));
|
assertRelationEquals(XSLFRelation.SLIDE_LAYOUT, slide.getRelations().get(0));
|
||||||
|
|
||||||
// Some dummy pictures
|
// Some dummy pictures
|
||||||
byte[][] pics = new byte[15][3];
|
byte[][] pics = new byte[15][3];
|
||||||
for (int i=0; i<pics.length; i++) {
|
for (int i=0; i<pics.length; i++) {
|
||||||
|
@ -294,13 +315,13 @@ public class TestXSLFBugs {
|
||||||
pics[i][j] = (byte)i;
|
pics[i][j] = (byte)i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a few pictures
|
// Add a few pictures
|
||||||
for (int i=0; i<10; i++) {
|
for (int i=0; i<10; i++) {
|
||||||
XSLFPictureData data = ss.addPicture(pics[i], PictureType.JPEG);
|
XSLFPictureData data = ss.addPicture(pics[i], PictureType.JPEG);
|
||||||
assertEquals(i, data.getIndex());
|
assertEquals(i, data.getIndex());
|
||||||
assertEquals(i+1, ss.getPictureData().size());
|
assertEquals(i+1, ss.getPictureData().size());
|
||||||
|
|
||||||
XSLFPictureShape shape = slide.createPicture(data);
|
XSLFPictureShape shape = slide.createPicture(data);
|
||||||
assertNotNull(shape.getPictureData());
|
assertNotNull(shape.getPictureData());
|
||||||
assertArrayEquals(pics[i], shape.getPictureData().getData());
|
assertArrayEquals(pics[i], shape.getPictureData().getData());
|
||||||
|
@ -312,13 +333,13 @@ public class TestXSLFBugs {
|
||||||
assertNotNull(shape.getPictureData());
|
assertNotNull(shape.getPictureData());
|
||||||
assertArrayEquals(pics[i], shape.getPictureData().getData());
|
assertArrayEquals(pics[i], shape.getPictureData().getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add past 10
|
// Add past 10
|
||||||
for (int i=10; i<15; i++) {
|
for (int i=10; i<15; i++) {
|
||||||
XSLFPictureData data = ss.addPicture(pics[i], PictureType.JPEG);
|
XSLFPictureData data = ss.addPicture(pics[i], PictureType.JPEG);
|
||||||
assertEquals(i, data.getIndex());
|
assertEquals(i, data.getIndex());
|
||||||
assertEquals(i+1, ss.getPictureData().size());
|
assertEquals(i+1, ss.getPictureData().size());
|
||||||
|
|
||||||
XSLFPictureShape shape = slide.createPicture(data);
|
XSLFPictureShape shape = slide.createPicture(data);
|
||||||
assertNotNull(shape.getPictureData());
|
assertNotNull(shape.getPictureData());
|
||||||
assertArrayEquals(pics[i], shape.getPictureData().getData());
|
assertArrayEquals(pics[i], shape.getPictureData().getData());
|
||||||
|
@ -330,44 +351,44 @@ public class TestXSLFBugs {
|
||||||
assertNotNull(shape.getPictureData());
|
assertNotNull(shape.getPictureData());
|
||||||
assertArrayEquals(pics[i], shape.getPictureData().getData());
|
assertArrayEquals(pics[i], shape.getPictureData().getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a duplicate, check the right one is picked
|
// Add a duplicate, check the right one is picked
|
||||||
XSLFPictureData data = ss.addPicture(pics[3], PictureType.JPEG);
|
XSLFPictureData data = ss.addPicture(pics[3], PictureType.JPEG);
|
||||||
assertEquals(3, data.getIndex());
|
assertEquals(3, data.getIndex());
|
||||||
assertEquals(15, ss.getPictureData().size());
|
assertEquals(15, ss.getPictureData().size());
|
||||||
|
|
||||||
XSLFPictureShape shape = slide.createPicture(data);
|
XSLFPictureShape shape = slide.createPicture(data);
|
||||||
assertNotNull(shape.getPictureData());
|
assertNotNull(shape.getPictureData());
|
||||||
assertArrayEquals(pics[3], shape.getPictureData().getData());
|
assertArrayEquals(pics[3], shape.getPictureData().getData());
|
||||||
assertEquals(17, slide.getShapes().size());
|
assertEquals(17, slide.getShapes().size());
|
||||||
|
|
||||||
|
|
||||||
// Save and re-load
|
// Save and re-load
|
||||||
XMLSlideShow ss2 = XSLFTestDataSamples.writeOutAndReadBack(ss);
|
XMLSlideShow ss2 = XSLFTestDataSamples.writeOutAndReadBack(ss);
|
||||||
slide = ss2.getSlides().get(0);
|
slide = ss2.getSlides().get(0);
|
||||||
|
|
||||||
// Check the 15 individual ones added
|
// Check the 15 individual ones added
|
||||||
for (int i=0; i<15; i++) {
|
for (int i=0; i<15; i++) {
|
||||||
shape = (XSLFPictureShape)slide.getShapes().get(i+1);
|
shape = (XSLFPictureShape)slide.getShapes().get(i+1);
|
||||||
assertNotNull(shape.getPictureData());
|
assertNotNull(shape.getPictureData());
|
||||||
assertArrayEquals(pics[i], shape.getPictureData().getData());
|
assertArrayEquals(pics[i], shape.getPictureData().getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the duplicate
|
// Check the duplicate
|
||||||
shape = (XSLFPictureShape)slide.getShapes().get(16);
|
shape = (XSLFPictureShape)slide.getShapes().get(16);
|
||||||
assertNotNull(shape.getPictureData());
|
assertNotNull(shape.getPictureData());
|
||||||
assertArrayEquals(pics[3], shape.getPictureData().getData());
|
assertArrayEquals(pics[3], shape.getPictureData().getData());
|
||||||
|
|
||||||
// Add another duplicate
|
// Add another duplicate
|
||||||
data = ss2.addPicture(pics[5], PictureType.JPEG);
|
data = ss2.addPicture(pics[5], PictureType.JPEG);
|
||||||
assertEquals(5, data.getIndex());
|
assertEquals(5, data.getIndex());
|
||||||
assertEquals(15, ss2.getPictureData().size());
|
assertEquals(15, ss2.getPictureData().size());
|
||||||
|
|
||||||
shape = slide.createPicture(data);
|
shape = slide.createPicture(data);
|
||||||
assertNotNull(shape.getPictureData());
|
assertNotNull(shape.getPictureData());
|
||||||
assertArrayEquals(pics[5], shape.getPictureData().getData());
|
assertArrayEquals(pics[5], shape.getPictureData().getData());
|
||||||
assertEquals(18, slide.getShapes().size());
|
assertEquals(18, slide.getShapes().size());
|
||||||
|
|
||||||
ss2.close();
|
ss2.close();
|
||||||
ss.close();
|
ss.close();
|
||||||
}
|
}
|
||||||
|
@ -381,7 +402,7 @@ public class TestXSLFBugs {
|
||||||
validateSlides(ss, slideTexts);
|
validateSlides(ss, slideTexts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateSlides(XMLSlideShow ss, String... slideTexts) throws IOException {
|
private void validateSlides(XMLSlideShow ss, String... slideTexts) throws IOException {
|
||||||
assertEquals(slideTexts.length, ss.getSlides().size());
|
assertEquals(slideTexts.length, ss.getSlides().size());
|
||||||
|
|
||||||
|
@ -390,21 +411,21 @@ public class TestXSLFBugs {
|
||||||
assertContains(getSlideText(slide), slideTexts[i]);
|
assertContains(getSlideText(slide), slideTexts[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertRelationEquals(XSLFRelation expected, POIXMLDocumentPart relation) {
|
private void assertRelationEquals(XSLFRelation expected, POIXMLDocumentPart relation) {
|
||||||
assertEquals(expected.getContentType(), relation.getPackagePart().getContentType());
|
assertEquals(expected.getContentType(), relation.getPackagePart().getContentType());
|
||||||
assertEquals(expected.getFileName(expected.getFileNameIndex(relation)), relation.getPackagePart().getPartName().getName());
|
assertEquals(expected.getFileName(expected.getFileNameIndex(relation)), relation.getPackagePart().getPartName().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bug58205() throws IOException {
|
public void bug58205() throws IOException {
|
||||||
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("themes.pptx");
|
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("themes.pptx");
|
||||||
|
|
||||||
int i = 1;
|
int i = 1;
|
||||||
for (XSLFSlideMaster sm : ss.getSlideMasters()) {
|
for (XSLFSlideMaster sm : ss.getSlideMasters()) {
|
||||||
assertEquals("rId"+(i++), ss.getRelationId(sm));
|
assertEquals("rId"+(i++), ss.getRelationId(sm));
|
||||||
}
|
}
|
||||||
|
|
||||||
ss.close();
|
ss.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,7 +480,7 @@ public class TestXSLFBugs {
|
||||||
ps2 = (XSLFPictureShape)slide.getShapes().get(1);
|
ps2 = (XSLFPictureShape)slide.getShapes().get(1);
|
||||||
assertEquals(url1, ps1.getHyperlink().getAddress());
|
assertEquals(url1, ps1.getHyperlink().getAddress());
|
||||||
assertEquals(url2, ps2.getHyperlink().getAddress());
|
assertEquals(url2, ps2.getHyperlink().getAddress());
|
||||||
|
|
||||||
ppt2.close();
|
ppt2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -468,7 +489,7 @@ public class TestXSLFBugs {
|
||||||
Color fillColor = new Color(1f,1f,0f,0.1f);
|
Color fillColor = new Color(1f,1f,0f,0.1f);
|
||||||
Color lineColor = new Color(25.3f/255f,1f,0f,0.4f);
|
Color lineColor = new Color(25.3f/255f,1f,0f,0.4f);
|
||||||
Color textColor = new Color(1f,1f,0f,0.6f);
|
Color textColor = new Color(1f,1f,0f,0.6f);
|
||||||
|
|
||||||
XMLSlideShow ppt1 = new XMLSlideShow();
|
XMLSlideShow ppt1 = new XMLSlideShow();
|
||||||
XSLFSlide sl = ppt1.createSlide();
|
XSLFSlide sl = ppt1.createSlide();
|
||||||
XSLFAutoShape as = sl.createAutoShape();
|
XSLFAutoShape as = sl.createAutoShape();
|
||||||
|
@ -491,7 +512,7 @@ public class TestXSLFBugs {
|
||||||
checkColor(textColor, as.getTextParagraphs().get(0).getTextRuns().get(0).getFontColor());
|
checkColor(textColor, as.getTextParagraphs().get(0).getTextRuns().get(0).getFontColor());
|
||||||
ppt2.close();
|
ppt2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkColor(Color expected, PaintStyle actualStyle) {
|
private static void checkColor(Color expected, PaintStyle actualStyle) {
|
||||||
assertTrue(actualStyle instanceof SolidPaint);
|
assertTrue(actualStyle instanceof SolidPaint);
|
||||||
SolidPaint ps = (SolidPaint)actualStyle;
|
SolidPaint ps = (SolidPaint)actualStyle;
|
||||||
|
@ -514,14 +535,14 @@ public class TestXSLFBugs {
|
||||||
|
|
||||||
XSLFSlideMaster srcSlideMaster = srcSlide.getSlideMaster();
|
XSLFSlideMaster srcSlideMaster = srcSlide.getSlideMaster();
|
||||||
XSLFSlideMaster newSlideMaster = newSlide.getSlideMaster();
|
XSLFSlideMaster newSlideMaster = newSlide.getSlideMaster();
|
||||||
newSlideMaster.importContent(srcSlideMaster);
|
newSlideMaster.importContent(srcSlideMaster);
|
||||||
|
|
||||||
newSlide.importContent(srcSlide);
|
newSlide.importContent(srcSlide);
|
||||||
XMLSlideShow rwPptx = XSLFTestDataSamples.writeOutAndReadBack(newPptx);
|
XMLSlideShow rwPptx = XSLFTestDataSamples.writeOutAndReadBack(newPptx);
|
||||||
|
|
||||||
PaintStyle ps = rwPptx.getSlides().get(0).getBackground().getFillStyle().getPaint();
|
PaintStyle ps = rwPptx.getSlides().get(0).getBackground().getFillStyle().getPaint();
|
||||||
assertTrue(ps instanceof TexturePaint);
|
assertTrue(ps instanceof TexturePaint);
|
||||||
|
|
||||||
rwPptx.close();
|
rwPptx.close();
|
||||||
newPptx.close();
|
newPptx.close();
|
||||||
srcPptx.close();
|
srcPptx.close();
|
||||||
|
@ -531,7 +552,7 @@ public class TestXSLFBugs {
|
||||||
public void bug59273() throws IOException {
|
public void bug59273() throws IOException {
|
||||||
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("bug59273.potx");
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("bug59273.potx");
|
||||||
ppt.getPackage().replaceContentType(
|
ppt.getPackage().replaceContentType(
|
||||||
XSLFRelation.PRESENTATIONML_TEMPLATE.getContentType(),
|
XSLFRelation.PRESENTATIONML_TEMPLATE.getContentType(),
|
||||||
XSLFRelation.MAIN.getContentType()
|
XSLFRelation.MAIN.getContentType()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -541,7 +562,7 @@ public class TestXSLFBugs {
|
||||||
assertEquals(1, size);
|
assertEquals(1, size);
|
||||||
size = pkg.getPartsByContentType(XSLFRelation.PRESENTATIONML_TEMPLATE.getContentType()).size();
|
size = pkg.getPartsByContentType(XSLFRelation.PRESENTATIONML_TEMPLATE.getContentType()).size();
|
||||||
assertEquals(0, size);
|
assertEquals(0, size);
|
||||||
|
|
||||||
rwPptx.close();
|
rwPptx.close();
|
||||||
ppt.close();
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
@ -594,7 +615,7 @@ public class TestXSLFBugs {
|
||||||
shadow.setDir(270000);
|
shadow.setDir(270000);
|
||||||
shadow.setDist(100000);
|
shadow.setDist(100000);
|
||||||
shadow.addNewSrgbClr().setVal(new byte[] {0x00, (byte)0xFF, 0x00});
|
shadow.addNewSrgbClr().setVal(new byte[] {0x00, (byte)0xFF, 0x00});
|
||||||
|
|
||||||
XMLSlideShow dst = new XMLSlideShow();
|
XMLSlideShow dst = new XMLSlideShow();
|
||||||
XSLFSlide sl2 = dst.createSlide();
|
XSLFSlide sl2 = dst.createSlide();
|
||||||
sl2.importContent(sl);
|
sl2.importContent(sl);
|
||||||
|
@ -602,7 +623,7 @@ public class TestXSLFBugs {
|
||||||
XSLFAutoShape as2 = (XSLFAutoShape)gs2.getShapes().get(0);
|
XSLFAutoShape as2 = (XSLFAutoShape)gs2.getShapes().get(0);
|
||||||
CTShape csh2 = (CTShape)as2.getXmlObject();
|
CTShape csh2 = (CTShape)as2.getXmlObject();
|
||||||
assertTrue(csh2.getSpPr().isSetEffectLst());
|
assertTrue(csh2.getSpPr().isSetEffectLst());
|
||||||
|
|
||||||
dst.close();
|
dst.close();
|
||||||
src.close();
|
src.close();
|
||||||
}
|
}
|
||||||
|
@ -626,9 +647,27 @@ public class TestXSLFBugs {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test60042() {
|
public void test60042() throws IOException {
|
||||||
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("60042.pptx");
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("60042.pptx");
|
||||||
ppt.removeSlide(0);
|
ppt.removeSlide(0);
|
||||||
ppt.createSlide();
|
ppt.createSlide();
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
|
public void test61515() throws IOException {
|
||||||
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("61515.pptx");
|
||||||
|
ppt.removeSlide(0);
|
||||||
|
assertEquals(1, ppt.createSlide().getRelations().size());
|
||||||
|
try {
|
||||||
|
XMLSlideShow saved = XSLFTestDataSamples.writeOutAndReadBack(ppt);
|
||||||
|
assertEquals(1, saved.getSlides().size());
|
||||||
|
XSLFSlide slide = saved.getSlides().get(0);
|
||||||
|
assertEquals(1, slide.getRelations().size());
|
||||||
|
saved.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
fail("Could not read back saved presentation.");
|
||||||
|
}
|
||||||
|
ppt.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue