(PrintJob pjob, Graphics pg, String s)
| 738 | } |
| 739 | |
| 740 | void printString (PrintJob pjob, Graphics pg, String s) { |
| 741 | int pageNum = 1; |
| 742 | int linesForThisPage = 0; |
| 743 | int linesForThisJob = 0; |
| 744 | int topMargin = 30; |
| 745 | int leftMargin = 30; |
| 746 | int bottomMargin = 30; |
| 747 | |
| 748 | if (!(pg instanceof PrintGraphics)) |
| 749 | throw new IllegalArgumentException ("Graphics contextt not PrintGraphics"); |
| 750 | if (IJ.isMacintosh()) { |
| 751 | topMargin = 0; |
| 752 | leftMargin = 0; |
| 753 | bottomMargin = 0; |
| 754 | } |
| 755 | StringReader sr = new StringReader (s); |
| 756 | LineNumberReader lnr = new LineNumberReader (sr); |
| 757 | String nextLine; |
| 758 | int pageHeight = pjob.getPageDimension().height - bottomMargin; |
| 759 | Font helv = new Font(getFontName(), Font.PLAIN, 10); |
| 760 | pg.setFont (helv); |
| 761 | FontMetrics fm = pg.getFontMetrics(helv); |
| 762 | int fontHeight = fm.getHeight(); |
| 763 | int fontDescent = fm.getDescent(); |
| 764 | int curHeight = topMargin; |
| 765 | try { |
| 766 | do { |
| 767 | nextLine = lnr.readLine(); |
| 768 | if (nextLine != null) { |
| 769 | nextLine = detabLine(nextLine); |
| 770 | if ((curHeight + fontHeight) > pageHeight) { |
| 771 | // New Page |
| 772 | pageNum++; |
| 773 | linesForThisPage = 0; |
| 774 | pg.dispose(); |
| 775 | pg = pjob.getGraphics(); |
| 776 | if (pg != null) |
| 777 | pg.setFont (helv); |
| 778 | curHeight = topMargin; |
| 779 | } |
| 780 | curHeight += fontHeight; |
| 781 | if (pg != null) { |
| 782 | pg.drawString (nextLine, leftMargin, curHeight - fontDescent); |
| 783 | linesForThisPage++; |
| 784 | linesForThisJob++; |
| 785 | } |
| 786 | } |
| 787 | } while (nextLine != null); |
| 788 | } catch (EOFException eof) { |
| 789 | // Fine, ignore |
| 790 | } catch (Throwable t) { // Anything else |
| 791 | IJ.handleException(t); |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | String detabLine(String s) { |
| 796 | if (s.indexOf('\t')<0) |
no test coverage detected