add basic support for hdphoto/wdp images in slideshows

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1892653 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-08-27 17:33:39 +00:00
parent 08d6e1019a
commit 5d0ea93bb4
5 changed files with 37 additions and 5 deletions

View File

@ -101,6 +101,11 @@ public interface PackageRelationshipTypes {
*/ */
String IMAGE_PART = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"; String IMAGE_PART = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
/**
* hdphoto type.
*/
String HDPHOTO_PART = "http://schemas.microsoft.com/office/2007/relationships/hdphoto";
/** /**
* Hyperlink type. * Hyperlink type.
*/ */

View File

@ -16,6 +16,7 @@
==================================================================== */ ==================================================================== */
package org.apache.poi.xslf.usermodel; package org.apache.poi.xslf.usermodel;
import static org.apache.poi.openxml4j.opc.PackageRelationshipTypes.HDPHOTO_PART;
import static org.apache.poi.openxml4j.opc.PackageRelationshipTypes.IMAGE_PART; import static org.apache.poi.openxml4j.opc.PackageRelationshipTypes.IMAGE_PART;
import java.util.HashMap; import java.util.HashMap;
@ -221,7 +222,12 @@ public final class XSLFRelation extends POIXMLRelation {
"/ppt/media/image#.wdp", "/ppt/media/image#.wdp",
XSLFPictureData::new, XSLFPictureData::new XSLFPictureData::new, XSLFPictureData::new
); );
public static final XSLFRelation HDPHOTO_WDP = new XSLFRelation(
PictureType.WDP.contentType,
HDPHOTO_PART,
"/ppt/media/hdphoto#.wdp",
XSLFPictureData::new, XSLFPictureData::new
);
public static final XSLFRelation IMAGE_SVG = new XSLFRelation( public static final XSLFRelation IMAGE_SVG = new XSLFRelation(
PictureType.SVG.contentType, PictureType.SVG.contentType,
IMAGE_PART, IMAGE_PART,

View File

@ -648,7 +648,13 @@ implements XSLFShapeContainer, Sheet<XSLFShape,XSLFTextParagraph> {
* @return ID of the created relationship * @return ID of the created relationship
*/ */
String importBlip(String blipId, POIXMLDocumentPart parent) { String importBlip(String blipId, POIXMLDocumentPart parent) {
final XSLFPictureData parData = parent.getRelationPartById(blipId).getDocumentPart(); final POIXMLDocumentPart docPart = parent.getRelationPartById(blipId).getDocumentPart();
XSLFPictureData parData;
if (docPart instanceof XSLFPictureData) {
parData = (XSLFPictureData)docPart;
} else {
throw new RuntimeException("cannot import blip " + blipId + " - document part is not XSLFPictureData type");
}
final XSLFPictureData pictureData; final XSLFPictureData pictureData;
if (getPackagePart().getPackage() == parent.getPackagePart().getPackage()) { if (getPackagePart().getPackage() == parent.getPackagePart().getPackage()) {
// handle ref counter correct, if the parent document is the same as this // handle ref counter correct, if the parent document is the same as this

View File

@ -32,9 +32,7 @@ import static org.junit.jupiter.api.Assumptions.assumeFalse;
import java.awt.Color; import java.awt.Color;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.net.URI; import java.net.URI;
import java.text.AttributedCharacterIterator; import java.text.AttributedCharacterIterator;
import java.text.AttributedCharacterIterator.Attribute; import java.text.AttributedCharacterIterator.Attribute;
@ -49,6 +47,7 @@ import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
import org.apache.poi.common.usermodel.HyperlinkType; import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.ooxml.POIXMLDocumentPart;
@ -75,7 +74,6 @@ import org.apache.poi.sl.usermodel.SlideShowFactory;
import org.apache.poi.sl.usermodel.TextRun; import org.apache.poi.sl.usermodel.TextRun;
import org.apache.poi.sl.usermodel.TextShape; import org.apache.poi.sl.usermodel.TextShape;
import org.apache.poi.sl.usermodel.VerticalAlignment; import org.apache.poi.sl.usermodel.VerticalAlignment;
import org.apache.poi.util.IOUtils;
import org.apache.commons.io.output.NullPrintStream; import org.apache.commons.io.output.NullPrintStream;
import org.apache.poi.xslf.usermodel.*; import org.apache.poi.xslf.usermodel.*;
import org.apache.poi.xslf.util.DummyGraphics2d; import org.apache.poi.xslf.util.DummyGraphics2d;
@ -1044,4 +1042,21 @@ class TestXSLFBugs {
assertEquals(TextRun.TextCap.ALL, act); assertEquals(TextRun.TextCap.ALL, act);
} }
} }
@Test
public void bug65523() throws IOException {
try (XMLSlideShow sourcePresentation = openSampleDocument("bug65523.pptx")) {
XMLSlideShow targetPresentation = new XMLSlideShow();
XSLFSlide targetPresentationSlide = targetPresentation.createSlide();
XSLFSlide sourceSlide = sourcePresentation.getSlides().get(0);
targetPresentationSlide.getSlideMaster().importContent(sourceSlide.getSlideMaster());
targetPresentationSlide.getSlideLayout().importContent(sourceSlide.getSlideLayout());
targetPresentationSlide.importContent(sourceSlide);
targetPresentation.write(new UnsynchronizedByteArrayOutputStream());
}
}
} }

Binary file not shown.