gmazza      2003/08/30 14:14:52

  Modified:    src/java/org/apache/fop/render/awt AWTPrintRenderer.java
                        AWTRenderer.java
               src/java/org/apache/fop/viewer PreviewDialog.java
  Log:
  Document paging within AWTRenderer & PreviewDialog activated (no content yet, just 
blank pages).
  
  Revision  Changes    Path
  1.5       +3 -3      xml-fop/src/java/org/apache/fop/render/awt/AWTPrintRenderer.java
  
  Index: AWTPrintRenderer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/render/awt/AWTPrintRenderer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AWTPrintRenderer.java     10 Aug 2003 15:43:13 -0000      1.4
  +++ AWTPrintRenderer.java     30 Aug 2003 21:14:52 -0000      1.5
  @@ -96,7 +96,7 @@
           super.stopRenderer();
   
           if (endNumber == -1) {
  -            endNumber = getPageCount();
  +            endNumber = getNumberOfPages();
           }
   
           Vector numbers = getInvalidPageNumbers();
  @@ -129,7 +129,7 @@
   
       private Vector getInvalidPageNumbers() {
           Vector vec = new Vector();
  -        int max = getPageCount();
  +        int max = getNumberOfPages();
           boolean isValid;
           for (int i = 0; i < max; i++) {
               isValid = true;
  
  
  
  1.9       +46 -54    xml-fop/src/java/org/apache/fop/render/awt/AWTRenderer.java
  
  Index: AWTRenderer.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/awt/AWTRenderer.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AWTRenderer.java  28 Aug 2003 23:43:50 -0000      1.8
  +++ AWTRenderer.java  30 Aug 2003 21:14:52 -0000      1.9
  @@ -75,8 +75,8 @@
   import java.awt.RenderingHints;
   import java.io.IOException;
   import java.io.OutputStream;
  -import java.util.List;
   import java.util.Map;
  +import java.util.Vector;
   
   // FOP
   import org.apache.fop.apps.Document;
  @@ -97,12 +97,9 @@
    */
   public class AWTRenderer extends AbstractRenderer implements Printable, Pageable {
   
  -    protected int pageWidth = 0;
  -    protected int pageHeight = 0;
       protected double scaleFactor = 100.0;
       protected int pageNumber = 0;
  -    protected List pageList = new java.util.Vector();
  -    //protected ProgressListener progressListener = null;
  +    protected Vector pageViewportList = new java.util.Vector();
   
       /** Font configuration */
       protected Document fontInfo;
  @@ -123,13 +120,6 @@
       protected Color saveColor = null;
   
       /**
  -     * Image Object and Graphics Object. The Graphics Object is the Graphics
  -     * object that is contained within the Image Object.
  -     */
  -    private BufferedImage pageImage = null;
  -    private Graphics2D graphics = null;
  -
  -    /**
        * The current (internal) font name
       */
       protected String currentFontName;
  @@ -168,10 +158,6 @@
           return translator;
       }
   
  -    public int getPageCount() {
  -        return pageList.size();
  -    }
  -
       public void setupFontInfo(FOTreeControl foTreeControl) {
           // create a temp Image to test font metrics on
           fontInfo = (Document) foTreeControl;
  @@ -196,12 +182,10 @@
           return scaleFactor;
       }
   
  -    public BufferedImage getLastRenderedPage() {
  -        return pageImage;
  -    }
  -
       public void startRenderer(OutputStream out)
       throws IOException {
  +        // empty pageViewportList, in case of a reload from PreviewDialog
  +        pageViewportList.removeAllElements();
       }
   
       public void stopRenderer()
  @@ -220,7 +204,7 @@
       }
   
       public int getNumberOfPages() {
  -        return 0;
  +        return pageViewportList.size();
       }
   
       public int print(Graphics g, PageFormat format, int pos) {
  @@ -251,53 +235,61 @@
           return frame;
       }
       
  -    private void transform(Graphics2D g2d, double zoomPercent, double angle) {
  -        AffineTransform at = g2d.getTransform();
  -        at.rotate(angle);
  -        at.scale(zoomPercent / 100.0, zoomPercent / 100.0);
  -        g2d.setTransform(at);
  +    /** This method override only stores the PageViewport in a vector.
  +      * No actual rendering performed -- this is done by getPageImage(pageNum) 
instead.
  +      * @param pageViewport the <code>PageViewport</code> object supplied by the 
Area Tree
  +      * @see org.apache.fop.render.Renderer 
  +    */
  +    public void renderPage(PageViewport pageViewport)  throws IOException, 
FOPException {
  +        pageViewportList.add(pageViewport);
       }
   
  -    /** @see org.apache.fop.render.Renderer */
  -    public void renderPage(PageViewport page)  throws IOException, FOPException {
  -//      Page p = page.getPage();
  +    /** Generates a desired page from the renderer's page viewport vector.
  +     * @param pageNum the 0-based page number to generate
  +     *  @return the <code>java.awt.image.BufferedImage</code> corresponding to the 
page
  +     *  @throws FOPException in case of an out-of-range page number requested
  +    */
  +    public BufferedImage getPageImage(int pageNum) throws FOPException {
  +        if (pageNum < 0 || pageNum >= pageViewportList.size()) {
  +            throw new FOPException("out-of-range page number (" + pageNum 
  +                + ") requested; only " + pageViewportList.size() 
  +                + " page(s) available.");
  +        }
  +        PageViewport pageViewport = (PageViewport) pageViewportList.get(pageNum);
  +        Page page = pageViewport.getPage();
           
  -        Rectangle2D bounds = page.getViewArea();
  -        pageWidth = (int)((float) bounds.getWidth() / 1000f + .5);
  -        pageHeight = (int)((float) bounds.getHeight() / 1000f + .5);
  +        Rectangle2D bounds = pageViewport.getViewArea();
  +        int pageWidth = (int)((float) bounds.getWidth() / 1000f + .5);
  +        int pageHeight = (int)((float) bounds.getHeight() / 1000f + .5);
   
  -        pageImage =
  +        BufferedImage pageImage =
               new BufferedImage((int)((pageWidth * (int)scaleFactor) / 100),
                                 (int)((pageHeight * (int)scaleFactor) / 100),
                                 BufferedImage.TYPE_INT_RGB);
   
  -        graphics = pageImage.createGraphics();
  +        Graphics2D graphics = pageImage.createGraphics();
           graphics.setRenderingHint (RenderingHints.KEY_FRACTIONALMETRICS,
                                      RenderingHints.VALUE_FRACTIONALMETRICS_ON);
   
  -        transform(graphics, scaleFactor, 0);
  -        drawFrame();
  +        // transform page based on scale factor supplied
  +        AffineTransform at = graphics.getTransform();
  +        at.scale(scaleFactor / 100.0, scaleFactor / 100.0);
  +        graphics.setTransform(at);
  +        
  +        // draw page frame
  +        graphics.setColor(Color.white);
  +        graphics.fillRect(0, 0, pageWidth, pageHeight);
  +        graphics.setColor(Color.black);
  +        graphics.drawRect(-1, -1, pageWidth + 2, pageHeight + 2);
  +        graphics.drawLine(pageWidth + 2, 0, pageWidth + 2, pageHeight + 2);
  +        graphics.drawLine(pageWidth + 3, 1, pageWidth + 3, pageHeight + 3);
  +        graphics.drawLine(0, pageHeight + 2, pageWidth + 2, pageHeight + 2);
  +        graphics.drawLine(1, pageHeight + 3, pageWidth + 3, pageHeight + 3);
   
           this.currentFontName = "";
           this.currentFontSize = 0;
  -//      renderPageAreas(p);
  -//      pageList.add(page);
  +//      renderPageAreas(page);
  +        return pageImage;
       }
   
  -    protected void drawFrame() {
  -        int width = pageWidth;
  -        int height = pageHeight;
  -
  -        graphics.setColor(Color.white);
  -        graphics.fillRect(0, 0, width, height);
  -
  -        graphics.setColor(Color.black);
  -        graphics.drawRect(-1, -1, width + 2, height + 2);
  -        graphics.drawLine(width + 2, 0, width + 2, height + 2);
  -        graphics.drawLine(width + 3, 1, width + 3, height + 3);
  -
  -        graphics.drawLine(0, height + 2, width + 2, height + 2);
  -        graphics.drawLine(1, height + 3, width + 3, height + 3);
  -    }
  -    
   }
  
  
  
  1.5       +26 -23    xml-fop/src/java/org/apache/fop/viewer/PreviewDialog.java
  
  Index: PreviewDialog.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/viewer/PreviewDialog.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PreviewDialog.java        28 Aug 2003 23:43:50 -0000      1.4
  +++ PreviewDialog.java        30 Aug 2003 21:14:52 -0000      1.5
  @@ -425,9 +425,7 @@
               pageLabel.setIcon(null);
               infoStatus.setText("");
               currentPage = 0;
  -            //Cleans up renderer - to be done
  -            //while (renderer.getPageCount() != 0)
  -            //    renderer.removePage(0);
  +
               try {
                   setStatus(translator.getString("Status.Build.FO.tree"));
                   driver.render(inputHandler);
  @@ -499,7 +497,9 @@
               scale.setSelectedIndex(5);
           }
           renderer.setScaleFactor(scaleFactor);
  -        showPage();
  +        if (renderer.getNumberOfPages() != 0) {
  +            showPage();
  +        }
       }
   
       private void scaleActionPerformed(ActionEvent e) {
  @@ -558,25 +558,28 @@
            * The run method that does the actual updating
            */
           public void run() {
  -            BufferedImage pageImage = null;
  -            Graphics graphics = null;
  -
  -//          renderer.render(currentPage);
  -            pageImage = renderer.getLastRenderedPage();
  -            if (pageImage == null)
  -                return;
  -            graphics = pageImage.getGraphics();
  -            graphics.setColor(Color.black);
  -            graphics.drawRect(0, 0, pageImage.getWidth() - 1,
  -                              pageImage.getHeight() - 1);
  -
  -            pageLabel.setIcon(new ImageIcon(pageImage));
  -            pageCount = renderer.getPageCount();
  -
  -            //Updates status bar
  -            infoStatus.setText(translator.getString("Status.Page") + " "
  -                + (currentPage + 1) + " "
  -                + translator.getString("Status.of") + " " + pageCount);
  +            try {
  +                BufferedImage pageImage = null;
  +                Graphics graphics = null;
  +    
  +                pageImage = renderer.getPageImage(currentPage);
  +                if (pageImage == null)
  +                    return;
  +                graphics = pageImage.getGraphics();
  +                graphics.setColor(Color.black);
  +                graphics.drawRect(0, 0, pageImage.getWidth() - 1,
  +                                  pageImage.getHeight() - 1);
  +    
  +                pageLabel.setIcon(new ImageIcon(pageImage));
  +                pageCount = renderer.getNumberOfPages();
  +    
  +                // Update status bar
  +                infoStatus.setText(translator.getString("Status.Page") + " "
  +                    + (currentPage + 1) + " "
  +                    + translator.getString("Status.of") + " " + pageCount);
  +            } catch (FOPException e) {
  +                reportException(e);
  +            }
           }
       }
   
  
  
  

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

Reply via email to