DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=40048>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=40048

           Summary: When using AWTRenderer for printing of document
                    incorrect imageable area is specified in
                    java.awt.print.PageFormat
           Product: Fop
           Version: 0.92
          Platform: Other
        OS/Version: other
            Status: NEW
          Severity: major
          Priority: P2
         Component: awt renderer
        AssignedTo: fop-dev@xmlgraphics.apache.org
        ReportedBy: [EMAIL PROTECTED]


The AWTRenderer.getPageFormat(int) method returns incorrect PageFormat. The
PageFormat contains incorrect imageable area. According to source code imageable
area should be (0, 0, page-width, page-height) but result PageFormat contains
another values.

After analyzing of source code of PageFormat it was determined that
PageFormat.setPaper(Paper) method clones passed Paper and stores reference to
new instance. IMHO, the reason of the bug is that AWTRenderer.getPageFormat(int)
invokes PageFormat.setPaper(Paper) method BEFORE applying of imageable area to
the Paper and as consequence PageFormat clones Paper with default imageable
area. That  is, imageable area is applied to another (original, not cloned)
instance of Paper.

The correct code should look like this:

public java.awt.print.PageFormat getPageFormat(int pageIndex)
throws IndexOutOfBoundsException {
                try {
                    if (pageIndex >= getNumberOfPages()) {
                        return null;
                    }
            
                    PageFormat pageFormat = new PageFormat();
            
                    Paper paper = new Paper();
            
                    Rectangle2D dim = getPageViewport(pageIndex).getViewArea();
                    double width = dim.getWidth();
                    double height = dim.getHeight();
            
                    // if the width is greater than the height assume lanscape 
mode
                    // and swap the width and height values in the paper format
                    if (width > height) {
                        paper.setImageableArea(0, 0, height / 1000d, width / 
1000d);
                        paper.setSize(height / 1000d, width / 1000d);
                        pageFormat.setOrientation(PageFormat.LANDSCAPE);
                    } else {
                        paper.setImageableArea(0, 0, width / 1000d, height / 
1000d);
                        paper.setSize(width / 1000d, height / 1000d);
                        pageFormat.setOrientation(PageFormat.PORTRAIT);
                    }

                    // Set Paper AFTER applying of imageable area.
                    pageFormat.setPaper(paper);

                    return pageFormat;
                } catch (FOPException fopEx) {
                    throw new IndexOutOfBoundsException(fopEx.getMessage());
                }
}

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

Reply via email to