Exemplo n.º 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();
  }
Exemplo n.º 2
0
  public void dispose() {
    if (shell != null) {
      shell.dispose();
      shell = null;
    }
    if (printer != null) {
      if (!printer.isDisposed()) {
        printer.endJob();
      }
      printer.dispose();
      printer = null;
    }
    jobStarted = false;

    //        if (providers != null) {
    //            for (Object o : providers.toArray()) {
    //                ((MindMapExportContentProvider) o).dispose();
    //            }
    //            providers = null;
    //        }
  }
Exemplo n.º 3
0
        @Override
        public void run() {
          PrintDialog dialog = new PrintDialog(getViewSite().getShell(), SWT.NONE);
          PrinterData data = dialog.open();
          if (data == null) {
            return;
          }
          if (data.printToFile) {
            data.fileName =
                "print.out"; // TODO you probably want to ask the user for a filename //$NON-NLS-1$
          }

          Printer printer = new Printer(data);
          try {
            Rectangle printerBounds = printer.getClientArea();
            Rectangle trimBounds =
                printer.computeTrim(
                    printerBounds.x, printerBounds.y, printerBounds.width, printerBounds.height);
            System.out.println(printerBounds + ", " + trimBounds); // $NON-NLS-1$

            if (printer.startJob(getPartName())) {
              viewer.print(printer);
              printer.endJob();
            }
          } catch (Throwable e) {
            e.printStackTrace();
          } finally {
            printer.dispose();
          }
        }
Exemplo n.º 4
0
  private void receivePrinterInfo() {
    dpi = new Point(printer.getDPI());
    pageBounds = new Rectangle(printer.getBounds());
    Rectangle trim = new Rectangle(printer.computeTrim(0, 0, 0, 0));
    pageMargins = new Insets(-trim.y, -trim.x, trim.right(), trim.bottom());

    pageClientArea = new Rectangle(printer.getClientArea());
    //        pageClientArea.x = pageBounds.x
    //                + (pageBounds.width - pageClientArea.width) / 2;
    //        pageClientArea.y = pageBounds.y
    //                + (pageBounds.height - pageClientArea.height) / 2;
    int leftMargin = getUserMargin(PrintConstants.LEFT_MARGIN);
    int rightMargin = getUserMargin(PrintConstants.RIGHT_MARGIN);
    int topMargin = getUserMargin(PrintConstants.TOP_MARGIN);
    int bottomMargin = getUserMargin(PrintConstants.BOTTOM_MARGIN);
    pageClientArea.expand(pageMargins);
    pageClientArea.x += leftMargin;
    pageClientArea.y += topMargin;
    pageClientArea.width -= leftMargin + rightMargin;
    pageClientArea.height -= topMargin + bottomMargin;

    //        needRotate = pageBounds.height > pageBounds.width;
    needRotate = false;
  }
Exemplo n.º 5
0
  private void render() {
    this.area =
        ImageExportUtils.createExportAreaProvider(
            source.getSourceArea(),
            ResizeConstants.RESIZE_STRETCH,
            needRotate ? pageClientArea.height : pageClientArea.width,
            needRotate ? pageClientArea.width : pageClientArea.height,
            source.getMargins());
    init(source, area);
    GC gc = new GC(printer);
    try {
      render(gc);
    } finally {
      gc.dispose();
    }

    printer.endPage();
  }
Exemplo n.º 6
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;
  }
Exemplo n.º 7
0
 /** @return the printerData */
 public PrinterData getPrinterData() {
   if (printerData == null) printerData = Printer.getDefaultPrinterData();
   if (printerData == null)
     printerData = Printer.getPrinterList() != null ? Printer.getPrinterList()[0] : null;
   return printerData;
 }