예제 #1
0
  private boolean start() {
    if (printer == null) {
      printer = new Printer(printerData);
    }

    receivePrinterInfo();

    if (!jobStarted) {
      if (!printer.startJob(jobName)) return false;
      jobStarted = true;
    }
    return printer.startPage();
  }
예제 #2
0
  public boolean performPrint(Shell shell, Image image) {
    GC gc = null;
    boolean success = true;

    PrintDialog dialog = new PrintDialog(shell);
    PrinterData pd = dialog.open();

    if (pd != null) {
      Printer printer = new Printer(pd);

      Rectangle bounds = image.getBounds();
      Rectangle area = printer.getClientArea();
      Point dpi = printer.getDPI();
      int xScale = dpi.x / 96;
      int yScale = dpi.y / 96;
      int width = bounds.width * xScale;
      int height = bounds.height * yScale;
      int pWidth = area.width - 5 * dpi.x / 4;
      int pHeight = area.height - 5 * dpi.x / 4;
      float factor =
          Math.min(
              1.0F, Math.min((float) pWidth / (float) width, (float) pHeight / (float) height));
      int aWidth = (int) (factor * width);
      int aHeight = (int) (factor * height);
      int xoff = (area.width - aWidth) / 2;
      int yoff = (area.height - aHeight) / 2;

      String jobName = ScreenshotMessages.getString("ScreenshotPlugin.Screenshot");

      if (printer.startJob(jobName)) {
        System.out.println(" Job gestartet\n");

        if (printer.startPage()) {
          System.out.println(" Seite gestartet\n");

          System.out.println(
              image.toString()
                  + ", "
                  + bounds.x
                  + ", "
                  + bounds.y
                  + ", "
                  + bounds.width
                  + ", "
                  + bounds.height
                  + ", "
                  + xoff
                  + ", "
                  + yoff
                  + ", "
                  + aWidth
                  + ", "
                  + aHeight);

          gc = new GC(printer);

          System.out.println(gc.toString());

          gc.drawImage(
              image, bounds.x, bounds.y, bounds.width, bounds.height, xoff, yoff, aWidth, aHeight);

          printer.endPage();
        }

        printer.endJob();
      } else {
        success = false;
      }

      if (gc != null) {
        gc.dispose();
      }

      printer.dispose();
    }

    return success;
  }