diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java index b9d7e37f6b..c2428bc2ed 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java @@ -31,6 +31,7 @@ import org.apache.poi.sl.usermodel.PictureShape; import org.apache.poi.sl.usermodel.Placeholder; import org.apache.poi.util.Beta; import org.apache.xmlbeans.XmlCursor; +import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip; import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties; @@ -110,7 +111,7 @@ public class XSLFPictureShape extends XSLFSimpleShape if (rel != null) { try { PackagePart imgPart = p.getRelatedPart(rel); - _data = new XSLFPictureData(imgPart, rel); + _data = new XSLFPictureData(imgPart); } catch (Exception e) { throw new POIXMLException(e); @@ -151,9 +152,29 @@ public class XSLFPictureShape extends XSLFSimpleShape return null; } - protected CTBlip getBlip(){ + protected CTBlipFillProperties getBlipFill() { 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(){ @@ -170,8 +191,7 @@ public class XSLFPictureShape extends XSLFSimpleShape @Override public Insets getClipping(){ - CTPicture ct = (CTPicture)getXmlObject(); - CTRelativeRect r = ct.getBlipFill().getSrcRect(); + CTRelativeRect r = getBlipFill().getSrcRect(); 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()); CTPicture ct = (CTPicture)getXmlObject(); - CTBlip blip = ct.getBlipFill().getBlip(); + CTBlip blip = getBlipFill().getBlip(); blip.setEmbed(relId); CTApplicationNonVisualDrawingProps nvPr = ct.getNvPicPr().getNvPr(); @@ -209,4 +229,4 @@ public class XSLFPictureShape extends XSLFSimpleShape } } -} +} \ No newline at end of file diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java index b91cf1789d..9d132baa17 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java @@ -215,12 +215,9 @@ implements Slide { } } - /** - * - * @return whether shapes on the master slide should be shown or not. - */ + @Override public boolean getFollowMasterGraphics(){ - return !_slide.isSetShowMasterSp() || _slide.getShowMasterSp(); + return _slide.isSetShowMasterSp() && _slide.getShowMasterSp(); } /** diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java index 01e7c5488d..15a4a169e4 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java @@ -113,7 +113,7 @@ implements MasterSheet { @Override public boolean getFollowMasterGraphics() { - return !_layout.isSetShowMasterSp() || _layout.getShowMasterSp(); + return _layout.isSetShowMasterSp() && _layout.getShowMasterSp(); } /** diff --git a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java index 42f6543c55..49551b3e53 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java @@ -18,7 +18,10 @@ package org.apache.poi.xslf; import static junit.framework.TestCase.assertEquals; 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.Dimension; @@ -36,6 +39,7 @@ import javax.imageio.ImageIO; import org.apache.poi.POIXMLDocumentPart; 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.xslf.usermodel.DrawingParagraph; import org.apache.poi.xslf.usermodel.DrawingTextBody; @@ -428,4 +432,12 @@ public class TestXSLFBugs { ppt.removeSlide(1); 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(); + } } diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java index fad3f82a00..0af1347aba 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java @@ -111,7 +111,7 @@ public class TestXSLFSlide { assertEquals(0, ppt.getSlides().size()); XSLFSlide slide = ppt.createSlide(); - assertTrue(slide.getFollowMasterGraphics()); + assertFalse(slide.getFollowMasterGraphics()); slide.setFollowMasterGraphics(false); assertFalse(slide.getFollowMasterGraphics()); slide.setFollowMasterGraphics(true); diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTheme.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTheme.java index ee95e771d4..912ecc0f3d 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTheme.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTheme.java @@ -99,7 +99,7 @@ public class TestXSLFTheme { assertTrue(sameColor(new Color(148, 198, 0), run2.getFontColor())); assertNull(sh2.getFillColor()); // no fill - assertTrue(slide.getSlideLayout().getFollowMasterGraphics()); + assertFalse(slide.getSlideLayout().getFollowMasterGraphics()); } void slide5(XSLFSlide slide){ @@ -113,7 +113,7 @@ public class TestXSLFTheme { // font size is 40pt and scale factor is 90% assertEquals(36.0, run2.getFontSize(), 0); - assertTrue(slide.getSlideLayout().getFollowMasterGraphics()); + assertFalse(slide.getSlideLayout().getFollowMasterGraphics()); } void slide6(XSLFSlide slide){ diff --git a/test-data/slideshow/2411-Performance_Up.pptx b/test-data/slideshow/2411-Performance_Up.pptx new file mode 100644 index 0000000000..46fe3972c3 Binary files /dev/null and b/test-data/slideshow/2411-Performance_Up.pptx differ