jeremias    2003/03/27 03:28:51

  Modified:    src/java/org/apache/fop/svg PDFDocumentGraphics2D.java
  Log:
  Adjust to changes in PDF library.
  Avalonize in a backwards-compatible way (optional logging and configuration).
  
  Revision  Changes    Path
  1.3       +107 -29   xml-fop/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
  
  Index: PDFDocumentGraphics2D.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PDFDocumentGraphics2D.java        15 Mar 2003 17:02:49 -0000      1.2
  +++ PDFDocumentGraphics2D.java        27 Mar 2003 11:28:51 -0000      1.3
  @@ -51,6 +51,7 @@
   package org.apache.fop.svg;
   
   import org.apache.fop.pdf.PDFDocument;
  +import org.apache.fop.pdf.PDFFilterList;
   import org.apache.fop.pdf.PDFPage;
   import org.apache.fop.pdf.PDFStream;
   import org.apache.fop.pdf.PDFState;
  @@ -59,6 +60,15 @@
   import org.apache.fop.pdf.PDFColor;
   import org.apache.fop.pdf.PDFAnnotList;
   import org.apache.fop.render.pdf.FontSetup;
  +import org.apache.avalon.framework.CascadingRuntimeException;
  +import org.apache.avalon.framework.activity.Initializable;
  +import org.apache.avalon.framework.configuration.Configurable;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.container.ContainerUtil;
  +import org.apache.avalon.framework.logger.ConsoleLogger;
  +import org.apache.avalon.framework.logger.LogEnabled;
  +import org.apache.avalon.framework.logger.Logger;
   import org.apache.fop.layout.FontInfo;
   
   import java.awt.Graphics;
  @@ -70,6 +80,7 @@
   import java.awt.geom.AffineTransform;
   import java.io.OutputStream;
   import java.io.IOException;
  +import java.util.List;
   
   /**
    * This class is a wrapper for the <tt>PDFGraphics2D</tt> that
  @@ -80,11 +91,18 @@
    * @version $Id$
    * @see org.apache.fop.svg.PDFGraphics2D
    */
  -public class PDFDocumentGraphics2D extends PDFGraphics2D {
  +public class PDFDocumentGraphics2D extends PDFGraphics2D
  +            implements LogEnabled, Configurable, Initializable {
  +    
       private PDFPage currentPage;
       private PDFStream pdfStream;
       private int width;
       private int height;
  +    private List fontList;
  +    
  +    //Avalon-dependent stuff
  +    private Logger logger;
  +    private Configuration cfg;
   
       /**
        * Create a new PDFDocumentGraphics2D.
  @@ -97,7 +115,7 @@
        * @param textAsShapes set this to true so that text will be rendered
        * using curves and not the font.
        */
  -    PDFDocumentGraphics2D(boolean textAsShapes) {
  +    public PDFDocumentGraphics2D(boolean textAsShapes) {
           super(textAsShapes);
   
           if (!textAsShapes) {
  @@ -106,16 +124,96 @@
               //FontState fontState = new FontState("Helvetica", "normal",
               //                          FontInfo.NORMAL, 12, 0);
           }
  +        try {
  +            initialize();
  +        } catch (Exception e) {
  +            //Should never happen
  +            throw new CascadingRuntimeException("Internal error", e);
  +        }
  +    }
  +
  +    /**
  +     * Create a new PDFDocumentGraphics2D.
  +     * This is used to create a new pdf document of the given height
  +     * and width.
  +     * The resulting document is written to the stream after rendering.
  +     *
  +     * @param textAsShapes set this to true so that text will be rendered
  +     * using curves and not the font.
  +     * @param stream the stream that the final document should be written to.
  +     * @param width the width of the document
  +     * @param height the height of the document
  +     * @throws IOException an io exception if there is a problem
  +     *         writing to the output stream
  +     */
  +    public PDFDocumentGraphics2D(boolean textAsShapes, OutputStream stream,
  +                                 int width, int height) throws IOException {
  +        this(textAsShapes);
  +        setupDocument(stream, width, height);
  +    }
  +
  +    /**
  +     * Create a new PDFDocumentGraphics2D.
  +     * This is used to create a new pdf document.
  +     * For use by the transcoder which needs font information
  +     * for the bridge before the document size is known.
  +     * The resulting document is written to the stream after rendering.
  +     * This constructor is Avalon-style.
  +     */
  +    public PDFDocumentGraphics2D() {
  +        super(false);
  +    }
  +
  +    /**
  +     * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(Logger)
  +     */
  +    public void enableLogging(Logger logger) {
  +        this.logger = logger;
  +    }
  +
  +    /**
  +     * Returns the logger.
  +     * @return Logger the logger
  +     */
  +    protected final Logger getLogger() {
  +        if (this.logger == null) {
  +            this.logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
  +        }
  +        return this.logger;
  +    }
   
  -        this.pdfDoc = new PDFDocument("FOP SVG Renderer");
  -        this.pdfDoc.enableLogging(new 
org.apache.avalon.framework.logger.NullLogger());
  +    /**
  +     * @see 
org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
  +     */
  +    public void configure(Configuration cfg) throws ConfigurationException {
  +        this.cfg = cfg;
  +        this.fontList = FontSetup.buildFontListFromConfiguration(cfg);
  +    }
  +
  +    /**
  +     * @see org.apache.avalon.framework.activity.Initializable#initialize()
  +     */
  +    public void initialize() throws Exception {
  +        if (this.fontInfo == null) {
  +            fontInfo = new FontInfo();
  +            FontSetup.setup(fontInfo, this.fontList);
  +            //FontState fontState = new FontState("Helvetica", "normal",
  +            //                          FontInfo.NORMAL, 12, 0);
  +        }
   
  +        this.pdfDoc = new PDFDocument("Apache FOP: SVG to PDF Transcoder");
  +        ContainerUtil.enableLogging(this.pdfDoc, getLogger().getChildLogger("pdf"));
  +        if (this.cfg != null) {
  +            this.pdfDoc.setFilterMap(
  +                PDFFilterList.buildFilterMapFromConfiguration(cfg));
  +        }
  +        
           graphicsState = new PDFState();
   
           currentFontName = "";
           currentFontSize = 0;
   
  -        pdfStream = this.pdfDoc.makeStream(PDFStream.CONTENT_FILTER, false);
  +        pdfStream = 
this.pdfDoc.getFactory().makeStream(PDFFilterList.CONTENT_FILTER, false);
       }
   
       /**
  @@ -131,7 +229,7 @@
           this.height = height;
   
           PDFResources pdfResources = this.pdfDoc.getResources();
  -        currentPage = this.pdfDoc.makePage(pdfResources,
  +        currentPage = this.pdfDoc.getFactory().makePage(pdfResources,
                                                      width, height);
           resourceContext = currentPage;
           pageRef = currentPage.referencePDF();
  @@ -143,26 +241,6 @@
       }
   
       /**
  -     * Create a new PDFDocumentGraphics2D.
  -     * This is used to create a new pdf document of the given height
  -     * and width.
  -     * The resulting document is written to the stream after rendering.
  -     *
  -     * @param textAsShapes set this to true so that text will be rendered
  -     * using curves and not the font.
  -     * @param stream the stream that the final document should be written to.
  -     * @param width the width of the document
  -     * @param height the height of the document
  -     * @throws IOException an io exception if there is a problem
  -     *         writing to the output stream
  -     */
  -    public PDFDocumentGraphics2D(boolean textAsShapes, OutputStream stream,
  -                                 int width, int height) throws IOException {
  -        this(textAsShapes);
  -        setupDocument(stream, width, height);
  -    }
  -
  -    /**
        * Get the font info for this pdf document.
        * @return the font information
        */
  @@ -222,13 +300,13 @@
           // restorePDFState();
   
           pdfStream.add(getString());
  -        this.pdfDoc.addStream(pdfStream);
  +        this.pdfDoc.registerObject(pdfStream);
           currentPage.setContents(pdfStream);
           PDFAnnotList annots = currentPage.getAnnotations();
           if (annots != null) {
  -            this.pdfDoc.addAnnotList(annots);
  +            this.pdfDoc.addObject(annots);
           }
  -        this.pdfDoc.addPage(currentPage);
  +        this.pdfDoc.addObject(currentPage);
           if (fontInfo != null) {
               FontSetup.addToResources(pdfDoc, pdfDoc.getResources(), fontInfo);
           }
  
  
  

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

Reply via email to