keiron      2002/11/11 00:50:55

  Modified:    src/org/apache/fop/pdf PDFDocument.java PDFPage.java
                        PDFResourceContext.java PDFRoot.java
               src/org/apache/fop/render/pdf PDFRenderer.java
                        PDFXMLHandler.java
               src/org/apache/fop/svg PDFDocumentGraphics2D.java
                        PDFGraphics2D.java
  Added:       src/org/apache/fop/pdf TransitionDictionary.java
                        PDFFormXObject.java
  Log:
  fixes problem of links not working after data output
  annotations now explicitly added
  fixed font name lookup error so now font output only once
  pdf renderer uses context to output things better
  added Form XObject
  add transition dictionary
  
  Revision  Changes    Path
  1.57      +25 -4     xml-fop/src/org/apache/fop/pdf/PDFDocument.java
  
  Index: PDFDocument.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFDocument.java,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- PDFDocument.java  3 Nov 2002 16:24:21 -0000       1.56
  +++ PDFDocument.java  11 Nov 2002 08:50:50 -0000      1.57
  @@ -1004,7 +1004,7 @@
               PDFFont font = new PDFFont(++this.objectcount, fontname,
                                          PDFFont.TYPE1, basefont, encoding);
               this.objects.add(font);
  -            fontMap.put(basefont, font);
  +            fontMap.put(fontname, font);
               return font;
           } else {
               byte subtype = PDFFont.TYPE1;
  @@ -1071,7 +1071,7 @@
                                        makeArray(metrics.getWidths(1)));
               }
   
  -            fontMap.put(basefont, font);
  +            fontMap.put(fontname, font);
   
               return font;
           }
  @@ -1190,6 +1190,19 @@
           return xObject;
       }
   
  +    public PDFFormXObject addFormXObject(PDFResourceContext res, PDFStream cont, 
PDFResources formres, String key) {
  +        PDFFormXObject xObject;
  +        xObject = new PDFFormXObject(++this.objectcount, ++this.xObjectCount,
  +                                 cont, formres.referencePDF());
  +        this.objects.add(xObject);
  +        this.resources.addXObject(xObject);
  +        if (res != null) {
  +            res.getPDFResources().addXObject(xObject);
  +        }
  +        return xObject;
  +
  +    }
  +
       /**
        * make a /Page object
        *
  @@ -1357,8 +1370,16 @@
            * to the list of objects
            */
           PDFAnnotList obj = new PDFAnnotList(++this.objectcount);
  -        this.objects.add(obj);
           return obj;
  +    }
  +
  +    /**
  +     * Add an annotation list object to the pdf document
  +     *
  +     * @param obj the annotation list to add 
  +     */ 
  +    public void addAnnotList(PDFAnnotList obj) {
  +        this.objects.add(obj);
       }
   
       /**
  
  
  
  1.18      +22 -1     xml-fop/src/org/apache/fop/pdf/PDFPage.java
  
  Index: PDFPage.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFPage.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- PDFPage.java      3 Nov 2002 16:24:22 -0000       1.17
  +++ PDFPage.java      11 Nov 2002 08:50:51 -0000      1.18
  @@ -44,6 +44,16 @@
       protected int pageheight;
   
       /**
  +     * Duration to display page
  +     */
  +    protected int duration = -1;
  +
  +    /**
  +     * Transition dictionary
  +     */
  +    protected TransitionDictionary trDictionary = null;
  +
  +    /**
        * create a /Page object
        *
        * @param number the object's number
  @@ -101,6 +111,11 @@
           this.parent = parent.referencePDF();
       }
   
  +    public void setTransition(int dur, TransitionDictionary tr) {
  +        duration = dur;
  +        trDictionary = tr;
  +    }
  +
       /**
        * represent this object as PDF
        *
  @@ -118,6 +133,12 @@
                          + 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");
  
  
  
  1.2       +5 -1      xml-fop/src/org/apache/fop/pdf/PDFResourceContext.java
  
  Index: PDFResourceContext.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFResourceContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PDFResourceContext.java   28 Jun 2002 10:09:06 -0000      1.1
  +++ PDFResourceContext.java   11 Nov 2002 08:50:51 -0000      1.2
  @@ -69,6 +69,10 @@
           this.annotList.addAnnot(annot);
       }
   
  +    public PDFAnnotList getAnnotations() {
  +        return this.annotList;
  +    }
  +
       public void addGState(PDFGState gstate) {
           this.resources.addGState(gstate);
       }
  
  
  
  1.11      +7 -9      xml-fop/src/org/apache/fop/pdf/PDFRoot.java
  
  Index: PDFRoot.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFRoot.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- PDFRoot.java      1 Aug 2001 23:08:55 -0000       1.10
  +++ PDFRoot.java      11 Nov 2002 08:50:51 -0000      1.11
  @@ -24,7 +24,7 @@
       /**
        * Root outline object
        */
  -    private PDFOutline _outline;
  +    private PDFOutline outline;
   
       /**
        * create a Root (/Catalog) object. NOTE: The PDFRoot
  @@ -67,15 +67,14 @@
           this.rootPages = pages;
       }
   
  -    public void setRootOutline(PDFOutline outline) {
  -        _outline = outline;
  +    public void setRootOutline(PDFOutline out) {
  +        outline = out;
       }
   
       public PDFOutline getRootOutline() {
  -        return _outline;
  +        return outline;
       }
   
  -
       /**
        * represent the object as PDF.
        *
  @@ -90,10 +89,9 @@
                                             + " obj\n<< /Type /Catalog\n/Pages "
                                             + this.rootPages.referencePDF()
                                             + "\n");
  -        if (_outline != null) {
  -            p.append(" /Outlines " + _outline.referencePDF() + "\n");
  +        if (outline != null) {
  +            p.append(" /Outlines " + outline.referencePDF() + "\n");
               p.append(" /PageMode /UseOutlines\n");
  -
           }
           p.append(" >>\nendobj\n");
           return p.toString().getBytes();
  
  
  
  1.1                  xml-fop/src/org/apache/fop/pdf/TransitionDictionary.java
  
  Index: TransitionDictionary.java
  ===================================================================
  /*
   * $Id: TransitionDictionary.java,v 1.1 2002/11/11 08:50:51 keiron Exp $
   * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
   * For details on use and redistribution please refer to the
   * LICENSE file included with these sources.
   */
  
  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;
  
      /**
       * Create a Transition Dictionary
       *
       * @param values the dictionary values to output
       */
      public TransitionDictionary(Map values) {
          dictionaryValues = values;
      }
  
      /**
       * Get the dictionary.
       * This returns the string containing the dictionary values.
       */
      public String getDictionary() {
          StringBuffer sb = new StringBuffer();
          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];
      }
  }
  
  
  
  
  1.1                  xml-fop/src/org/apache/fop/pdf/PDFFormXObject.java
  
  Index: PDFFormXObject.java
  ===================================================================
  /*
   * $Id: PDFFormXObject.java,v 1.1 2002/11/11 08:50:51 keiron Exp $
   * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
   * For details on use and redistribution please refer to the
   * LICENSE file included with these sources.
   */
  
  package org.apache.fop.pdf;
  
  // Java
  import java.io.IOException;
  import java.io.OutputStream;
  
  /**
   * PDF Form XObject
   *
   * A derivative of the PDFXObject, is a PDF Stream that has not only a
   * dictionary but a stream of image data.
   */
  public class PDFFormXObject extends PDFXObject {
      private PDFStream contents;
      private String resRef;
  
      /**
       * create a FormXObject with the given number and name and load the
       * image in the object
       *
       * @param number the pdf object number
       * @param xnumber the pdf object X number
       * @param cont the pdf stream contents
       */
      public PDFFormXObject(int number, int xnumber, PDFStream cont, String ref) {
          super(number, xnumber, null);
          contents = cont;
          resRef = ref;
      }
  
      /**
       * Output the form stream as PDF.
       * This sets up the form XObject dictionary and adds the content
       * data stream.
       *
       * @param stream the output stream to write the data
       * @throws IOException if there is an error writing the data
       * @return the length of the data written
       */
      protected int output(OutputStream stream) throws IOException {
          int length = 0;
  
          String dictEntries = contents.applyFilters();
  
          String p = this.number + " " + this.generation + " obj\n";
          p = p + "<</Type /XObject\n";
          p = p + "/Subtype /Form\n";
          p = p + "/FormType 1\n";
          p = p + "/BBox [0 0 1000 1000]\n";
          p = p + "/Matrix [1 0 0 1 0 0]\n";
          p = p + "/Resources " + resRef + "\n";
          p = p + "/Length " + (contents.getDataLength() + 1) + "\n";
  
          p = p + dictEntries;
          p = p + ">>\n";
  
          // push the pdf dictionary on the writer
          byte[] pdfBytes = p.getBytes();
          stream.write(pdfBytes);
          length += pdfBytes.length;
          // push all the image data on the writer
          // and takes care of length for trailer
          length += contents.outputStreamData(stream);
  
          pdfBytes = ("endobj\n").getBytes();
          stream.write(pdfBytes);
          length += pdfBytes.length;
          // let it gc
          // this object is retained as a reference to inserting
          // the same image but the image data is no longer needed
          contents = null;
          return length;
      }
  }
  
  
  
  
  1.129     +14 -10    xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java
  
  Index: PDFRenderer.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java,v
  retrieving revision 1.128
  retrieving revision 1.129
  diff -u -r1.128 -r1.129
  --- PDFRenderer.java  6 Nov 2002 15:36:29 -0000       1.128
  +++ PDFRenderer.java  11 Nov 2002 08:50:52 -0000      1.129
  @@ -22,7 +22,8 @@
   import org.apache.fop.pdf.PDFDocument; 
   import org.apache.fop.pdf.PDFInfo;
   import org.apache.fop.pdf.PDFResources;
  -import org.apache.fop.pdf.PDFXObject;      
  +import org.apache.fop.pdf.PDFResourceContext;
  +import org.apache.fop.pdf.PDFXObject;
   import org.apache.fop.pdf.PDFPage;        
   import org.apache.fop.pdf.PDFState;
   import org.apache.fop.pdf.PDFLink;
  @@ -131,7 +132,7 @@
       /**
        * the current annotation list to add annotations to
        */
  -    protected PDFAnnotList currentAnnotList;
  +    protected PDFResourceContext currentContext = null;
   
       /**
        * the current page to add annotations to
  @@ -369,16 +370,17 @@
           // Transform origin at top left to origin at bottom left
           currentStream.add("1 0 0 -1 0 "
                              + (int) Math.round(pageHeight / 1000) + " cm\n");
  -        //currentStream.add("BT\n");
           currentFontName = "";
   
           Page p = page.getPage();
           renderPageAreas(p);
   
  -        //currentStream.add("ET\n");
  -
           this.pdfDoc.addStream(currentStream);
           currentPage.setContents(currentStream);
  +        PDFAnnotList annots = currentPage.getAnnotations();
  +        if (annots != null) {
  +            this.pdfDoc.addAnnotList(annots);
  +        }
           this.pdfDoc.addPage(currentPage);
           this.pdfDoc.output(ostream);
       }
  @@ -899,7 +901,7 @@
        * Checks to see if we have some text rendering commands open
        * still and writes out the TJ command to the stream if we do
        */
  -    private void closeText() {
  +    protected void closeText() {
           if (textOpen) {
               currentStream.add("] TJ\n");
               textOpen = false;
  @@ -989,14 +991,14 @@
                   return;
               }
               FopPDFImage pdfimage = new FopPDFImage(fopimage, url);
  -            int xobj = pdfDoc.addImage(null, pdfimage).getXNumber();
  +            int xobj = pdfDoc.addImage(currentContext, pdfimage).getXNumber();
               fact.releaseImage(url, userAgent);
           } else if ("image/jpeg".equals(mime)) {
               if (!fopimage.load(FopImage.ORIGINAL_DATA, userAgent)) {
                   return;
               }
               FopPDFImage pdfimage = new FopPDFImage(fopimage, url);
  -            int xobj = pdfDoc.addImage(null, pdfimage).getXNumber();
  +            int xobj = pdfDoc.addImage(currentContext, pdfimage).getXNumber();
               fact.releaseImage(url, userAgent);
   
               int w = (int) pos.getWidth() / 1000;
  @@ -1008,7 +1010,7 @@
                   return;
               }
               FopPDFImage pdfimage = new FopPDFImage(fopimage, url);
  -            int xobj = pdfDoc.addImage(null, pdfimage).getXNumber();
  +            int xobj = pdfDoc.addImage(currentContext, pdfimage).getXNumber();
               fact.releaseImage(url, userAgent);
   
               int w = (int) pos.getWidth() / 1000;
  @@ -1049,6 +1051,8 @@
           context.setProperty(PDFXMLHandler.OUTPUT_STREAM, ostream);
           context.setProperty(PDFXMLHandler.PDF_STATE, currentState);
           context.setProperty(PDFXMLHandler.PDF_PAGE, currentPage);
  +        context.setProperty(PDFXMLHandler.PDF_CONTEXT, currentContext == null ? 
currentPage: currentContext);
  +        context.setProperty(PDFXMLHandler.PDF_CONTEXT, currentContext);
           context.setProperty(PDFXMLHandler.PDF_STREAM, currentStream);
           context.setProperty(PDFXMLHandler.PDF_XPOS,
                               new Integer(currentBlockIPPosition + (int) pos.getX()));
  
  
  
  1.10      +11 -2     xml-fop/src/org/apache/fop/render/pdf/PDFXMLHandler.java
  
  Index: PDFXMLHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/PDFXMLHandler.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PDFXMLHandler.java        11 Sep 2002 09:51:13 -0000      1.9
  +++ PDFXMLHandler.java        11 Nov 2002 08:50:53 -0000      1.10
  @@ -14,6 +14,7 @@
   import org.apache.fop.pdf.PDFState;
   import org.apache.fop.pdf.PDFStream;
   import org.apache.fop.pdf.PDFNumber;
  +import org.apache.fop.pdf.PDFResourceContext;
   import org.apache.fop.svg.PDFTextElementBridge;
   import org.apache.fop.svg.PDFAElementBridge;
   import org.apache.fop.svg.PDFGraphics2D;
  @@ -63,6 +64,11 @@
       public static final String PDF_PAGE = "pdfPage";
   
       /**
  +     * The current PDF page for page renference and as a resource context.
  +     */
  +    public static final String PDF_CONTEXT = "pdfContext";
  +
  +    /**
        * The current PDF stream to draw directly to.
        */
       public static final String PDF_STREAM = "pdfStream";
  @@ -141,6 +147,7 @@
           pdfi.outputStream = (OutputStream)context.getProperty(OUTPUT_STREAM);
           pdfi.pdfState = (PDFState)context.getProperty(PDF_STATE);
           pdfi.pdfPage = (PDFPage)context.getProperty(PDF_PAGE);
  +        pdfi.pdfContext = (PDFResourceContext)context.getProperty(PDF_CONTEXT);
           pdfi.currentStream = (PDFStream)context.getProperty(PDF_STREAM);
           pdfi.width = ((Integer)context.getProperty(PDF_WIDTH)).intValue();
           pdfi.height = ((Integer)context.getProperty(PDF_HEIGHT)).intValue();
  @@ -164,6 +171,8 @@
           public PDFState pdfState;
           /** see PDF_PAGE */
           public PDFPage pdfPage;
  +        /** see PDF_CONTEXT */
  +        public PDFResourceContext pdfContext;
           /** see PDF_STREAM */
           public PDFStream currentStream;
           /** see PDF_WIDTH */
  @@ -256,7 +265,7 @@
               }
   
               PDFGraphics2D graphics = new PDFGraphics2D(true, pdfInfo.fi, 
pdfInfo.pdfDoc,
  -                                     pdfInfo.pdfPage, 
pdfInfo.pdfPage.referencePDF(),
  +                                     pdfInfo.pdfContext, 
pdfInfo.pdfPage.referencePDF(),
                                        pdfInfo.currentFontName,
                                        pdfInfo.currentFontSize);
               graphics.setGraphicContext(new 
org.apache.batik.ext.awt.g2d.GraphicContext());
  
  
  
  1.25      +7 -2      xml-fop/src/org/apache/fop/svg/PDFDocumentGraphics2D.java
  
  Index: PDFDocumentGraphics2D.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFDocumentGraphics2D.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- PDFDocumentGraphics2D.java        30 Oct 2002 15:37:04 -0000      1.24
  +++ PDFDocumentGraphics2D.java        11 Nov 2002 08:50:54 -0000      1.25
  @@ -14,6 +14,7 @@
   import org.apache.fop.pdf.PDFNumber;
   import org.apache.fop.pdf.PDFResources;
   import org.apache.fop.pdf.PDFColor;
  +import org.apache.fop.pdf.PDFAnnotList;
   import org.apache.fop.render.pdf.FontSetup;
   import org.apache.fop.layout.FontInfo;
   
  @@ -179,6 +180,10 @@
           pdfStream.add(getString());
           this.pdfDoc.addStream(pdfStream);
           currentPage.setContents(pdfStream);
  +        PDFAnnotList annots = currentPage.getAnnotations();
  +        if (annots != null) {
  +            this.pdfDoc.addAnnotList(annots);
  +        }
           this.pdfDoc.addPage(currentPage);
           if (fontInfo != null) {
               FontSetup.addToResources(pdfDoc, pdfDoc.getResources(), fontInfo);
  
  
  
  1.45      +8 -2      xml-fop/src/org/apache/fop/svg/PDFGraphics2D.java
  
  Index: PDFGraphics2D.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFGraphics2D.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- PDFGraphics2D.java        8 Nov 2002 10:48:00 -0000       1.44
  +++ PDFGraphics2D.java        11 Nov 2002 08:50:54 -0000      1.45
  @@ -18,6 +18,7 @@
   import org.apache.fop.pdf.PDFPattern;
   import org.apache.fop.pdf.PDFDocument;
   import org.apache.fop.pdf.PDFLink;
  +import org.apache.fop.pdf.PDFAnnotList;
   import org.apache.fop.pdf.BitmapImage;
   import org.apache.fop.layout.FontInfo;
   import org.apache.fop.layout.FontState;
  @@ -984,6 +985,11 @@
                                   translate, null, pattStream.getBuffer());
   
           currentStream.write(myPat.getColorSpaceOut(fill));
  +
  +        PDFAnnotList annots = context.getAnnotations();
  +        if (annots != null) {
  +            this.pdfDoc.addAnnotList(annots);
  +        }
   
           if (outputStream != null) {
               try {
  
  
  

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

Reply via email to