mirror of https://github.com/apache/poi.git
XSLF: do not display Master Slide objects by default
XSLF: fix alternate content handling for picture shapes git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1736935 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1e65636048
commit
57aa67b524
|
@ -31,6 +31,7 @@ import org.apache.poi.sl.usermodel.PictureShape;
|
||||||
import org.apache.poi.sl.usermodel.Placeholder;
|
import org.apache.poi.sl.usermodel.Placeholder;
|
||||||
import org.apache.poi.util.Beta;
|
import org.apache.poi.util.Beta;
|
||||||
import org.apache.xmlbeans.XmlCursor;
|
import org.apache.xmlbeans.XmlCursor;
|
||||||
|
import org.apache.xmlbeans.XmlException;
|
||||||
import org.apache.xmlbeans.XmlObject;
|
import org.apache.xmlbeans.XmlObject;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties;
|
||||||
|
@ -110,7 +111,7 @@ public class XSLFPictureShape extends XSLFSimpleShape
|
||||||
if (rel != null) {
|
if (rel != null) {
|
||||||
try {
|
try {
|
||||||
PackagePart imgPart = p.getRelatedPart(rel);
|
PackagePart imgPart = p.getRelatedPart(rel);
|
||||||
_data = new XSLFPictureData(imgPart, rel);
|
_data = new XSLFPictureData(imgPart);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
throw new POIXMLException(e);
|
throw new POIXMLException(e);
|
||||||
|
@ -151,9 +152,29 @@ public class XSLFPictureShape extends XSLFSimpleShape
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CTBlip getBlip(){
|
protected CTBlipFillProperties getBlipFill() {
|
||||||
CTPicture ct = (CTPicture)getXmlObject();
|
CTPicture ct = (CTPicture)getXmlObject();
|
||||||
return ct.getBlipFill().getBlip();
|
CTBlipFillProperties bfp = ct.getBlipFill();
|
||||||
|
if (bfp != null) {
|
||||||
|
return bfp;
|
||||||
|
}
|
||||||
|
|
||||||
|
String xquery =
|
||||||
|
"declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main'; "
|
||||||
|
+ "declare namespace mc='http://schemas.openxmlformats.org/markup-compatibility/2006' "
|
||||||
|
+ ".//mc:Fallback/p:blipFill"
|
||||||
|
;
|
||||||
|
XmlObject xo = selectProperty(XmlObject.class, xquery);
|
||||||
|
try {
|
||||||
|
xo = CTPicture.Factory.parse(xo.getDomNode());
|
||||||
|
} catch (XmlException xe) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return ((CTPicture)xo).getBlipFill();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CTBlip getBlip(){
|
||||||
|
return getBlipFill().getBlip();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getBlipLink(){
|
protected String getBlipLink(){
|
||||||
|
@ -170,8 +191,7 @@ public class XSLFPictureShape extends XSLFSimpleShape
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Insets getClipping(){
|
public Insets getClipping(){
|
||||||
CTPicture ct = (CTPicture)getXmlObject();
|
CTRelativeRect r = getBlipFill().getSrcRect();
|
||||||
CTRelativeRect r = ct.getBlipFill().getSrcRect();
|
|
||||||
return (r == null) ? null : new Insets(r.getT(), r.getL(), r.getB(), r.getR());
|
return (r == null) ? null : new Insets(r.getT(), r.getL(), r.getB(), r.getR());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +204,7 @@ public class XSLFPictureShape extends XSLFSimpleShape
|
||||||
String relId = getSheet().importBlip(blipId, p.getSheet().getPackagePart());
|
String relId = getSheet().importBlip(blipId, p.getSheet().getPackagePart());
|
||||||
|
|
||||||
CTPicture ct = (CTPicture)getXmlObject();
|
CTPicture ct = (CTPicture)getXmlObject();
|
||||||
CTBlip blip = ct.getBlipFill().getBlip();
|
CTBlip blip = getBlipFill().getBlip();
|
||||||
blip.setEmbed(relId);
|
blip.setEmbed(relId);
|
||||||
|
|
||||||
CTApplicationNonVisualDrawingProps nvPr = ct.getNvPicPr().getNvPr();
|
CTApplicationNonVisualDrawingProps nvPr = ct.getNvPicPr().getNvPr();
|
||||||
|
@ -209,4 +229,4 @@ public class XSLFPictureShape extends XSLFSimpleShape
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -215,12 +215,9 @@ implements Slide<XSLFShape,XSLFTextParagraph> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
*
|
|
||||||
* @return whether shapes on the master slide should be shown or not.
|
|
||||||
*/
|
|
||||||
public boolean getFollowMasterGraphics(){
|
public boolean getFollowMasterGraphics(){
|
||||||
return !_slide.isSetShowMasterSp() || _slide.getShowMasterSp();
|
return _slide.isSetShowMasterSp() && _slide.getShowMasterSp();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -113,7 +113,7 @@ implements MasterSheet<XSLFShape,XSLFTextParagraph> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getFollowMasterGraphics() {
|
public boolean getFollowMasterGraphics() {
|
||||||
return !_layout.isSetShowMasterSp() || _layout.getShowMasterSp();
|
return _layout.isSetShowMasterSp() && _layout.getShowMasterSp();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,7 +18,10 @@ package org.apache.poi.xslf;
|
||||||
|
|
||||||
import static junit.framework.TestCase.assertEquals;
|
import static junit.framework.TestCase.assertEquals;
|
||||||
import static org.apache.poi.POITestCase.assertContains;
|
import static org.apache.poi.POITestCase.assertContains;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
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.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
@ -36,6 +39,7 @@ import javax.imageio.ImageIO;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLDocumentPart;
|
import org.apache.poi.POIXMLDocumentPart;
|
||||||
import org.apache.poi.POIXMLDocumentPart.RelationPart;
|
import org.apache.poi.POIXMLDocumentPart.RelationPart;
|
||||||
|
import org.apache.poi.sl.usermodel.PaintStyle;
|
||||||
import org.apache.poi.sl.usermodel.PictureData.PictureType;
|
import org.apache.poi.sl.usermodel.PictureData.PictureType;
|
||||||
import org.apache.poi.xslf.usermodel.DrawingParagraph;
|
import org.apache.poi.xslf.usermodel.DrawingParagraph;
|
||||||
import org.apache.poi.xslf.usermodel.DrawingTextBody;
|
import org.apache.poi.xslf.usermodel.DrawingTextBody;
|
||||||
|
@ -428,4 +432,12 @@ public class TestXSLFBugs {
|
||||||
ppt.removeSlide(1);
|
ppt.removeSlide(1);
|
||||||
assertNotNull(ppt.createSlide());
|
assertNotNull(ppt.createSlide());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void blibFillAlternateContent() throws IOException {
|
||||||
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("2411-Performance_Up.pptx");
|
||||||
|
XSLFPictureShape ps = (XSLFPictureShape)ppt.getSlides().get(4).getShapes().get(0);
|
||||||
|
assertNotNull(ps.getPictureData());
|
||||||
|
ppt.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class TestXSLFSlide {
|
||||||
assertEquals(0, ppt.getSlides().size());
|
assertEquals(0, ppt.getSlides().size());
|
||||||
|
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
assertTrue(slide.getFollowMasterGraphics());
|
assertFalse(slide.getFollowMasterGraphics());
|
||||||
slide.setFollowMasterGraphics(false);
|
slide.setFollowMasterGraphics(false);
|
||||||
assertFalse(slide.getFollowMasterGraphics());
|
assertFalse(slide.getFollowMasterGraphics());
|
||||||
slide.setFollowMasterGraphics(true);
|
slide.setFollowMasterGraphics(true);
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class TestXSLFTheme {
|
||||||
assertTrue(sameColor(new Color(148, 198, 0), run2.getFontColor()));
|
assertTrue(sameColor(new Color(148, 198, 0), run2.getFontColor()));
|
||||||
assertNull(sh2.getFillColor()); // no fill
|
assertNull(sh2.getFillColor()); // no fill
|
||||||
|
|
||||||
assertTrue(slide.getSlideLayout().getFollowMasterGraphics());
|
assertFalse(slide.getSlideLayout().getFollowMasterGraphics());
|
||||||
}
|
}
|
||||||
|
|
||||||
void slide5(XSLFSlide slide){
|
void slide5(XSLFSlide slide){
|
||||||
|
@ -113,7 +113,7 @@ public class TestXSLFTheme {
|
||||||
// font size is 40pt and scale factor is 90%
|
// font size is 40pt and scale factor is 90%
|
||||||
assertEquals(36.0, run2.getFontSize(), 0);
|
assertEquals(36.0, run2.getFontSize(), 0);
|
||||||
|
|
||||||
assertTrue(slide.getSlideLayout().getFollowMasterGraphics());
|
assertFalse(slide.getSlideLayout().getFollowMasterGraphics());
|
||||||
}
|
}
|
||||||
|
|
||||||
void slide6(XSLFSlide slide){
|
void slide6(XSLFSlide slide){
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue