]> source.dussan.org Git - poi.git/commitdiff
XSLF: do not display Master Slide objects by default
authorAndreas Beeker <kiwiwings@apache.org>
Mon, 28 Mar 2016 22:52:01 +0000 (22:52 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Mon, 28 Mar 2016 22:52:01 +0000 (22:52 +0000)
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

src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java
src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java
src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTheme.java
test-data/slideshow/2411-Performance_Up.pptx [new file with mode: 0644]

index b9d7e37f6b6c6cc69b2412361118a8afc2aef61e..c2428bc2ed9424c4d65f44f2edf934ae9ec0de93 100644 (file)
@@ -31,6 +31,7 @@ import org.apache.poi.sl.usermodel.PictureShape;
 import org.apache.poi.sl.usermodel.Placeholder;\r
 import org.apache.poi.util.Beta;\r
 import org.apache.xmlbeans.XmlCursor;\r
+import org.apache.xmlbeans.XmlException;\r
 import org.apache.xmlbeans.XmlObject;\r
 import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip;\r
 import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties;\r
@@ -110,7 +111,7 @@ public class XSLFPictureShape extends XSLFSimpleShape
             if (rel != null) {\r
                 try {\r
                     PackagePart imgPart = p.getRelatedPart(rel);\r
-                    _data = new XSLFPictureData(imgPart, rel);\r
+                    _data = new XSLFPictureData(imgPart);\r
                 }\r
                 catch (Exception e) {\r
                     throw new POIXMLException(e);\r
@@ -151,9 +152,29 @@ public class XSLFPictureShape extends XSLFSimpleShape
         return null;\r
     }\r
 \r
-    protected CTBlip getBlip(){\r
+    protected CTBlipFillProperties getBlipFill() {\r
         CTPicture ct = (CTPicture)getXmlObject();\r
-        return ct.getBlipFill().getBlip();\r
+        CTBlipFillProperties bfp = ct.getBlipFill();\r
+        if (bfp != null) {\r
+            return bfp;\r
+        }\r
+                    \r
+        String xquery =\r
+                "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main'; "\r
+              + "declare namespace mc='http://schemas.openxmlformats.org/markup-compatibility/2006' "\r
+              + ".//mc:Fallback/p:blipFill"\r
+              ;\r
+        XmlObject xo = selectProperty(XmlObject.class, xquery);\r
+        try {\r
+            xo = CTPicture.Factory.parse(xo.getDomNode());\r
+        } catch (XmlException xe) {\r
+            return null;\r
+        }\r
+        return ((CTPicture)xo).getBlipFill();\r
+    }\r
+    \r
+    protected CTBlip getBlip(){\r
+        return getBlipFill().getBlip();\r
     }\r
     \r
     protected String getBlipLink(){\r
@@ -170,8 +191,7 @@ public class XSLFPictureShape extends XSLFSimpleShape
 \r
     @Override\r
     public Insets getClipping(){\r
-        CTPicture ct = (CTPicture)getXmlObject();\r
-        CTRelativeRect r = ct.getBlipFill().getSrcRect();\r
+        CTRelativeRect r = getBlipFill().getSrcRect();\r
         return (r == null) ? null : new Insets(r.getT(), r.getL(), r.getB(), r.getR());\r
     }\r
 \r
@@ -184,7 +204,7 @@ public class XSLFPictureShape extends XSLFSimpleShape
         String relId = getSheet().importBlip(blipId, p.getSheet().getPackagePart());\r
 \r
         CTPicture ct = (CTPicture)getXmlObject();\r
-        CTBlip blip = ct.getBlipFill().getBlip();\r
+        CTBlip blip = getBlipFill().getBlip();\r
         blip.setEmbed(relId);\r
 \r
         CTApplicationNonVisualDrawingProps nvPr = ct.getNvPicPr().getNvPr();\r
@@ -209,4 +229,4 @@ public class XSLFPictureShape extends XSLFSimpleShape
         }\r
 \r
     }\r
-}\r
+}
\ No newline at end of file
index b91cf1789dec2331591c1e61105e1382972efb6f..9d132baa17013ac41163d59cb34ef31cfc415200 100644 (file)
@@ -215,12 +215,9 @@ implements Slide<XSLFShape,XSLFTextParagraph> {
         }
     }
 
-    /**
-     *
-     * @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();
     }
 
     /**
index 01e7c5488df137280367dc225edd03d28ff81703..15a4a169e4eca4f70632cd6d520ebfb511fc1ba5 100644 (file)
@@ -113,7 +113,7 @@ implements MasterSheet<XSLFShape,XSLFTextParagraph> {
 
     @Override
     public boolean getFollowMasterGraphics() {
-        return !_layout.isSetShowMasterSp() || _layout.getShowMasterSp();
+        return _layout.isSetShowMasterSp() && _layout.getShowMasterSp();
     }
 
     /**
index 42f6543c550eb3b7626052386847f66cb4d5ab6e..49551b3e532d9504366a494121fd0a7a0415b67f 100644 (file)
@@ -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();
+    }
 }
index fad3f82a005374a105ebf640e702c2e198bfe16e..0af1347abaa18b5380bb9030d35c47704fc5d873 100644 (file)
@@ -111,7 +111,7 @@ public class TestXSLFSlide {
         assertEquals(0, ppt.getSlides().size());\r
 \r
         XSLFSlide slide = ppt.createSlide();\r
-        assertTrue(slide.getFollowMasterGraphics());\r
+        assertFalse(slide.getFollowMasterGraphics());\r
         slide.setFollowMasterGraphics(false);\r
         assertFalse(slide.getFollowMasterGraphics());\r
         slide.setFollowMasterGraphics(true);\r
index ee95e771d4ce21fe6c1f7fabf7e4a44d08ff731d..912ecc0f3dd7cfabbc8dd9b4fd5f20f95e30dda8 100644 (file)
@@ -99,7 +99,7 @@ public class TestXSLFTheme {
         assertTrue(sameColor(new Color(148, 198, 0), run2.getFontColor()));\r
         assertNull(sh2.getFillColor());  // no fill\r
 \r
-        assertTrue(slide.getSlideLayout().getFollowMasterGraphics());\r
+        assertFalse(slide.getSlideLayout().getFollowMasterGraphics());\r
     }\r
 \r
     void slide5(XSLFSlide slide){\r
@@ -113,7 +113,7 @@ public class TestXSLFTheme {
         // font size is 40pt and scale factor is 90%\r
         assertEquals(36.0, run2.getFontSize(), 0);\r
 \r
-        assertTrue(slide.getSlideLayout().getFollowMasterGraphics());\r
+        assertFalse(slide.getSlideLayout().getFollowMasterGraphics());\r
     }\r
 \r
     void slide6(XSLFSlide slide){\r
diff --git a/test-data/slideshow/2411-Performance_Up.pptx b/test-data/slideshow/2411-Performance_Up.pptx
new file mode 100644 (file)
index 0000000..46fe397
Binary files /dev/null and b/test-data/slideshow/2411-Performance_Up.pptx differ