diff options
5 files changed, 122 insertions, 3 deletions
diff --git a/src/java/org/apache/poi/sl/usermodel/Slide.java b/src/java/org/apache/poi/sl/usermodel/Slide.java index 1f77ba6e5d..3b2913269d 100644 --- a/src/java/org/apache/poi/sl/usermodel/Slide.java +++ b/src/java/org/apache/poi/sl/usermodel/Slide.java @@ -53,4 +53,20 @@ public interface Slide< * @since POI 3.16-beta2 */ boolean getDisplayPlaceholder(Placeholder placeholder); + + /** + * Sets the slide visibility + * + * @param hidden slide visibility, if {@code true} the slide is hidden, {@code false} shows the slide + * + * @since POI 4.0.0 + */ + void setHidden(boolean hidden); + + /** + * @return the slide visibility, the slide is hidden when {@code true} - or shown when {@code false} + * + * @since POI 4.0.0 + */ + boolean isHidden(); } 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 cfa5873cc5..53b645a868 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java @@ -124,6 +124,7 @@ implements Slide<XSLFShape,XSLFTextParagraph> { return "sld"; } + @Override public XSLFSlideLayout getMasterSheet(){ return getSlideLayout(); } @@ -162,6 +163,7 @@ implements Slide<XSLFShape,XSLFTextParagraph> { return _comments; } + @Override public XSLFNotes getNotes() { if(_notes == null) { for (POIXMLDocumentPart p : getRelations()) { @@ -217,10 +219,12 @@ implements Slide<XSLFShape,XSLFTextParagraph> { } + @Override public boolean getFollowMasterObjects() { return getFollowMasterGraphics(); } + @Override public void setFollowMasterObjects(boolean follow) { setFollowMasterGraphics(follow); } @@ -260,20 +264,24 @@ implements Slide<XSLFShape,XSLFTextParagraph> { return this; } + @Override public boolean getFollowMasterBackground() { return false; } + @Override @NotImplemented public void setFollowMasterBackground(boolean follow) { // not implemented ... also not in the specs throw new UnsupportedOperationException(); } + @Override public boolean getFollowMasterColourScheme() { return false; } + @Override @NotImplemented public void setFollowMasterColourScheme(boolean follow) { // not implemented ... only for OLE objects in the specs @@ -309,4 +317,24 @@ implements Slide<XSLFShape,XSLFTextParagraph> { public boolean getDisplayPlaceholder(Placeholder placeholder) { return false; } + + + @Override + public void setHidden(boolean hidden) { + CTSlide sld = getXmlObject(); + if (hidden) { + sld.setShow(false); + } else { + // if the attribute does not exist, the slide is shown + if (sld.isSetShow()) { + sld.unsetShow(); + } + } + } + + @Override + public boolean isHidden() { + CTSlide sld = getXmlObject(); + return sld.isSetShow() && !sld.getShow(); + } } diff --git a/src/ooxml/testcases/org/apache/poi/sl/TestSlide.java b/src/ooxml/testcases/org/apache/poi/sl/TestSlide.java new file mode 100644 index 0000000000..6c4c49e63f --- /dev/null +++ b/src/ooxml/testcases/org/apache/poi/sl/TestSlide.java @@ -0,0 +1,73 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.apache.poi.sl; + +import static org.apache.poi.sl.SLCommonUtils.xslfOnly; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeFalse; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.apache.poi.hslf.usermodel.HSLFSlideShow; +import org.apache.poi.sl.usermodel.SlideShow; +import org.apache.poi.sl.usermodel.SlideShowFactory; +import org.apache.poi.xslf.usermodel.XMLSlideShow; +import org.junit.Test; + +public class TestSlide { + + @Test + public void hideHSLF() throws IOException { + assumeFalse(xslfOnly()); + SlideShow<?,?> ppt1 = new HSLFSlideShow(); + hideSlide(ppt1); + ppt1.close(); + } + + @Test + public void hideXSLF() throws IOException { + SlideShow<?,?> ppt1 = new XMLSlideShow(); + hideSlide(ppt1); + ppt1.close(); + } + + private void hideSlide(SlideShow<?,?> ppt1) throws IOException { + ppt1.createSlide().setHidden(true); + ppt1.createSlide(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ppt1.write(bos); + ppt1.close(); + + InputStream is = new ByteArrayInputStream(bos.toByteArray()); + SlideShow<?,?> ppt2 = SlideShowFactory.create(is); + + Boolean[] hiddenState = ppt2.getSlides().stream().map(e -> e.isHidden()).toArray(Boolean[]::new); + + assertTrue(hiddenState[0]); + assertFalse(hiddenState[1]); + + ppt2.close(); + } +}
\ No newline at end of file diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java index 14867a5a46..9936630dfc 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java @@ -460,6 +460,7 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe return this.getPPDrawing().getTextboxWrappers(); } + @Override public void setHidden(boolean hidden) { org.apache.poi.hslf.record.Slide cont = getSlideRecord(); @@ -473,7 +474,8 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe slideInfo.setEffectTransitionFlagByBit(SSSlideInfoAtom.HIDDEN_BIT, hidden); } - public boolean getHidden() { + @Override + public boolean isHidden() { SSSlideInfoAtom slideInfo = (SSSlideInfoAtom)getSlideRecord().findFirstOfType(RecordTypes.SSSlideInfoAtom.typeID); return (slideInfo == null) diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSlideAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSlideAtom.java index c32d37bd65..3e2fc49b14 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSlideAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSlideAtom.java @@ -89,8 +89,8 @@ public final class TestSlideAtom { HSLFSlideShow ss2 = HSLFTestDataSamples.writeOutAndReadBack(ss1); slide1 = ss2.getSlides().get(0); slide2 = ss2.getSlides().get(1); - assertFalse(slide1.getHidden()); - assertTrue(slide2.getHidden()); + assertFalse(slide1.isHidden()); + assertTrue(slide2.isHidden()); ss2.close(); ss1.close(); } |