Author: jeremias
Date: Tue Feb  5 04:34:56 2008
New Revision: 618626

URL: http://svn.apache.org/viewvc?rev=618626&view=rev
Log:
Change PDFPage to use PDFDictionary in order to make it possible to better set 
MediaBox/TrimBox/BleedBox.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFArray.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFPage.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResourceContext.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/TransitionDictionary.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFArray.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFArray.java?rev=618626&r1=618625&r2=618626&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFArray.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFArray.java Tue Feb  5 
04:34:56 2008
@@ -69,6 +69,20 @@
     /**
      * Create an array object.
      * @param parent the array's parent if any
+     * @param values the actual array wrapped by this object
+     */
+    public PDFArray(PDFObject parent, double[] values) {
+        /* generic creation of PDF object */
+        super(parent);
+
+        for (int i = 0, c = values.length; i < c; i++) {
+            this.values.add(new Double(values[i]));
+        }
+    }
+
+    /**
+     * Create an array object.
+     * @param parent the array's parent if any
      * @param values the actual values wrapped by this object
      */
     public PDFArray(PDFObject parent, Collection values) {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFPage.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFPage.java?rev=618626&r1=618625&r2=618626&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFPage.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFPage.java Tue Feb  5 
04:34:56 2008
@@ -19,6 +19,8 @@
  
 package org.apache.fop.pdf;
 
+import java.awt.geom.Rectangle2D;
+
 /**
  * Class representing a /Page object.
  * <p>
@@ -29,40 +31,10 @@
  */
 public class PDFPage extends PDFResourceContext {
 
-    /**
-     * Holds a reference on the parent PDFPages object.
-     */
-    private String parentRef;
-
-    /**
-     * the contents stream
-     */
-    protected PDFStream contents;
-
-    /**
-     * the width of the page in points
-     */
-    protected int pagewidth;
-
-    /**
-     * the height of the page in points
-     */
-    protected int pageheight;
-
     /** the page index (zero-based) */
     protected int pageIndex;
     
     /**
-     * Duration to display page
-     */
-    protected int duration = -1;
-
-    /**
-     * Transition dictionary
-     */
-    protected TransitionDictionary trDictionary = null;
-
-    /**
      * Create a /Page object
      *
      * @param resources the /Resources object
@@ -77,10 +49,10 @@
         /* generic creation of object */
         super(resources);
 
+        put("Type", new PDFName("Page"));
         /* set fields using parameters */
-        this.contents = contents;
-        this.pagewidth = pageWidth;
-        this.pageheight = pageHeight;
+        setContents(contents);
+        setSimplePageSize(pageWidth, pageHeight);
         this.pageIndex = pageIndex;
     }
 
@@ -97,13 +69,51 @@
         this(resources, null, pageWidth, pageHeight, pageIndex);
     }
 
+    private void setSimplePageSize(int width, int height) {
+        Rectangle2D box = new Rectangle2D.Double(0, 0, width, height);
+        setMediaBox(box);
+        setBleedBox(box); //Recommended by PDF/X
+        setTrimBox(box); //Needed for PDF/X
+    }
+    
+    private PDFArray toPDFArray(Rectangle2D box) {
+        return new PDFArray(this, new double[] {
+                box.getX(), box.getY(), box.getMaxX(), box.getMaxY()});
+    }
+    
+    /**
+     * Sets the "MediaBox" entry
+     * @param box the media rectangle
+     */
+    public void setMediaBox(Rectangle2D box) {
+        put("MediaBox", toPDFArray(box));
+    }
+    
+    /**
+     * Sets the "TrimBox" entry
+     * @param box the trim rectangle
+     */
+    public void setTrimBox(Rectangle2D box) {
+        put("TrimBox", toPDFArray(box));
+    }
+    
+    /**
+     * Sets the "BleedBox" entry
+     * @param box the bleed rectangle
+     */
+    public void setBleedBox(Rectangle2D box) {
+        put("BleedBox", toPDFArray(box));
+    }
+    
     /**
      * set this page contents
      *
      * @param contents the contents of the page
      */
     public void setContents(PDFStream contents) {
-        this.contents = contents;
+        if (contents != null) {
+            put("Contents", new PDFReference(contents));
+        }
     }
 
     /**
@@ -112,7 +122,7 @@
      * @param parent the /Pages object that is this page's parent
      */
     public void setParent(PDFPages parent) {
-        this.parentRef = parent.referencePDF();
+        put("Parent", new PDFReference(parent));
     }
 
     /**
@@ -124,24 +134,8 @@
      * @param tr the transition dictionary
      */
     public void setTransition(int dur, TransitionDictionary tr) {
-        duration = dur;
-        trDictionary = tr;
-    }
-
-    /**
-     * Returns the page width.
-     * @return the page width
-     */
-    public int getWidth() {
-        return this.pagewidth;
-    }
-
-    /**
-     * Returns the page height.
-     * @return the page height
-     */
-    public int getHeight() {
-        return this.pageheight;
+        put("Dur", new Integer(dur));
+        put("Trans", tr);
     }
 
     /**
@@ -150,35 +144,6 @@
      */
     public int getPageIndex() {
         return this.pageIndex;
-    }
-    
-    /**
-     * [EMAIL PROTECTED]
-     */
-    public String toPDFString() {
-        StringBuffer sb = new StringBuffer();
-
-        String box = "[ 0 0 " + getWidth() + " " + getHeight() + " ]";
-        sb = sb.append(getObjectID()
-                       + "<< /Type /Page\n" 
-                       + "/Parent " + this.parentRef + "\n"
-                       + "/MediaBox " + box + "\n" 
-                       + "/TrimBox " + box + "\n" //Needed for PDF/X
-                       + "/BleedBox " + box + "\n" //Recommended by PDF/X
-                       + "/Resources " + this.resources.referencePDF() + "\n" 
-                       + "/Contents " + this.contents.referencePDF() + "\n");
-        if (this.annotList != null) {
-            sb = sb.append("/Annots " + this.annotList.referencePDF() + "\n");
-        }
-        if (this.duration != -1) {
-            sb = sb.append("/Dur " + this.duration + "\n");
-        }
-        if (this.trDictionary != null) {
-            sb = sb.append("/Trans << " + this.trDictionary.getDictionary() + 
" >>\n");
-        }
-
-        sb = sb.append(">>\nendobj\n");
-        return sb.toString();
     }
 
 }

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResourceContext.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResourceContext.java?rev=618626&r1=618625&r2=618626&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResourceContext.java 
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResourceContext.java 
Tue Feb  5 04:34:56 2008
@@ -33,17 +33,7 @@
  * to the memory profile this was causing OOM issues. So, we store
  * only the object ID of the parent, rather than the parent itself.
  */
-public class PDFResourceContext extends PDFObject {
-
-    /**
-     * the page's /Resource object
-     */
-    protected PDFResources resources;
-
-    /**
-     * the list of annotation objects for this page
-     */
-    protected PDFAnnotList annotList;
+public class PDFResourceContext extends PDFDictionary {
 
     /**
      * Creates a new ResourceContext.
@@ -54,9 +44,7 @@
         super();
 
         /* set fields using parameters */
-        //this.document = doc;
-        this.resources = resources;
-        this.annotList = null;
+        put("Resources", resources);
     }
 
     /**
@@ -65,7 +53,7 @@
      * @return the resources in this resource context
      */
     public PDFResources getPDFResources() {
-        return this.resources;
+        return (PDFResources)get("Resources");
     }
 
     /**
@@ -74,10 +62,12 @@
      * @param annot a PDFAnnotList list of annotations
      */
     public void addAnnotation(PDFObject annot) {
-        if (this.annotList == null) {
-            this.annotList = getDocument().getFactory().makeAnnotList();
+        PDFAnnotList annotList = getAnnotations();
+        if (annotList == null) {
+            annotList = getDocument().getFactory().makeAnnotList();
+            put("Annots", annotList);
         }
-        this.annotList.addAnnot(annot);
+        annotList.addAnnot(annot);
     }
 
     /**
@@ -86,7 +76,7 @@
      * @return the current annotation list
      */
     public PDFAnnotList getAnnotations() {
-        return this.annotList;
+        return (PDFAnnotList)get("Annots");
     }
 
     /**

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/TransitionDictionary.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/TransitionDictionary.java?rev=618626&r1=618625&r2=618626&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/TransitionDictionary.java 
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/TransitionDictionary.java 
Tue Feb  5 04:34:56 2008
@@ -19,50 +19,21 @@
  
 package org.apache.fop.pdf;
 
-import java.util.Map;
-import java.util.Iterator;
-
 /**
  * Transition Dictionary
  * This class is used to build a transition dictionary to
  * specify the transition between pages.
  */
-public class TransitionDictionary extends PDFObject {
-
-    private Map dictionaryValues;
+public class TransitionDictionary extends PDFDictionary {
 
     /**
      * Create a Transition Dictionary
      *
      * @param values the dictionary values to output
      */
-    public TransitionDictionary(Map values) {
-        dictionaryValues = values;
+    public TransitionDictionary() {
+        put("Type", new PDFName("Trans"));
     }
 
-    /**
-     * Get the dictionary.
-     * This returns the string containing the dictionary values.
-     *
-     * @return the string with the dictionary values
-     */
-    public String getDictionary() {
-        StringBuffer sb = new StringBuffer();
-        sb.append("/Type /Trans\n");
-        for (Iterator iter = dictionaryValues.keySet().iterator(); 
iter.hasNext();) {
-            Object key = iter.next();
-            sb.append(key + " " + dictionaryValues.get(key) + "\n");
-        }
-        return sb.toString();
-    }
-
-    /**
-     * there is nothing to return for the toPDF method, as it should not be 
called
-     *
-     * @return an empty string
-     */
-    public byte[] toPDF() {
-        return new byte[0];
-    }
 }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to