Example #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;
 }
Example #2
0
  public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
    int lineHeight = fm.getHeight();
    int linesPerPage = (int) (pageFormat.getImageableHeight() / lineHeight);
    int lineCount = textArea.getLineCount();
    int lastPage = lineCount / linesPerPage;

    if (pageIndex > lastPage) {
      return NO_SUCH_PAGE;

    } else {
      Graphics2D g2d = (Graphics2D) g;
      TokenMarker tokenMarker = textArea.getDocument().getTokenMarker();
      int firstLine = pageIndex * linesPerPage;
      g2d.translate(
          Math.max(54, pageFormat.getImageableX()),
          pageFormat.getImageableY() - firstLine * lineHeight);
      printing = true;
      for (int line = firstLine; line < firstLine + linesPerPage; line++) {
        paintLine(g2d, tokenMarker, line, 0);
      }
      printing = false;
      return PAGE_EXISTS;
    }
  }