You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2016/07/09 15:02:10 UTC

svn commit: r1752010 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: cos/COSName.java pdmodel/interactive/action/PDActionSound.java

Author: tilman
Date: Sat Jul  9 15:02:10 2016
New Revision: 1752010

URL: http://svn.apache.org/viewvc?rev=1752010&view=rev
Log:
PDFBOX-3324: add entries specific to a sound action; deprecate or delete /S

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionSound.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java?rev=1752010&r1=1752009&r2=1752010&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java Sat Jul  9 15:02:10 2016
@@ -340,6 +340,7 @@ public final class COSName extends COSBa
     public static final COSName MEDIA_BOX = new COSName("MediaBox");
     public static final COSName METADATA = new COSName("Metadata");
     public static final COSName MISSING_WIDTH = new COSName("MissingWidth");
+    public static final COSName MIX = new COSName("Mix");
     public static final COSName MK = new COSName("MK");
     public static final COSName ML = new COSName("ML");
     public static final COSName MM_TYPE1 = new COSName("MMType1");
@@ -435,6 +436,7 @@ public final class COSName extends COSBa
     public static final COSName RD = new COSName("RD");
     public static final COSName REASON = new COSName("Reason");
     public static final COSName REASONS = new COSName("Reasons");
+    public static final COSName REPEAT = new COSName("Repeat");
     public static final COSName RECIPIENTS = new COSName("Recipients");
     public static final COSName RECT = new COSName("Rect");
     public static final COSName REGISTRY = new COSName("Registry");
@@ -490,6 +492,7 @@ public final class COSName extends COSBa
     public static final COSName SV = new COSName("SV");
     public static final COSName SW = new COSName("SW");
     public static final COSName SY = new COSName("Sy");
+    public static final COSName SYNCHRONOUS = new COSName("Synchronous");
     // T
     public static final COSName T = new COSName("T");
     public static final COSName TARGET = new COSName("Target");
@@ -536,6 +539,7 @@ public final class COSName extends COSBa
     public static final COSName VIEW_AREA = new COSName("ViewArea");
     public static final COSName VIEW_CLIP = new COSName("ViewClip");
     public static final COSName VIEWER_PREFERENCES = new COSName("ViewerPreferences");
+    public static final COSName VOLUME = new COSName("Volume");
     // W
     public static final COSName W = new COSName("W");
     public static final COSName W2 = new COSName("W2");

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionSound.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionSound.java?rev=1752010&r1=1752009&r2=1752010&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionSound.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionSound.java Sat Jul  9 15:02:10 2016
@@ -17,13 +17,18 @@
 
 package org.apache.pdfbox.pdmodel.interactive.action;
 
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSBoolean;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSNumber;
+import org.apache.pdfbox.cos.COSStream;
 
 /**
- * This represents a Sound action that can be executed in a PDF document
+ * This represents a Sound action that can be executed in a PDF document.
  *
  * @author Timur Kamalov
+ * @author Tilman Hausherr
  */
 public class PDActionSound extends PDAction
 {
@@ -53,25 +58,148 @@ public class PDActionSound extends PDAct
     }
 
     /**
-     * This will get the type of action that the actions dictionary describes. It must be Sound for
-     * a Sound action.
+     * Sets the sound object.
+     * 
+     * @param sound the sound object defining the sound that shall be played.
+     */
+    public void setSound(COSStream sound)
+    {
+        action.setItem(COSName.SOUND, sound);
+    }
+
+    /**
+     * Gets the sound object.
+     * 
+     * @return The sound object defining the sound that shall be played.
+     */
+    public COSStream getSound()
+    {
+        COSBase base = action.getDictionaryObject(COSName.SOUND);
+        if (base instanceof COSStream)
+        {
+            return (COSStream) base;
+        }
+        return null;
+    }
+    
+    /**
+     * Gets the volume at which to play the sound, in the range −1.0 to 1.0.
+     *
+     * @param volume The volume at which to play the sound, in the range −1.0 to 1.0.
+     * 
+     * @throws IllegalArgumentException if the volume parameter is outside of the range −1.0 to 1.0.
+     */
+    public void setVolume(float volume)
+    {
+        if (volume < -1 || volume > 1)
+        {
+            throw new IllegalArgumentException("volume outside of the range −1.0 to 1.0");
+        }
+        action.setFloat(COSName.VOLUME, volume);
+    }
+
+    /**
+     * Sets the volume.
+     *
+     * @return The volume at which to play the sound, in the range −1.0 to 1.0. Default value: 1.0.
+     */
+    public float getVolume()
+    {
+        COSBase base = action.getDictionaryObject(COSName.VOLUME);
+        if (base instanceof COSNumber)
+        {
+            float volume = ((COSNumber) base).floatValue();
+            if (volume < -1 || volume > 1)
+            {
+                volume = 1;
+            }
+            return volume;
+        }
+        return 1;
+    }
+    
+    /**
+     * A flag specifying whether to play the sound synchronously or asynchronously. When true, the
+     * reader allows no further user interaction other than canceling the sound until the sound has
+     * been completely played.
+     *
+     * @param synchronous Whether to play the sound synchronously (true) or asynchronously (false).
+     */
+    public void setSynchronous(boolean synchronous)
+    {
+        action.setBoolean(COSName.SYNCHRONOUS, synchronous);
+    }
+
+    /**
+     * Gets the synchronous flag. It specifyes whether to play the sound synchronously or
+     * asynchronously. When true, the reader allows no further user interaction other than canceling
+     * the sound until the sound has been completely played.
      *
-     * @return The S entry of the specific Sound action dictionary.
+     * @return Whether to play the sound synchronously (true) or asynchronously (false, also the
+     * default).
      */
-    public String getS()
+    public boolean getSynchronous()
     {
-        return action.getNameAsString(COSName.S);
+        COSBase base = action.getDictionaryObject(COSName.SYNCHRONOUS);
+        if (base instanceof COSBoolean)
+        {
+            return ((COSBoolean) base).getValue();
+        }
+        return false;
+    }
+    
+    /**
+     * A flag specifying whether to repeat the sound indefinitely.
+     *
+     * @param repeat Whether to repeat the sound indefinitely.
+     */
+    public void setRepeat(boolean repeat)
+    {
+        action.setBoolean(COSName.REPEAT, repeat);
     }
 
     /**
-     * This will set the type of action that the actions dictionary describes. It must be Sound for
-     * a Sound action.
+     * Gets whether to repeat the sound indefinitely.
      *
-     * @param s The Sound action.
+     * @return Whether to repeat the sound indefinitely (default: false).
      */
-    public void setS(String s)
+    public boolean getRepeat()
     {
-        action.setName(COSName.S, s);
+        COSBase base = action.getDictionaryObject(COSName.REPEAT);
+        if (base instanceof COSBoolean)
+        {
+            return ((COSBoolean) base).getValue();
+        }
+        return false;
     }
 
+    /**
+     * The flag specifying whether to mix this sound with any other sound already playing. If this
+     * flag is false, any previously playing sound shall be stopped before starting this sound; this
+     * can be used to stop a repeating sound (see Repeat). Default value: false.
+     *
+     * @param mix whether to mix this sound with any other sound already playing.
+     * (false).
+     */
+    public void setMix(boolean mix)
+    {
+        action.setBoolean(COSName.MIX, mix);
+    }
+
+    /**
+     * Gets the flag specifying whether to mix this sound with any other sound already playing. If
+     * this flag is false, any previously playing sound shall be stopped before starting this sound;
+     * this can be used to stop a repeating sound (see Repeat).
+     *
+     * @return whether to mix this sound with any other sound already playing (default: false).
+     */
+    public boolean getMix()
+    {
+        COSBase base = action.getDictionaryObject(COSName.MIX);
+        if (base instanceof COSBoolean)
+        {
+            return ((COSBoolean) base).getValue();
+        }
+        return false;
+    }
 }