You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2008/12/09 16:00:42 UTC

svn commit: r724729 [3/6] - in /xmlgraphics/fop/branches/Temp_AreaTreeNewDesign: ./ conf/ lib/ src/documentation/content/xdocs/ src/documentation/content/xdocs/dev/svg/ src/documentation/content/xdocs/trunk/ src/java/META-INF/services/ src/java/org/apa...

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/pdf/PDFDocument.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/pdf/PDFDocument.java?rev=724729&r1=724728&r2=724729&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/pdf/PDFDocument.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/pdf/PDFDocument.java Tue Dec  9 07:00:35 2008
@@ -29,9 +29,12 @@
 import java.security.NoSuchAlgorithmException;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
@@ -42,7 +45,7 @@
 /* font support based on work by Takayuki Takeuchi */
 
 /**
- * class representing a PDF document.
+ * Class representing a PDF document.
  *
  * The document is built up by calling various methods and then finally
  * output to given filehandle using output method.
@@ -72,53 +75,38 @@
     /** Integer constant to represent PDF 1.4 */
     public static final int PDF_VERSION_1_4 = 4;
 
-    /**
-     * the encoding to use when converting strings to PDF commandos.
-     */
+    /** the encoding to use when converting strings to PDF commands */
     public static final String ENCODING = "ISO-8859-1";
 
+    /** the counter for object numbering */
+    protected int objectcount = 0;
+
+    /** the logger instance */
     private Log log = LogFactory.getLog("org.apache.fop.pdf");
 
-    /**
-     * the current character position
-     */
-    protected int position = 0;
+    /** the current character position */
+    private int position = 0;
 
-    /**
-     * the character position of each object
-     */
-    protected List location = new java.util.ArrayList();
+    /** character position of xref table */
+    private int xref;
 
-    /** List of objects to write in the trailer */
-    private List trailerObjects = new java.util.ArrayList();
+    /** the character position of each object */
+    private List location = new ArrayList();
 
-    /**
-     * the counter for object numbering
-     */
-    protected int objectcount = 0;
-
-    /**
-     * the objects themselves
-     */
-    protected List objects = new java.util.LinkedList();
+    /** List of objects to write in the trailer */
+    private List trailerObjects = new ArrayList();
 
-    /**
-     * character position of xref table
-     */
-    protected int xref;
+    /** the objects themselves */
+    private List objects = new LinkedList();
 
     /** Indicates what PDF version is active */
-    protected int pdfVersion = PDF_VERSION_1_4;
+    private int pdfVersion = PDF_VERSION_1_4;
 
-    /**
-     * Indicates which PDF profiles are active (PDF/A, PDF/X etc.)
-     */
-    protected PDFProfile pdfProfile = new PDFProfile(this);
+    /** Indicates which PDF profiles are active (PDF/A, PDF/X etc.) */
+    private PDFProfile pdfProfile = new PDFProfile(this);
 
-    /**
-     * the /Root object
-     */
-    protected PDFRoot root;
+    /** the /Root object */
+    private PDFRoot root;
 
     /** The root outline object */
     private PDFOutline outlineRoot = null;
@@ -126,107 +114,67 @@
     /** The /Pages object (mark-fop@inomial.com) */
     private PDFPages pages;
 
-    /**
-     * the /Info object
-     */
-    protected PDFInfo info;
+    /** the /Info object */
+    private PDFInfo info;
 
-    /**
-     * the /Resources object
-     */
-    protected PDFResources resources;
+    /** the /Resources object */
+    private PDFResources resources;
 
-    /**
-     * the documents encryption, if exists
-     */
-    protected PDFEncryption encryption;
+    /** the document's encryption, if it exists */
+    private PDFEncryption encryption;
 
-    /**
-     * the colorspace (0=RGB, 1=CMYK)
-     */
-    protected PDFDeviceColorSpace colorspace =
+    /** the colorspace (0=RGB, 1=CMYK) */
+    private PDFDeviceColorSpace colorspace =
         new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
 
-    /**
-     * the counter for Pattern name numbering (e.g. 'Pattern1')
-     */
-    protected int patternCount = 0;
+    /** the counter for Pattern name numbering (e.g. 'Pattern1') */
+    private int patternCount = 0;
 
-    /**
-     * the counter for Shading name numbering
-     */
-    protected int shadingCount = 0;
+    /** the counter for Shading name numbering */
+    private int shadingCount = 0;
 
-    /**
-     * the counter for XObject numbering
-     */
-    protected int xObjectCount = 0;
+    /** the counter for XObject numbering */
+    private int xObjectCount = 0;
 
-    /**
-     * the XObjects Map.
-     * Should be modified (works only for image subtype)
-     */
-    protected Map xObjectsMap = new java.util.HashMap();
+    /** the {@link PDFXObject}s map */
+    /* TODO: Should be modified (works only for image subtype) */
+    private Map xObjectsMap = new HashMap();
 
-    /**
-     * the Font Map.
-     */
-    protected Map fontMap = new java.util.HashMap();
+    /** The {@link PDFFont} map */
+    private Map fontMap = new HashMap();
 
-    /**
-     * The filter map.
-     */
-    protected Map filterMap = new java.util.HashMap();
+    /** The {@link PDFFilter} map */
+    private Map filterMap = new HashMap();
 
-    /**
-     * List of PDFGState objects.
-     */
-    protected List gstates = new java.util.ArrayList();
+    /** List of {@link PDFGState}s. */
+    private List gstates = new ArrayList();
 
-    /**
-     * List of functions.
-     */
-    protected List functions = new java.util.ArrayList();
+    /** List of {@link PDFFunction}s. */
+    private List functions = new ArrayList();
 
-    /**
-     * List of shadings.
-     */
-    protected List shadings = new java.util.ArrayList();
+    /** List of {@link PDFShading}s. */
+    private List shadings = new ArrayList();
 
-    /**
-     * List of patterns.
-     */
-    protected List patterns = new java.util.ArrayList();
+    /** List of {@link PDFPattern}s. */
+    private List patterns = new ArrayList();
 
-    /**
-     * List of Links.
-     */
-    protected List links = new java.util.ArrayList();
+    /** List of {@link PDFLink}s. */
+    private List links = new ArrayList();
 
-    /**
-     * List of Destinations.
-     */
-    protected List destinations;
+    /** List of {@link PDFDestination}s. */
+    private List destinations;
 
-    /**
-     * List of FileSpecs.
-     */
-    protected List filespecs = new java.util.ArrayList();
+    /** List of {@link PDFFileSpec}s. */
+    private List filespecs = new ArrayList();
 
-    /**
-     * List of GoToRemotes.
-     */
-    protected List gotoremotes = new java.util.ArrayList();
+    /** List of {@link PDFGoToRemote}s. */
+    private List gotoremotes = new ArrayList();
 
-    /**
-     * List of GoTos.
-     */
-    protected List gotos = new java.util.ArrayList();
+    /** List of {@link PDFGoTo}s. */
+    private List gotos = new ArrayList();
 
-    /**
-     * List of PDFLaunch objects.
-     */
-    protected List launches = new java.util.ArrayList();
+    /** List of {@link PDFLaunch}es. */
+    private List launches = new ArrayList();
 
     /**
      * The PDFDests object for the name dictionary.
@@ -258,7 +206,7 @@
         this.pages = getFactory().makePages();
 
         // Create the Root object
-        this.root = getFactory().makeRoot(pages);
+        this.root = getFactory().makeRoot(this.pages);
 
         // Create the Resources object
         this.resources = getFactory().makeResources();
@@ -268,7 +216,8 @@
     }
 
     /**
-     * @return the integer representing the active PDF version (one of PDFDocument.PDF_VERSION_*)
+     * @return the integer representing the active PDF version
+     *          (one of PDFDocument.PDF_VERSION_*)
      */
     public int getPDFVersion() {
         return this.pdfVersion;
@@ -293,7 +242,8 @@
 
     /**
      * Returns the factory for PDF objects.
-     * @return PDFFactory the factory
+     *
+     * @return the {@link PDFFactory} object
      */
     public PDFFactory getFactory() {
         return this.factory;
@@ -303,7 +253,8 @@
      * Indicates whether stream encoding on-the-fly is enabled. If enabled
      * stream can be serialized without the need for a buffer to merely
      * calculate the stream length.
-     * @return boolean true if on-the-fly encoding is enabled
+     *
+     * @return <code>true</code> if on-the-fly encoding is enabled
      */
     public boolean isEncodingOnTheFly() {
         return this.encodingOnTheFly;
@@ -311,8 +262,9 @@
 
     /**
      * Converts text to a byte array for writing to a PDF file.
+     *
      * @param text text to convert/encode
-     * @return byte[] the resulting byte array
+     * @return the resulting <code>byte</code> array
      */
     public static byte[] encode(String text) {
         try {
@@ -327,6 +279,7 @@
      * buffered to reduce the number of calls to the encoding converter so don't forget
      * to <code>flush()</code> the Writer after use or before writing directly to the
      * underlying OutputStream.
+     *
      * @param out the OutputStream to write to
      * @return the requested Writer
      */
@@ -339,7 +292,7 @@
     }
 
     /**
-     * set the producer of the document
+     * Sets the producer of the document.
      *
      * @param producer string indicating application producing the PDF
      */
@@ -348,16 +301,16 @@
     }
 
     /**
-      * Set the creation date of the document.
+      * Sets the creation date of the document.
       *
       * @param date Date to be stored as creation date in the PDF.
       */
     public void setCreationDate(Date date) {
-        info.setCreationDate(date);
+        this.info.setCreationDate(date);
     }
 
     /**
-      * Set the creator of the document.
+      * Sets the creator of the document.
       *
       * @param creator string indicating application creating the document
       */
@@ -366,7 +319,7 @@
     }
 
     /**
-     * Set the filter map to use for filters in this document.
+     * Sets the filter map to use for filters in this document.
      *
      * @param map the map of filter lists for each stream type
      */
@@ -375,7 +328,7 @@
     }
 
     /**
-     * Get the filter map used for filters in this document.
+     * Returns the {@link PDFFilter}s map used for filters in this document.
      *
      * @return the map of filters being used
      */
@@ -384,36 +337,38 @@
     }
 
     /**
-     * Returns the PDFPages object associated with the root object.
-     * @return the PDFPages object
+     * Returns the {@link PDFPages} object associated with the root object.
+     *
+     * @return the {@link PDFPages} object
      */
     public PDFPages getPages() {
         return this.pages;
     }
 
     /**
-     * Get the PDF root object.
+     * Get the {@link PDFRoot} object for this document.
      *
-     * @return the PDFRoot object
+     * @return the {@link PDFRoot} object
      */
     public PDFRoot getRoot() {
         return this.root;
     }
 
     /**
-     * Get the pdf info object for this document.
+     * Get the {@link PDFInfo} object for this document.
      *
-     * @return the PDF Info object for this document
+     * @return the {@link PDFInfo} object
      */
     public PDFInfo getInfo() {
-        return info;
+        return this.info;
     }
 
     /**
-     * Registers a PDFObject in this PDF document. The PDF is assigned a new
-     * object number.
-     * @param obj PDFObject to add
-     * @return PDFObject the PDFObject added (its object number set)
+     * Registers a {@link PDFObject} in this PDF document.
+     * The object is assigned a new object number.
+     *
+     * @param obj {@link PDFObject} to add
+     * @return the added {@link PDFObject} added (with its object number set)
      */
     public PDFObject registerObject(PDFObject obj) {
         assignObjectNumber(obj);
@@ -422,9 +377,10 @@
     }
 
     /**
-     * Assigns the PDFObject a object number and sets the parent of the
-     * PDFObject to this PDFDocument.
-     * @param obj PDFObject to assign a number to
+     * Assigns the {@link PDFObject} an object number,
+     * and sets the parent of the {@link PDFObject} to this document.
+     *
+     * @param obj {@link PDFObject} to assign a number to
      */
     public void assignObjectNumber(PDFObject obj) {
         if (obj == null) {
@@ -450,9 +406,10 @@
     }
 
     /**
-     * Adds an PDFObject to this document. The object must have a object number
-     * assigned.
-     * @param obj PDFObject to add
+     * Adds a {@link PDFObject} to this document.
+     * The object <em>MUST</em> have an object number assigned.
+     *
+     * @param obj {@link PDFObject} to add
      */
     public void addObject(PDFObject obj) {
         if (obj == null) {
@@ -521,6 +478,7 @@
 
     /**
      * Apply the encryption filter to a PDFStream if encryption is enabled.
+     *
      * @param stream PDFStream to encrypt
      */
     public void applyEncryption(AbstractPDFStream stream) {
@@ -531,13 +489,14 @@
 
     /**
      * Enables PDF encryption.
+     *
      * @param params The encryption parameters for the pdf file
      */
     public void setEncryption(PDFEncryptionParams params) {
         getProfile().verifyEncryptionAllowed();
         this.encryption = PDFEncryptionManager.newInstance(++this.objectcount, params);
-        if (encryption != null) {
-            PDFObject pdfObject = (PDFObject)encryption;
+        if (this.encryption != null) {
+            PDFObject pdfObject = (PDFObject)this.encryption;
             pdfObject.setDocument(this);
             addTrailerObject(pdfObject);
         } else {
@@ -549,6 +508,7 @@
 
     /**
      * Indicates whether encryption is active for this PDF or not.
+     *
      * @return boolean True if encryption is active
      */
     public boolean isEncryptionActive() {
@@ -557,10 +517,11 @@
 
     /**
      * Returns the active Encryption object.
+     *
      * @return the Encryption object
      */
     public PDFEncryption getEncryption() {
-        return encryption;
+        return this.encryption;
     }
 
     private Object findPDFObject(List list, PDFObject compare) {
@@ -576,21 +537,23 @@
     /**
      * Looks through the registered functions to see if one that is equal to
      * a reference object exists
+     *
      * @param compare reference object
      * @return the function if it was found, null otherwise
      */
     protected PDFFunction findFunction(PDFFunction compare) {
-        return (PDFFunction)findPDFObject(functions, compare);
+        return (PDFFunction)findPDFObject(this.functions, compare);
     }
 
     /**
      * Looks through the registered shadings to see if one that is equal to
      * a reference object exists
+     *
      * @param compare reference object
      * @return the shading if it was found, null otherwise
      */
     protected PDFShading findShading(PDFShading compare) {
-        return (PDFShading)findPDFObject(shadings, compare);
+        return (PDFShading)findPDFObject(this.shadings, compare);
     }
 
     /**
@@ -598,24 +561,27 @@
      * The problem with this is for tiling patterns the pattern
      * data stream is stored and may use up memory, usually this
      * would only be a small amount of data.
+     *
      * @param compare reference object
      * @return the shading if it was found, null otherwise
      */
     protected PDFPattern findPattern(PDFPattern compare) {
-        return (PDFPattern)findPDFObject(patterns, compare);
+        return (PDFPattern)findPDFObject(this.patterns, compare);
     }
 
     /**
      * Finds a font.
+     *
      * @param fontname name of the font
      * @return PDFFont the requested font, null if it wasn't found
      */
     protected PDFFont findFont(String fontname) {
-        return (PDFFont)fontMap.get(fontname);
+        return (PDFFont)this.fontMap.get(fontname);
     }
 
     /**
      * Finds a named destination.
+     *
      * @param compare reference object to use as search template
      * @return the link if found, null otherwise
      */
@@ -630,58 +596,64 @@
 
     /**
      * Finds a link.
+     *
      * @param compare reference object to use as search template
      * @return the link if found, null otherwise
      */
     protected PDFLink findLink(PDFLink compare) {
-        return (PDFLink)findPDFObject(links, compare);
+        return (PDFLink)findPDFObject(this.links, compare);
     }
 
     /**
      * Finds a file spec.
+     *
      * @param compare reference object to use as search template
      * @return the file spec if found, null otherwise
      */
     protected PDFFileSpec findFileSpec(PDFFileSpec compare) {
-        return (PDFFileSpec)findPDFObject(filespecs, compare);
+        return (PDFFileSpec)findPDFObject(this.filespecs, compare);
     }
 
     /**
      * Finds a goto remote.
+     *
      * @param compare reference object to use as search template
      * @return the goto remote if found, null otherwise
      */
     protected PDFGoToRemote findGoToRemote(PDFGoToRemote compare) {
-        return (PDFGoToRemote)findPDFObject(gotoremotes, compare);
+        return (PDFGoToRemote)findPDFObject(this.gotoremotes, compare);
     }
 
     /**
      * Finds a goto.
+     *
      * @param compare reference object to use as search template
      * @return the goto if found, null otherwise
      */
     protected PDFGoTo findGoTo(PDFGoTo compare) {
-        return (PDFGoTo)findPDFObject(gotos, compare);
+        return (PDFGoTo)findPDFObject(this.gotos, compare);
     }
 
     /**
      * Finds a launch.
+     *
      * @param compare reference object to use as search template
      * @return the launch if found, null otherwise
      */
     protected PDFLaunch findLaunch(PDFLaunch compare) {
-        return (PDFLaunch) findPDFObject(launches, compare);
+        return (PDFLaunch) findPDFObject(this.launches, compare);
     }
 
     /**
      * Looks for an existing GState to use
+     *
      * @param wanted requested features
      * @param current currently active features
-     * @return PDFGState the GState if found, null otherwise
+     * @return the GState if found, null otherwise
      */
     protected PDFGState findGState(PDFGState wanted, PDFGState current) {
         PDFGState poss;
-        Iterator iter = gstates.iterator();
+        Iterator iter = this.gstates.iterator();
         while (iter.hasNext()) {
             PDFGState avail = (PDFGState)iter.next();
             poss = new PDFGState();
@@ -695,7 +667,7 @@
     }
 
     /**
-     * Get the PDF color space object.
+     * Returns the PDF color space object.
      *
      * @return the color space
      */
@@ -704,7 +676,7 @@
     }
 
     /**
-     * Get the color space.
+     * Returns the color space.
      *
      * @return the color space
      */
@@ -723,12 +695,12 @@
     }
 
     /**
-     * Get the font map for this document.
+     * Returns the font map for this document.
      *
      * @return the map of fonts used in this document
      */
     public Map getFontMap() {
-        return fontMap;
+        return this.fontMap;
     }
 
     /**
@@ -741,7 +713,7 @@
     protected InputStream resolveURI(String uri)
         throws java.io.FileNotFoundException {
         try {
-            /**@todo Temporary hack to compile, improve later */
+            /* TODO: Temporary hack to compile, improve later */
             return new java.net.URL(uri).openStream();
         } catch (Exception e) {
             throw new java.io.FileNotFoundException(
@@ -757,8 +729,7 @@
      * @deprecated Use getXObject instead (so forms are treated in the same way)
      */
     public PDFImageXObject getImage(String key) {
-        PDFImageXObject xObject = (PDFImageXObject)xObjectsMap.get(key);
-        return xObject;
+        return (PDFImageXObject)this.xObjectsMap.get(key);
     }
 
     /**
@@ -768,8 +739,7 @@
      * @return the PDFXObject for the key if found
      */
     public PDFXObject getXObject(String key) {
-        PDFXObject xObject = (PDFXObject)xObjectsMap.get(key);
-        return xObject;
+        return (PDFXObject)this.xObjectsMap.get(key);
     }
 
     /**
@@ -778,7 +748,7 @@
      * @return the PDFDests object (which represents the /Dests entry).
      */
     public PDFDests getDests() {
-        return dests;
+        return this.dests;
     }
 
     /**
@@ -787,7 +757,7 @@
      */
     public void addDestination(PDFDestination destination) {
         if (this.destinations == null) {
-            this.destinations = new java.util.ArrayList();
+            this.destinations = new ArrayList();
         }
         this.destinations.add(destination);
     }
@@ -799,7 +769,7 @@
      */
     public List getDestinationList() {
         if (hasDestinations()) {
-            return destinations;
+            return this.destinations;
         } else {
             return Collections.EMPTY_LIST;
         }
@@ -818,7 +788,7 @@
      * Add an image to the PDF document.
      * This adds an image to the PDF objects.
      * If an image with the same key already exists it will return the
-     * old PDFXObject.
+     * old {@link PDFXObject}.
      *
      * @param res the PDF resource context to add to, may be null
      * @param img the PDF image to add
@@ -827,7 +797,7 @@
     public PDFImageXObject addImage(PDFResourceContext res, PDFImage img) {
         // check if already created
         String key = img.getKey();
-        PDFImageXObject xObject = (PDFImageXObject)xObjectsMap.get(key);
+        PDFImageXObject xObject = (PDFImageXObject)this.xObjectsMap.get(key);
         if (xObject != null) {
             if (res != null) {
                 res.getPDFResources().addXObject(xObject);
@@ -852,7 +822,7 @@
      * Add a form XObject to the PDF document.
      * This adds a Form XObject to the PDF objects.
      * If a Form XObject with the same key already exists it will return the
-     * old PDFFormXObject.
+     * old {@link PDFFormXObject}.
      *
      * @param res the PDF resource context to add to, may be null
      * @param cont the PDF Stream contents of the Form XObject
@@ -896,19 +866,19 @@
      * @return the PDF Outline root object
      */
     public PDFOutline getOutlineRoot() {
-        if (outlineRoot != null) {
-            return outlineRoot;
+        if (this.outlineRoot != null) {
+            return this.outlineRoot;
         }
 
-        outlineRoot = new PDFOutline(null, null, true);
-        assignObjectNumber(outlineRoot);
-        addTrailerObject(outlineRoot);
-        root.setRootOutline(outlineRoot);
-        return outlineRoot;
+        this.outlineRoot = new PDFOutline(null, null, true);
+        assignObjectNumber(this.outlineRoot);
+        addTrailerObject(this.outlineRoot);
+        this.root.setRootOutline(this.outlineRoot);
+        return this.outlineRoot;
     }
 
     /**
-     * get the /Resources object for the document
+     * Get the /Resources object for the document
      *
      * @return the /Resources object
      */
@@ -919,16 +889,18 @@
     /**
      * Ensure there is room in the locations xref for the number of
      * objects that have been created.
+     * @param objidx    the object's index
+     * @param position  the position
      */
     private void setLocation(int objidx, int position) {
-        while (location.size() <= objidx) {
-            location.add(LOCATION_PLACEHOLDER);
+        while (this.location.size() <= objidx) {
+            this.location.add(LOCATION_PLACEHOLDER);
         }
-        location.set(objidx, new Integer(position));
+        this.location.set(objidx, new Integer(position));
     }
 
     /**
-     * write the entire document out
+     * Writes out the entire document
      *
      * @param stream the OutputStream to output the document to
      * @throws IOException if there is an exception writing to the output stream
@@ -1009,23 +981,23 @@
     }
 
     /**
-     * write the trailer
+     * Write the trailer
      *
      * @param stream the OutputStream to write the trailer to
      * @throws IOException if there is an exception writing to the output stream
      */
     public void outputTrailer(OutputStream stream) throws IOException {
         if (hasDestinations()) {
-            Collections.sort(destinations, new DestinationComparator());
-            dests = getFactory().makeDests(destinations);
+            Collections.sort(this.destinations, new DestinationComparator());
+            this.dests = getFactory().makeDests(this.destinations);
             if (this.root.getNames() == null) {
                 this.root.setNames(getFactory().makeNames());
             }
             this.root.getNames().setDests(dests);
         }
         output(stream);
-        for (int count = 0; count < trailerObjects.size(); count++) {
-            PDFObject o = (PDFObject)trailerObjects.get(count);
+        for (int count = 0; count < this.trailerObjects.size(); count++) {
+            PDFObject o = (PDFObject)this.trailerObjects.get(count);
             this.location.set(
                 o.getObjectNumber() - 1,
                 new Integer(this.position));
@@ -1036,39 +1008,36 @@
         this.position += outputXref(stream);
 
         /* construct the trailer */
-        String pdf =
-            "trailer\n"
-                + "<<\n"
-                + "/Size "
-                + (this.objectcount + 1)
-                + "\n"
-                + "/Root "
-                + this.root.referencePDF()
-                + "\n"
-                + "/Info "
-                + this.info.referencePDF()
-                + "\n";
-        if (this.encryption != null) {
-            pdf += this.encryption.getTrailerEntry();
+        StringBuffer pdf = new StringBuffer(128);
+        pdf.append("trailer\n<<\n/Size ")
+                .append(this.objectcount + 1)
+                .append("\n/Root ")
+                .append(this.root.referencePDF())
+                .append("\n/Info ")
+                .append(this.info.referencePDF())
+                .append('\n');
+
+        if (this.isEncryptionActive()) {
+            pdf.append(this.encryption.getTrailerEntry());
         } else {
-            pdf += getIDEntry();
+            pdf.append(this.getIDEntry());
         }
-            pdf += "\n"
-                + ">>\n"
-                + "startxref\n"
-                + this.xref
-                + "\n"
-                + "%%EOF\n";
+
+        pdf.append("\n>>\nstartxref\n")
+                .append(this.xref)
+                .append("\n%%EOF\n");
 
         /* write the trailer */
-        stream.write(encode(pdf));
+        stream.write(encode(pdf.toString()));
     }
 
     /**
-     * write the xref table
+     * Write the xref table
      *
      * @param stream the OutputStream to write the xref table to
      * @return the number of characters written
+     * @throws IOException in case of an error writing the result to
+     *          the parameter stream
      */
     private int outputXref(OutputStream stream) throws IOException {
 
@@ -1077,18 +1046,20 @@
 
         /* construct initial part of xref */
         StringBuffer pdf = new StringBuffer(128);
-        pdf.append(
-            "xref\n0 " + (this.objectcount + 1) + "\n0000000000 65535 f \n");
+        pdf.append("xref\n0 ");
+        pdf.append(this.objectcount + 1);
+        pdf.append("\n0000000000 65535 f \n");
 
+        String s, loc;
         for (int count = 0; count < this.location.size(); count++) {
-            String x = this.location.get(count).toString();
+            final String padding = "0000000000";
+            s = this.location.get(count).toString();
 
             /* contruct xref entry for object */
-            String padding = "0000000000";
-            String loc = padding.substring(x.length()) + x;
+            loc = padding.substring(s.length()) + s;
 
             /* append to xref table */
-            pdf = pdf.append(loc + " 00000 n \n");
+            pdf = pdf.append(loc).append(" 00000 n \n");
         }
 
         /* write the xref table and return the character length */

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/pdf/package.html
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/pdf/package.html?rev=724729&r1=724728&r2=724729&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/pdf/package.html (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/pdf/package.html Tue Dec  9 07:00:35 2008
@@ -1,3 +1,20 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!-- $Id: package.html 643433 2008-04-01 15:08:24Z acumiskey $ -->
 <HTML>
 <TITLE>org.apache.fop.pdf Package</TITLE>
 <BODY>

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractGenericSVGHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractGenericSVGHandler.java?rev=724729&r1=724728&r2=724729&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractGenericSVGHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractGenericSVGHandler.java Tue Dec  9 07:00:35 2008
@@ -21,9 +21,7 @@
 
 // Java
 import java.awt.Dimension;
-import java.awt.Graphics2D;
 import java.awt.geom.AffineTransform;
-import java.awt.geom.Rectangle2D;
 import java.io.IOException;
 
 import org.w3c.dom.Document;
@@ -37,7 +35,11 @@
 import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
 import org.apache.xmlgraphics.util.QName;
 
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.events.EventBroadcaster;
 import org.apache.fop.fo.extensions.ExtensionElementMapping;
+import org.apache.fop.image.loader.batik.BatikUtil;
+import org.apache.fop.image.loader.batik.Graphics2DImagePainterImpl;
 import org.apache.fop.render.RendererContext.RendererContextWrapper;
 import org.apache.fop.svg.SVGEventProducer;
 import org.apache.fop.svg.SVGUserAgent;
@@ -54,6 +56,9 @@
     protected static final QName CONVERSION_MODE = new QName(
             ExtensionElementMapping.URI, null, "conversion-mode");
 
+    /** "bitmap" value for the "conversion-mode" extension attribute. */
+    protected static final String BITMAP = "bitmap";
+
     /** {@inheritDoc} */
     public void handleXML(RendererContext context,
                 Document doc, String ns) throws Exception {
@@ -64,65 +69,101 @@
     }
 
     /**
-     * Render the SVG document.
-     * @param context the renderer context
-     * @param doc the SVG document
-     * @throws IOException In case of an I/O error while painting the image
+     * Creates a graphics 2D image painter implementation
+     *
+     * @param root the batik graphics node root
+     * @param ctx the batik bridge context
+     * @param imageSize the image size
+     * @return a new graphics 2D image painter implementation
      */
-    protected void renderSVGDocument(final RendererContext context,
-            final Document doc) throws IOException {
-        updateRendererContext(context);
-        final RendererContextWrapper wrappedContext = RendererContext.wrapRendererContext(context);
-        int x = wrappedContext.getCurrentXPosition();
-        int y = wrappedContext.getCurrentYPosition();
+    protected Graphics2DImagePainter createGraphics2DImagePainter(
+            GraphicsNode root, BridgeContext ctx, Dimension imageSize) {
+        return new Graphics2DImagePainterImpl(root, ctx, imageSize);
+    }
 
-        //Prepare
-        SVGUserAgent ua = new SVGUserAgent(
-                context.getUserAgent(),
-                new AffineTransform());
+    /**
+     * Builds the GVT root
+     *
+     * @param rendererContext the renderer context
+     * @param ctx the batik bridge context
+     * @param doc the document
+     * @return a built GVT root tree
+     */
+    protected GraphicsNode buildGraphicsNode(
+            FOUserAgent userAgent, BridgeContext ctx, Document doc) {
         GVTBuilder builder = new GVTBuilder();
-        final BridgeContext ctx = new BridgeContext(ua);
-
-        //Build the GVT tree
         final GraphicsNode root;
         try {
             root = builder.build(ctx, doc);
         } catch (Exception e) {
-            SVGEventProducer eventProducer = SVGEventProducer.Provider.get(
-                    context.getUserAgent().getEventBroadcaster());
-            eventProducer.svgNotBuilt(this, e, getDocumentURI(doc));
-            return;
+            EventBroadcaster eventBroadcaster
+                = userAgent.getEventBroadcaster();
+            SVGEventProducer eventProducer = SVGEventProducer.Provider.get(eventBroadcaster);
+            final String uri = getDocumentURI(doc);
+            eventProducer.svgNotBuilt(this, e, uri);
+            return null;
         }
+        return root;
+    }
 
-        //Create the painter
-        Graphics2DImagePainter painter = new Graphics2DImagePainter() {
+    /**
+     * Returns the image size
+     * @param wrappedContext renderer context wrapper
+     *
+     * @return the image size
+     */
+    protected Dimension getImageSize(RendererContextWrapper wrappedContext) {
+        final int width = wrappedContext.getWidth();
+        final int height = wrappedContext.getHeight();
+        return new Dimension(width, height);
+    }
+
+    /**
+     * Render the SVG document.
+     *
+     * @param rendererContext the renderer context
+     * @param doc the SVG document
+     * @throws IOException In case of an I/O error while painting the image
+     */
+    protected void renderSVGDocument(final RendererContext rendererContext,
+            final Document doc) throws IOException {
+        updateRendererContext(rendererContext);
+
+        //Prepare
+        FOUserAgent userAgent = rendererContext.getUserAgent();
+        SVGUserAgent svgUserAgent = new SVGUserAgent(userAgent, new AffineTransform());
 
-            public void paint(Graphics2D g2d, Rectangle2D area) {
-                // If no viewbox is defined in the svg file, a viewbox of 100x100 is
-                // assumed, as defined in SVGUserAgent.getViewportSize()
-                float iw = (float) ctx.getDocumentSize().getWidth();
-                float ih = (float) ctx.getDocumentSize().getHeight();
-                float w = (float) area.getWidth();
-                float h = (float) area.getHeight();
-                g2d.scale(w / iw, h / ih);
-
-                root.paint(g2d);
-            }
-
-            public Dimension getImageSize() {
-                return new Dimension(wrappedContext.getWidth(), wrappedContext.getHeight());
-            }
+        //Create Batik BridgeContext
+        final BridgeContext bridgeContext = new BridgeContext(svgUserAgent);
 
-        };
+        //Cloning SVG DOM as Batik attaches non-thread-safe facilities (like the CSS engine)
+        //to it.
+        Document clonedDoc = BatikUtil.cloneSVGDocument(doc);
+
+        //Build the GVT tree
+        final GraphicsNode root = buildGraphicsNode(userAgent, bridgeContext, clonedDoc);
+
+        // Create Graphics2DImagePainter
+        final RendererContextWrapper wrappedContext = RendererContext.wrapRendererContext(
+                rendererContext);
+        Dimension imageSize = getImageSize(wrappedContext);
+        final Graphics2DImagePainter painter = createGraphics2DImagePainter(
+                root, bridgeContext, imageSize);
 
         //Let the painter paint the SVG on the Graphics2D instance
-        Graphics2DAdapter adapter = context.getRenderer().getGraphics2DAdapter();
-        adapter.paintImage(painter, context,
-                x, y, wrappedContext.getWidth(), wrappedContext.getHeight());
+        Graphics2DAdapter g2dAdapter = rendererContext.getRenderer().getGraphics2DAdapter();
+
+        //Paint the image
+        final int x = wrappedContext.getCurrentXPosition();
+        final int y = wrappedContext.getCurrentYPosition();
+        final int width = wrappedContext.getWidth();
+        final int height = wrappedContext.getHeight();
+        g2dAdapter.paintImage(painter, rendererContext, x, y, width, height);
     }
 
     /**
      * Gets the document URI from a Document instance if possible.
+     *
      * @param doc the Document
      * @return the URI or null
      */
@@ -138,6 +179,7 @@
     /**
      * Override this method to update the renderer context if it needs special settings for
      * certain conditions.
+     *
      * @param context the renderer context
      */
     protected void updateRendererContext(RendererContext context) {

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java?rev=724729&r1=724728&r2=724729&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java Tue Dec  9 07:00:35 2008
@@ -54,8 +54,8 @@
     protected BufferedImage paintToBufferedImage(
             org.apache.xmlgraphics.java2d.Graphics2DImagePainter painter,
              RendererContextWrapper context, int resolution, boolean gray, boolean withAlpha) {
-        int bmw = (int)Math.ceil(UnitConv.mpt2px(context.getWidth(), resolution));
-        int bmh = (int)Math.ceil(UnitConv.mpt2px(context.getHeight(), resolution));
+        int bmw = mpt2px(context.getWidth(), resolution);
+        int bmh = mpt2px(context.getHeight(), resolution);
         BufferedImage bi;
         if (gray) {
             if (withAlpha) {
@@ -102,6 +102,17 @@
         return bi;
     }
 
+    /**
+     * Converts millipoints to pixels
+     *
+     * @param unit the unit to convert in mpts
+     * @param resolution the target resolution
+     * @return the converted unit in pixels
+     */
+    protected int mpt2px(int unit, int resolution) {
+        return (int)Math.ceil(UnitConv.mpt2px(unit, resolution));
+    }
+
     private static BufferedImage createGrayBufferedImageWithAlpha(int width, int height) {
         BufferedImage bi;
         boolean alphaPremultiplied = true;

Copied: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractImageHandlerRegistry.java (from r724689, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractImageHandlerRegistry.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractImageHandlerRegistry.java?p2=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractImageHandlerRegistry.java&p1=xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractImageHandlerRegistry.java&r1=724689&r2=724729&rev=724729&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractImageHandlerRegistry.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractImageHandlerRegistry.java Tue Dec  9 07:00:35 2008
@@ -27,6 +27,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.apache.xmlgraphics.image.loader.Image;
 import org.apache.xmlgraphics.image.loader.ImageFlavor;
 import org.apache.xmlgraphics.util.Service;
@@ -43,8 +44,8 @@
 
     private static final Comparator HANDLER_COMPARATOR = new Comparator() {
         public int compare(Object o1, Object o2) {
-            ImageHandler h1 = (ImageHandler)o1;
-            ImageHandler h2 = (ImageHandler)o2;
+            ImageHandlerBase h1 = (ImageHandlerBase)o1;
+            ImageHandlerBase h2 = (ImageHandlerBase)o2;
             return h1.getPriority() - h2.getPriority();
         }
     };
@@ -76,8 +77,8 @@
      */
     public void addHandler(String classname) {
         try {
-            ImageHandler handlerInstance
-                = (ImageHandler)Class.forName(classname).newInstance();
+            ImageHandlerBase handlerInstance
+                = (ImageHandlerBase)Class.forName(classname).newInstance();
             addHandler(handlerInstance);
         } catch (ClassNotFoundException e) {
             throw new IllegalArgumentException("Could not find "
@@ -99,13 +100,13 @@
      * Add an image handler. The handler itself is inspected to find out what it supports.
      * @param handler the ImageHandler instance
      */
-    public synchronized void addHandler(ImageHandler handler) {
+    public synchronized void addHandler(ImageHandlerBase handler) {
         this.handlers.put(handler.getSupportedImageClass(), handler);
 
         //Sorted insert
         ListIterator iter = this.handlerList.listIterator();
         while (iter.hasNext()) {
-            ImageHandler h = (ImageHandler)iter.next();
+            ImageHandlerBase h = (ImageHandlerBase)iter.next();
             if (getHandlerComparator().compare(handler, h) < 0) {
                 iter.previous();
                 break;
@@ -121,7 +122,7 @@
      * @param img the Image to be handled
      * @return the ImageHandler responsible for handling the image or null if none is available
      */
-    public ImageHandler getHandler(Image img) {
+    public ImageHandlerBase getHandler(Image img) {
         return getHandler(img.getClass());
     }
 
@@ -131,11 +132,11 @@
      * @param imageClass the Image subclass for which to get a handler
      * @return the ImageHandler responsible for handling the image or null if none is available
      */
-    public synchronized ImageHandler getHandler(Class imageClass) {
-        ImageHandler handler = null;
+    public synchronized ImageHandlerBase getHandler(Class imageClass) {
+        ImageHandlerBase handler = null;
         Class cl = imageClass;
         while (cl != null) {
-            handler = (ImageHandler)handlers.get(cl);
+            handler = (ImageHandlerBase)handlers.get(cl);
             if (handler != null) {
                 break;
             }
@@ -154,7 +155,7 @@
             List flavors = new java.util.ArrayList();
             Iterator iter = this.handlerList.iterator();
             while (iter.hasNext()) {
-                ImageFlavor[] f = ((ImageHandler)iter.next()).getSupportedImageFlavors();
+                ImageFlavor[] f = ((ImageHandlerBase)iter.next()).getSupportedImageFlavors();
                 for (int i = 0; i < f.length; i++) {
                     flavors.add(f[i]);
                 }
@@ -175,7 +176,7 @@
         Iterator providers = Service.providers(imageHandlerClass);
         if (providers != null) {
             while (providers.hasNext()) {
-                ImageHandler handler = (ImageHandler)providers.next();
+                ImageHandlerBase handler = (ImageHandlerBase)providers.next();
                 try {
                     if (log.isDebugEnabled()) {
                         log.debug("Dynamically adding ImageHandler: "

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java?rev=724729&r1=724728&r2=724729&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java Tue Dec  9 07:00:35 2008
@@ -26,13 +26,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.w3c.dom.Document;
-
 import org.apache.batik.parser.AWTTransformProducer;
-
-import org.apache.xmlgraphics.image.loader.ImageSize;
-import org.apache.xmlgraphics.util.QName;
-
 import org.apache.fop.area.Area;
 import org.apache.fop.area.Block;
 import org.apache.fop.area.BlockViewport;
@@ -48,7 +42,10 @@
 import org.apache.fop.fo.extensions.ExtensionElementMapping;
 import org.apache.fop.fonts.FontMetrics;
 import org.apache.fop.traits.BorderProps;
+import org.apache.xmlgraphics.image.loader.ImageSize;
+import org.apache.xmlgraphics.util.QName;
 import org.apache.xmlgraphics.util.UnitConv;
+import org.w3c.dom.Document;
 
 /**
  * Abstract base class for renderers like PDF and PostScript where many painting operations
@@ -270,6 +267,11 @@
         drawBorders(borderRect, bpsBefore, bpsAfter, bpsStart, bpsEnd);
     }
 
+    private static final int BEFORE = 0;
+    private static final int END = 1;
+    private static final int AFTER = 2;
+    private static final int START = 3;
+
     /**
      * Draws borders.
      * @param borderRect the border rectangle
@@ -280,45 +282,46 @@
      */
     protected void drawBorders(Rectangle2D.Float borderRect,
             BorderProps bpsBefore, BorderProps bpsAfter, BorderProps bpsStart, BorderProps bpsEnd) {
+        //TODO generalize each of the four conditions into using a parameterized drawBorder()
+        boolean[] border = new boolean[] {
+                (bpsBefore != null), (bpsEnd != null),
+                (bpsAfter != null), (bpsStart != null)};
         float startx = borderRect.x;
         float starty = borderRect.y;
         float width = borderRect.width;
         float height = borderRect.height;
-        boolean[] b = new boolean[] {
-            (bpsBefore != null), (bpsEnd != null),
-            (bpsAfter != null), (bpsStart != null)};
-        if (!b[0] && !b[1] && !b[2] && !b[3]) {
-            return;
-        }
-        float[] bw = new float[] {
-            (b[0] ? bpsBefore.width / 1000f : 0.0f),
-            (b[1] ? bpsEnd.width / 1000f : 0.0f),
-            (b[2] ? bpsAfter.width / 1000f : 0.0f),
-            (b[3] ? bpsStart.width / 1000f : 0.0f)};
+        float[] borderWidth = new float[] {
+            (border[BEFORE] ? bpsBefore.width / 1000f : 0.0f),
+            (border[END] ? bpsEnd.width / 1000f : 0.0f),
+            (border[AFTER] ? bpsAfter.width / 1000f : 0.0f),
+            (border[START] ? bpsStart.width / 1000f : 0.0f)};
         float[] clipw = new float[] {
             BorderProps.getClippedWidth(bpsBefore) / 1000f,
             BorderProps.getClippedWidth(bpsEnd) / 1000f,
             BorderProps.getClippedWidth(bpsAfter) / 1000f,
             BorderProps.getClippedWidth(bpsStart) / 1000f};
-        starty += clipw[0];
-        height -= clipw[0];
-        height -= clipw[2];
-        startx += clipw[3];
-        width -= clipw[3];
-        width -= clipw[1];
+        starty += clipw[BEFORE];
+        height -= clipw[BEFORE];
+        height -= clipw[AFTER];
+        startx += clipw[START];
+        width -= clipw[START];
+        width -= clipw[END];
 
         boolean[] slant = new boolean[] {
-            (b[3] && b[0]), (b[0] && b[1]), (b[1] && b[2]), (b[2] && b[3])};
+            (border[START] && border[BEFORE]),
+            (border[BEFORE] && border[END]),
+            (border[END] && border[AFTER]),
+            (border[AFTER] && border[START])};
         if (bpsBefore != null) {
             endTextObject();
 
             float sx1 = startx;
-            float sx2 = (slant[0] ? sx1 + bw[3] - clipw[3] : sx1);
+            float sx2 = (slant[BEFORE] ? sx1 + borderWidth[START] - clipw[START] : sx1);
             float ex1 = startx + width;
-            float ex2 = (slant[1] ? ex1 - bw[1] + clipw[1] : ex1);
-            float outery = starty - clipw[0];
-            float clipy = outery + clipw[0];
-            float innery = outery + bw[0];
+            float ex2 = (slant[END] ? ex1 - borderWidth[END] + clipw[END] : ex1);
+            float outery = starty - clipw[BEFORE];
+            float clipy = outery + clipw[BEFORE];
+            float innery = outery + borderWidth[BEFORE];
 
             saveGraphicsState();
             moveTo(sx1, clipy);
@@ -326,10 +329,10 @@
             float ex1a = ex1;
             if (bpsBefore.mode == BorderProps.COLLAPSE_OUTER) {
                 if (bpsStart != null && bpsStart.mode == BorderProps.COLLAPSE_OUTER) {
-                    sx1a -= clipw[3];
+                    sx1a -= clipw[START];
                 }
                 if (bpsEnd != null && bpsEnd.mode == BorderProps.COLLAPSE_OUTER) {
-                    ex1a += clipw[1];
+                    ex1a += clipw[END];
                 }
                 lineTo(sx1a, outery);
                 lineTo(ex1a, outery);
@@ -347,12 +350,12 @@
             endTextObject();
 
             float sy1 = starty;
-            float sy2 = (slant[1] ? sy1 + bw[0] - clipw[0] : sy1);
+            float sy2 = (slant[END] ? sy1 + borderWidth[BEFORE] - clipw[BEFORE] : sy1);
             float ey1 = starty + height;
-            float ey2 = (slant[2] ? ey1 - bw[2] + clipw[2] : ey1);
-            float outerx = startx + width + clipw[1];
-            float clipx = outerx - clipw[1];
-            float innerx = outerx - bw[1];
+            float ey2 = (slant[AFTER] ? ey1 - borderWidth[AFTER] + clipw[AFTER] : ey1);
+            float outerx = startx + width + clipw[END];
+            float clipx = outerx - clipw[END];
+            float innerx = outerx - borderWidth[END];
 
             saveGraphicsState();
             moveTo(clipx, sy1);
@@ -360,10 +363,10 @@
             float ey1a = ey1;
             if (bpsEnd.mode == BorderProps.COLLAPSE_OUTER) {
                 if (bpsBefore != null && bpsBefore.mode == BorderProps.COLLAPSE_OUTER) {
-                    sy1a -= clipw[0];
+                    sy1a -= clipw[BEFORE];
                 }
                 if (bpsAfter != null && bpsAfter.mode == BorderProps.COLLAPSE_OUTER) {
-                    ey1a += clipw[2];
+                    ey1a += clipw[AFTER];
                 }
                 lineTo(outerx, sy1a);
                 lineTo(outerx, ey1a);
@@ -380,12 +383,12 @@
             endTextObject();
 
             float sx1 = startx;
-            float sx2 = (slant[3] ? sx1 + bw[3] - clipw[3] : sx1);
+            float sx2 = (slant[START] ? sx1 + borderWidth[AFTER] - clipw[AFTER] : sx1);
             float ex1 = startx + width;
-            float ex2 = (slant[2] ? ex1 - bw[1] + clipw[1] : ex1);
-            float outery = starty + height + clipw[2];
-            float clipy = outery - clipw[2];
-            float innery = outery - bw[2];
+            float ex2 = (slant[AFTER] ? ex1 - borderWidth[END] + clipw[END] : ex1);
+            float outery = starty + height + clipw[AFTER];
+            float clipy = outery - clipw[AFTER];
+            float innery = outery - borderWidth[AFTER];
 
             saveGraphicsState();
             moveTo(ex1, clipy);
@@ -393,10 +396,10 @@
             float ex1a = ex1;
             if (bpsAfter.mode == BorderProps.COLLAPSE_OUTER) {
                 if (bpsStart != null && bpsStart.mode == BorderProps.COLLAPSE_OUTER) {
-                    sx1a -= clipw[3];
+                    sx1a -= clipw[START];
                 }
                 if (bpsEnd != null && bpsEnd.mode == BorderProps.COLLAPSE_OUTER) {
-                    ex1a += clipw[1];
+                    ex1a += clipw[END];
                 }
                 lineTo(ex1a, outery);
                 lineTo(sx1a, outery);
@@ -413,12 +416,12 @@
             endTextObject();
 
             float sy1 = starty;
-            float sy2 = (slant[0] ? sy1 + bw[0] - clipw[0] : sy1);
+            float sy2 = (slant[BEFORE] ? sy1 + borderWidth[BEFORE] - clipw[BEFORE] : sy1);
             float ey1 = sy1 + height;
-            float ey2 = (slant[3] ? ey1 - bw[2] + clipw[2] : ey1);
-            float outerx = startx - clipw[3];
-            float clipx = outerx + clipw[3];
-            float innerx = outerx + bw[3];
+            float ey2 = (slant[START] ? ey1 - borderWidth[AFTER] + clipw[AFTER] : ey1);
+            float outerx = startx - clipw[START];
+            float clipx = outerx + clipw[START];
+            float innerx = outerx + borderWidth[START];
 
             saveGraphicsState();
             moveTo(clipx, ey1);
@@ -426,10 +429,10 @@
             float ey1a = ey1;
             if (bpsStart.mode == BorderProps.COLLAPSE_OUTER) {
                 if (bpsBefore != null && bpsBefore.mode == BorderProps.COLLAPSE_OUTER) {
-                    sy1a -= clipw[0];
+                    sy1a -= clipw[BEFORE];
                 }
                 if (bpsAfter != null && bpsAfter.mode == BorderProps.COLLAPSE_OUTER) {
-                    ey1a += clipw[2];
+                    ey1a += clipw[AFTER];
                 }
                 lineTo(outerx, ey1a);
                 lineTo(outerx, sy1a);
@@ -451,10 +454,6 @@
      * rendered
      */
     protected void renderInlineAreaBackAndBorders(InlineArea area) {
-        float x = currentIPPosition / 1000f;
-        float y = (currentBPPosition + area.getOffset()) / 1000f;
-        float width = area.getIPD() / 1000f;
-        float height = area.getBPD() / 1000f;
         float borderPaddingStart = area.getBorderAndPaddingWidthStart() / 1000f;
         float borderPaddingBefore = area.getBorderAndPaddingWidthBefore() / 1000f;
         float bpwidth = borderPaddingStart
@@ -462,12 +461,15 @@
         float bpheight = borderPaddingBefore
                 + (area.getBorderAndPaddingWidthAfter() / 1000f);
 
+        float height = area.getBPD() / 1000f;
         if (height != 0.0f || bpheight != 0.0f && bpwidth != 0.0f) {
+            float x = currentIPPosition / 1000f;
+            float y = (currentBPPosition + area.getOffset()) / 1000f;
+            float width = area.getIPD() / 1000f;
             drawBackAndBorders(area, x, y - borderPaddingBefore
                                 , width + bpwidth
                                 , height + bpheight);
         }
-
     }
 
     /** Constant for the fox:transform extension attribute */
@@ -483,26 +485,24 @@
         int saveBP = currentBPPosition;
 
         CTM ctm = bv.getCTM();
-        int borderPaddingStart = bv.getBorderAndPaddingWidthStart();
         int borderPaddingBefore = bv.getBorderAndPaddingWidthBefore();
-        //This is the content-rect
-        float width = bv.getIPD() / 1000f;
-        float height = bv.getBPD() / 1000f;
 
-        if (bv.getPositioning() == Block.ABSOLUTE
-                || bv.getPositioning() == Block.FIXED) {
+        int positioning = bv.getPositioning();
+        if (positioning == Block.ABSOLUTE || positioning == Block.FIXED) {
 
             //For FIXED, we need to break out of the current viewports to the
             //one established by the page. We save the state stack for restoration
             //after the block-container has been painted. See below.
             List breakOutList = null;
-            if (bv.getPositioning() == Block.FIXED) {
+            if (positioning == Block.FIXED) {
                 breakOutList = breakOutOfStateStack();
             }
 
             AffineTransform positionTransform = new AffineTransform();
             positionTransform.translate(bv.getXOffset(), bv.getYOffset());
 
+            int borderPaddingStart = bv.getBorderAndPaddingWidthStart();
+
             //"left/"top" (bv.getX/YOffset()) specify the position of the content rectangle
             positionTransform.translate(-borderPaddingStart, -borderPaddingBefore);
 
@@ -514,39 +514,62 @@
                 positionTransform.concatenate(freeTransform);
             }
 
-            saveGraphicsState();
             //Viewport position
-            concatenateTransformationMatrix(UnitConv.mptToPt(positionTransform));
+            if (!positionTransform.isIdentity()) {
+                establishTransformationMatrix(positionTransform);
+            }
+
+            //This is the content-rect
+            float width = bv.getIPD() / 1000f;
+            float height = bv.getBPD() / 1000f;
 
             //Background and borders
-            float bpwidth = (borderPaddingStart + bv.getBorderAndPaddingWidthEnd()) / 1000f;
-            float bpheight = (borderPaddingBefore + bv.getBorderAndPaddingWidthAfter()) / 1000f;
-            drawBackAndBorders(bv, 0, 0, width + bpwidth, height + bpheight);
+            float borderPaddingWidth
+                = (borderPaddingStart + bv.getBorderAndPaddingWidthEnd()) / 1000f;
+            float borderPaddingHeight
+                = (borderPaddingBefore + bv.getBorderAndPaddingWidthAfter()) / 1000f;
+            drawBackAndBorders(bv, 0, 0, width + borderPaddingWidth, height + borderPaddingHeight);
 
             //Shift to content rectangle after border painting
             AffineTransform contentRectTransform = new AffineTransform();
             contentRectTransform.translate(borderPaddingStart, borderPaddingBefore);
-            concatenateTransformationMatrix(UnitConv.mptToPt(contentRectTransform));
+
+            if (!contentRectTransform.isIdentity()) {
+                establishTransformationMatrix(contentRectTransform);
+            }
 
             //Clipping
             if (bv.getClip()) {
                 clipRect(0f, 0f, width, height);
             }
 
-            saveGraphicsState();
             //Set up coordinate system for content rectangle
             AffineTransform contentTransform = ctm.toAffineTransform();
-            concatenateTransformationMatrix(UnitConv.mptToPt(contentTransform));
+            if (!contentTransform.isIdentity()) {
+                establishTransformationMatrix(contentTransform);
+            }
 
             currentIPPosition = 0;
             currentBPPosition = 0;
             renderBlocks(bv, children);
 
-            restoreGraphicsState();
-            restoreGraphicsState();
+            if (!contentTransform.isIdentity()) {
+                restoreGraphicsState();
+            }
+
+            if (!contentRectTransform.isIdentity()) {
+                restoreGraphicsState();
+            }
+
+            if (!positionTransform.isIdentity()) {
+                restoreGraphicsState();
+            }
 
-            if (breakOutList != null) {
-                restoreStateStackAfterBreakOut(breakOutList);
+            //For FIXED, we need to restore break out now we are done
+            if (positioning == Block.FIXED) {
+                if (breakOutList != null) {
+                    restoreStateStackAfterBreakOut(breakOutList);
+                }
             }
 
             currentIPPosition = saveIP;
@@ -599,8 +622,7 @@
         at.translate(0, block.getSpaceBefore());
 
         if (!at.isIdentity()) {
-            saveGraphicsState();
-            concatenateTransformationMatrix(UnitConv.mptToPt(at));
+            establishTransformationMatrix(at);
         }
 
         currentIPPosition = 0;
@@ -632,8 +654,7 @@
         at.translate(currentIPPosition, currentBPPosition);
 
         if (!at.isIdentity()) {
-            saveGraphicsState();
-            concatenateTransformationMatrix(UnitConv.mptToPt(at));
+            establishTransformationMatrix(at);
         }
 
         currentIPPosition = 0;
@@ -845,4 +866,16 @@
         renderDocument(doc, ns, pos, fo.getForeignAttributes());
     }
 
+    /**
+     * Establishes a new coordinate system with the given transformation matrix.
+     * The current graphics state is saved and the new coordinate system is concatenated.
+     * @param block
+     *
+     * @param at the transformation matrix
+     */
+    protected void establishTransformationMatrix(AffineTransform at) {
+        saveGraphicsState();
+        concatenateTransformationMatrix(UnitConv.mptToPt(at));
+    }
+
 }

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractRenderer.java?rev=724729&r1=724728&r2=724729&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractRenderer.java Tue Dec  9 07:00:35 2008
@@ -29,11 +29,8 @@
 import java.util.List;
 import java.util.Set;
 
-import org.w3c.dom.Document;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.area.Area;
@@ -69,6 +66,7 @@
 import org.apache.fop.events.ResourceEventProducer;
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fonts.FontInfo;
+import org.w3c.dom.Document;
 
 /**
  * Abstract base class for all renderers. The Abstract renderer does all the
@@ -505,7 +503,7 @@
      */
     protected void renderBlocks(Block parent, List blocks) {
         int saveIP = currentIPPosition;
-        int saveBP = currentBPPosition;
+//        int saveBP = currentBPPosition;
 
         // Calculate the position of the content rectangle.
         if (parent != null && !parent.getTraitAsBoolean(Trait.IS_VIEWPORT_AREA)) {

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandler.java?rev=724729&r1=724728&r2=724729&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandler.java Tue Dec  9 07:00:35 2008
@@ -23,26 +23,11 @@
 import java.io.IOException;
 
 import org.apache.xmlgraphics.image.loader.Image;
-import org.apache.xmlgraphics.image.loader.ImageFlavor;
 
 /**
- * This interface is used for handling all sorts of image types for PDF output.
+ * This interface is a service provider interface for image handlers.
  */
-public interface ImageHandler {
-
-    /**
-     * Returns the priority for this image handler. A lower value means higher priority. This
-     * information is used to build the ordered/prioritized list of supported ImageFlavors.
-     * The built-in handlers use priorities between 100 and 999.
-     * @return a positive integer (>0) indicating the priority
-     */
-    int getPriority();
-
-    /**
-     * Returns the {@link ImageFlavor}s supported by this instance
-     * @return the supported image flavors
-     */
-    ImageFlavor[] getSupportedImageFlavors();
+public interface ImageHandler extends ImageHandlerBase {
 
     /**
      * Indicates whether the image handler is compatible with the indicated target represented
@@ -58,12 +43,6 @@
     boolean isCompatible(RenderingContext targetContext, Image image);
 
     /**
-     * Returns the {@link Image} subclass supported by this instance.
-     * @return the Image type
-     */
-    Class getSupportedImageClass();
-
-    /**
      * Handles the given {@link Image} instance painting it at the indicated position in the
      * output format being generated.
      * @param context the rendering context

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandler.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Tue Dec  9 07:00:35 2008
@@ -1 +1 @@
-Id
+Revision Id

Copied: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandlerBase.java (from r724710, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ImageHandler.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandlerBase.java?p2=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandlerBase.java&p1=xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ImageHandler.java&r1=724710&r2=724729&rev=724729&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ImageHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandlerBase.java Tue Dec  9 07:00:35 2008
@@ -21,7 +21,12 @@
 
 import org.apache.xmlgraphics.image.loader.ImageFlavor;
 
-public interface ImageHandler {
+/**
+ * This interface is a service provider base interface for image handlers. It only contains
+ * methods necessary for registration and is extended by sub-interfaces with the actual
+ * image handling contract.
+ */
+public interface ImageHandlerBase {
 
     /**
      * Returns the priority for this image handler. A lower value means higher priority. This

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandlerBase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandlerBase.java
------------------------------------------------------------------------------
    svn:keywords = Revision Id

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandlerBase.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Dec  9 07:00:35 2008
@@ -0,0 +1,2 @@
+/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/ImageHandler.java:630874-721418
+/xmlgraphics/fop/branches/fop-0_95/src/java/org/apache/fop/render/ImageHandler.java:684572,688085,688696

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/PrintRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/PrintRenderer.java?rev=724729&r1=724728&r2=724729&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/PrintRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/PrintRenderer.java Tue Dec  9 07:00:35 2008
@@ -24,8 +24,6 @@
 import java.util.List;
 import java.util.Map;
 
-import org.w3c.dom.Document;
-
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.Trait;
@@ -37,6 +35,7 @@
 import org.apache.fop.fonts.FontResolver;
 import org.apache.fop.fonts.FontTriplet;
 import org.apache.fop.fonts.base14.Base14FontCollection;
+import org.w3c.dom.Document;
 
 /** Abstract base class of "Print" type renderers.  */
 public abstract class PrintRenderer extends AbstractRenderer {
@@ -109,6 +108,14 @@
     }
 
     /**
+     * Instantiates a RendererContext for an image
+     * @return a newly created RendererContext.
+     */
+    protected RendererContext instantiateRendererContext() {
+        return new RendererContext(this, getMimeType());
+    }
+
+    /**
      * Creates a RendererContext for an image.
      * @param x the x coordinate (in millipoints)
      * @param y the y coordinate (in millipoints)
@@ -119,8 +126,7 @@
      */
     protected RendererContext createRendererContext(int x, int y, int width, int height,
             Map foreignAttributes) {
-        RendererContext context;
-        context = new RendererContext(this, getMimeType());
+        RendererContext context = instantiateRendererContext();
         context.setUserAgent(userAgent);
 
         context.setProperty(RendererContextConstants.WIDTH,

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RendererContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RendererContext.java?rev=724729&r1=724728&r2=724729&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RendererContext.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RendererContext.java Tue Dec  9 07:00:35 2008
@@ -20,9 +20,12 @@
 package org.apache.fop.render;
 
 //Java
+import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.fo.extensions.ExtensionElementMapping;
+import org.apache.xmlgraphics.util.QName;
 
 /**
  * The Render Context for external handlers. This provides a rendering context
@@ -30,21 +33,28 @@
  * render target.
  */
 public class RendererContext {
+    /** conversion-mode extension attribute */
+    protected static final QName CONVERSION_MODE = new QName(
+            ExtensionElementMapping.URI, null, "conversion-mode");
 
-    private String mime;
-    private AbstractRenderer renderer;
+    /** "bitmap" value for the "conversion-mode" extension attribute. */
+    protected static final String BITMAP = "bitmap";
+
+    private final String mime;
+    private final AbstractRenderer renderer;
     private FOUserAgent userAgent;
-    private Map props = new java.util.HashMap();
+
+    private final Map/*<String,Object>*/ props = new java.util.HashMap/*<String,Object>*/();
 
     /**
-     * Contructor for this class. It takes a MIME type as parameter.
+     * Constructor for this class. It takes a MIME type as parameter.
      *
-     * @param renderer The current renderer
-     * @param m  The MIME type of the output that's generated.
+     * @param renderer the current renderer
+     * @param mime the MIME type of the output that's generated.
      */
-    public RendererContext(AbstractRenderer renderer, String m) {
+    public RendererContext(AbstractRenderer renderer, String mime) {
         this.renderer = renderer;
-        this.mime = m;
+        this.mime = mime;
     }
 
     /**
@@ -112,6 +122,19 @@
         return wrapper;
     }
 
+    /** {@inheritDoc} **/
+    public String toString() {
+        StringBuffer stringBuffer = new StringBuffer("RendererContext{\n");
+        Iterator it = props.keySet().iterator();
+        while (it.hasNext()) {
+            String key = (String)it.next();
+            Object value = props.get(key);
+            stringBuffer.append("\t" + key + "=" + value + "\n");
+        }
+        stringBuffer.append("}");
+        return stringBuffer.toString();
+    }
+
     /**
      * Base class for a wrapper around RendererContext to access its properties in a type-safe,
      * renderer-specific way.
@@ -158,6 +181,19 @@
         public Map getForeignAttributes() {
             return (Map)context.getProperty(RendererContextConstants.FOREIGN_ATTRIBUTES);
         }
+
+        /** {@inheritDoc} */
+        public String toString() {
+            return "RendererContextWrapper{"
+                + "userAgent=" + getUserAgent()
+                + "x=" + getCurrentXPosition()
+                + "y=" + getCurrentYPosition()
+                + "width=" + getWidth()
+                + "height=" + getHeight()
+                + "foreignAttributes=" + getForeignAttributes()
+            + "}";
+
+        }
     }
 }
 

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPEventProducer.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPEventProducer.xml?rev=724729&r1=724728&r2=724729&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPEventProducer.xml (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPEventProducer.xml Tue Dec  9 07:00:35 2008
@@ -1,3 +1 @@
-<?xml version="1.0" encoding="UTF-8"?><catalogue xml:lang="en">
-  <message key="org.apache.fop.render.afp.AFPEventProducer.warnDefaultFontSetup">No AFP fonts configured. Using default setup.</message>
-</catalogue>
+<?xml version="1.0" encoding="UTF-8"?><catalogue xml:lang="en"/>

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java?rev=724729&r1=724728&r2=724729&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java Tue Dec  9 07:00:35 2008
@@ -19,40 +19,87 @@
 
 package org.apache.fop.render.afp;
 
+import java.awt.Dimension;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
 import java.io.IOException;
 
-import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
-
+import org.apache.fop.afp.AFPGraphics2D;
+import org.apache.fop.afp.AFPGraphicsObjectInfo;
+import org.apache.fop.afp.AFPPaintingState;
+import org.apache.fop.afp.AFPResourceManager;
 import org.apache.fop.render.AbstractGraphics2DAdapter;
 import org.apache.fop.render.RendererContext;
+import org.apache.fop.render.RendererContext.RendererContextWrapper;
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
 
 /**
  * Graphics2DAdapter implementation for AFP.
  */
 public class AFPGraphics2DAdapter extends AbstractGraphics2DAdapter {
 
+    private final AFPPaintingState paintingState;
+
     /**
      * Main constructor
+     *
+     * @param paintingState the AFP painting state
      */
-    public AFPGraphics2DAdapter() {
+    public AFPGraphics2DAdapter(AFPPaintingState paintingState) {
+        this.paintingState = paintingState;
     }
 
     /** {@inheritDoc} */
     public void paintImage(Graphics2DImagePainter painter,
-            RendererContext context,
+            RendererContext rendererContext,
             int x, int y, int width, int height) throws IOException {
-        RendererContext.RendererContextWrapper wrappedContext
-                = new RendererContext.RendererContextWrapper(context);
-        AFPRenderer afp = (AFPRenderer)context.getRenderer();
-        Boolean grayObj = (Boolean)context.getProperty(AFPRendererContextConstants.AFP_GRAYSCALE);
-        boolean gray = (grayObj != null ? grayObj.booleanValue() : false);
-
-        //Paint to a BufferedImage
-        int resolution = (int)Math.round(context.getUserAgent().getTargetResolution());
-        BufferedImage bi = paintToBufferedImage(painter, wrappedContext, resolution, gray, false);
 
-        afp.drawBufferedImage(bi, resolution, x, y, width, height);
+        AFPRendererContext afpRendererContext = (AFPRendererContext)rendererContext;
+        AFPInfo afpInfo = afpRendererContext.getInfo();
+
+        final boolean textAsShapes = false;
+        AFPGraphics2D g2d = afpInfo.createGraphics2D(textAsShapes);
+
+        paintingState.save();
+
+        //Fallback solution: Paint to a BufferedImage
+        if (afpInfo.paintAsBitmap()) {
+
+            // paint image
+            RendererContextWrapper rendererContextWrapper
+                = RendererContext.wrapRendererContext(rendererContext);
+            float targetResolution = rendererContext.getUserAgent().getTargetResolution();
+            int resolution = Math.round(targetResolution);
+            boolean colorImages = afpInfo.isColorSupported();
+            BufferedImage bufferedImage = paintToBufferedImage(
+                    painter, rendererContextWrapper, resolution, !colorImages, false);
+
+            // draw image
+            AffineTransform at = paintingState.getData().getTransform();
+            at.translate(x, y);
+            g2d.drawImage(bufferedImage, at, null);
+        } else {
+            AFPGraphicsObjectInfo graphicsObjectInfo = new AFPGraphicsObjectInfo();
+            graphicsObjectInfo.setPainter(painter);
+            graphicsObjectInfo.setGraphics2D(g2d);
+
+            // get the 'width' and 'height' attributes of the SVG document
+            Dimension imageSize = painter.getImageSize();
+            float imw = (float)imageSize.getWidth() / 1000f;
+            float imh = (float)imageSize.getHeight() / 1000f;
+
+            Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
+            graphicsObjectInfo.setArea(area);
+            AFPResourceManager resourceManager = afpInfo.getResourceManager();
+            resourceManager.createObject(graphicsObjectInfo);
+        }
+
+        paintingState.restore();
     }
 
+    /** {@inheritDoc} */
+    protected int mpt2px(int unit, int resolution) {
+        return Math.round(paintingState.getUnitConverter().mpt2units(unit));
+    }
 }

Copied: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandler.java (from r724689, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandler.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandler.java?p2=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandler.java&p1=xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandler.java&r1=724689&r2=724729&rev=724729&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandler.java Tue Dec  9 07:00:35 2008
@@ -29,12 +29,12 @@
 import org.apache.fop.afp.AFPPaintingState;
 import org.apache.fop.afp.AFPResourceInfo;
 import org.apache.fop.afp.AFPUnitConverter;
-import org.apache.fop.render.ImageHandler;
+import org.apache.fop.render.ImageHandlerBase;
 
 /**
  * A base abstract AFP image handler
  */
-public abstract class AFPImageHandler implements ImageHandler {
+public abstract class AFPImageHandler implements ImageHandlerBase {
     private static final int X = 0;
     private static final int Y = 1;
 



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org