]> source.dussan.org Git - poi.git/commitdiff
Bugzilla 55560 : Patch for hiding slides in HSLF
authorYegor Kozlov <yegor@apache.org>
Sat, 9 Nov 2013 11:57:21 +0000 (11:57 +0000)
committerYegor Kozlov <yegor@apache.org>
Sat, 9 Nov 2013 11:57:21 +0000 (11:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1540295 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hslf/model/Slide.java
src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java
src/scratchpad/src/org/apache/poi/hslf/record/SSSlideInfoAtom.java [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hslf/record/TestSlideAtom.java

index 60ab2b120efe3fc5978aaa83cb070ddd1b9cbb4a..79ef820ac8455f29efc9fbc5348e0c055c0872c9 100644 (file)
@@ -32,6 +32,7 @@ import org.apache.poi.hslf.record.HeadersFootersContainer;
 import org.apache.poi.hslf.record.Record;
 import org.apache.poi.hslf.record.RecordContainer;
 import org.apache.poi.hslf.record.RecordTypes;
+import org.apache.poi.hslf.record.SSSlideInfoAtom;
 import org.apache.poi.hslf.record.SlideAtom;
 import org.apache.poi.hslf.record.StyleTextProp9Atom;
 import org.apache.poi.hslf.record.TextHeaderAtom;
@@ -488,4 +489,25 @@ public final class Slide extends Sheet
        public EscherTextboxWrapper[] getTextboxWrappers() {
                return this.getPPDrawing().getTextboxWrappers();
        }
+
+       public void setHidden(boolean hidden) {
+               org.apache.poi.hslf.record.Slide cont = getSlideRecord();
+               
+               SSSlideInfoAtom slideInfo = 
+                       (SSSlideInfoAtom)cont.findFirstOfType(RecordTypes.SSSlideInfoAtom.typeID);
+               if (slideInfo == null) {
+                       slideInfo = new SSSlideInfoAtom();
+                       cont.addChildAfter(slideInfo, cont.findFirstOfType(RecordTypes.SlideAtom.typeID));
+               }
+               
+               slideInfo.setEffectTransitionFlagByBit(SSSlideInfoAtom.HIDDEN_BIT, hidden);
+       }
+       
+       public boolean getHidden() {
+               SSSlideInfoAtom slideInfo = 
+                       (SSSlideInfoAtom)getSlideRecord().findFirstOfType(RecordTypes.SSSlideInfoAtom.typeID);
+               return (slideInfo == null)
+                       ? false
+                       : slideInfo.getEffectTransitionFlagByBit(SSSlideInfoAtom.HIDDEN_BIT);
+       }
 }
index 455e261c21a16818bef659cbbe8da2cb549002e0..2b2dc4bddf4a8bb96792345f76e74f50de1d5cdb 100644 (file)
@@ -46,7 +46,7 @@ public final class RecordTypes {
     public static final Type SlidePersistAtom = new Type(1011,SlidePersistAtom.class);
     public static final Type SSlideLayoutAtom = new Type(1015,null);
     public static final Type MainMaster = new Type(1016,MainMaster.class);
-    public static final Type SSSlideInfoAtom = new Type(1017,null);
+    public static final Type SSSlideInfoAtom = new Type(1017,SSSlideInfoAtom.class);
     public static final Type SlideViewInfo = new Type(1018,null);
     public static final Type GuideAtom = new Type(1019,null);
     public static final Type ViewInfo = new Type(1020,null);
diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SSSlideInfoAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/SSSlideInfoAtom.java
new file mode 100644 (file)
index 0000000..0fbc7ff
--- /dev/null
@@ -0,0 +1,289 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.hslf.record;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+\r
+import org.apache.poi.util.LittleEndian;\r
+import org.apache.poi.util.LittleEndianConsts;\r
+\r
+/**\r
+ * A SlideShowSlideInfo Atom (type 1017).<br/>\r
+ * <br/>\r
+ *  \r
+ * An atom record that specifies which transition effects to perform\r
+ * during a slide show, and how to advance to the next presentation slide.<br/>\r
+ * <br/>\r
+ *\r
+ * Combination of effectType and effectDirection:\r
+ * <table>\r
+ * <tr><th>type</th><th>description</th><th>direction</th></tr>\r
+ * <tr><td>0</td><td>cut</td><td>0x00 = no transition, 0x01 = black transition</td></tr>\r
+ * <tr><td>1</td><td>random</td><td>0x00</td></tr>\r
+ * <tr><td>2</td><td>blinds</td><td>0x00 = vertical, 0x01 = horizontal</td></tr>\r
+ * <tr><td>3</td><td>checker</td><td>like blinds</td></tr>\r
+ * <tr><td>4</td><td>cover</td><td>0x00 = left, 0x01 = up, 0x02 = right, 0x03 = down, 0x04 = left/up, 0x05 = right/up, 0x06 left/down, 0x07 = left/down</td></tr>\r
+ * <tr><td>5</td><td>dissolve</td><td>0x00</td></tr>\r
+ * <tr><td>6</td><td>fade</td><td>0x00</td></tr>\r
+ * <tr><td>7</td><td>uncover</td><td>like cover</td></tr>\r
+ * <tr><td>8</td><td>random bars</td><td>like blinds</td></tr>\r
+ * <tr><td>9</td><td>strips</td><td>like 0x04 - 0x07 of cover</td></tr>\r
+ * <tr><td>10</td><td>wipe</td><td>like 0x00 - 0x03 of cover</td></tr>\r
+ * <tr><td>11</td><td>box in/out</td><td>0x00 = out, 0x01 = in</td></tr>\r
+ * <tr><td>13</td><td>split</td><td>0x00 = horizontally out, 0x01 = horizontally in, 0x02 = vertically out, 0x03 = vertically in</td></tr>\r
+ * <tr><td>17</td><td>diamond</td><td>0x00</td></tr>\r
+ * <tr><td>18</td><td>plus</td><td>0x00</td></tr>\r
+ * <tr><td>19</td><td>wedge</td><td>0x00</td></tr>\r
+ * <tr><td>20</td><td>push</td><td>like 0x00 - 0x03 of cover</td></tr>\r
+ * <tr><td>21</td><td>comb</td><td>like blinds</td></tr>\r
+ * <tr><td>22</td><td>newsflash</td><td>0x00</td></tr>\r
+ * <tr><td>23</td><td>alphafade</td><td>0x00</td></tr>\r
+ * <tr><td>26</td><td>wheel</td><td>number of radial divisions (0x01,0x02,0x03,0x04,0x08)</td></tr>\r
+ * <tr><td>27</td><td>circle</td><td>0x00</td></tr>\r
+ * <tr><td>255</td><td>undefined</td><td>0x00</td></tr>\r
+ * </table>\r
+ */\r
+public class SSSlideInfoAtom extends RecordAtom {\r
+    /**\r
+     * A bit that specifies whether the presentation slide can be\r
+     * manually advanced by the user during the slide show.\r
+     */\r
+    public static int MANUAL_ADVANCE_BIT     = 1 << 0;\r
+    \r
+    /**\r
+     * A bit that specifies whether the corresponding slide is \r
+     * hidden and is not displayed during the slide show.\r
+     */\r
+    public static int HIDDEN_BIT             = 1 << 2;\r
+    \r
+    /**\r
+     * A bit that specifies whether to play the sound specified by soundIfRef.\r
+     */\r
+    public static int SOUND_BIT              = 1 << 4;\r
+    \r
+    /**\r
+     * A bit that specifies whether the sound specified by soundIdRef is\r
+     * looped continuously when playing until the next sound plays.\r
+     */\r
+    public static int LOOP_SOUND_BIT         = 1 << 6;\r
+    \r
+    /**\r
+     * A bit that specifies whether to stop any currently playing \r
+     * sound when the transition starts.\r
+     */\r
+    public static int STOP_SOUND_BIT         = 1 << 8;\r
+    \r
+    /**\r
+     * A bit that specifies whether the slide will automatically\r
+     * advance after slideTime milliseconds during the slide show.\r
+     */\r
+    public static int AUTO_ADVANCE_BIT       = 1 << 10;\r
+\r
+    /**\r
+     * A bit that specifies whether to display the cursor during\r
+     * the slide show. \r
+     */\r
+    public static int CURSOR_VISIBLE_BIT     = 1 << 12;\r
+    \r
+    // public static int RESERVED1_BIT       = 1 << 1;\r
+    // public static int RESERVED2_BIT       = 1 << 3;\r
+    // public static int RESERVED3_BIT       = 1 << 5;\r
+    // public static int RESERVED4_BIT       = 1 << 7;\r
+    // public static int RESERVED5_BIT       = 1 << 9;\r
+    // public static int RESERVED6_BIT       = 1 << 11;\r
+    // public static int RESERVED7_BIT       = 1 << 13 | 1 << 14 | 1 << 15;\r
+    \r
+    private static long _type = RecordTypes.SSSlideInfoAtom.typeID;\r
+\r
+    private byte[] _header;\r
+\r
+    /**\r
+     * A signed integer that specifies an amount of time, in milliseconds, to wait\r
+     * before advancing to the next presentation slide. It MUST be greater than or equal to 0 and\r
+     * less than or equal to 86399000. It MUST be ignored unless AUTO_ADVANCE_BIT is TRUE.\r
+     */\r
+    private int _slideTime = 0;\r
+    \r
+    /**\r
+     * A SoundIdRef that specifies which sound to play when the transition starts. \r
+     */\r
+    private int _soundIdRef = 0;\r
+\r
+    /**\r
+     * A byte that specifies the variant of effectType. In combination of the effectType\r
+     * there are further restriction and specification of this field.\r
+     */\r
+    private short _effectDirection = 0; // byte\r
+    \r
+    /**\r
+     * A byte that specifies which transition is used when transitioning to the\r
+     * next presentation slide during a slide show. Exact rendering of any transition is \r
+     * determined by the rendering application. As such, the same transition can have\r
+     * many variations depending on the implementation.\r
+     */\r
+    private short _effectType = 0; // byte\r
+    \r
+    /**\r
+     * Various flags - see bitmask for more details\r
+     */\r
+    private short _effectTransitionFlags = 0;\r
+    \r
+    /**\r
+     * A byte value that specifies how long the transition takes to run.\r
+     * (0x00 = 0.75 seconds, 0x01 = 0.5 seconds, 0x02 = 0.25 seconds) \r
+     */\r
+    private short _speed = 0; // byte\r
+    private byte[] _unused; // 3-byte\r
+\r
+    public SSSlideInfoAtom() {\r
+        _header = new byte[8];\r
+        LittleEndian.putShort(_header, 0, (short)0);\r
+        LittleEndian.putShort(_header, 2, (short)_type);\r
+        LittleEndian.putShort(_header, 4, (short)0x10);\r
+        LittleEndian.putShort(_header, 6, (short)0);\r
+        _unused = new byte[3];\r
+    }\r
+    \r
+    public SSSlideInfoAtom(byte[] source, int offset, int len) {\r
+        int ofs = offset;\r
+\r
+        // Sanity Checking\r
+        if(len != 24) len = 24;\r
+        assert(source.length >= offset+len);\r
+        \r
+        // Get the header\r
+        _header = LittleEndian.getByteArray(source,ofs,8);\r
+        ofs += _header.length;\r
+        \r
+        assert(LittleEndian.getShort(_header, 0) == 0);\r
+        assert(LittleEndian.getShort(_header, 2) == RecordTypes.SSSlideInfoAtom.typeID);\r
+        assert(LittleEndian.getShort(_header, 4) == 0x10);\r
+        assert(LittleEndian.getShort(_header, 6) == 0);\r
+\r
+        _slideTime = LittleEndian.getInt(source, ofs);\r
+        assert(0 <= _slideTime && _slideTime <= 86399000);\r
+        ofs += LittleEndianConsts.INT_SIZE;\r
+        _soundIdRef = LittleEndian.getInt(source, ofs);\r
+        ofs += LittleEndianConsts.INT_SIZE;\r
+        _effectDirection = LittleEndian.getUByte(source, ofs);\r
+        ofs += LittleEndianConsts.BYTE_SIZE;\r
+        _effectType = LittleEndian.getUByte(source, ofs);\r
+        ofs += LittleEndianConsts.BYTE_SIZE;\r
+        _effectTransitionFlags = LittleEndian.getShort(source, ofs);\r
+        ofs += LittleEndianConsts.SHORT_SIZE;\r
+        _speed = LittleEndian.getUByte(source, ofs);\r
+        ofs += LittleEndianConsts.BYTE_SIZE;\r
+        _unused = LittleEndian.getByteArray(source,ofs,3);\r
+    }\r
+\r
+    /**\r
+     * Write the contents of the record back, so it can be written\r
+     *  to disk\r
+     */\r
+    public void writeOut(OutputStream out) throws IOException {\r
+        // Header - size or type unchanged\r
+        out.write(_header);\r
+        writeLittleEndian(_slideTime, out);\r
+        writeLittleEndian(_soundIdRef, out);\r
+        \r
+        byte byteBuf[] = new byte[LittleEndianConsts.BYTE_SIZE];\r
+        LittleEndian.putUByte(byteBuf, 0, _effectDirection);\r
+        out.write(byteBuf);\r
+        LittleEndian.putUByte(byteBuf, 0, _effectType);\r
+        out.write(byteBuf);\r
+        \r
+        writeLittleEndian(_effectTransitionFlags, out);\r
+        LittleEndian.putUByte(byteBuf, 0, _speed);\r
+        out.write(byteBuf);\r
+\r
+        assert(_unused.length == 3);\r
+        out.write(_unused);\r
+    }\r
+    \r
+    /**\r
+     * We are of type 1017\r
+     */\r
+    public long getRecordType() { return _type; }\r
+\r
+\r
+    public int getSlideTime() {\r
+        return _slideTime;\r
+    }\r
+\r
+    public void setSlideTime(int slideTime) {\r
+        this._slideTime = slideTime;\r
+    }\r
+\r
+    public int getSoundIdRef() {\r
+        return _soundIdRef;\r
+    }\r
+\r
+    public void setSoundIdRef(int soundIdRef) {\r
+        this._soundIdRef = soundIdRef;\r
+    }\r
+\r
+    public short getEffectDirection() {\r
+        return _effectDirection;\r
+    }\r
+\r
+    public void setEffectDirection(short effectDirection) {\r
+        this._effectDirection = effectDirection;\r
+    }\r
+\r
+    public short getEffectType() {\r
+        return _effectType;\r
+    }\r
+\r
+    public void setEffectType(short effectType) {\r
+        this._effectType = effectType;\r
+    }\r
+\r
+    public short getEffectTransitionFlags() {\r
+        return _effectTransitionFlags;\r
+    }\r
+\r
+    public void setEffectTransitionFlags(short effectTransitionFlags) {\r
+        this._effectTransitionFlags = effectTransitionFlags;\r
+    }\r
+\r
+    /**\r
+     * Use one of the bitmasks MANUAL_ADVANCE_BIT ... CURSOR_VISIBLE_BIT\r
+     * @param bitmask\r
+     * @param enabled\r
+     */\r
+    public void setEffectTransitionFlagByBit(int bitmask, boolean enabled) {\r
+        if (enabled) {\r
+            _effectTransitionFlags |= bitmask;\r
+        } else {\r
+            _effectTransitionFlags &= (0xFFFF ^ bitmask);\r
+        }\r
+    }\r
+\r
+    public boolean getEffectTransitionFlagByBit(int bitmask) {\r
+        return ((_effectTransitionFlags & bitmask) != 0);\r
+    }\r
+    \r
+    public short getSpeed() {\r
+        return _speed;\r
+    }\r
+\r
+    public void setSpeed(short speed) {\r
+        this._speed = speed;\r
+    }\r
+}\r
index 28b122abae5c07589a864e79a8ac3df7314f7b15..26e608bc37c82eec5ce6ac5c9bc1bc280d82d59d 100644 (file)
 
 package org.apache.poi.hslf.record;
 
-import org.apache.poi.hslf.record.SlideAtom.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileOutputStream;
 
 import junit.framework.TestCase;
-import java.io.ByteArrayOutputStream;
+
+import org.apache.poi.hslf.record.SlideAtom.SSlideLayoutAtom;
+import org.apache.poi.hslf.usermodel.SlideShow;
 
 /**
  * Tests that SlideAtom works properly
@@ -71,4 +75,19 @@ public final class TestSlideAtom extends TestCase {
                        assertEquals(data_a[i],b[i]);
                }
        }
+       
+       public void testSSSlideInfoAtom() throws Exception {
+               SlideShow ss = new SlideShow();
+               org.apache.poi.hslf.model.Slide slide1 = ss.createSlide(), slide2 = ss.createSlide();
+               slide2.setHidden(true);
+
+               ByteArrayOutputStream bos = new ByteArrayOutputStream(4096);
+               ss.write(bos);
+               ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+               ss = new SlideShow(bis);
+               slide1 = ss.getSlides()[0];
+               slide2 = ss.getSlides()[1];
+               assertFalse(slide1.getHidden());
+               assertTrue(slide2.getHidden());
+       }
 }