Author: lehmi
Date: Sat Feb 16 13:18:27 2013
New Revision: 1446893

URL: http://svn.apache.org/r1446893
Log:
undoing changes committed in r1446888

Removed:
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/TempRadialShadingContext.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/testSplit.java
Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSArray.java
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSDictionaryMap.java
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElement.java
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureTreeRoot.java
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/AxialShadingPaint.java
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingResources.java
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingContext.java
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingPaint.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSArray.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSArray.java?rev=1446893&r1=1446892&r2=1446893&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSArray.java 
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSArray.java Sat 
Feb 16 13:18:27 2013
@@ -309,7 +309,7 @@ public class COSArray extends COSBase im
         }
         else
         {
-            set( index, null );
+            set ( index, null );
         }
     }   
 
@@ -551,7 +551,7 @@ public class COSArray extends COSBase im
      *
      *  @return the COSArray as List
      */
-    public List<?> toList()
+    public List<COSBase> toList()
     {
         ArrayList<COSBase> retList = new ArrayList<COSBase>(size());
         for (int i = 0; i < size(); i++)

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSDictionaryMap.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSDictionaryMap.java?rev=1446893&r1=1446892&r2=1446893&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSDictionaryMap.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSDictionaryMap.java
 Sat Feb 16 13:18:27 2013
@@ -38,10 +38,10 @@ import org.apache.pdfbox.cos.COSString;
  * @author <a href="mailto:[email protected]";>Ben Litchfield</a>
  * @version $Revision: 1.10 $
  */
-public class COSDictionaryMap<K,V> implements Map<K,V>
+public class COSDictionaryMap implements Map
 {
     private COSDictionary map;
-    private Map<K,V> actuals;
+    private Map actuals;
 
     /**
      * Constructor for this map.
@@ -49,7 +49,7 @@ public class COSDictionaryMap<K,V> imple
      * @param actualsMap The map with standard java objects as values.
      * @param dicMap The map with COSBase objects as values.
      */
-    public COSDictionaryMap( Map<K,V> actualsMap, COSDictionary dicMap )
+    public COSDictionaryMap( Map actualsMap, COSDictionary dicMap )
     {
         actuals = actualsMap;
         map = dicMap;
@@ -91,7 +91,7 @@ public class COSDictionaryMap<K,V> imple
     /**
      * {@inheritDoc}
      */
-    public V get(Object key)
+    public Object get(Object key)
     {
         return actuals.get( key );
     }
@@ -99,7 +99,7 @@ public class COSDictionaryMap<K,V> imple
     /**
      * {@inheritDoc}
      */
-    public V put(K key, V value)
+    public Object put(Object key, Object value)
     {
         COSObjectable object = (COSObjectable)value;
 
@@ -110,7 +110,7 @@ public class COSDictionaryMap<K,V> imple
     /**
      * {@inheritDoc}
      */
-    public V remove(Object key)
+    public Object remove(Object key)
     {
         map.removeItem( COSName.getPDFName( (String)key ) );
         return actuals.remove( key );
@@ -119,7 +119,7 @@ public class COSDictionaryMap<K,V> imple
     /**
      * {@inheritDoc}
      */
-    public void putAll(Map<? extends K, ? extends V> t)
+    public void putAll(Map t)
     {
         throw new RuntimeException( "Not yet implemented" );
     }
@@ -136,7 +136,7 @@ public class COSDictionaryMap<K,V> imple
     /**
      * {@inheritDoc}
      */
-    public Set<K> keySet()
+    public Set keySet()
     {
         return actuals.keySet();
     }
@@ -144,7 +144,7 @@ public class COSDictionaryMap<K,V> imple
     /**
      * {@inheritDoc}
      */
-    public Collection<V> values()
+    public Collection values()
     {
         return actuals.values();
     }
@@ -152,7 +152,7 @@ public class COSDictionaryMap<K,V> imple
     /**
      * {@inheritDoc}
      */
-    public Set<Map.Entry<K, V>> entrySet()
+    public Set entrySet()
     {
         return Collections.unmodifiableSet(actuals.entrySet());
     }
@@ -165,7 +165,7 @@ public class COSDictionaryMap<K,V> imple
         boolean retval = false;
         if( o instanceof COSDictionaryMap )
         {
-            COSDictionaryMap<K,V> other = (COSDictionaryMap)o;
+            COSDictionaryMap other = (COSDictionaryMap)o;
             retval = other.map.equals( this.map );
         }
         return retval;
@@ -195,9 +195,9 @@ public class COSDictionaryMap<K,V> imple
      *
      * @return A proper COSDictionary
      */
-    public static COSDictionary convert( Map<?,?> someMap )
+    public static COSDictionary convert( Map someMap )
     {
-        Iterator<?> iter = someMap.keySet().iterator();
+        Iterator iter = someMap.keySet().iterator();
         COSDictionary dic = new COSDictionary();
         while( iter.hasNext() )
         {
@@ -216,12 +216,12 @@ public class COSDictionaryMap<K,V> imple
      * @return A standard java map.
      * @throws IOException If there is an error during the conversion.
      */
-    public static COSDictionaryMap<String, Object> convertBasicTypesToMap( 
COSDictionary map ) throws IOException
+    public static COSDictionaryMap convertBasicTypesToMap( COSDictionary map ) 
throws IOException
     {
-        COSDictionaryMap<String, Object> retval = null;
+        COSDictionaryMap retval = null;
         if( map != null )
         {
-            Map<String, Object> actualMap = new HashMap<String, Object>();
+            Map actualMap = new HashMap();
             for( COSName key : map.keySet() )
             {
                 COSBase cosObj = map.getDictionaryObject( key );
@@ -252,7 +252,7 @@ public class COSDictionaryMap<K,V> imple
                 }
                 actualMap.put( key.getName(), actualObject );
             }
-            retval = new COSDictionaryMap<String, Object>( actualMap, map );
+            retval = new COSDictionaryMap( actualMap, map );
         }
 
         return retval;

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java?rev=1446893&r1=1446892&r2=1446893&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java
 Sat Feb 16 13:18:27 2013
@@ -41,572 +41,523 @@ import org.apache.pdfbox.pdmodel.PDDocum
 import org.apache.pdfbox.pdmodel.common.filespecification.PDFileSpecification;
 
 /**
- * A PDStream represents a stream in a PDF document. Streams are tied to a
- * single PDF document.
- * 
+ * A PDStream represents a stream in a PDF document.  Streams are tied to a 
single
+ * PDF document.
+ *
  * @author <a href="mailto:[email protected]";>Ben Litchfield</a>
  * @version $Revision: 1.17 $
  */
 public class PDStream implements COSObjectable
 {
-    private COSStream stream;
+       private COSStream stream;
 
-    /**
-     * This will create a new PDStream object.
-     */
-    protected PDStream()
-    {
-        // should only be called by PDMemoryStream
-    }
-
-    /**
-     * This will create a new PDStream object.
-     * 
-     * @param document
-     *            The document that the stream will be part of.
-     */
-    public PDStream(PDDocument document)
-    {
-        stream = new COSStream(document.getDocument().getScratchFile());
-    }
-
-    /**
-     * Constructor.
-     * 
-     * @param str
-     *            The stream parameter.
-     */
-    public PDStream(COSStream str)
-    {
-        stream = str;
-    }
-
-    /**
-     * Constructor. Reads all data from the input stream and embeds it into the
-     * document, this will close the InputStream.
-     * 
-     * @param doc
-     *            The document that will hold the stream.
-     * @param str
-     *            The stream parameter.
-     * @throws IOException
-     *             If there is an error creating the stream in the document.
-     */
-    public PDStream(PDDocument doc, InputStream str) throws IOException
-    {
-        this(doc, str, false);
-    }
-
-    /**
-     * Constructor. Reads all data from the input stream and embeds it into the
-     * document, this will close the InputStream.
-     * 
-     * @param doc
-     *            The document that will hold the stream.
-     * @param str
-     *            The stream parameter.
-     * @param filtered
-     *            True if the stream already has a filter applied.
-     * @throws IOException
-     *             If there is an error creating the stream in the document.
-     */
-    public PDStream(PDDocument doc, InputStream str, boolean filtered)
-            throws IOException
-    {
-        OutputStream output = null;
-        try
-        {
-            stream = new COSStream(doc.getDocument().getScratchFile());
-            if (filtered)
-            {
-                output = stream.createFilteredStream();
-            } 
-            else
-            {
-                output = stream.createUnfilteredStream();
-            }
-            byte[] buffer = new byte[1024];
-            int amountRead = -1;
-            while ((amountRead = str.read(buffer)) != -1)
-            {
-                output.write(buffer, 0, amountRead);
-            }
-        } 
-        finally
-        {
-            if (output != null)
-            {
-                output.close();
-            }
-            if (str != null)
-            {
-                str.close();
-            }
-        }
-    }
-
-    /**
-     * If there are not compression filters on the current stream then this 
will
-     * add a compression filter, flate compression for example.
-     */
-    public void addCompression()
-    {
-        List<COSName> filters = getFilters();
-        if (filters == null)
-        {
-            filters = new ArrayList<COSName>();
-            filters.add(COSName.FLATE_DECODE);
-            setFilters(filters);
-        }
-    }
-
-    /**
-     * Create a pd stream from either a regular COSStream on a COSArray of cos
-     * streams.
-     * 
-     * @param base
-     *            Either a COSStream or COSArray.
-     * @return A PDStream or null if base is null.
-     * @throws IOException
-     *             If there is an error creating the PDStream.
-     */
-    public static PDStream createFromCOS(COSBase base) throws IOException
-    {
-        PDStream retval = null;
-        if (base instanceof COSStream)
-        {
-            retval = new PDStream((COSStream) base);
-        } 
-        else if (base instanceof COSArray)
-        {
-            if (((COSArray) base).size() > 0)
-            {
-                retval = new PDStream(new COSStreamArray((COSArray) base));
-            }
-        } 
-        else
-        {
-            if (base != null)
-            {
-                throw new IOException("Contents are unknown type:"
-                        + base.getClass().getName());
-            }
-        }
-        return retval;
-    }
-
-    /**
-     * Convert this standard java object to a COS object.
-     * 
-     * @return The cos object that matches this Java object.
-     */
-    public COSBase getCOSObject()
-    {
-        return stream;
-    }
-
-    /**
-     * This will get a stream that can be written to.
-     * 
-     * @return An output stream to write data to.
-     * 
-     * @throws IOException
-     *             If an IO error occurs during writing.
-     */
-    public OutputStream createOutputStream() throws IOException
-    {
-        return stream.createUnfilteredStream();
-    }
-
-    /**
-     * This will get a stream that can be read from.
-     * 
-     * @return An input stream that can be read from.
-     * 
-     * @throws IOException
-     *             If an IO error occurs during reading.
-     */
-    public InputStream createInputStream() throws IOException
-    {
-        return stream.getUnfilteredStream();
-    }
-
-    /**
-     * This will get a stream with some filters applied but not others. This is
-     * useful when doing images, ie filters = [flate,dct], we want to remove
-     * flate but leave dct
-     * 
-     * @param stopFilters
-     *            A list of filters to stop decoding at.
-     * @return A stream with decoded data.
-     * @throws IOException
-     *             If there is an error processing the stream.
-     */
-    public InputStream getPartiallyFilteredStream(List<String> stopFilters)
-            throws IOException
-    {
-        FilterManager manager = stream.getFilterManager();
-        InputStream is = stream.getFilteredStream();
-        ByteArrayOutputStream os = new ByteArrayOutputStream();
-        List<COSName> filters = getFilters();
-        COSName nextFilter = null;
-        boolean done = false;
-        for (int i = 0; i < filters.size() && !done; i++)
-        {
-            os.reset();
-            nextFilter = filters.get(i);
-            if (stopFilters.contains(nextFilter.getName()))
-            {
-                done = true;
-            } 
-            else
-            {
-                Filter filter = manager.getFilter(nextFilter);
-                filter.decode(is, os, stream, i);
-                is = new ByteArrayInputStream(os.toByteArray());
-            }
-        }
-        return is;
-    }
-
-    /**
-     * Get the cos stream associated with this object.
-     * 
-     * @return The cos object that matches this Java object.
-     */
-    public COSStream getStream()
-    {
-        return stream;
-    }
-
-    /**
-     * This will get the length of the filtered/compressed stream. This is
-     * readonly in the PD Model and will be managed by this class.
-     * 
-     * @return The length of the filtered stream.
-     */
-    public int getLength()
-    {
-        return stream.getInt(COSName.LENGTH, 0);
-    }
-
-    /**
-     * This will get the list of filters that are associated with this stream.
-     * Or null if there are none.
-     * 
-     * @return A list of all encoding filters to apply to this stream.
-     */
-    public List<COSName> getFilters()
-    {
-        List<COSName> retval = null;
-        COSBase filters = stream.getFilters();
-        if (filters instanceof COSName)
-        {
-            COSName name = (COSName) filters;
-            retval = new COSArrayList<COSName>(name, name, stream,
-                    COSName.FILTER);
-        } 
-        else if (filters instanceof COSArray)
-        {
-            retval = (List<COSName>) ((COSArray) filters).toList();
-        }
-        return retval;
-    }
-
-    /**
-     * This will set the filters that are part of this stream.
-     * 
-     * @param filters
-     *            The filters that are part of this stream.
-     */
-    public void setFilters(List<COSName> filters)
-    {
-        COSBase obj = COSArrayList.converterToCOSArray(filters);
-        stream.setItem(COSName.FILTER, obj);
-    }
-
-    /**
-     * Get the list of decode parameters. Each entry in the list will refer to
-     * an entry in the filters list.
-     * 
-     * @return The list of decode parameters.
-     * 
-     * @throws IOException
-     *             if there is an error retrieving the parameters.
-     */
-    public List<Object> getDecodeParms() throws IOException
-    {
-        List<Object> retval = null;
-
-        COSBase dp = stream.getDictionaryObject(COSName.DECODE_PARMS);
-        if (dp == null)
-        {
-            // See PDF Ref 1.5 implementation note 7, the DP is sometimes used
-            // instead.
-            dp = stream.getDictionaryObject(COSName.DP);
-        }
-        if (dp instanceof COSDictionary)
-        {
-            Map<?, ?> map = COSDictionaryMap
-                    .convertBasicTypesToMap((COSDictionary) dp);
-            retval = new COSArrayList<Object>(map, dp, stream,
-                    COSName.DECODE_PARMS);
-        } 
-        else if (dp instanceof COSArray)
-        {
-            COSArray array = (COSArray) dp;
-            List<Object> actuals = new ArrayList<Object>();
-            for (int i = 0; i < array.size(); i++)
-            {
-                actuals.add(COSDictionaryMap
-                        .convertBasicTypesToMap((COSDictionary) array
-                                .getObject(i)));
-            }
-            retval = new COSArrayList<Object>(actuals, array);
-        }
-
-        return retval;
-    }
-
-    /**
-     * This will set the list of decode parameterss.
-     * 
-     * @param decodeParams
-     *            The list of decode parameterss.
-     */
-    public void setDecodeParms(List<?> decodeParams)
-    {
-        stream.setItem(COSName.DECODE_PARMS,
-                COSArrayList.converterToCOSArray(decodeParams));
-    }
-
-    /**
-     * This will get the file specification for this stream. This is only
-     * required for external files.
-     * 
-     * @return The file specification.
-     * 
-     * @throws IOException
-     *             If there is an error creating the file spec.
-     */
-    public PDFileSpecification getFile() throws IOException
-    {
-        COSBase f = stream.getDictionaryObject(COSName.F);
-        PDFileSpecification retval = PDFileSpecification.createFS(f);
-        return retval;
-    }
-
-    /**
-     * Set the file specification.
-     * 
-     * @param f
-     *            The file specification.
-     */
-    public void setFile(PDFileSpecification f)
-    {
-        stream.setItem(COSName.F, f);
-    }
-
-    /**
-     * This will get the list of filters that are associated with this stream.
-     * Or null if there are none.
-     * 
-     * @return A list of all encoding filters to apply to this stream.
-     */
-    public List<String> getFileFilters()
-    {
-        List<String> retval = null;
-        COSBase filters = stream.getDictionaryObject(COSName.F_FILTER);
-        if (filters instanceof COSName)
-        {
-            COSName name = (COSName) filters;
-            retval = new COSArrayList<String>(name.getName(), name, stream,
-                    COSName.F_FILTER);
-        } 
-        else if (filters instanceof COSArray)
-        {
-            retval = COSArrayList
-                    .convertCOSNameCOSArrayToList((COSArray) filters);
-        }
-        return retval;
-    }
-
-    /**
-     * This will set the filters that are part of this stream.
-     * 
-     * @param filters
-     *            The filters that are part of this stream.
-     */
-    public void setFileFilters(List<String> filters)
-    {
-        COSBase obj = COSArrayList.convertStringListToCOSNameCOSArray(filters);
-        stream.setItem(COSName.F_FILTER, obj);
-    }
-
-    /**
-     * Get the list of decode parameters. Each entry in the list will refer to
-     * an entry in the filters list.
-     * 
-     * @return The list of decode parameters.
-     * 
-     * @throws IOException
-     *             if there is an error retrieving the parameters.
-     */
-    public List<Object> getFileDecodeParams() throws IOException
-    {
-        List<Object> retval = null;
-
-        COSBase dp = stream.getDictionaryObject(COSName.F_DECODE_PARMS);
-        if (dp instanceof COSDictionary)
-        {
-            Map<?, ?> map = COSDictionaryMap
-                    .convertBasicTypesToMap((COSDictionary) dp);
-            retval = new COSArrayList<Object>(map, dp, stream,
-                    COSName.F_DECODE_PARMS);
-        } 
-        else if (dp instanceof COSArray)
-        {
-            COSArray array = (COSArray) dp;
-            List<Object> actuals = new ArrayList<Object>();
-            for (int i = 0; i < array.size(); i++)
-            {
-                actuals.add(COSDictionaryMap
-                        .convertBasicTypesToMap((COSDictionary) array
-                                .getObject(i)));
-            }
-            retval = new COSArrayList<Object>(actuals, array);
-        }
-
-        return retval;
-    }
-
-    /**
-     * This will set the list of decode params.
-     * 
-     * @param decodeParams
-     *            The list of decode params.
-     */
-    public void setFileDecodeParams(List<?> decodeParams)
-    {
-        stream.setItem("FDecodeParams",
-                COSArrayList.converterToCOSArray(decodeParams));
-    }
-
-    /**
-     * This will copy the stream into a byte array.
-     * 
-     * @return The byte array of the filteredStream
-     * @throws IOException
-     *             When getFilteredStream did not work
-     */
-    public byte[] getByteArray() throws IOException
-    {
-        ByteArrayOutputStream output = new ByteArrayOutputStream();
-        byte[] buf = new byte[1024];
-        InputStream is = null;
-        try
-        {
-            is = createInputStream();
-            int amountRead = -1;
-            while ((amountRead = is.read(buf)) != -1)
-            {
-                output.write(buf, 0, amountRead);
-            }
-        } 
-        finally
-        {
-            if (is != null)
-            {
-                is.close();
-            }
-        }
-        return output.toByteArray();
-    }
-
-    /**
-     * A convenience method to get this stream as a string. Uses the default
-     * system encoding.
-     * 
-     * @return a String representation of this (input) stream.
-     * 
-     * @throws IOException
-     *             if there is an error while converting the stream to a 
string.
-     */
-    public String getInputStreamAsString() throws IOException
-    {
-        byte[] bStream = getByteArray();
-        return new String(bStream, "ISO-8859-1");
-    }
-
-    /**
-     * Get the metadata that is part of the document catalog. This will return
-     * null if there is no meta data for this object.
-     * 
-     * @return The metadata for this object.
-     * @throws IllegalStateException
-     *             if the value of the metadata entry is different from a 
stream
-     *             or null
-     */
-    public PDMetadata getMetadata()
-    {
-        PDMetadata retval = null;
-        COSBase mdStream = stream.getDictionaryObject(COSName.METADATA);
-        if (mdStream != null)
-        {
-            if (mdStream instanceof COSStream)
-            {
-                retval = new PDMetadata((COSStream) mdStream);
-            } 
-            else if (mdStream instanceof COSNull)
-            {
-                // null is authorized
-            } 
-            else
-            {
-                throw new IllegalStateException(
-                        "Expected a COSStream but was a "
-                                + mdStream.getClass().getSimpleName());
-            }
-        }
-        return retval;
-    }
-
-    /**
-     * Set the metadata for this object. This can be null.
-     * 
-     * @param meta
-     *            The meta data for this object.
-     */
-    public void setMetadata(PDMetadata meta)
-    {
-        stream.setItem(COSName.METADATA, meta);
-    }
-
-    /**
-     * Get the decoded stream length.
-     * 
-     * @since Apache PDFBox 1.1.0
-     * @see <a
-     *      
href="https://issues.apache.org/jira/browse/PDFBOX-636";>PDFBOX-636</a>
-     * @return the decoded stream length
-     */
-    public int getDecodedStreamLength()
-    {
-        return this.stream.getInt(COSName.DL);
-    }
-
-    /**
-     * Set the decoded stream length.
-     * 
-     * @since Apache PDFBox 1.1.0
-     * @see <a
-     *      
href="https://issues.apache.org/jira/browse/PDFBOX-636";>PDFBOX-636</a>
-     * @param decodedStreamLength
-     *            the decoded stream length
-     */
-    public void setDecodedStreamLength(int decodedStreamLength)
-    {
-        this.stream.setInt(COSName.DL, decodedStreamLength);
-    }
+       /**
+        * This will create a new PDStream object.
+        */
+       protected PDStream()
+       {
+               //should only be called by PDMemoryStream
+       }
+
+       /**
+        * This will create a new PDStream object.
+        *
+        * @param document The document that the stream will be part of.
+        */
+       public PDStream( PDDocument document )
+       {
+               stream = new COSStream( document.getDocument().getScratchFile() 
);
+       }
+
+       /**
+        * Constructor.
+        *
+        * @param str The stream parameter.
+        */
+       public PDStream( COSStream str )
+       {
+               stream = str;
+       }
+
+       /**
+        * Constructor.  Reads all data from the input stream and embeds it 
into the
+        * document, this will close the InputStream.
+        *
+        * @param doc The document that will hold the stream.
+        * @param str The stream parameter.
+        * @throws IOException If there is an error creating the stream in the 
document.
+        */
+       public PDStream( PDDocument doc, InputStream str ) throws IOException
+       {
+               this( doc, str, false );
+       }
+
+       /**
+        * Constructor.  Reads all data from the input stream and embeds it 
into the
+        * document, this will close the InputStream.
+        *
+        * @param doc The document that will hold the stream.
+        * @param str The stream parameter.
+        * @param filtered True if the stream already has a filter applied.
+        * @throws IOException If there is an error creating the stream in the 
document.
+        */
+       public PDStream( PDDocument doc, InputStream str, boolean filtered ) 
throws IOException
+       {
+               OutputStream output = null;
+               try
+               {
+                       stream = new COSStream( 
doc.getDocument().getScratchFile() );
+                       if( filtered )
+                       {
+                               output = stream.createFilteredStream();
+                       }
+                       else
+                       {
+                               output = stream.createUnfilteredStream();
+                       }
+                       byte[] buffer = new byte[ 1024 ];
+                       int amountRead = -1;
+                       while( (amountRead = str.read(buffer)) != -1 )
+                       {
+                               output.write( buffer, 0, amountRead );
+                       }
+               }
+               finally
+               {
+                       if( output != null )
+                       {
+                               output.close();
+                       }
+                       if( str != null )
+                       {
+                               str.close();
+                       }
+               }
+       }
+
+       /**
+        * If there are not compression filters on the current stream then this
+        * will add a compression filter, flate compression for example.
+        */
+       public void addCompression()
+       {
+               List filters = getFilters();
+               if( filters == null )
+               {
+                       filters = new ArrayList();
+                       filters.add( COSName.FLATE_DECODE );
+                       setFilters( filters );
+               }
+       }
+
+       /**
+        * Create a pd stream from either a regular COSStream on a COSArray of 
cos streams.
+        * @param base Either a COSStream or COSArray.
+        * @return A PDStream or null if base is null.
+        * @throws IOException If there is an error creating the PDStream.
+        */
+       public static PDStream createFromCOS( COSBase base ) throws IOException
+       {
+               PDStream retval = null;
+               if( base instanceof COSStream )
+               {
+                       retval = new PDStream( (COSStream)base );
+               }
+               else if( base instanceof COSArray )
+               {
+                       if (((COSArray)base).size() > 0) {
+                               retval = new PDStream( new COSStreamArray( 
(COSArray)base ) );
+                       }
+               }
+               else
+               {
+                       if( base != null )
+                       {
+                               throw new IOException( "Contents are unknown 
type:" + base.getClass().getName() );
+                       }
+               }
+               return retval;
+       }
+
+
+       /**
+        * Convert this standard java object to a COS object.
+        *
+        * @return The cos object that matches this Java object.
+        */
+       public COSBase getCOSObject()
+       {
+               return stream;
+       }
+
+       /**
+        * This will get a stream that can be written to.
+        *
+        * @return An output stream to write data to.
+        *
+        * @throws IOException If an IO error occurs during writing.
+        */
+       public OutputStream createOutputStream() throws IOException
+       {
+               return stream.createUnfilteredStream();
+       }
+
+       /**
+        * This will get a stream that can be read from.
+        *
+        * @return An input stream that can be read from.
+        *
+        * @throws IOException If an IO error occurs during reading.
+        */
+       public InputStream createInputStream() throws IOException
+       {
+               return stream.getUnfilteredStream();
+       }
+
+       /**
+        * This will get a stream with some filters applied but not others.  
This is useful
+        * when doing images, ie filters = [flate,dct], we want to remove flate 
but leave dct
+        *
+        * @param stopFilters A list of filters to stop decoding at.
+        * @return A stream with decoded data.
+        * @throws IOException If there is an error processing the stream.
+        */
+       public InputStream getPartiallyFilteredStream( List stopFilters ) 
throws IOException
+       {
+               FilterManager manager = stream.getFilterManager();
+               InputStream is = stream.getFilteredStream();
+               ByteArrayOutputStream os = new ByteArrayOutputStream();
+               List filters = getFilters();
+               String nextFilter = null;
+               boolean done = false;
+               for( int i=0; i<filters.size() && !done; i++ )
+               {
+                       os.reset();
+                       nextFilter = (String)filters.get( i );
+                       if( stopFilters.contains( nextFilter ) )
+                       {
+                               done = true;
+                       }
+                       else
+                       {
+                               Filter filter = manager.getFilter( 
COSName.getPDFName(nextFilter) );
+                               filter.decode( is, os, stream, i );
+                               is = new ByteArrayInputStream( os.toByteArray() 
);
+                       }
+               }
+               return is;
+       }
+
+       /**
+        * Get the cos stream associated with this object.
+        *
+        * @return The cos object that matches this Java object.
+        */
+       public COSStream getStream()
+       {
+               return stream;
+       }
+
+       /**
+        * This will get the length of the filtered/compressed stream.  This is 
readonly in the
+        * PD Model and will be managed by this class.
+        *
+        * @return The length of the filtered stream.
+        */
+       public int getLength()
+       {
+               return stream.getInt( "Length", 0 );
+       }
+
+       /**
+        * This will get the list of filters that are associated with this 
stream.  Or
+        * null if there are none.
+        * @return A list of all encoding filters to apply to this stream.
+        */
+       public List getFilters()
+       {
+               List retval = null;
+               COSBase filters = stream.getFilters();
+               if( filters instanceof COSName )
+               {
+                       COSName name = (COSName)filters;
+                       retval = new COSArrayList( name.getName(), name, 
stream, COSName.FILTER );
+               }
+               else if( filters instanceof COSArray )
+               {
+                       retval = COSArrayList.convertCOSNameCOSArrayToList( 
(COSArray)filters );
+               }
+               return retval;
+       }
+
+       /**
+        * This will set the filters that are part of this stream.
+        *
+        * @param filters The filters that are part of this stream.
+        */
+       public void setFilters( List filters )
+       {
+               COSBase obj = COSArrayList.convertStringListToCOSNameCOSArray( 
filters );
+               stream.setItem( COSName.FILTER, obj );
+       }
+
+       /**
+        * Get the list of decode parameters.  Each entry in the list will 
refer to
+        * an entry in the filters list.
+        *
+        * @return The list of decode parameters.
+        *
+        * @throws IOException if there is an error retrieving the parameters.
+        */
+       public List getDecodeParms() throws IOException
+       {
+               List retval = null;
+
+               COSBase dp = stream.getDictionaryObject( COSName.DECODE_PARMS );
+               if( dp == null )
+               {
+                       //See PDF Ref 1.5 implementation note 7, the DP is 
sometimes used instead.
+                       dp = stream.getDictionaryObject( COSName.DP );
+               }
+               if( dp instanceof COSDictionary )
+               {
+                       Map map = COSDictionaryMap.convertBasicTypesToMap( 
(COSDictionary)dp );
+                       retval = new COSArrayList(map, dp, stream, 
COSName.DECODE_PARMS );
+               }
+               else if( dp instanceof COSArray )
+               {
+                       COSArray array = (COSArray)dp;
+                       List actuals = new ArrayList();
+                       for( int i=0; i<array.size(); i++ )
+                       {
+                               actuals.add(
+                                               
COSDictionaryMap.convertBasicTypesToMap(
+                                                               
(COSDictionary)array.getObject( i ) ) );
+                       }
+                       retval = new COSArrayList(actuals, array);
+               }
+
+               return retval;
+       }
+
+       /**
+        * This will set the list of decode parameterss.
+        *
+        * @param decodeParams The list of decode parameterss.
+        */
+       public void setDecodeParms( List decodeParams )
+       {
+               stream.setItem(
+                               COSName.DECODE_PARMS, 
COSArrayList.converterToCOSArray( decodeParams ) );
+       }
+
+       /**
+        * This will get the file specification for this stream.  This is only
+        * required for external files.
+        *
+        * @return The file specification.
+        *
+        * @throws IOException If there is an error creating the file spec.
+        */
+       public PDFileSpecification getFile() throws IOException
+       {
+               COSBase f = stream.getDictionaryObject( COSName.F );
+               PDFileSpecification retval = PDFileSpecification.createFS( f );
+               return retval;
+       }
+
+       /**
+        * Set the file specification.
+        * @param f The file specification.
+        */
+       public void setFile( PDFileSpecification f )
+       {
+               stream.setItem( COSName.F, f );
+       }
+
+       /**
+        * This will get the list of filters that are associated with this 
stream.  Or
+        * null if there are none.
+        * @return A list of all encoding filters to apply to this stream.
+        */
+       public List getFileFilters()
+       {
+               List retval = null;
+               COSBase filters = stream.getDictionaryObject( COSName.F_FILTER 
);
+               if( filters instanceof COSName )
+               {
+                       COSName name = (COSName)filters;
+                       retval = new COSArrayList( name.getName(), name, 
stream, COSName.F_FILTER );
+               }
+               else if( filters instanceof COSArray )
+               {
+                       retval = COSArrayList.convertCOSNameCOSArrayToList( 
(COSArray)filters );
+               }
+               return retval;
+       }
+
+       /**
+        * This will set the filters that are part of this stream.
+        *
+        * @param filters The filters that are part of this stream.
+        */
+       public void setFileFilters( List filters )
+       {
+               COSBase obj = COSArrayList.convertStringListToCOSNameCOSArray( 
filters );
+               stream.setItem( COSName.F_FILTER, obj );
+       }
+
+       /**
+        * Get the list of decode parameters.  Each entry in the list will 
refer to
+        * an entry in the filters list.
+        *
+        * @return The list of decode parameters.
+        *
+        * @throws IOException if there is an error retrieving the parameters.
+        */
+       public List getFileDecodeParams() throws IOException
+       {
+               List retval = null;
+
+               COSBase dp = stream.getDictionaryObject( COSName.F_DECODE_PARMS 
);
+               if( dp instanceof COSDictionary )
+               {
+                       Map map = COSDictionaryMap.convertBasicTypesToMap( 
(COSDictionary)dp );
+                       retval = new COSArrayList(map, dp, stream, 
COSName.F_DECODE_PARMS );
+               }
+               else if( dp instanceof COSArray )
+               {
+                       COSArray array = (COSArray)dp;
+                       List actuals = new ArrayList();
+                       for( int i=0; i<array.size(); i++ )
+                       {
+                               actuals.add(
+                                               
COSDictionaryMap.convertBasicTypesToMap(
+                                                               
(COSDictionary)array.getObject( i ) ) );
+                       }
+                       retval = new COSArrayList(actuals, array);
+               }
+
+               return retval;
+       }
+
+       /**
+        * This will set the list of decode params.
+        *
+        * @param decodeParams The list of decode params.
+        */
+       public void setFileDecodeParams( List decodeParams )
+       {
+               stream.setItem(
+                               "FDecodeParams", 
COSArrayList.converterToCOSArray( decodeParams ) );
+       }
+
+       /**
+        * This will copy the stream into a byte array.
+        *
+        * @return The byte array of the filteredStream
+        * @throws IOException When getFilteredStream did not work
+        */
+       public byte[] getByteArray() throws IOException
+       {
+               ByteArrayOutputStream output = new ByteArrayOutputStream();
+               byte[] buf = new byte[1024];
+               InputStream is = null;
+               try
+               {
+                       is = createInputStream();
+                       int amountRead = -1;
+                       while( (amountRead = is.read( buf )) != -1)
+                       {
+                               output.write( buf, 0, amountRead );
+                       }
+               }
+               finally
+               {
+                       if( is != null )
+                       {
+                               is.close();
+                       }
+               }
+               return output.toByteArray();
+       }
+
+       /**
+        * A convenience method to get this stream as a string.  Uses
+        * the default system encoding.
+        *
+        * @return a String representation of this (input) stream.
+        *
+        * @throws IOException if there is an error while converting the stream
+        *                     to a string.
+        */
+       public String getInputStreamAsString() throws IOException
+       {
+               byte[] bStream = getByteArray();
+               return new String(bStream, "ISO-8859-1");
+       }
+
+       /**
+        * Get the metadata that is part of the document catalog.  This will
+        * return null if there is no meta data for this object.
+        *
+        * @return The metadata for this object.
+        * @throws IllegalStateException if the value of the metadata entry is 
different from a stream or null
+        */
+       public PDMetadata getMetadata ()
+       {
+               PDMetadata retval = null;
+               COSBase mdStream = stream.getDictionaryObject( COSName.METADATA 
);
+               if( mdStream != null )
+               {
+                       if (mdStream instanceof COSStream) 
+                       {
+                               retval = new PDMetadata( (COSStream)mdStream );
+                       }
+                       else if (mdStream instanceof COSNull) 
+                       {
+                               // null is authorized
+                       }
+                       else
+                       {
+                               throw new IllegalStateException("Expected a 
COSStream but was a " + mdStream.getClass().getSimpleName());
+                       }
+               }
+               return retval;
+       }
+
+       /**
+        * Set the metadata for this object.  This can be null.
+        *
+        * @param meta The meta data for this object.
+        */
+       public void setMetadata( PDMetadata meta )
+       {
+               stream.setItem( COSName.METADATA, meta );
+       }
+
+       /**
+        * Get the decoded stream length.
+        *
+        * @since Apache PDFBox 1.1.0
+        * @see <a 
href="https://issues.apache.org/jira/browse/PDFBOX-636";>PDFBOX-636</a>
+        * @return the decoded stream length
+        */
+       public int getDecodedStreamLength()
+       {
+               return this.stream.getInt(COSName.DL);
+       }
+
+       /**
+        * Set the decoded stream length.
+        *
+        * @since Apache PDFBox 1.1.0
+        * @see <a 
href="https://issues.apache.org/jira/browse/PDFBOX-636";>PDFBOX-636</a>
+        * @param decodedStreamLength the decoded stream length
+        */
+       public void setDecodedStreamLength(int decodedStreamLength)
+       {
+               this.stream.setInt(COSName.DL, decodedStreamLength);
+       }
 
 }

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElement.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElement.java?rev=1446893&r1=1446892&r2=1446893&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElement.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElement.java
 Sat Feb 16 13:18:27 2013
@@ -37,9 +37,9 @@ import org.apache.pdfbox.pdmodel.documen
  */
 public class PDStructureElement extends PDStructureNode
 {
-    
     public static final String TYPE = "StructElem";
 
+
     /**
      * Constructor with required values.
      *
@@ -490,7 +490,7 @@ public class PDStructureElement extends 
     }
 
     /**
-     * Increments th revision number.
+     * Increments th revision number
      */
     public void incrementRevisionNumber()
     {
@@ -606,14 +606,15 @@ public class PDStructureElement extends 
     public String getStandardStructureType()
     {
         String type = this.getStructureType();
-        Map<String,Object> roleMap = getRoleMap();
-        if (roleMap.containsKey(type))
+        String mappedType;
+        while (true)
         {
-            Object mappedValue = getRoleMap().get(type);
-            if (mappedValue instanceof String)
+            mappedType = this.getRoleMap().get(type);
+            if ((mappedType == null) || type.equals(mappedType))
             {
-                type = (String)mappedValue;
+                break;
             }
+            type = mappedType;
         }
         return type;
     }
@@ -741,7 +742,7 @@ public class PDStructureElement extends 
      * 
      * @return the role map
      */
-    private Map<String, Object> getRoleMap()
+    private Map<String, String> getRoleMap()
     {
         PDStructureTreeRoot root = this.getStructureTreeRoot();
         if (root != null)

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureTreeRoot.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureTreeRoot.java?rev=1446893&r1=1446892&r2=1446893&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureTreeRoot.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureTreeRoot.java
 Sat Feb 16 13:18:27 2013
@@ -100,7 +100,8 @@ public class PDStructureTreeRoot extends
      * 
      * @return the role map
      */
-    public Map<String, Object> getRoleMap()
+    @SuppressWarnings("unchecked")
+    public Map<String, String> getRoleMap()
     {
         COSBase rm = 
this.getCOSDictionary().getDictionaryObject(COSName.ROLE_MAP);
         if (rm instanceof COSDictionary)
@@ -114,7 +115,7 @@ public class PDStructureTreeRoot extends
                 e.printStackTrace();
             }
         }
-        return new Hashtable<String, Object>();
+        return new Hashtable<String, String>();
     }
 
     /**

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/AxialShadingPaint.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/AxialShadingPaint.java?rev=1446893&r1=1446892&r2=1446893&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/AxialShadingPaint.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/AxialShadingPaint.java
 Sat Feb 16 13:18:27 2013
@@ -24,7 +24,6 @@ import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.ColorModel;
 
-import org.apache.pdfbox.pdmodel.common.PDMatrix;
 import org.apache.pdfbox.util.Matrix;
 
 /**
@@ -39,7 +38,6 @@ public class AxialShadingPaint implement
 
     private PDShadingType2 shading;
     private Matrix currentTransformationMatrix;
-    private Matrix shadingMatrix;
     private int pageHeight;
     
     /**
@@ -49,14 +47,12 @@ public class AxialShadingPaint implement
      * @param ctm current transformation matrix
      * @param pageSizeValue size of the current page
      */
-    public AxialShadingPaint(PDShadingType2 shadingType2, Matrix ctm, int 
pageHeightValue, Matrix shMatrix) 
+    public AxialShadingPaint(PDShadingType2 shadingType2, Matrix ctm, int 
pageHeightValue) 
     {
         shading = shadingType2;
         currentTransformationMatrix = ctm;
-        shadingMatrix = shMatrix;
         pageHeight = pageHeightValue;
     }
-
     /**
      * {@inheritDoc}
      */
@@ -71,7 +67,7 @@ public class AxialShadingPaint implement
     public PaintContext createContext(ColorModel cm, Rectangle deviceBounds,
             Rectangle2D userBounds, AffineTransform xform, RenderingHints 
hints) 
     {
-        return new AxialShadingContext(shading, cm, xform, 
currentTransformationMatrix, pageHeight, shadingMatrix);
+        return new AxialShadingContext(shading, cm, xform, 
currentTransformationMatrix, pageHeight);
     }
 
 }

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingResources.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingResources.java?rev=1446893&r1=1446892&r2=1446893&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingResources.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingResources.java
 Sat Feb 16 13:18:27 2013
@@ -25,7 +25,6 @@ import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
-import org.apache.pdfbox.pdmodel.common.PDMatrix;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpaceFactory;

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingContext.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingContext.java?rev=1446893&r1=1446892&r2=1446893&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingContext.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingContext.java
 Sat Feb 16 13:18:27 2013
@@ -17,11 +17,8 @@
 package org.apache.pdfbox.pdmodel.graphics.shading;
 
 import java.awt.PaintContext;
-import java.awt.Point;
 import java.awt.color.ColorSpace;
 import java.awt.geom.AffineTransform;
-import java.awt.geom.NoninvertibleTransformException;
-import java.awt.geom.Point2D;
 import java.awt.image.ColorModel;
 import java.awt.image.Raster;
 import java.awt.image.WritableRaster;
@@ -53,20 +50,15 @@ public class RadialShadingContext implem
     private ColorSpace shadingColorSpace;
     private PDFunction shadingTinttransform;
 
-    private AffineTransform transformAT = null;
-    private Matrix currentCTM = null;
-    private int currentPageHeight;
-    private float maximumHeight;
-    private float clippingHeight;
-
+    private float[] coords;
     private float[] domain;
     private boolean[] extend;
-    private float x0;
-    private float x1;
-    private float y0;
-    private float y1;
-    private float r0;
-    private float r1;
+    private double x1x0; 
+    private double y1y0;
+    private double r1r0;
+    private double x1x0pow2;
+    private double y1y0pow2;
+    private double r0pow2;
 
     private float d1d0;
     private double denom;
@@ -87,53 +79,32 @@ public class RadialShadingContext implem
      * 
      */
     public RadialShadingContext(PDShadingType3 shadingType3, ColorModel 
colorModelValue, 
-            AffineTransform xform, Matrix ctm, int pageHeight, Matrix 
shMatrix, float clipHeight) 
+            AffineTransform xform, Matrix ctm, int pageHeight) 
     {
-        float[] coords = shadingType3.getCoords().toFloatArray();
-        x0 = coords[0];
-        y0 = coords[1];
-        r0 = coords[2];
-        x1 = coords[3];
-        y1 = coords[4];
-        r1 = coords[5];
-        if (clipHeight > 0)
+        coords = shadingType3.getCoords().toFloatArray();
+        if (ctm != null)
         {
-            maximumHeight = 0;
-            clippingHeight = clipHeight;
+            // the shading is used in combination with the sh-operator
+            float[] coordsTemp = new float[coords.length]; 
+            // transform the coords from shading to user space
+            ctm.createAffineTransform().transform(coords, 0, coordsTemp, 0, 1);
+            ctm.createAffineTransform().transform(coords, 3, coordsTemp, 3, 1);
+            // move the 0,0-reference
+            coordsTemp[1] = pageHeight - coordsTemp[1];
+            coordsTemp[4] = pageHeight - coordsTemp[4];
+            // transform the coords from user to device space
+            xform.transform(coordsTemp, 0, coords, 0, 1);
+            xform.transform(coordsTemp, 3, coords, 3, 1);
         }
         else
         {
-            maximumHeight = Math.max((y1+r1),(y0+r0)) - Math.min((y1-r1), 
(y0-r0));
-            clippingHeight = 0;
-        }
-        // transformation
-//        if (shMatrix != null)
-//        {
-//            transformAT = xform;
-//            transformAT.translate(0, -maximumHeight);
-//            transformAT.concatenate(shMatrix.createAffineTransform());
-//        }
-//        else if (currentCTM != null)
-//        {
-//            transformAT = ctm.createAffineTransform();
-//            transformAT.translate(0, -clippingHeight);
-//            transformAT.concatenate(xform);
-//        }
-//        else
-//        {
-//            transformAT = xform;
-//            transformAT.translate(0, -clipHeight);
-//        }
-        try
-        {
-            transformAT = xform.createInverse();
-        } 
-        catch (NoninvertibleTransformException e)
-        {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
+            // the shading is used as pattern colorspace in combination
+            // with a fill-, stroke- or showText-operator
+            float translateY = (float)xform.getTranslateY();
+            // move the 0,0-reference including the y-translation from user to 
device space
+            coords[1] = pageHeight + translateY - coords[1];
+            coords[4] = pageHeight + translateY - coords[4];
         }
-        currentPageHeight = pageHeight;
         // colorSpace 
         try 
         {
@@ -206,7 +177,13 @@ public class RadialShadingContext implem
             extend = new boolean[]{false,false};
         }
         // calculate some constants to be used in getRaster
-        denom = Math.pow(r1-r0,2) - Math.pow(x1-x0,2) - Math.pow(y1-y0,2);
+        x1x0 = coords[3] - coords[0]; 
+        y1y0 = coords[4] - coords[1];
+        r1r0 = coords[5] - coords[2];
+        x1x0pow2 = Math.pow(x1x0,2);
+        y1y0pow2 = Math.pow(y1y0,2);
+        r0pow2 = Math.pow(coords[2],2);
+        denom = x1x0pow2 + y1y0pow2 - Math.pow(r1r0, 2);
         d1d0 = domain[1]-domain[0];
         // TODO take a possible Background value into account
         
@@ -220,7 +197,6 @@ public class RadialShadingContext implem
         function = null;
         shadingColorSpace = null;
         shadingTinttransform = null;
-        currentCTM = null;
     }
 
     /**
@@ -236,14 +212,16 @@ public class RadialShadingContext implem
      */
     public Raster getRaster(int x, int y, int w, int h) 
     {
+        // create writable raster
+        WritableRaster raster = 
getColorModel().createCompatibleWritableRaster(w, h);
         float[] input = new float[1];
-        float inputValue = 0;
+        float inputValue;
         int[] data = new int[w * h * 3];
         for (int j = 0; j < h; j++) 
         {
             for (int i = 0; i < w; i++) 
             {
-                float[] inputValues = calculateInputValues( x+i, y+j);
+                float[] inputValues = calculateInputValues(x + i, y + j);
                 // choose 1 of the 2 values
                 if (inputValues[0] >= domain[0] && inputValues[0] <= domain[1])
                 {
@@ -265,46 +243,37 @@ public class RadialShadingContext implem
                     {
                         inputValue = inputValues[1];
                     }
-                    // both are not in the domain
+                    // TODO
+                    // both are not in the domain -> choose the first as I 
don't know it better
                     else
                     {
-                        if (!extend[0] && !extend[1])
-                        {
-                            // TODO background
-                            continue;
-                        }
-                        boolean extended = false;
-                        // extend
-                        if (extend[0])
-                        {
-                            if((r0 + inputValues[0]*(r1-r0)) >= 0 && 
inputValues[0] < 0)
-                            {
-                                inputValue = domain[0];
-                                extended = true;
-                            }
-                            else if ((r0 + inputValues[1]*(r1-r0)) >= 0 && 
inputValues[1] < 0)
-                            {
-                                inputValue = domain[0];
-                                extended = true;
-                            }
-                        }
-                        if (!extended && extend[1])
-                        {
-                            if((r0 + inputValues[0]*(r1-r0)) >= 0 && 
inputValues[0] > 0)
-                            {
-                                inputValue = domain[1];
-                                extended = true;
-                            }
-                            else if((r0 + inputValues[1]*(r1-r0)) >= 0 && 
inputValues[1] > 0)
-                            {
-                                inputValue = domain[1];
-                                extended = true;
-                            }
-                        }
-                        if (!extended)
-                        {
-                            continue;
-                        }
+                        inputValue = inputValues[0];
+                    }
+                }
+                // input value is out of range
+                if (inputValue < domain[0])
+                {
+                    // the shading has to be extended if extend[0] == true
+                    if (extend[0])
+                    {
+                        inputValue = domain[0];
+                    }
+                    else 
+                    {
+                        continue;
+                    }
+                }
+                // input value is out of range
+                else if (inputValue > domain[1])
+                {
+                    // the shading has to be extended if extend[1] == true
+                    if (extend[1])
+                    {
+                        inputValue = domain[1];
+                    }
+                    else 
+                    {
+                        continue;
                     }
                 }
                 input[0] = (float)(domain[0] + (d1d0*inputValue));
@@ -332,8 +301,6 @@ public class RadialShadingContext implem
                 data[index+2] = (int)(values[2]*255);
             }
         }
-        // create writable raster
-        WritableRaster raster = 
getColorModel().createCompatibleWritableRaster(w, h);
         raster.setPixels(0, 0, w, h, data);
         return raster;
     }
@@ -364,23 +331,12 @@ public class RadialShadingContext implem
          *  The following code calculates the 2 possible values of s
          */
         
-//        float[] srcPoint = new float[] {x, currentPageHeight + maximumHeight 
+ clippingHeight - y };
-      float[] srcPoint = new float[] {x, currentPageHeight - y };
-//        float[] srcPoint = new float[] {x,y};
-        float[] dstPoint = new float[2];
-        transformAT.transform(srcPoint, 0, dstPoint, 0, 1);
-        // -p/2
-        float p = r0*(r1-r0) + (dstPoint[0]-x0)*(x1-x0) + 
(dstPoint[1]-y0)*(y1-y0);
-        p /= -denom;
-        // q
-        float q = (float)(Math.pow(r0,2) - Math.pow((dstPoint[0]-x0),2) 
-Math.pow((dstPoint[1]-y0),2)); 
-        q /= denom;
-        // root
-        float root = (float)Math.sqrt(Math.pow(p , 2) - q);
-        // results
-        if (denom > 0)
-            return new float[]{(p - root), (p + root)};
-        else
-            return new float[]{(p + root), (p - root)};
+        float[] values = new float[2];
+        double p = (-0.25)*((x - coords[0])*x1x0 + (y - coords[1])*y1y0 - 
r1r0) / denom;
+        double q = (Math.pow(x - coords[0],2) + Math.pow(y - coords[1],2) - 
r0pow2) / denom;
+        double root = Math.sqrt(Math.pow(p , 2) - q);
+        values[0] = (float)((-1)*p + root);
+        values[1] = (float)((-1)*p - root);
+        return values;
     }
 }

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingPaint.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingPaint.java?rev=1446893&r1=1446892&r2=1446893&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingPaint.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingPaint.java
 Sat Feb 16 13:18:27 2013
@@ -24,7 +24,6 @@ import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.ColorModel;
 
-import org.apache.pdfbox.pdmodel.common.PDMatrix;
 import org.apache.pdfbox.util.Matrix;
 
 /**
@@ -39,9 +38,7 @@ public class RadialShadingPaint implemen
 
     private PDShadingType3 shading;
     private Matrix currentTransformationMatrix;
-    private Matrix shadingMatrix;
     private int pageHeight;
-    private float clippingHeight;
     
     /**
      * Constructor.
@@ -50,29 +47,13 @@ public class RadialShadingPaint implemen
      * @param ctm current transformation matrix
      * @param pageSizeValue size of the current page
      */
-    public RadialShadingPaint(PDShadingType3 shadingType3, Matrix ctm, int 
pageHeightValue, Matrix shMatrix) 
+    public RadialShadingPaint(PDShadingType3 shadingType3, Matrix ctm, int 
pageHeightValue) 
     {
         shading = shadingType3;
         currentTransformationMatrix = ctm;
         pageHeight = pageHeightValue;
-        shadingMatrix = shMatrix;
     }
     /**
-     * Constructor.
-     * 
-     * @param shadingType3 the shading resources
-     * @param ctm current transformation matrix
-     * @param pageSizeValue size of the current page
-     */
-    public RadialShadingPaint(PDShadingType3 shadingType3, Matrix ctm, int 
pageHeightValue, float clipHeight) 
-    {
-        shading = shadingType3;
-        currentTransformationMatrix = ctm;
-        pageHeight = pageHeightValue;
-        clippingHeight = clipHeight;
-    }
-
-    /**
      * {@inheritDoc}
      */
     public int getTransparency() 
@@ -86,7 +67,7 @@ public class RadialShadingPaint implemen
     public PaintContext createContext(ColorModel cm, Rectangle deviceBounds,
             Rectangle2D userBounds, AffineTransform xform, RenderingHints 
hints) 
     {
-        return new RadialShadingContext(shading, cm, xform, 
currentTransformationMatrix, pageHeight, shadingMatrix, clippingHeight);
+        return new RadialShadingContext(shading, cm, xform, 
currentTransformationMatrix, pageHeight);
     }
 
 }


Reply via email to