Esempio n. 1
0
  public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
    Graphics2D g2 = (Graphics2D) g;
    if (page > getPageCount(g2, pf)) return Printable.NO_SUCH_PAGE;
    g2.translate(pf.getImageableX(), pf.getImageableY());

    drawPage(g2, pf, page);
    return Printable.PAGE_EXISTS;
  }
Esempio n. 2
0
    public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
      if (pgIndex > 0) return Printable.NO_SUCH_PAGE;

      Graphics2D g2d = (Graphics2D) g;
      g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
      doPaint(g2d);
      return Printable.PAGE_EXISTS;
    }
Esempio n. 3
0
 /**
  * Gets the page count of this section.
  *
  * @param g2 the graphics context
  * @param pf the page format
  * @return the number of pages needed
  */
 public int getPageCount(Graphics2D g2, PageFormat pf) {
   if (message.equals("")) return 0;
   FontRenderContext context = g2.getFontRenderContext();
   Font f = new Font("Serif", Font.PLAIN, 72);
   Rectangle2D bounds = f.getStringBounds(message, context);
   scale = pf.getImageableHeight() / bounds.getHeight();
   double width = scale * bounds.getWidth();
   int pages = (int) Math.ceil(width / pf.getImageableWidth());
   return pages;
 }
Esempio n. 4
0
 /**
  * Draws 1/2" crop marks in the corners of the page.
  *
  * @param g2 the graphics context
  * @param pf the page format
  */
 public void drawCropMarks(Graphics2D g2, PageFormat pf) {
   final double C = 36; // crop mark length = 1/2 inch
   double w = pf.getImageableWidth();
   double h = pf.getImageableHeight();
   g2.draw(new Line2D.Double(0, 0, 0, C));
   g2.draw(new Line2D.Double(0, 0, C, 0));
   g2.draw(new Line2D.Double(w, 0, w, C));
   g2.draw(new Line2D.Double(w, 0, w - C, 0));
   g2.draw(new Line2D.Double(0, h, 0, h - C));
   g2.draw(new Line2D.Double(0, h, C, h));
   g2.draw(new Line2D.Double(w, h, w, h - C));
   g2.draw(new Line2D.Double(w, h, w - C, h));
 }
Esempio n. 5
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;
 }
Esempio n. 6
0
  public void drawPage(Graphics2D g2, PageFormat pf, int page) {
    if (message.equals("")) return;
    page--; // account for cover page

    drawCropMarks(g2, pf);
    g2.clip(new Rectangle2D.Double(0, 0, pf.getImageableWidth(), pf.getImageableHeight()));
    g2.translate(-page * pf.getImageableWidth(), 0);
    g2.scale(scale, scale);
    FontRenderContext context = g2.getFontRenderContext();
    Font f = new Font("Serif", Font.PLAIN, 72);
    TextLayout layout = new TextLayout(message, f, context);
    AffineTransform transform = AffineTransform.getTranslateInstance(0, layout.getAscent());
    Shape outline = layout.getOutline(transform);
    g2.draw(outline);
  }
 /**
  * ü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;
  }