Uploaded image for project: 'FOP'
  1. FOP
  2. FOP-1210

When using AWTRenderer for printing of document incorrect imageable area is specified in java.awt.print.PageFormat

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Resolution: Fixed
    • 0.92
    • None
    • renderer/awt
    • None
    • Operating System: other
      Platform: Other
    • 40048

    Description

      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()); }

      }

      Attachments

        Issue Links

          Activity

            People

              fop-dev@xmlgraphics.apache.org fop-dev
              iistomin@ciklum.net Igor Istomin
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: