Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 3
0
  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;
  }
Ejemplo n.º 4
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;
  }
 /**
  * überschreibt die JPanel-Methode und liefert den (skalierten) Druckbereich, welcher zur
  * Verfügung steht.
  */
 public int getHeight() {
   return (int) (pf.getImageableHeight() / printskal * antVertikal);
 }
 /**
  * überschreibt die JPanel-Methode und liefert den (skalierten) Druckbereich, welcher zur
  * Verfügung steht.
  */
 public int getWidth() {
   return (int) (pf.getImageableWidth() / printskal * antHorizontal);
 }
  public int print(Graphics graphics, PageFormat pageformat, int pageIndex)
      throws PrinterException {
    if (pageIndex >= 1) return Printable.NO_SUCH_PAGE;

    this.pf = pageformat;
    g = (Graphics2D) graphics;
    g.scale(printskal, printskal);

    // auf den sichtbaren Bereich ausrichten
    g.translate(pf.getImageableX() / printskal, pf.getImageableY() / printskal);

    // -----------------
    // 1. Teil: Graphik
    // -----------------
    antVertikal = antGraph;
    antHorizontal = 1.0d;
    schriftgrStd = (int) (schriftgrGraph / printskal);

    double zusRandabst = 2d * schriftgrText;
    if (MIT_Lasten || MIT_Auflagerkräften) zusRandabst = maxPfeil;

    // -----------------------------
    // Intermezzo: Massstab abfragen
    // -----------------------------
    if (!MASSSTABABGEFRAGT) {
      if (ZOOMALL) koord = new clKoord(ZoomPkt1, ZoomPkt2, this, zusRandabst);
      else koord = new clKoord(ZoomPkt1, ZoomPkt2, this);
      // maximalen Massstab bestimmen
      double minzoomfaktor = koord.m(dpi / zoll);

      // Massstab abfragen
      clPrintGraphDialog dialog = new clPrintGraphDialog(parent, minzoomfaktor, locale);
      if (dialog.abgebrochen())
        throw new PrinterException(
            tr("druckenabgebrochen")); // return Printable.NO_SUCH_PAGE; // abgebrochen
      einheit = dialog.getEinheit();
      mst = dialog.getMst();
      // debug
      // mst = 100d;
      MASSSTABABGEFRAGT = true;
      // debug
      // System.out.println("minzoomfaktor " + Fkt.nf(minzoomfaktor,1));
      // System.out.println("Massstab 1:" + Fkt.nf(mst,1) + "  Einheit " + Fkt.nf(einheit,3) + "m");
    }
    koord = new clKoord(ZoomPkt1, ZoomPkt2, this, true, einheit * (dpi / zoll) / mst);
    // debug
    // System.out.println("mst " + Fkt.nf(mst,1));

    g.setPaint(Color.black);

    if (Kn != null) {
      if (MIT_Hintergrund) darstellenHintergrund();
      darstellenFachwerk(true);
      if (MIT_KnNr) darstellenKnNr();
      if (MIT_StabNr) darstellenStabNr();
      if (MIT_Lasten) darstellenLasten(MIT_Stabkräften);
      if (MIT_Auflagerkräften) darstellenAuflagerkräfte(MIT_Stabkräften);
      if (MIT_Stabkräften) darstellenStabkräfte();
      if (MIT_Mechanismus) darstellenMechanismus();
    }

    // -------------------------
    // 2. Teil: Text
    // -------------------------
    g.translate(0d, antGraph * pf.getImageableHeight() / printskal);
    antVertikal = antTxt;
    antHorizontal = 1.0d;
    double Feldhöhe = antVertikal * pf.getImageableHeight() / printskal;
    double Feldbreite = antHorizontal * pf.getImageableWidth() / printskal;
    int anzmöglzeilen = 2; // mind. eine Zeile am Schluss freilassen
    int anzmöglbuchst = 30;
    int schriftgr =
        schriftskal(
            Feldhöhe, Feldbreite, anzmöglzeilen, anzmöglbuchst, (int) (schriftgrText / printskal));
    float za = (float) faktorza * (float) schriftgr;
    g.setFont(new Font("Monospaced", Font.PLAIN, schriftgr));

    // Zoomfaktor bestimmen
    double zoomfaktor = koord.m(dpi / zoll) * einheit;
    g.drawString("1 : " + Fkt.nf(zoomfaktor, 1), 0f, (float) schriftgr + 1f * za);

    // drucken
    paint(g);
    // schongedruckt = true;
    return Printable.PAGE_EXISTS;
  }