FOP
  1. FOP
  2. FOP-1210

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

    Details

    • Type: Bug Bug
    • Status: Closed
    • Resolution: Fixed
    • Affects Version/s: 0.92
    • Fix Version/s: None
    • Component/s: renderer/awt
    • Labels:
      None
    • Environment:
      Operating System: other
      Platform: Other
    • External issue ID:
      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()); }

      }

        Issue Links

          Activity

          Hide
          Jeremias Maerki added a comment -
              • FOP-1148 has been marked as a duplicate of this bug. ***
          Show
          Jeremias Maerki added a comment - FOP-1148 has been marked as a duplicate of this bug. ***
          Hide
          Jeremias Maerki added a comment -
          Show
          Jeremias Maerki added a comment - Fixed: http://svn.apache.org/viewvc?rev=424966&view=rev Thanks for the hint.
          Hide
          Glenn Adams added a comment -

          batch transition pre-FOP1.0 resolved+fixed bugs to closed+fixed

          Show
          Glenn Adams added a comment - batch transition pre-FOP1.0 resolved+fixed bugs to closed+fixed

            People

            • Assignee:
              fop-dev
              Reporter:
              Igor Istomin
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development