Ejemplo n.º 1
0
  /**
   * Returns the y coordinate of the upper left point of the imageable area of the <code>Paper
   * </code> object associated with this <code>PageFormat</code>. This method takes into account the
   * orientation of the page.
   *
   * @return the y coordinate of the upper left point of the imageable area of the <code>Paper
   *     </code> object associated with this <code>PageFormat</code>.
   */
  public double getImageableY() {
    double y;

    switch (getOrientation()) {
      case LANDSCAPE:
        y = mPaper.getImageableX();
        break;

      case PORTRAIT:
        y = mPaper.getImageableY();
        break;

      case REVERSE_LANDSCAPE:
        y = mPaper.getWidth() - (mPaper.getImageableX() + mPaper.getImageableWidth());
        break;

      default:
        /* This should never happen since it signifies that the
         * PageFormat is in an invalid orientation.
         */
        throw new InternalError("unrecognized orientation");
    }

    return y;
  }
Ejemplo n.º 2
0
  public void printableJob(Printable printable) throws PrintException {
    try {
      synchronized (this) {
        if (job != null) { // shouldn't happen
          throw new PrintException("already printing");
        } else {
          job = new sun.awt.windows.WPrinterJob();
        }
      }
      PrintService svc = getPrintService();
      job.setPrintService(svc);
      if (copies == 0) {
        Copies c = (Copies) svc.getDefaultAttributeValue(Copies.class);
        copies = c.getValue();
      }

      if (mediaName == null) {
        Object media = svc.getDefaultAttributeValue(Media.class);
        if (media instanceof MediaSizeName) {
          mediaName = (MediaSizeName) media;
          mediaSize = MediaSize.getMediaSizeForName(mediaName);
        }
      }

      if (orient == null) {
        orient = (OrientationRequested) svc.getDefaultAttributeValue(OrientationRequested.class);
      }

      job.setCopies(copies);
      job.setJobName(jobName);
      PageFormat pf = new PageFormat();
      if (mediaSize != null) {
        Paper p = new Paper();
        p.setSize(mediaSize.getX(MediaSize.INCH) * 72.0, mediaSize.getY(MediaSize.INCH) * 72.0);
        p.setImageableArea(72.0, 72.0, p.getWidth() - 144.0, p.getHeight() - 144.0);
        pf.setPaper(p);
      }
      if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
        pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
      } else if (orient == OrientationRequested.LANDSCAPE) {
        pf.setOrientation(PageFormat.LANDSCAPE);
      }
      job.setPrintable(printable, pf);
      job.print(reqAttrSet);
      notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
      return;
    } catch (PrinterException pe) {
      notifyEvent(PrintJobEvent.JOB_FAILED);
      throw new PrintException(pe);
    } finally {
      printReturned = true;
      notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
  }
Ejemplo n.º 3
0
  /**
   * Returns the height, in 1/72nds of an inch, of the page. This method takes into account the
   * orientation of the page when determining the height.
   *
   * @return the height of the page.
   */
  public double getHeight() {
    double height;
    int orientation = getOrientation();

    if (orientation == PORTRAIT) {
      height = mPaper.getHeight();
    } else {
      height = mPaper.getWidth();
    }

    return height;
  }
Ejemplo n.º 4
0
  /**
   * Returns the width, in 1/72nds of an inch, of the page. This method takes into account the
   * orientation of the page when determining the width.
   *
   * @return the width of the page.
   */
  public double getWidth() {
    double width;
    int orientation = getOrientation();

    if (orientation == PORTRAIT) {
      width = mPaper.getWidth();
    } else {
      width = mPaper.getHeight();
    }

    return width;
  }
Ejemplo n.º 5
0
  /**
   * Returns a transformation matrix that translates user space rendering to the requested
   * orientation of the page. The values are placed into the array as
   * {&nbsp;m00,&nbsp;m10,&nbsp;m01,&nbsp;m11,&nbsp;m02,&nbsp;m12} in the form required by the
   * {@link AffineTransform} constructor.
   *
   * @return the matrix used to translate user space rendering to the orientation of the page.
   * @see java.awt.geom.AffineTransform
   */
  public double[] getMatrix() {
    double[] matrix = new double[6];

    switch (mOrientation) {
      case LANDSCAPE:
        matrix[0] = 0;
        matrix[1] = -1;
        matrix[2] = 1;
        matrix[3] = 0;
        matrix[4] = 0;
        matrix[5] = mPaper.getHeight();
        break;

      case PORTRAIT:
        matrix[0] = 1;
        matrix[1] = 0;
        matrix[2] = 0;
        matrix[3] = 1;
        matrix[4] = 0;
        matrix[5] = 0;
        break;

      case REVERSE_LANDSCAPE:
        matrix[0] = 0;
        matrix[1] = 1;
        matrix[2] = -1;
        matrix[3] = 0;
        matrix[4] = mPaper.getWidth();
        matrix[5] = 0;
        break;

      default:
        throw new IllegalArgumentException();
    }

    return matrix;
  }