예제 #1
0
 /** [Internal] */
 public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
   if (pi >= 1) {
     return Printable.NO_SUCH_PAGE;
   }
   RepaintManager currentManager = RepaintManager.currentManager(this);
   currentManager.setDoubleBufferingEnabled(false);
   Graphics2D g2 = (Graphics2D) g;
   initState(g2, true);
   g2.translate((int) (pf.getImageableX() + 1), (int) (pf.getImageableY() + 1));
   g2.scale(printScale, printScale);
   doBuffer(g2, true, null);
   currentManager.setDoubleBufferingEnabled(true);
   return Printable.PAGE_EXISTS;
 }
예제 #2
0
 /** This method is required to implement the Printable interface */
 public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
   if (pageIndex >= 1) {
     return NO_SUCH_PAGE;
   }
   Graphics2D g2 = (Graphics2D) g;
   Dimension cs = printTarget.getSize();
   g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
   double imageableWidth = pageFormat.getImageableWidth();
   double imageableHeight = pageFormat.getImageableHeight();
   double scale = 1;
   if (cs.width >= imageableWidth) {
     scale = imageableWidth / cs.width;
   }
   g2.scale(scale, scale);
   // g2.translate((imageableWidth - cs.width)*scale/2,
   //             (imageableHeight - cs.height)*scale/2);
   printTarget.paintAll(g2);
   return Printable.PAGE_EXISTS;
 }
예제 #3
0
 public int print(Graphics g, PageFormat f, int pageIndex) {
   if (pageIndex > 0) {
     return (NO_SUCH_PAGE);
   } else {
     Graphics2D g2d = (Graphics2D) g;
     //      Rectangle2D rect = new Rectangle2D.Double(f.getImageableX(),
     //              f.getImageableY(),
     //              f.getImageableWidth(),
     //              f.getImageableHeight());
     f.getImageableX();
     f.getImageableY();
     f.getImageableWidth();
     f.getImageableHeight();
     // g2d.translate(f.getImageableX(), f.getImageableY());
     disableDoubleBuffering(componentToBePrinted);
     componentToBePrinted.print(g2d) /*.paint(g2d)*/;
     enableDoubleBuffering(componentToBePrinted);
     return (PAGE_EXISTS);
   }
 }
예제 #4
0
  public int print(Graphics g, PageFormat pf, int pageIndex) {
    int response = NO_SUCH_PAGE;

    Graphics2D g2 = (Graphics2D) g;
    disableDoubleBuffering(componentToBePrinted);
    Dimension d = componentToBePrinted.getSize();
    double panelWidth = d.width;
    double panelHeight = d.height;
    double pageHeight = pf.getImageableHeight();
    double pageWidth = pf.getImageableWidth();
    double scale = pageWidth / panelWidth;
    int totalNumPages = (int) Math.ceil(scale * panelHeight / pageHeight);
    if (pageIndex >= totalNumPages) {
      response = NO_SUCH_PAGE;
    } else {
      g2.translate(pf.getImageableX(), pf.getImageableY());
      g2.translate(0f, -pageIndex * pageHeight);
      g2.scale(scale, scale);
      componentToBePrinted.paint(g2);
      enableDoubleBuffering(componentToBePrinted);
      response = Printable.PAGE_EXISTS;
    }
    return response;
  }
  public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException {
    // Component printMe = getPrintComponent();

    Graphics2D g2 = (Graphics2D) g;
    g2.setColor(Color.black); // set default foreground color to black

    // for faster printing, turn off double buffering
    // RepaintManager.currentManager(this).setDoubleBufferingEnabled(false);

    Dimension d = printComponent.getSize(); // get size of document
    double panelWidth = d.width; // width in pixels
    double panelHeight = d.height; // height in pixels
    double pageHeight = pf.getImageableHeight(); // height of printer page
    double pageWidth = pf.getImageableWidth(); // width of printer page
    double scale = pageWidth / panelWidth;
    int totalNumPages = (int) Math.ceil(scale * panelHeight / pageHeight);

    // make sure we don't print empty pages
    if (pageIndex >= totalNumPages) {
      return Printable.NO_SUCH_PAGE;
    }

    // shift Graphic to line up with beginning of print-imageable region
    g2.translate(pf.getImageableX(), pf.getImageableY());

    // shift Graphic to line up with beginning of next page to print
    g2.translate(0f, -pageIndex * pageHeight);

    // scale the page so the width fits...
    g2.scale(scale, scale);

    // PRINT IT!
    printComponent.paint(g2);

    return Printable.PAGE_EXISTS;
  }
예제 #6
0
  /**
   * The printing interface.
   *
   * @param g the graphic context.
   * @param pf the page format.
   * @param page the page number.
   * @return PAGE_EXISTS if the page has to be printed.
   * @throws PrinterException if a printing error occurs.
   */
  public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
    int npages = 0;

    // This might be explained as follows:
    // 1 - The Java printing system normally works with an internal
    // resolution which is 72 dpi (probably inspired by Postscript).
    // 2 - To have a sufficient resolution, this is increased by 16 times,
    // by using the scale method of the graphic object associated to the
    // printer. This gives a 72 dpi * 16=1152 dpi resolution.
    // 3 - The 0.127 mm pitch used in FidoCadJ corresponds to a 200 dpi
    // resolution. Calculating 1152 dpi / 200 dpi gives the 5.76 constant

    double xscale = 1.0 / 16; // Set 1152 logical units for an inch
    double yscale = 1.0 / 16; // as the standard resolution is 72
    double zoom = 5.76; // act in a 1152 dpi resolution as 1:1

    Graphics2D g2d = (Graphics2D) g;

    // User (0,0) is typically outside the imageable area, so we must
    // translate by the X and Y values in the PageFormat to avoid clipping

    if (printMirror) {
      g2d.translate(pf.getImageableX() + pf.getImageableWidth(), pf.getImageableY());
      g2d.scale(-xscale, yscale);

    } else {
      g2d.translate(pf.getImageableX(), pf.getImageableY());
      g2d.scale(xscale, yscale);
    }

    int printerWidth = (int) pf.getImageableWidth() * 16;

    // Perform an adjustement if we need to fit the drawing to the page.
    if (printFitToPage) {
      MapCoordinates zoomm =
          DrawingSize.calculateZoomToFit(
              cc.dmp, (int) pf.getImageableWidth() * 16, (int) pf.getImageableHeight() * 16, false);
      zoom = zoomm.getXMagnitude();
    }

    MapCoordinates m = new MapCoordinates();

    m.setMagnitudes(zoom, zoom);

    PointG o = new PointG(0, 0);

    int imageWidth = DrawingSize.getImageSize(cc.dmp, zoom, false, o).width;
    npages = (int) Math.floor((imageWidth - 1) / (double) printerWidth);

    // Check if we need more than one page
    if (printerWidth < imageWidth) {
      g2d.translate(-(printerWidth * page), 0);
    }

    // Check if printing is finished.
    if (page > npages) {
      return NO_SUCH_PAGE;
    }
    // Now we perform our rendering
    cc.drawingAgent.draw(new Graphics2DSwing(g2d), m);

    /* tell the caller that this page is part of the printed document */
    return PAGE_EXISTS;
  }
예제 #7
0
  public int print(Graphics g, PageFormat pf, int pageIndex) {
    Font f1 = new Font("SERIF", Font.PLAIN, 8);
    FontMetrics metric = g.getFontMetrics(f1);
    int lineHeight = metric.getHeight();

    if (pageBreak == null) {
      initLines();
      int s = (numLines % 3);
      if (s > 0) numLines = numLines + (3 - s);
      numLines /= 3;

      int linesPerPage = (int) (pf.getImageableHeight() / lineHeight);
      int numBreaks = (numLines / linesPerPage);
      pageBreak = new int[numBreaks];
      for (int b = 0; b < numBreaks; b++) {
        pageBreak[b] = (b + 1) * linesPerPage;
      }
    }

    if (pageIndex > pageBreak.length) {
      return NO_SUCH_PAGE;
    }

    Graphics2D g2d = (Graphics2D) g;
    g2d.translate(pf.getImageableX(), pf.getImageableY());

    int y = 0;

    g.setFont(new Font("SERIF", Font.PLAIN, 9));

    int start = 0;
    if (pageIndex == 0) start = 0;
    else start = pageBreak[pageIndex - 1];

    int end = 0;

    if (pageIndex == pageBreak.length) end = numLines;
    else end = pageBreak[pageIndex];

    if (chk % 2 == 1 && (end - start) != lineHeight) {

      for (int line = start; line < end && i < x; line += 9) {
        y += (2 * lineHeight);
        g.drawString("" + textLines[i][0], 30, y);
        g.drawString(textLines[i][1], 30, y + lineHeight);
        g.drawString(textLines[i][2], 30, y + 2 * lineHeight);
        g.drawString(textLines[i][3], 30, y + 3 * lineHeight);
        g.drawString(textLines[i][4], 30, y + 4 * lineHeight);
        g.drawString(textLines[i][5], 30, y + 5 * lineHeight);
        g.drawString(textLines[i][6], 30, y + 6 * lineHeight);

        if ((i + 1) < x) {
          g.drawString(textLines[i + 1][0], 225, y);
          g.drawString(textLines[i + 1][1], 225, y + lineHeight);
          g.drawString(textLines[i + 1][2], 225, y + 2 * lineHeight);
          g.drawString(textLines[i + 1][3], 225, y + 3 * lineHeight);
          g.drawString(textLines[i + 1][4], 225, y + 4 * lineHeight);
          g.drawString(textLines[i + 1][5], 225, y + 5 * lineHeight);
          g.drawString(textLines[i + 1][6], 225, y + 6 * lineHeight);
        }
        if ((i + 2) < x) {
          g.drawString(textLines[i + 2][0], 415, y);
          g.drawString(textLines[i + 2][1], 415, y + lineHeight);
          g.drawString(textLines[i + 2][2], 415, y + 2 * lineHeight);
          g.drawString(textLines[i + 2][3], 415, y + 3 * lineHeight);
          g.drawString(textLines[i + 2][4], 415, y + 4 * lineHeight);
          g.drawString(textLines[i + 2][5], 415, y + 5 * lineHeight);
          g.drawString(textLines[i + 2][6], 415, y + 6 * lineHeight);
        }
        y += 7 * lineHeight;
        i += 3;
      }

    } else {

      for (int line = start; line < end && i < x; line += 8) {}
    }
    chk++;

    return PAGE_EXISTS;
  }