#61671 - XSLFSlide does not contain isHidden and setHidden like HSLFSlide does

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1814122 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2017-11-02 23:15:19 +00:00
parent 00ac2545bb
commit 37e4c32065
5 changed files with 122 additions and 3 deletions

View File

@ -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();
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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)

View File

@ -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();
}