You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2010/11/05 02:25:03 UTC
svn commit: r1031388 - in
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox:
cos/COSDictionary.java filter/CCITTFaxDecodeFilter.java
Author: lehmi
Date: Fri Nov 5 01:25:02 2010
New Revision: 1031388
URL: http://svn.apache.org/viewvc?rev=1031388&view=rev
Log:
PDFBOX-887: added the usage of abbreviated names for image parameters
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxDecodeFilter.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java?rev=1031388&r1=1031387&r2=1031388&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java Fri Nov 5 01:25:02 2010
@@ -149,6 +149,8 @@ public class COSDictionary extends COSBa
* @param secondKey The second key to try.
*
* @return The object that matches the key.
+ *
+ * @deprecated use {@link #getDictionaryObject(COSName, COSName)} using COSName constants instead
*/
public COSBase getDictionaryObject( String firstKey, String secondKey )
{
@@ -168,6 +170,28 @@ public class COSDictionary extends COSBa
* dereference it and get it from the document. If the object is COSNull then
* null will be returned.
*
+ * @param firstKey The first key to try.
+ * @param secondKey The second key to try.
+ *
+ * @return The object that matches the key.
+ */
+ public COSBase getDictionaryObject( COSName firstKey, COSName secondKey )
+ {
+ COSBase retval = getDictionaryObject( firstKey );
+ if( retval == null && secondKey != null)
+ {
+ retval = getDictionaryObject( secondKey );
+ }
+ return retval;
+ }
+ /**
+ * This is a special case of getDictionaryObject that takes multiple keys, it will handle
+ * the situation where multiple keys could get the same value, ie if either CS or ColorSpace
+ * is used to get the colorspace.
+ * This will get an object from this dictionary. If the object is a reference then it will
+ * dereference it and get it from the document. If the object is COSNull then
+ * null will be returned.
+ *
* @param keyList The list of keys to find a value.
*
* @return The object that matches the key.
@@ -902,8 +926,23 @@ public class COSDictionary extends COSBa
*/
public boolean getBoolean( COSName key, boolean defaultValue )
{
+ return getBoolean( key, null, defaultValue);
+ }
+
+ /**
+ * This is a convenience method that will get the dictionary object that
+ * is expected to be a COSBoolean and convert it to a primitive boolean.
+ *
+ * @param firstKey The first key to the item in the dictionary.
+ * @param secondKey The second key to the item in the dictionary.
+ * @param defaultValue The value returned if the entry is null.
+ *
+ * @return The entry converted to a boolean.
+ */
+ public boolean getBoolean( COSName firstKey, COSName secondKey, boolean defaultValue )
+ {
boolean retval = defaultValue;
- COSBase bool = getDictionaryObject( key );
+ COSBase bool = getDictionaryObject( firstKey, secondKey );
if( bool != null && bool instanceof COSBoolean)
{
retval = ((COSBoolean)bool).getValue();
@@ -1041,8 +1080,37 @@ public class COSDictionary extends COSBa
*/
public int getInt( COSName key, int defaultValue )
{
+ return getInt( key, null, defaultValue);
+ }
+
+ /**
+ * This is a convenience method that will get the dictionary object that
+ * is expected to be an integer. If the dictionary value is null then the
+ * default Value -1 will be returned.
+ *
+ * @param firstKey The first key to the item in the dictionary.
+ * @param secondKey The second key to the item in the dictionary.
+ * @return The integer value.
+ */
+ public int getInt( COSName firstKey, COSName secondKey )
+ {
+ return getInt( firstKey, secondKey, -1 );
+ }
+
+ /**
+ * This is a convenience method that will get the dictionary object that
+ * is expected to be an integer. If the dictionary value is null then the
+ * default Value will be returned.
+ *
+ * @param firstKey The first key to the item in the dictionary.
+ * @param secondKey The second key to the item in the dictionary.
+ * @param defaultValue The value to return if the dictionary item is null.
+ * @return The integer value.
+ */
+ public int getInt( COSName firstKey, COSName secondKey, int defaultValue )
+ {
int retval = defaultValue;
- COSBase obj = getDictionaryObject( key );
+ COSBase obj = getDictionaryObject( firstKey, secondKey );
if( obj != null && obj instanceof COSNumber)
{
retval = ((COSNumber)obj).intValue();
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxDecodeFilter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxDecodeFilter.java?rev=1031388&r1=1031387&r2=1031388&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxDecodeFilter.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxDecodeFilter.java Fri Nov 5 01:25:02 2010
@@ -72,7 +72,7 @@ public class CCITTFaxDecodeFilter implem
throws IOException
{
// Get ImageParams from PDF
- COSBase baseObj = options.getDictionaryObject(new String[] {"DecodeParms","DP"});
+ COSBase baseObj = options.getDictionaryObject(COSName.DECODE_PARMS, COSName.DP);
COSDictionary dict = null;
if( baseObj instanceof COSDictionary )
{
@@ -100,9 +100,15 @@ public class CCITTFaxDecodeFilter implem
+ baseObj.getClass().getName() );
}
- int width = options.getInt(COSName.WIDTH);
- int height = options.getInt(COSName.HEIGHT);
+ int width = options.getInt(COSName.WIDTH, COSName.W);
+ int height = options.getInt(COSName.HEIGHT, COSName.H);
int length = options.getInt(COSName.LENGTH);
+ // if the length isn't given within the dictionary,
+ // the length of the inputstream is used
+ if (length == -1)
+ {
+ length = compressedData.available();
+ }
int compressionType = dict.getInt(COSName.K);
boolean blackIs1 = dict.getBoolean(COSName.BLACK_IS_1, false);